6 * The rest Copyright 2002-2005 (c) GForge Team
7 * Copyright (C) 2009 Sylvain Beucler
10 * This file is part of FusionForge.
12 * FusionForge is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * GForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with GForge; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 require dirname(__FILE__).'/../../env.inc.php';
28 require_once $gfcommon.'include/pre.php';
29 require $gfcommon.'include/cron_utils.php';
33 $res=db_query_params ('SELECT user_name,user_id,authorized_keys
35 WHERE authorized_keys != $1
36 AND status=$2 AND unix_status = $3',
41 for ($i=0; $i<db_numrows($res); $i++) {
44 $ssh_key=db_result($res,$i,'authorized_keys');
45 $username=db_result($res,$i,'user_name');
46 $dir = forge_get_config('homedir_prefix').'/'.$username;
47 if (util_is_root_dir($dir)) {
48 $err .= "Error! homedir_prefix/username Points To Root Directory!";
51 $uid=db_result($res,$i,'user_id');
53 $ssh_key=str_replace('###',"\n",$ssh_key);
56 $ssh_dir = "forge_get_config('homedir_prefix')/$username/.ssh";
57 if (!is_dir($ssh_dir)) {
58 mkdir ($ssh_dir, 0755);
61 # Set the effective uid/gid to this user, so as to avoid symlink attacks
62 $userinfo = posix_getpwnam($username);
63 posix_setegid($userinfo['gid']);
64 posix_seteuid($userinfo['uid']);
65 $h8 = fopen("$ssh_dir/authorized_keys","w");
66 fwrite($h8,'# This file is automatically generated from your account settings.'."\n");
72 system("chown $username:users forge_get_config('homedir_prefix')/$username");
73 system("chown $username:users $ssh_dir");
74 system("chmod 0644 $ssh_dir/authorized_keys");
75 system("chown $username:users $ssh_dir/authorized_keys");