Fix system users: sudoers and nested sudo
This commit is contained in:
@@ -1560,12 +1560,18 @@ class ServerController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$homeFlag = $createHome ? '-m' : '-M';
|
$homeFlag = $createHome ? '-m' : '-M';
|
||||||
$cmd = "sudo useradd {$homeFlag} -p \$(sudo openssl passwd -6 '{$password}')";
|
$groupsFlag = '';
|
||||||
if (!empty($groups)) {
|
if (!empty($groups)) {
|
||||||
$sanitized = preg_replace('/[^a-z0-9_,-]/', '', $groups);
|
$sanitized = preg_replace('/[^a-z0-9_,-]/', '', $groups);
|
||||||
$cmd .= " -G {$sanitized}";
|
$groupsFlag = " -G {$sanitized}";
|
||||||
|
}
|
||||||
|
$cmd = "sudo useradd {$homeFlag}{$groupsFlag} {$username} 2>&1; echo EXIT:\$?";
|
||||||
|
$result = $ssh->exec($cmd);
|
||||||
|
$exitCode = (int) trim(explode('EXIT:', $result['output'] ?? 'EXIT:-1')[1] ?? '-1');
|
||||||
|
if ($exitCode === 0) {
|
||||||
|
$b64 = base64_encode("{$username}:{$password}");
|
||||||
|
$ssh->exec("echo {$b64} | base64 -d | sudo chpasswd 2>&1");
|
||||||
}
|
}
|
||||||
$cmd .= " {$username} 2>&1; echo EXIT:\$?";
|
|
||||||
|
|
||||||
$result = $ssh->exec($cmd);
|
$result = $ssh->exec($cmd);
|
||||||
$exitCode = (int) trim(explode('EXIT:', $result['output'] ?? 'EXIT:-1')[1] ?? '-1');
|
$exitCode = (int) trim(explode('EXIT:', $result['output'] ?? 'EXIT:-1')[1] ?? '-1');
|
||||||
|
|||||||
Reference in New Issue
Block a user