4 require_once('squal_pre.php');
7 // Default values for the script
9 define('DEFAULT_SHELL','/bin/bash'); //use /bin/grap for cvs-only
10 define('USER_ID_ADD',10000);
11 define('GROUP_ID_ADD',50000);
12 define('USER_DEFAULT_GROUP','users');
13 define('FILE_EXTENSION',''); // use .new when testing
14 define('CVS_ROOT','/cvsroot/');
17 // Get the users' unix_name and password out of the database
18 // ONLY USERS WITH CVS COMMIT PRIVS ARE ADDED
20 $res = db_query("SELECT distinct users.user_name,users.unix_pw,users.user_id
22 WHERE users.user_id=user_group.user_id
23 AND user_group.cvs_flags='1'
25 ORDER BY user_id ASC");
27 $users =& util_result_column_to_array($res,'user_name');
28 $user_ids =& util_result_column_to_array($res,'user_id');
29 $user_pws =& util_result_column_to_array($res,'unix_pw');
32 // Get anonymous pserver users
34 $res7=db_query("SELECT unix_group_name FROM groups WHERE status='A' AND is_public='1' AND enable_anoncvs='1';");
36 $rows = db_numrows($res7);
37 for($k = 0; $k < $rows; $k++) {
38 $pserver_anon[db_result($res7,$k,'unix_group_name')]=',anonymous';
42 // Read in the "default" users
44 $h = fopen("/etc/passwd.org","r");
45 $passwdcontents = fread($h,filesize("/etc/passwd.org"));
47 $passwdlines = explode("\n",$passwdcontents);
50 // Write the "default" users to a temp file
52 $h2 = fopen("/etc/passwd".FILE_EXTENSION,"w");
53 for($k = 0; $k < count($passwdlines); $k++) {
54 $passwdline = explode(":",$passwdlines[$k]);
55 $def_users[$passwdline[0]]=1;
56 fwrite($h2,$passwdlines[$k]."\n");
60 // Now append the users from the gforge database
62 for($i = 0; $i < count($users); $i++) {
64 if ($def_users[$users[$i]]) {
66 //this username was already existing in the "default" file
70 $line = $users[$i] . ":x:" . ($user_ids[$i] + USER_ID_ADD) . ":" .
71 ($user_ids[$i] + USER_ID_ADD) . "::/home/$users[$i]:".DEFAULT_SHELL."\n";
82 // this is where we add users to /etc/shadow
84 $h3 = fopen("/etc/shadow.org","r");
85 $shadowcontents = fread($h3,filesize("/etc/shadow.org"));
87 $shadowlines = explode("\n",$shadowcontents);
90 // Write the "default" shadow to a temp file
92 $h4 = fopen("/etc/shadow".FILE_EXTENSION,"w");
93 for($k = 0; $k < count($shadowlines); $k++) {
94 $shadowline = explode(":",$shadowlines[$k]);
95 $def_shadow[$shadowline[0]]=1;
96 fwrite($h4,$shadowlines[$k]."\n");
100 // Now append the users from the gforge database
102 for($i = 0; $i < count($users); $i++) {
104 if ($def_shadow[$users[$i]]) {
106 //this username was already existing in the "default" file
110 $line = $users[$i] . ":" . $user_pws[$i] . ":12090:0:99999:7:::\n";
120 // Read the groups from the "default" file
122 $h5 = fopen("/etc/group.org","r");
123 $groupcontents = fread($h5,filesize("/etc/group.org"));
125 $grouplines = explode("\n",$groupcontents);
128 // Write the "default" groups to a temp file
130 $h6 = fopen("/etc/group".FILE_EXTENSION,"w");
131 for($k = 0; $k < count($grouplines); $k++) {
132 $groupline = explode(":",$grouplines[$k]);
133 $def_group[$groupline[0]]=1;
134 fwrite($h6,$grouplines[$k]."\n");
138 // Add the groups from the gforge database
140 $res=db_query("SELECT group_id,unix_group_name FROM groups WHERE status='A'");
141 for($i = 0; $i < db_numrows($res); $i++) {
142 $groups[] = db_result($res,$i,'unix_group_name');
143 $gids[db_result($res,$i,'unix_group_name')]=db_result($res,$i,'group_id')+GROUP_ID_ADD;
146 for($i = 0; $i < count($groups); $i++) {
148 if ($def_group[$groups[$i]]) {
150 //this groupname was already existing in the "default" file
154 $line = $groups[$i] . ":x:" . ($gids[$groups[$i]]) . ":";
156 $resusers=db_query("SELECT user_name
157 FROM users,user_group,groups
158 WHERE groups.group_id=user_group.group_id
159 AND users.user_id=user_group.user_id
160 AND user_group.cvs_flags='1'
162 AND groups.unix_group_name='$groups[$i]'");
163 $gmembers =& util_result_column_to_array($resusers,'user_name');
164 $line .= implode(',',$gmembers).$pserver_anon[$groups[$i]]."\n";
175 // this is where we give a user a home
177 foreach($users as $user) {
178 if (is_dir("/home/".$user)) {
181 @mkdir("/home/".$user);
182 // system("chown $user:".USER_DEFAULT_GROUP." /home/".$user);
184 system("chown $user:".USER_DEFAULT_GROUP." /home/".$user);