3 * account.php - A library of common account management functions.
5 * Copyright 1999-2001 (c) VA Linux Systems
9 * This file is part of GForge.
11 * GForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * GForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * account_pwvalid() - Validates a password
29 * @param string The plaintext password string
30 * @returns true on success/false on failure
33 function account_pwvalid($pw) {
35 if (strlen($pw) < 6) {
36 $GLOBALS['register_error'] = $Language->getText('common_include_account','sixchar');
43 * account_namevalid() - Validates a login username
45 * @param string The username string
46 * @returns true on success/false on failure
49 function account_namevalid($name) {
52 if (strrpos($name,' ') > 0) {
53 $GLOBALS['register_error'] = $Language->getText('common_include_account','nospace');
58 if (strlen($name) < 3) {
59 $GLOBALS['register_error'] = $Language->getText('common_include_account','tooshort');
62 if (strlen($name) > 15) {
63 $GLOBALS['register_error'] = $Language->getText('common_include_account','toolong');
67 if (!ereg('^[a-z][-a-z0-9_]+$', $name)) {
68 $GLOBALS['register_error'] = $Language->getText('common_include_account','illegal');
73 if (eregi("^((root)|(bin)|(daemon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)"
74 . "|(uucp)|(operator)|(games)|(mysql)|(httpd)|(nobody)|(dummy)"
75 . "|(www)|(cvs)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download))$",$name)) {
76 $GLOBALS['register_error'] = "Name is reserved.";
79 if ( exec("getent passwd $name") != "" ){
80 $GLOBALS['register_error'] = $Language->getText('account_register','err_userexist');
83 if (eregi("^(anoncvs_)",$name)) {
84 $GLOBALS['register_error'] = $Language->getText('common_include_account','cvsreserved');
92 * account_groupnamevalid() - Validates an account group name
94 * @param string The group name string
95 * @returns true on success/false on failure
98 function account_groupnamevalid($name) {
100 if (!account_namevalid($name)) return 0;
103 if (eregi("^((www[0-9]?)|(cvs[0-9]?)|(shell[0-9]?)|(ftp[0-9]?)|(irc[0-9]?)|(news[0-9]?)"
104 . "|(mail[0-9]?)|(ns[0-9]?)|(download[0-9]?)|(pub)|(users)|(compile)|(lists)"
105 . "|(slayer)|(orbital)|(tokyojoe)|(webdev)|(projects)|(cvs)|(slayer)|(monitor)|(mirrors?))$",$name)) {
106 $GLOBALS['register_error'] = $Language->getText('common_include_account','dnsreserved');
110 if (eregi("_",$name)) {
111 $GLOBALS['register_error'] = $Language->getText('common_include_account','nounderscore');
119 * rannum() - Generate a random number
121 * This is a local function used for account_salt()
123 * @return int $num A random number
127 mt_srand((double)microtime()*1000000);
128 $num = mt_rand(46,122);
133 * genchr() - Generate a random character
135 * This is a local function used for account_salt()
137 * @return int $num A random character
143 } while ( ( $num > 57 && $num < 65 ) || ( $num > 90 && $num < 97 ) );
149 * account_gensalt() - A random salt generator
151 * @returns The random salt string
154 function account_gensalt(){
158 $salt = "$1$" . "$a$b";
163 * account_genunixpw() - Generate unix password
165 * @param string The plaintext password string
166 * @return The encrypted password
169 function account_genunixpw($plainpw) {
170 return crypt($plainpw,account_gensalt());
174 * account_shellselects() - Print out shell selects
176 * @param string The current shell
179 function account_shellselects($current) {
180 $shells = file("/etc/shells");
181 $shells[count($shells)] = "/bin/cvssh";
183 for ($i = 0; $i < count($shells); $i++) {
184 $this_shell = chop($shells[$i]);
186 if ($current == $this_shell) {
187 echo "<option selected value=$this_shell>$this_shell</option>\n";
189 if (! ereg("^#",$this_shell)){
190 echo "<option value=$this_shell>$this_shell</option>\n";
197 * account_user_homedir() - Returns full path of user home directory
199 * @param string The username
200 * @return home directory path
202 function account_user_homedir($user) {
203 //return '/home/users/'.substr($user,0,1).'/'.substr($user,0,2).'/'.$user;
204 return $GLOBALS['homedir_prefix'].'/'.$user;
208 * account_group_homedir() - Returns full path of group home directory
210 * @param string The group name
211 * @return home directory path
213 function account_group_homedir($group) {
214 //return '/home/groups/'.substr($group,0,1).'/'.substr($group,0,2).'/'.$group;
215 return $GLOBALS['groupdir_prefix'].'/'.$group;