diff --git a/lam/lib/baseModule.inc b/lam/lib/baseModule.inc index df01944f..49d5be06 100644 --- a/lam/lib/baseModule.inc +++ b/lam/lib/baseModule.inc @@ -521,12 +521,15 @@ class baseModule { } } + /** + * Checks if the attribute values follow the LDAP syntax. + * Not every LDAP attribute allows UTF-8 strings. Therefore we do a syntax check here + * and change UTF-8 strings to ASCII strings if needed. + * The maximum length of the attributes is checked, too. + * + * @return mixed 0 if no errors/warnings occured, otherwise an array of status messages. + */ function input_check() { - /* We have to some string checks now. Not every ldap attributes allow utf8 - * strings. Therefore we do a syntax check here and change utf8 strings to ascci - * strings. Only "7bit" ascci is allowed - * We check als the max length as defined in ldap. - */ // Do a check for every ldap attribute $attributes = array_keys($this->attributes); for ($i=0; $iattributes[$attributes[$i]]['SYNTAX']=='1.3.6.1.4.1.1466.115.121.1.11') { // found "7bit" ascii attribute // convert utf8 in us-ascii - $convert = array ( 'ä' => 'ae', 'Ä' => 'Ae', 'ö' => 'Oe', 'ü' => 'ue', 'Ü' => 'ue', - 'ß' => 'ss', 'é' => 'e', 'è' => 'e', 'ô' => 'o' + $convert = array ( 'ä' => 'ae', 'Ä' => 'Ae', 'ö' => 'Oe', 'ü' => 'ue', 'Ü' => 'Ue', + 'ß' => 'ss', 'é' => 'e', 'è' => 'e', 'ô' => 'o', 'ç' => 'c' ); $index = array_keys($convert); - for ($j=0; $jattributes[$attributes[$i]]); $j++) + for ($j=0; $jattributes[$attributes[$i]]); $j++) { + $replaced = false; + // replace special characters for ($k=0; $kattributes[$attributes[$i]][$j]); if ($temp!=$this->attributes[$attributes[$i]][$j]) { - $this->attributes[$attributes[$i]][$j] = $temp; - $messages[$attributes[$i]][] = array('WARN', _($attributes[$i]), _('Changed value because only ASCII characters are allowed.')); + $this->attributes[$attributes[$i]][$j] = $temp; + $replaced = true; } } + // remove remaining UTF-8 characters + for ($c = 0; $c < strlen($this->attributes[$attributes[$i]][$j]); $c++) { + if (ord($this->attributes[$attributes[$i]][$j][$c]) > 127) { + $this->attributes[$attributes[$i]][$j] = substr($this->attributes[$attributes[$i]][$j], 0, $c) . + substr($this->attributes[$attributes[$i]][$j], $c + 2); + $replaced = true; + } + } + if ($replaced) { + $messages[$attributes[$i]][] = array('WARN', _($attributes[$i]), _('Changed value because only ASCII characters are allowed.')); + } + } } // TODO length check } - if (count($messages)!=0) return $messages; + if (count($messages)!=0) return $messages; else return 0; }