fixed some little bugs.

Changed get_preg to avoid possible php bug
This commit is contained in:
katagia 2004-10-11 12:20:27 +00:00
parent 3e7773b38b
commit 08b99f008e
2 changed files with 37 additions and 15 deletions

View File

@ -424,25 +424,30 @@ class samba3domain {
* because many of them are used several times. * because many of them are used several times.
**/ **/
function get_preg($argument, $regexp) { function get_preg($argument, $regexp) {
/* Bug in php preg_match doesn't work correct with utf8
*/
$language = explode(":", $_SESSION['language']);
$language2 = explode ('.', $language[0]);
setlocale(LC_ALL, $language2[0]);
// First we check "positive" cases // First we check "positive" cases
$pregexpr = ''; $pregexpr = '';
switch ($regexp) { switch ($regexp) {
case 'password': // fixme where do i get an exact regexp? case 'password': // fixme where do i get an exact regexp?
$pregexpr = '/^([[:alnum:]\\ \\|\\#\\*\\,\\.\\;\\:\\_\\+\\!\\%\\&\\/\\?\\{\\(\\)\\}-])*$/'; $pregexpr = '/^([[:alnum:]\\ \\|\\#\\*\\,\\.\\;\\:\\_\\+\\!\\%\\&\\/\\?\\{\\(\\)\\}-])*$/u';
break; break;
case 'groupname': // first character must be a letter. All letters, numbers, space and ._- are allowed characters case 'groupname': // first character must be a letter. All letters, numbers, space and ._- are allowed characters
case 'username': // first character must be a letter. All letters, numbers, space and ._- are allowed characters case 'username': // first character must be a letter. All letters, numbers, space and ._- are allowed characters
$pregexpr = '/^[[:alpha:]]([[:alnum:]\\.\\ \\_-])*$/'; $pregexpr = '/^[[:alpha:]]([[:alnum:]\\.\\ \\_-])*$/u';
break; break;
case 'usernameList': // comma separated list of user names case 'usernameList': // comma separated list of user names
case 'groupnameList': // comma separated list of group names case 'groupnameList': // comma separated list of group names
$pregexpr = '/^[[:alpha:]]([[:alnum:]\\.\\ \\_-])*(,[[:alpha:]]([[:alnum:]\\.\\ \\_-])*)*$/'; $pregexpr = '/^[[:alpha:]]([[:alnum:]\\.\\ \\_-])*(,[[:alpha:]]([[:alnum:]\\.\\ \\_-])*)*$/u';
break; break;
case 'hostname': // first character must be letter, last must be $. Only normal letters, numbers and ._- are allowed case 'hostname': // first character must be letter, last must be $. Only normal letters, numbers and ._- are allowed
$pregexpr = '/^[a-zA-Z]([a-zA-Z0-9\\.\\_-])*\\$$/'; $pregexpr = '/^[a-zA-Z]([a-zA-Z0-9\\.\\_-])*\\$$/u';
break; break;
case 'realname': // Allow all letters, space and .-_ case 'realname': // Allow all letters, space and .-_
$pregexpr = '/^[[:alpha:]]([[:alpha:]\\.\\ \\_-])*$/'; $pregexpr = '/^[[:alpha:]]([[:alpha:]\\.\\ \\_-])*$/u';
break; break;
case "telephone": // Allow numbers, space, brackets, /-+. case "telephone": // Allow numbers, space, brackets, /-+.
$pregexpr = '/^(\\+)*([0-9\\.\\ \\(\\)\\/-])*$/'; $pregexpr = '/^(\\+)*([0-9\\.\\ \\(\\)\\/-])*$/';
@ -451,25 +456,25 @@ function get_preg($argument, $regexp) {
$pregexpr = '/^(([0-9a-z\\._-])+[@]([0-9a-z-])+([.]([0-9a-z-])+)*)*$/'; $pregexpr = '/^(([0-9a-z\\._-])+[@]([0-9a-z-])+([.]([0-9a-z-])+)*)*$/';
break; break;
case "street": // Allow all letters, numbers, space and .-_ case "street": // Allow all letters, numbers, space and .-_
$pregexpr = '/^([[:alnum:]\\.\\ \\_-])*$/'; $pregexpr = '/^([[:alnum:]\\.\\ \\_-])*$/u';
break; break;
case "postalAddress": // Allow all letters, numbers, space and .-_ case "postalAddress": // Allow all letters, numbers, space and .-_
case "postalCode": // Allow all letters, numbers, space and .-_ case "postalCode": // Allow all letters, numbers, space and .-_
case "title": // Allow all letters, numbers, space and .-_ case "title": // Allow all letters, numbers, space and .-_
case "employeeType": // Allow all letters, numbers, space and .-_ case "employeeType": // Allow all letters, numbers, space and .-_
$pregexpr = '/^([[:alnum:]\\.\\ \\_-])*$/'; $pregexpr = '/^([[:alnum:]\\.\\ \\_-])*$/u';
break; break;
case "homeDirectory": // Homapath, /path/...... case "homeDirectory": // Homapath, /path/......
$pregexpr = '/^([\/]([[:alnum:]\\.\\ \\_-])+)+$/'; $pregexpr = '/^([\/]([[:alnum:]\\.\\ \\_-])+)+$/u';
break; break;
case "digit": // Normal number case "digit": // Normal number
$pregexpr = '/^[[:digit:]]*$/'; $pregexpr = '/^[[:digit:]]*$/';
break; break;
case "UNC": // UNC Path, e.g. \\server\share\folder\... case "UNC": // UNC Path, e.g. \\server\share\folder\...
$pregexpr = '/^([\\\][\\\]([a-zA-Z0-9\\.-])+)([\\\]([[:alnum:]\\.\\ \\_-])+)+$/'; $pregexpr = '/^([\\\][\\\]([a-zA-Z0-9\\.-])+)([\\\]([[:alnum:]\\.\\ \\_-])+)+$/u';
break; break;
case "logonscript": // path to login-script. normal unix file case "logonscript": // path to login-script. normal unix file
$pregexpr = '/^(([\/])*([[:alnum:]\\.\\ \\_-])+([\/]([[:alnum:]\\.\\ \\_-])+)*((\\.bat)|(\\.cmd)))*$/'; $pregexpr = '/^(([\/])*([[:alnum:]\\.\\ \\_-])+([\/]([[:alnum:]\\.\\ \\_-])+)*((\\.bat)|(\\.cmd)))*$/u';
break; break;
case "workstations": // comma separated list with windows-hosts case "workstations": // comma separated list with windows-hosts
$pregexpr = '/^(([a-zA-Z0-9\\.\\_-])+(,[a-zA-Z0-9\\.\\_-])*)*$/'; $pregexpr = '/^(([a-zA-Z0-9\\.\\_-])+(,[a-zA-Z0-9\\.\\_-])*)*$/';
@ -485,8 +490,12 @@ function get_preg($argument, $regexp) {
break; break;
} }
if ($pregexpr!='') if ($pregexpr!='')
if (preg_match($pregexpr, $argument)) return true; if (preg_match($pregexpr, $argument)) {
/* Bug in php preg_match doesn't work correct with utf8
*/
setlocale(LC_ALL, $language[0]);
return true;
}
// Now we check "negative" cases, characters which are not allowed // Now we check "negative" cases, characters which are not allowed
$pregexpr = ''; $pregexpr = '';
switch ($regexp) { switch ($regexp) {
@ -501,7 +510,15 @@ function get_preg($argument, $regexp) {
break; break;
} }
if ($pregexpr!='') if ($pregexpr!='')
if (!preg_match($pregexpr, $argument)) return true; if (!preg_match($pregexpr, $argument)) {
/* Bug in php preg_match doesn't work correct with utf8
*/
setlocale(LC_ALL, $language[0]);
return true;
}
/* Bug in php preg_match doesn't work correct with utf8
*/
setlocale(LC_ALL, $language[0]);
return false; return false;
} }

View File

@ -183,6 +183,7 @@ class sambaSamAccount extends baseModule {
function get_attributes() { function get_attributes() {
$return = $this->attributes; $return = $this->attributes;
$return['sambaLMPassword'] = $this->sambaLMPassword(); $return['sambaLMPassword'] = $this->sambaLMPassword();
$return['sambaNTPassword'] = $this->sambaLMPassword();
return $return; return $return;
} }
@ -258,6 +259,7 @@ class sambaSamAccount extends baseModule {
for ($i=0; $i<count($sambaDomains); $i++ ) for ($i=0; $i<count($sambaDomains); $i++ )
if ($this->attributes['sambaDomainName'][0] == $sambaDomains[$i]->name) { if ($this->attributes['sambaDomainName'][0] == $sambaDomains[$i]->name) {
$SID = $sambaDomains[$i]->SID; $SID = $sambaDomains[$i]->SID;
$RIDbase = $sambaDomains[$i]->RIDbase;
} }
$flag = "["; $flag = "[";
if ($post['sambaAcctFlagsD']) $flag .= "D"; if ($post['sambaAcctFlagsD']) $flag .= "D";
@ -320,12 +322,15 @@ class sambaSamAccount extends baseModule {
if ($_SESSION['cache']->in_cache($SID."-500", 'sambaSID', 'user')!=$_SESSION[$this->base]->dn_orig) if ($_SESSION['cache']->in_cache($SID."-500", 'sambaSID', 'user')!=$_SESSION[$this->base]->dn_orig)
$errors['sambaSID'][] = $this->messages['rid'][0]; $errors['sambaSID'][] = $this->messages['rid'][0];
} }
if ($post['sambaSID']== _('Guest')) { else if ($post['sambaSID']== _('Guest')) {
$this->attributes['sambaSID'][0] = $SID."-501"; $this->attributes['sambaSID'][0] = $SID."-501";
// Do a check if an administrator already exists // Do a check if an guest already exists
if ($_SESSION['cache']->in_cache($SID."-501", 'sambaSID', 'user')!=$_SESSION[$this->base]->dn_orig) if ($_SESSION['cache']->in_cache($SID."-501", 'sambaSID', 'user')!=$_SESSION[$this->base]->dn_orig)
$errors['sambaSID'][] = $this->messages['rid'][1]; $errors['sambaSID'][] = $this->messages['rid'][1];
} }
else if ($post['sambaSID']== _('Ordinary user')) {
$this->attributes['sambaSID'][0] = $SID."-". (($_SESSION[$this->base]->module['posixAccount']->attributes['uidNumber'][0]*2)+$RIDbase);
}
// Check values // Check values
$this->attributes['sambaHomePath'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['sambaHomePath'][0]); $this->attributes['sambaHomePath'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['sambaHomePath'][0]);
$this->attributes['sambaHomePath'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['sambaHomePath'][0]); $this->attributes['sambaHomePath'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['sambaHomePath'][0]);