Skip to content

Commit 9d5bde2

Browse files
author
Marius Burkard
committed
- Don't pass password to useradd and use chpasswd with proc_open instead, fixes #5416
1 parent e958363 commit 9d5bde2

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

server/lib/classes/system.inc.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,4 +2191,31 @@ public function create_jailkit_chroot($home_dir, $app_sections = array()) {
21912191
return true;
21922192
}
21932193

2194+
2195+
public function pipe_exec($cmd, $stdin, &$retval = null, &$stderr = null) {
2196+
$descriptors = array(
2197+
0 => array('pipe', 'r'),
2198+
1 => array('pipe', 'w'),
2199+
2 => array('pipe', 'w')
2200+
);
2201+
2202+
$result = '';
2203+
$pipes = null;
2204+
$proc = proc_open($cmd, $descriptors, $pipes);
2205+
if(is_resource($proc)) {
2206+
fwrite($pipes[0], $stdin);
2207+
fclose($pipes[0]);
2208+
2209+
$result = stream_get_contents($pipes[1]);
2210+
$stderr = stream_get_contents($pipes[2]);
2211+
fclose($pipes[1]);
2212+
fclose($pipes[2]);
2213+
2214+
$retval = proc_close($proc);
2215+
2216+
return $result;
2217+
} else {
2218+
return false;
2219+
}
2220+
}
21942221
}

server/plugins-available/shelluser_base_plugin.inc.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,20 @@ function insert($event_name, $data) {
129129
$app->system->chgrp($homedir,$data['new']['pgroup'],false);
130130
}
131131
$command = 'useradd -d ? -g ? -o'; // non unique
132-
if($data['new']['password'] != '') $command .= ' -p ' . escapeshellarg($data['new']['password']);
133132
$command .= ' -s ? -u ? ?';
134133
$app->system->exec_safe($command, $homedir, $data['new']['pgroup'], $data['new']['shell'], $uid, $data['new']['username']);
135134
$app->log("Executed command: ".$command, LOGLEVEL_DEBUG);
136135
$app->log("Added shelluser: ".$data['new']['username'], LOGLEVEL_DEBUG);
137-
136+
137+
if($data['new']['password'] != '') {
138+
$retval = null;
139+
$stderr = '';
140+
$app->system->pipe_exec('chpasswd -e ' . escapeshellarg($data['new']['username']), $data['new']['username'] . ':' . $data['new']['password'], $retval, $stderr);
141+
if($retval != 0) {
142+
$app->log("Command chpasswd failed for user ".$data['new']['username'] . ' with code ' . $retval . ': ' . $stderr, LOGLEVEL_WARN);
143+
}
144+
}
145+
138146
$app->system->chown($data['new']['dir'],$data['new']['username'],false);
139147
$app->system->chgrp($data['new']['dir'],$data['new']['pgroup'],false);
140148

0 commit comments

Comments
 (0)