Main Page | Directories | File List | File Members

account.php File Reference

Go to the source code of this file.

Functions

 account_pwvalid ($pw)
 account_namevalid ($name, $allow_dashes=0, $allow_underscores=1)
 account_emailvalid ($email)
 account_groupnamevalid ($name)
 account_gensalt ()
 account_genunixpw ($plainpw)
 account_nextuid ()
 account_shellselects ($current)


Function Documentation

account_emailvalid email  ) 
 

Definition at line 114 of file account.php.

References db_numrows(), db_query(), and utils_get_content().

Referenced by register_valid().

00115 {
00116   if (db_numrows(db_query("SELECT user_id FROM user WHERE "
00117                           . "email LIKE '".addslashes($email)."'")) > 0)
00118     {
00119       fb(_("An account associated with that email address has already been created."),1);
00120       return 0;
00121     }
00122 
00123   utils_get_content("forbidden_mail_domains");
00124 
00125   if ($GLOBALS['forbid_mail_domains_regexp'])
00126     {
00127       if (preg_match($GLOBALS['forbid_mail_domains_regexp'], addslashes($email)))
00128         {
00129           fb(_("It is not allowed to associate an account with this email address."),1);
00130           return 0;
00131         }
00132     }
00133   return 1;
00134 }

account_gensalt  ) 
 

Definition at line 235 of file account.php.

Referenced by account_genunixpw().

00236 {
00237   function rannum(){         
00238     mt_srand((double)microtime()*1000000);                
00239     $num = mt_rand(46,122);               
00240     return $num;                  
00241   }          
00242   function genchr(){
00243     do {          
00244       $num = rannum();            
00245     } while ( ( $num > 57 && $num < 65 ) || ( $num > 90 && $num < 97 ) );         
00246     $char = chr($num);    
00247     return $char;         
00248   }        
00249 
00250   $a = genchr(); 
00251   $b = genchr();
00252   #     $salt = "$1$" . "$a$b";
00253   $salt = "$a$b";
00254   return $salt; 
00255 }

account_genunixpw plainpw  ) 
 

Definition at line 258 of file account.php.

References account_gensalt().

Referenced by register_valid().

00259 {
00260   return crypt($plainpw,account_gensalt());
00261 }

account_groupnamevalid name  ) 
 

Definition at line 136 of file account.php.

References account_namevalid(), group, and utils_get_content().

00137 {
00138   
00139   # Test with the usual namevalid function, allowing dashes
00140   if (!account_namevalid($name, 1, 0)) 
00141     { return 0; }
00142   
00143   utils_get_content("forbidden_group_names");
00144 
00145   # All these groups are invalid by default. There can be used for system
00146   # services and already be existing on the system.
00147   # Please, keep that list in alphabetic order.
00148   $forbid_group_regexp = "/^(".
00149      "(adm)|".
00150      "(admin)|". 
00151      "(apache)|".
00152      "(bin)|".   
00153      "(compile)|".
00154      "(cvs[0-9]?)|".
00155      "(daemon)|".
00156      "(disk)|".
00157      "(download[0-9]?)|".
00158      "(exim)|".
00159      "(fencepost)|".
00160      "(ftp)|".
00161      "(ftp[0-9]?)|".
00162      "(gnudist)|".
00163      "(ident)|".
00164      "(irc[0-9]?)|".
00165      "(lists)|".
00166      "(lp)|".
00167      "(mail[0-9]?)|".
00168      "(man)|".
00169      "(monitor)|".
00170      "(mirrors?)|".
00171      "(nogroup)|".
00172      "(ns[0-9]?)|".
00173      "(news[0-9]?)|".
00174      "(ntp)|".
00175      "(postfix)|".
00176      "(projects)|".
00177      "(pub)|".
00178      "(root)|".
00179      "(rpc)|".
00180      "(rpcuser)|".
00181      "(shadow)|".
00182      "(shell[0-9]?)|".
00183      "(slayer)|".
00184      "(sshd)|".
00185      "(staff)|".
00186      "(sudo)|".
00187      "(savane-keyrings)|".   # reserved for keyrings 
00188      "(svusers)|".   # users group for savane users
00189      "(sys)|".
00190      "(tty)|".
00191      "(uucp)|".
00192      "(users)|".
00193      "(utmp)|".
00194      "(web.*)|".
00195      "(wheel)|".
00196      "(www[0-9]?)|".
00197      "(www-data)|".
00198      "(xfs)".
00199      ")$/";
00200   
00201   # Illegal names: check the hardcoded list unless the variable
00202   #      $only_specific_forbid_group_regexp is true
00203   if (!$GLOBALS['only_specific_forbid_group_regexp'])
00204     {
00205       dbg("apply standard regexp");
00206       if (preg_match($forbid_group_regexp,$name))
00207         {
00208           fb(_("This group name is not allowed."),1);
00209           return 0;
00210         }
00211     }
00212 
00213   # Illegal names: check the site specific list if a list is given
00214   #      (by consequence, the variable return true)
00215   if ($GLOBALS['specific_forbid_group_regexp']) 
00216     {
00217       dbg("apply specific regexp");
00218       if (preg_match($GLOBALS['specific_forbid_group_regexp'],$name))
00219         {
00220           fb(_("This group name is not allowed."),1);
00221           return 0;
00222         }
00223     }
00224   
00225   if (eregi("_",$name))
00226     {
00227       fb(_("Group name cannot contain underscore for DNS reasons."),1);
00228       return 0;
00229     }
00230 
00231   return 1;
00232 }

