PageRenderTime 62ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/Branch_4_6-mysql/gforge/common/include/account.php

https://gitlab.com/oslc-cm-server/olbergers-ff5-oslc
PHP | 245 lines | 122 code | 21 blank | 102 comment | 25 complexity | 2cc8479ab49a2e0e481d425d5367e7d5 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /**
  3. * account.php - A library of common account management functions.
  4. *
  5. * Copyright 1999-2001 (c) VA Linux Systems
  6. *
  7. * @version $Id$
  8. *
  9. * This file is part of GForge.
  10. *
  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.
  15. *
  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.
  20. *
  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
  24. */
  25. /**
  26. * account_pwvalid() - Validates a password
  27. *
  28. * @param string The plaintext password string
  29. * @returns true on success/false on failure
  30. *
  31. */
  32. function account_pwvalid($pw) {
  33. global $Language;
  34. if (strlen($pw) < 6) {
  35. $GLOBALS['register_error'] = $Language->getText('common_include_account','sixchar');
  36. return 0;
  37. }
  38. return 1;
  39. }
  40. /**
  41. * account_namevalid() - Validates a login username
  42. *
  43. * @param string The username string
  44. * @returns true on success/false on failure
  45. *
  46. */
  47. function account_namevalid($name) {
  48. global $Language;
  49. // no spaces
  50. if (strrpos($name,' ') > 0) {
  51. $GLOBALS['register_error'] = $Language->getText('common_include_account','nospace');
  52. return 0;
  53. }
  54. // min and max length
  55. if (strlen($name) < 3) {
  56. $GLOBALS['register_error'] = $Language->getText('common_include_account','tooshort');
  57. return 0;
  58. }
  59. if (strlen($name) > 15) {
  60. $GLOBALS['register_error'] = $Language->getText('common_include_account','toolong');
  61. return 0;
  62. }
  63. if (!ereg('^[a-z][-a-z0-9_]+$', $name)) {
  64. $GLOBALS['register_error'] = $Language->getText('common_include_account','illegal');
  65. return 0;
  66. }
  67. // illegal names
  68. if (eregi("^((root)|(bin)|(daemon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)"
  69. . "|(uucp)|(operator)|(games)|(mysql)|(httpd)|(nobody)|(dummy)"
  70. . "|(www)|(cvs)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download))$",$name)) {
  71. $GLOBALS['register_error'] = "Name is reserved.";
  72. return 0;
  73. }
  74. if ( exec("getent passwd $name") != "" ){
  75. $GLOBALS['register_error'] = $Language->getText('account_register','err_userexist');
  76. return 0;
  77. }
  78. if (eregi("^(anoncvs_)",$name)) {
  79. $GLOBALS['register_error'] = $Language->getText('common_include_account','cvsreserved');
  80. return 0;
  81. }
  82. return 1;
  83. }
  84. /**
  85. * account_groupnamevalid() - Validates an account group name
  86. *
  87. * @param string The group name string
  88. * @returns true on success/false on failure
  89. *
  90. */
  91. function account_groupnamevalid($name) {
  92. global $Language;
  93. if (!account_namevalid($name)) return 0;
  94. // illegal names
  95. if (eregi("^((www[0-9]?)|(cvs[0-9]?)|(shell[0-9]?)|(ftp[0-9]?)|(irc[0-9]?)|(news[0-9]?)"
  96. . "|(mail[0-9]?)|(ns[0-9]?)|(download[0-9]?)|(pub)|(users)|(compile)|(lists)"
  97. . "|(slayer)|(orbital)|(tokyojoe)|(webdev)|(projects)|(cvs)|(slayer)|(monitor)|(mirrors?))$",$name)) {
  98. $GLOBALS['register_error'] = $Language->getText('common_include_account','dnsreserved');
  99. return 0;
  100. }
  101. if (eregi("_",$name)) {
  102. $GLOBALS['register_error'] = $Language->getText('common_include_account','nounderscore');
  103. return 0;
  104. }
  105. return 1;
  106. }
  107. /**
  108. * rannum() - Generate a random number
  109. *
  110. * This is a local function used for account_salt()
  111. *
  112. * @return int $num A random number
  113. *
  114. */
  115. function rannum(){
  116. mt_srand((double)microtime()*1000000);
  117. $num = mt_rand(46,122);
  118. return $num;
  119. }
  120. /**
  121. * genchr() - Generate a random character
  122. *
  123. * This is a local function used for account_salt()
  124. *
  125. * @return int $num A random character
  126. *
  127. */
  128. function genchr(){
  129. do {
  130. $num = rannum();
  131. } while ( ( $num > 57 && $num < 65 ) || ( $num > 90 && $num < 97 ) );
  132. $char = chr($num);
  133. return $char;
  134. }
  135. /**
  136. * account_gensalt() - A random salt generator
  137. *
  138. * @returns The random salt string
  139. *
  140. */
  141. function account_gensalt(){
  142. global $unix_cipher;
  143. // ncommander: modified for cipher selection
  144. // crypt() selects the cipher based on
  145. // the salt, so ...
  146. $a = genchr();
  147. $b = genchr();
  148. switch($unix_cipher) {
  149. case 'DES':
  150. $salt = "$a$b";
  151. break;
  152. default:
  153. case 'MD5':
  154. $salt = "$1$" . "$a$b";
  155. break;
  156. case 'Blowfish':
  157. $i = 0;
  158. while (!$i = 16) {
  159. $salt .= rand(64,126);
  160. $i++;
  161. }
  162. return "$2a$".$salt;
  163. break;
  164. }
  165. return $salt;
  166. }
  167. /**
  168. * account_genunixpw() - Generate unix password
  169. *
  170. * @param string The plaintext password string
  171. * @return The encrypted password
  172. *
  173. */
  174. function account_genunixpw($plainpw) {
  175. // ncommander: Support clear password hashing
  176. // for usergroup_plain.php
  177. global $unix_cipher;
  178. if (strcasecmp($unix_cipher, 'Plain') == 0) {
  179. return $plainpw;
  180. } else {
  181. return crypt($plainpw,account_gensalt());
  182. }
  183. }
  184. /**
  185. * account_shellselects() - Print out shell selects
  186. *
  187. * @param string The current shell
  188. *
  189. */
  190. function account_shellselects($current) {
  191. $shells = file("/etc/shells");
  192. $shells[count($shells)] = "/bin/cvssh";
  193. for ($i = 0; $i < count($shells); $i++) {
  194. $this_shell = chop($shells[$i]);
  195. if ($current == $this_shell) {
  196. echo "<option selected value=$this_shell>$this_shell</option>\n";
  197. } else {
  198. if (! ereg("^#",$this_shell)){
  199. echo "<option value=$this_shell>$this_shell</option>\n";
  200. }
  201. }
  202. }
  203. }
  204. /**
  205. * account_user_homedir() - Returns full path of user home directory
  206. *
  207. * @param string The username
  208. * @return home directory path
  209. */
  210. function account_user_homedir($user) {
  211. //return '/home/users/'.substr($user,0,1).'/'.substr($user,0,2).'/'.$user;
  212. return $GLOBALS['homedir_prefix'].'/'.$user;
  213. }
  214. /**
  215. * account_group_homedir() - Returns full path of group home directory
  216. *
  217. * @param string The group name
  218. * @return home directory path
  219. */
  220. function account_group_homedir($group) {
  221. //return '/home/groups/'.substr($group,0,1).'/'.substr($group,0,2).'/'.$group;
  222. return $GLOBALS['groupdir_prefix'].'/'.$group;
  223. }
  224. ?>