-added function to read user attributes from given user dn

This commit is contained in:
dechutes 2003-03-17 23:25:17 +00:00
parent 1f5a75333e
commit ffd68b369c
1 changed files with 109 additions and 83 deletions

View File

@ -24,6 +24,9 @@ $Id$
// ldap.php provides basic functions to connect to the OpenLDAP server and get lists of users and groups. // ldap.php provides basic functions to connect to the OpenLDAP server and get lists of users and groups.
include_once("../config/config.php"); include_once("../config/config.php");
// class representing local user entry with attributes of ldap user entry
include_once("userentry.php");
class Ldap{ class Ldap{
// object of Config to access preferences // object of Config to access preferences
@ -108,6 +111,29 @@ class Ldap{
} }
} }
// fills the UserEntry object with attributes from the ldap server with the
// given dn of an user entry
function getUser ($in_user_dn) {
$user = new UserEntry();
$attrs = array();
$resource = ldap_read ($this->server,
$in_user_dn, "(objectClass=*)", $attrs);
$entry = ldap_first_entry ($this->server, $resource);
// attributes which are not multivalued ...
$uid = ldap_get_values ($this->server, $entry, "uid");
$user->setUid ($uid[0]);
$cn = ldap_get_values ($this->server, $entry, "cn");
$user->setCn ($cn[0]);
$sn = ldap_get_values ($this->server, $entry, "sn");
$user->setSn ($sn[0]);
$givenName = ldap_get_values ($this->server, $entry, "givenName");
$user->setGivenName ($givenName[0]);
$homeDirectory = ldap_get_values ($this->server, $entry, "homeDirectory");
$user->setHomeDirectory ($homeDirectory[0]);
return $user;
}
// closes connection to server // closes connection to server
function close() { function close() {
ldap_close($this->server); ldap_close($this->server);