account_namevalid name,
allow_dashes = 0,
allow_underscores = 1
 

Definition at line 41 of file account.php.

Referenced by account_groupnamevalid(), and register_valid().

00042 {
00043   # By default, underscore are allowed, creating no specific issue for an
00044   # account name. It may creates trouble if the account is use to handle DNS...
00045   if ($allow_underscores) {
00046     $underscore = "_";
00047   }
00048 
00049   # By default, dashes are not allowed, creating issue with mailing list name
00050   # and many other potential conflicts. However, it is usually convenient for
00051   # groups name.
00052   if ($allow_dashes) {
00053     $dashes = "-";
00054   }
00055   
00056   # no spaces
00057   if (strrpos($name,' ') > 0)
00058     {
00059       fb(_("There cannot be any spaces in the login name."),1); 
00060       return 0;
00061     }
00062 
00063   # min and max length
00064   $MIN_ACCNAME_LENGTH= 3;
00065   $MAX_ACCNAME_LENGTH= 16;
00066 
00067   if (strlen($name) < $MIN_ACCNAME_LENGTH)
00068     {
00069       fb(sprintf(ngettext("Account name is too short. It must be at least %s character.", "Account name is too short. It must be at least %s characters.", $MIN_ACCNAME_LENGTH), $MIN_ACCNAME_LENGTH),1);
00070       return 0;
00071     }
00072 
00073   if (strlen($name) > $MAX_ACCNAME_LENGTH)
00074     {
00075       fb(sprintf(ngettext("Account name is too long. It must be at most %s character.", "Account name is too long. It must be at most %s characters.", $MAX_ACCNAME_LENGTH), $MAX_ACCNAME_LENGTH),1);
00076       return 0;
00077     }
00078 
00079   # must start with an alphanumeric non numeric
00080   if (strspn($name,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") == 0)
00081     {
00082       fb(_("Account name must begin with an alphabetical character."),1);
00083       return 0;
00084     }
00085 
00086   # must contain only legal characters and underscores, and maybe dashes and 
00087   # underscore, depending on the arguments
00088   if (strspn($name,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$underscore$dashes")
00089       != strlen($name))
00090     {
00091       if ($allow_underscore) 
00092         { fb(_("Account name must only contain alphanumerics and underscores."),1); }
00093       elseif ($allow_dashes) 
00094         { fb(_("Account name must only contain alphanumerics and dashes."),1); }
00095       else { fb(_("Account name must only contain alphanumerics."),1); }
00096 
00097       return 0;
00098     }
00099     
00100   # illegal names
00101   if (eregi("^((root)|(savane-keyrings)|(bin)|(daemon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)"
00102             . "|(uucp)|(apache)|(operator)|(invalid)|(games)|(mysql)|(httpd)|(nobody)|(dummy)|(opensource)"
00103             . "|(web)|(www)|(cvs)|(anoncvs)|(anonymous)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download))$",$name))
00104     {
00105       fb(_("That account name is reserved."),1);
00106       return 0;
00107     }
00108                 
00109   return 1;
00110 }

account_nextuid  ) 
 

Definition at line 264 of file account.php.

References $row, db_fetch_array(), and db_query().

00265 {
00266   db_query("SELECT max(unix_uid) AS maxid FROM user");
00267   $row = db_fetch_array();
00268   return ($row[maxid] + 1);
00269 }

account_pwvalid pw  ) 
 

Definition at line 28 of file account.php.

References $GLOBALS.

Referenced by register_valid().

00029 {
00030   $MIN_PASSWD_LENGTH=3;
00031   if (strlen($pw) < $MIN_PASSWD_LENGTH)
00032     {
00033       $err_msg = sprintf(ngettext("Password must be at least %s character.", "Password must be at least %s characters.", $MIN_PASSWD_LENGTH), $MIN_PASSWD_LENGTH);
00034       $GLOBALS['register_error'] = $err_msg;
00035       fb($err_msg, 1);
00036       return 0;
00037     }
00038   return 1;
00039 }

account_shellselects current  ) 
 

Definition at line 272 of file account.php.

00273 {
00274   $shells = file("/etc/shells");
00275 
00276   for ($i = 0; $i < count($shells); $i++)
00277     {
00278       $this_shell = chop($shells[$i]);
00279       echo "<option ".(($current == $this_shell)?"selected ":"")."value=$this_shell>$this_shell</option>\n";
00280     }
00281 }


Generated on Sun Feb 26 13:23:04 2006 for Savane PHP Frontend Developer Reference by  doxygen 1.4.4