Added error handling for missing attributes in ldap lookups
This commit is contained in:
parent
60982069f6
commit
5c199783c2
@ -15,12 +15,19 @@ class Ldap {
|
||||
}
|
||||
|
||||
public function get_attribute($uid, $attribute) {
|
||||
$attribute = strtolower($attribute);
|
||||
$data = $this->search("uid=$uid", $attribute);
|
||||
if($data['count'] !== 1) {
|
||||
$err = "LDAP search for '$uid' did not return exactly one result";
|
||||
throw new Exception($err);
|
||||
}
|
||||
return $data[0][strtolower($attribute)][0];
|
||||
$result = $data[0];
|
||||
if(!in_array($attribute, $result) || !$result[$attribute][0] ) {
|
||||
$err = "LDAP search for '$uid' did not return "
|
||||
."a value for '$attribute'";
|
||||
throw new Exception($err);
|
||||
}
|
||||
return $result[$attribute][0];
|
||||
}
|
||||
|
||||
public function get_user($uid) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user