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) {
34 if (strlen($pw) < 6) {
35 $GLOBALS['register_error'] = _('Password must be at least 6 characters.');
42 * account_namevalid() - Validates a login username
44 * @param string The username string
45 * @returns true on success/false on failure
48 function account_namevalid($name) {
50 if (strrpos($name,' ') > 0) {
51 $GLOBALS['register_error'] = _('There cannot be any spaces in the login name.');
56 if (strlen($name) < 3) {
57 $GLOBALS['register_error'] = _('Name is too short. It must be at least 3 characters.');
60 if (strlen($name) > 15) {
61 $GLOBALS['register_error'] = _('Name is too long. It must be less than 15 characters.');
65 if (!ereg('^[a-z][-a-z0-9_]+$', $name)) {
66 $GLOBALS['register_error'] = _('Illegal character in name.');
71 if (eregi("^((root)|(bin)|(daemon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)"
72 . "|(uucp)|(operator)|(games)|(mysql)|(httpd)|(nobody)|(dummy)"
73 . "|(www)|(cvs)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download))$",$name)) {
74 $GLOBALS['register_error'] = "Name is reserved.";
77 if ( exec("getent passwd $name") != "" ){
78 $GLOBALS['register_error'] = _('That username already exists.');
81 if (eregi("^(anoncvs_)",$name)) {
82 $GLOBALS['register_error'] = _('Name is reserved for CVS.');
90 * account_groupnamevalid() - Validates an account group name
92 * @param string The group name string
93 * @returns true on success/false on failure
96 function account_groupnamevalid($name) {
97 if (!account_namevalid($name)) return 0;
100 if (eregi("^((www[0-9]?)|(cvs[0-9]?)|(shell[0-9]?)|(ftp[0-9]?)|(irc[0-9]?)|(news[0-9]?)"
101 . "|(mail[0-9]?)|(ns[0-9]?)|(download[0-9]?)|(pub)|(users)|(compile)|(lists)"
102 . "|(slayer)|(orbital)|(tokyojoe)|(webdev)|(projects)|(cvs)|(slayer)|(monitor)|(mirrors?))$",$name)) {
103 $GLOBALS['register_error'] = _('Name is reserved for DNS purposes.');
107 if (eregi("_",$name)) {
108 $GLOBALS['register_error'] = _('Group name cannot contain underscore for DNS reasons.');
116 * rannum() - Generate a random number
118 * This is a local function used for account_salt()
120 * @return int $num A random number
124 mt_srand((double)microtime()*1000000);
125 $num = mt_rand(46,122);
130 * genchr() - Generate a random character
132 * This is a local function used for account_salt()
134 * @return int $num A random character
140 } while ( ( $num > 57 && $num < 65 ) || ( $num > 90 && $num < 97 ) );
146 * account_gensalt() - A random salt generator
148 * @returns The random salt string
151 function account_gensalt(){
153 // ncommander: modified for cipher selection
154 // crypt() selects the cipher based on
159 switch($unix_cipher) {
165 $salt = "$1$" . "$a$b";
170 $salt .= rand(64,126);
180 * account_genunixpw() - Generate unix password
182 * @param string The plaintext password string
183 * @return The encrypted password
186 function account_genunixpw($plainpw) {
187 // ncommander: Support clear password hashing
188 // for usergroup_plain.php
190 if (strcasecmp($unix_cipher, 'Plain') == 0) {
193 return crypt($plainpw,account_gensalt());
198 * account_shellselects() - Print out shell selects
200 * @param string The current shell
203 function account_shellselects($current) {
204 $shells = file("/etc/shells");
205 $shells[count($shells)] = "/bin/cvssh";
207 for ($i = 0; $i < count($shells); $i++) {
208 $this_shell = chop($shells[$i]);
210 if ($current == $this_shell) {
211 echo "<option selected value=$this_shell>$this_shell</option>\n";
213 if (! ereg("^#",$this_shell)){
214 echo "<option value=$this_shell>$this_shell</option>\n";
221 * account_user_homedir() - Returns full path of user home directory
223 * @param string The username
224 * @return home directory path
226 function account_user_homedir($user) {
227 //return '/home/users/'.substr($user,0,1).'/'.substr($user,0,2).'/'.$user;
228 return $GLOBALS['homedir_prefix'].'/'.$user;
232 * account_group_homedir() - Returns full path of group home directory
234 * @param string The group name
235 * @return home directory path
237 function account_group_homedir($group) {
238 //return '/home/groups/'.substr($group,0,1).'/'.substr($group,0,2).'/'.$group;
239 return $GLOBALS['groupdir_prefix'].'/'.$group;
244 // c-file-style: "bsd"