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) {
51 if (strrpos($name,' ') > 0) {
52 $GLOBALS['register_error'] = _('There cannot be any spaces in the login name.');
57 if (strlen($name) < 3) {
58 $GLOBALS['register_error'] = _('Name is too short. It must be at least 3 characters.');
61 if (strlen($name) > 15) {
62 $GLOBALS['register_error'] = _('Name is too long. It must be less than 15 characters.');
66 if (!ereg('^[a-z][-a-z0-9_]+$', $name)) {
67 $GLOBALS['register_error'] = _('Illegal character in name.');
72 if (eregi("^((root)|(bin)|(daemon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)"
73 . "|(uucp)|(operator)|(games)|(mysql)|(httpd)|(nobody)|(dummy)"
74 . "|(www)|(cvs)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download))$",$name)) {
75 $GLOBALS['register_error'] = _('Name is reserved.');
78 if (forge_get_config('use_shell')) {
79 if ( exec("getent passwd $name") != "" ){
80 $GLOBALS['register_error'] = _('That username already exists.');
83 if ( exec("getent group $name") != "" ){
84 $GLOBALS['register_error'] = _('That username already exists.');
88 if (eregi("^(anoncvs_)",$name)) {
89 $GLOBALS['register_error'] = _('Name is reserved for CVS.');
97 * account_groupnamevalid() - Validates an account group name
99 * @param string The group name string
100 * @returns true on success/false on failure
103 function account_groupnamevalid($name) {
104 if (!account_namevalid($name)) return 0;
107 if (eregi("^((www[0-9]?)|(cvs[0-9]?)|(shell[0-9]?)|(ftp[0-9]?)|(irc[0-9]?)|(news[0-9]?)"
108 . "|(mail[0-9]?)|(ns[0-9]?)|(download[0-9]?)|(pub)|(users)|(compile)|(lists)"
109 . "|(slayer)|(orbital)|(tokyojoe)|(webdev)|(projects)|(cvs)|(slayer)|(monitor)|(mirrors?))$",$name)) {
110 $GLOBALS['register_error'] = _('Name is reserved for DNS purposes.');
114 if (eregi("_",$name)) {
115 $GLOBALS['register_error'] = _('Group name cannot contain underscore for DNS reasons.');
123 * rannum() - Generate a random number
125 * This is a local function used for account_salt()
127 * @return int $num A random number
131 mt_srand((double)microtime()*1000000);
132 $num = mt_rand(46,122);
137 * genchr() - Generate a random character
139 * This is a local function used for account_salt()
141 * @return int $num A random character
147 } while ( ( $num > 57 && $num < 65 ) || ( $num > 90 && $num < 97 ) );
153 * account_gensalt() - A random salt generator
155 * @returns The random salt string
158 function account_gensalt(){
160 // ncommander: modified for cipher selection
161 // crypt() selects the cipher based on
166 switch($unix_cipher) {
172 $salt = "$1$" . "$a$b";
177 $salt .= rand(64,126);
187 * account_genunixpw() - Generate unix password
189 * @param string The plaintext password string
190 * @return The encrypted password
193 function account_genunixpw($plainpw) {
194 // ncommander: Support clear password hashing
195 // for usergroup_plain.php
197 if (strcasecmp($unix_cipher, 'Plain') == 0) {
200 return crypt($plainpw,account_gensalt());
205 * account_shellselects() - Print out shell selects
207 * @param string The current shell
210 function account_shellselects($current) {
211 $shells = file("/etc/shells");
212 $shells[count($shells)] = "/bin/cvssh";
214 for ($i = 0; $i < count($shells); $i++) {
215 $this_shell = chop($shells[$i]);
217 if ($current == $this_shell) {
218 echo "<option selected value=$this_shell>$this_shell</option>\n";
220 if (! ereg("^#",$this_shell)){
221 echo "<option value=$this_shell>$this_shell</option>\n";
228 * account_user_homedir() - Returns full path of user home directory
230 * @param string The username
231 * @return home directory path
233 function account_user_homedir($user) {
234 //return '/home/users/'.substr($user,0,1).'/'.substr($user,0,2).'/'.$user;
235 return $GLOBALS['homedir_prefix'].'/'.$user;
239 * account_group_homedir() - Returns full path of group home directory
241 * @param string The group name
242 * @return home directory path
244 function account_group_homedir($group) {
245 //return '/home/groups/'.substr($group,0,1).'/'.substr($group,0,2).'/'.$group;
246 return $GLOBALS['groupdir_prefix'].'/'.$group;
251 // c-file-style: "bsd"