3 * FusionForge account functions
5 * Copyright 1999-2001, VA Linux Systems, Inc.
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 * account_pwvalid() - Validates a password
28 * @param string The plaintext password string
29 * @returns true on success/false on failure
32 function account_pwvalid($pw) {
33 if (strlen($pw) < 6) {
34 $GLOBALS['register_error'] = _('Password must be at least 6 characters.');
41 * account_namevalid() - Validates a login username
43 * @param string The username string
44 * @returns true on success/false on failure
47 function account_namevalid($name) {
49 if (strrpos($name,' ') > 0) {
50 $GLOBALS['register_error'] = _('There cannot be any spaces in the login name.');
55 if (strlen($name) < 3) {
56 $GLOBALS['register_error'] = _('Name is too short. It must be at least 3 characters.');
59 if (strlen($name) > 15) {
60 $GLOBALS['register_error'] = _('Name is too long. It must be less than 15 characters.');
64 if (!ereg('^[a-z][-a-z0-9_]+$', $name)) {
65 $GLOBALS['register_error'] = _('Illegal character in name.');
70 if (eregi("^((root)|(bin)|(daemon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)"
71 . "|(uucp)|(operator)|(games)|(mysql)|(httpd)|(nobody)|(dummy)"
72 . "|(www)|(cvs)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download))$",$name)) {
73 $GLOBALS['register_error'] = "Name is reserved.";
76 if ( exec("getent passwd $name") != "" ){
77 $GLOBALS['register_error'] = _('That username already exists.');
80 if (eregi("^(anoncvs_)",$name)) {
81 $GLOBALS['register_error'] = _('Name is reserved for CVS.');
89 * account_groupnamevalid() - Validates an account group name
91 * @param string The group name string
92 * @returns true on success/false on failure
95 function account_groupnamevalid($name) {
96 if (!account_namevalid($name)) return 0;
99 if (eregi("^((www[0-9]?)|(cvs[0-9]?)|(shell[0-9]?)|(ftp[0-9]?)|(irc[0-9]?)|(news[0-9]?)"
100 . "|(mail[0-9]?)|(ns[0-9]?)|(download[0-9]?)|(pub)|(users)|(compile)|(lists)"
101 . "|(slayer)|(orbital)|(tokyojoe)|(webdev)|(projects)|(cvs)|(slayer)|(monitor)|(mirrors?))$",$name)) {
102 $GLOBALS['register_error'] = _('Name is reserved for DNS purposes.');
106 if (eregi("_",$name)) {
107 $GLOBALS['register_error'] = _('Group name cannot contain underscore for DNS reasons.');
115 * rannum() - Generate a random number
117 * This is a local function used for account_salt()
119 * @return int $num A random number
123 mt_srand((double)microtime()*1000000);
124 $num = mt_rand(46,122);
129 * genchr() - Generate a random character
131 * This is a local function used for account_salt()
133 * @return int $num A random character
139 } while ( ( $num > 57 && $num < 65 ) || ( $num > 90 && $num < 97 ) );
145 * account_gensalt() - A random salt generator
147 * @returns The random salt string
150 function account_gensalt(){
152 // ncommander: modified for cipher selection
153 // crypt() selects the cipher based on
158 switch($unix_cipher) {
164 $salt = "$1$" . "$a$b";
169 $salt .= rand(64,126);
179 * account_genunixpw() - Generate unix password
181 * @param string The plaintext password string
182 * @return The encrypted password
185 function account_genunixpw($plainpw) {
186 // ncommander: Support clear password hashing
187 // for usergroup_plain.php
189 if (strcasecmp($unix_cipher, 'Plain') == 0) {
192 return crypt($plainpw,account_gensalt());
197 * account_shellselects() - Print out shell selects
199 * @param string The current shell
202 function account_shellselects($current) {
203 $shells = file("/etc/shells");
204 $shells[count($shells)] = "/bin/cvssh";
206 for ($i = 0; $i < count($shells); $i++) {
207 $this_shell = chop($shells[$i]);
209 if ($current == $this_shell) {
210 echo "<option selected value=$this_shell>$this_shell</option>\n";
212 if (! ereg("^#",$this_shell)){
213 echo "<option value=$this_shell>$this_shell</option>\n";
220 * account_user_homedir() - Returns full path of user home directory
222 * @param string The username
223 * @return home directory path
225 function account_user_homedir($user) {
226 //return '/home/users/'.substr($user,0,1).'/'.substr($user,0,2).'/'.$user;
227 return $GLOBALS['homedir_prefix'].'/'.$user;
231 * account_group_homedir() - Returns full path of group home directory
233 * @param string The group name
234 * @return home directory path
236 function account_group_homedir($group) {
237 //return '/home/groups/'.substr($group,0,1).'/'.substr($group,0,2).'/'.$group;
238 return $GLOBALS['groupdir_prefix'].'/'.$group;
243 // c-file-style: "bsd"