'A',
'A'));
+function create_authkeys($params) {
+ $ssh_dir = $params['ssh_dir'];
+ $ssh_key = $params['ssh_key'];
+ if (!is_dir($ssh_dir)) {
+ mkdir ($ssh_dir, 0755);
+ }
+ $h8 = fopen("$ssh_dir/authorized_keys","w");
+ fwrite($h8,'# This file is automatically generated from your account settings.'."\n");
+ fwrite($h8,$ssh_key);
+ fclose($h8);
+ chmod ("$ssh_dir/authorized_keys", 0644);
+}
+
for ($i=0; $i<db_numrows($res); $i++) {
$err .= "Error! homedir_prefix/username Points To Root Directory!";
continue;
}
- $uid=db_result($res,$i,'user_id');
- $ssh_key=str_replace('###',"\n",$ssh_key);
- $uid += 1000;
-
- $ssh_dir = forge_get_config('homedir_prefix')."/$username/.ssh";
- if (!is_dir($ssh_dir)) {
- mkdir ($ssh_dir, 0755);
- }
-
- # Set the effective uid/gid to this user, so as to avoid symlink attacks
- $userinfo = posix_getpwnam($username);
- posix_setegid($userinfo['gid']);
- posix_seteuid($userinfo['uid']);
- $h8 = fopen("$ssh_dir/authorized_keys","w");
- fwrite($h8,'# This file is automatically generated from your account settings.'."\n");
- fwrite($h8,$ssh_key);
- fclose($h8);
- posix_seteuid(0);
- posix_setegid(0);
-
- system("chown $username:users ".forge_get_config('homedir_prefix')."/$username");
- system("chown $username:users $ssh_dir");
- system("chmod 0644 $ssh_dir/authorized_keys");
- system("chown $username:users $ssh_dir/authorized_keys");
+ $params = array();
+ $params['ssh_key'] = str_replace('###',"\n",$ssh_key);
+ $params['ssh_dir'] = forge_get_config('homedir_prefix')."/$username/.ssh";
+ util_sudo_effective_user($username, "create_authkeys", $params);
}
cron_entry(15,$err);