3
To check the User or get the User from LDAP you have to get the Information from the LDAP Server like this:
le="color: #000000"><?php function getUser($userName, $includeGroups=false) { global $xoopsConfig; $this->error = null; $userObj = null; $entryDN = $xoopsConfig['ldapusercont']; $filter = "(cn=".$userName.")"; $justthese = array("uidnumber", "cn", "gecos", "webidsynchid"); if($includeGroups) { $justthese[] = "groupmembership"; } $info = $this->findLDAPObject($entryDN, $justthese, $filter); if(!$info) { $this->error = "User $userName not found"; unset($justthese); return null; } $userObj = new xoopsLDAPUser; $userObj->dn = $info[0]["dn"]; $userObj->cn = $info[0]["cn"][0]; $userObj->extid = $info[0]["webidsynchid"][0]; if(isset($info[0]["uidnumber"][0])) { $userObj->uid = $info[0]["uidnumber"][0]; $userObj->gecos = $info[0]["gecos"][0]; } if ($info[0]["groupmembership"]["count"] > 0) { $userObj->groups = array(); for($i = 0; $i < $info[0]["groupmembership"]["count"]; $i++) { $userObj->groups[] = $info[0]["groupmembership"][$i]; } } unset($info); return $userObj; }
This is just a example there must be more inside, so it would be an own Class for connecting to the LDAP Server:
le="color: #000000"><?php function connect() { global $xoopsConfig; $this->error = null; $server = ($xoopsConfig['ldapcleartext'] == 1) ? "ldap" : "ldaps"; $server .= "://" . $xoopsConfig['ldapserver']; $this->conn = ldap_connect($server, $xoopsConfig['ldapserverport']); if(!$this->conn) { $this->conn = null; $this->error = "Failed connection to " . $server; return false; } return true; }
Get an LDAP object associated with a given DN
le="color: #000000"><?php function findLDAPObject($dn, $attributes=null, $filter=null) { $this->error = null; if(!$filter) { $filter = "(objectclass=*)"; } $sr = ldap_search($this->conn, $dn, $filter, $attributes); if(!$sr) { return $this->returnLDAPFailure("Search for Object: $dn"); } if(ldap_count_entries($this->conn, $sr) < 1) { $this->error = "No entries found for $dn"; return false; } $info = ldap_get_entries($this->conn, $sr); return $info; }
le="color: #000000"><?php function returnLDAPFailure($prefString) { $this->error = $prefString . " LDAP Error: " . ldap_err2str(ldap_errno($this->conn)); return false; } // Private // Authenticate a user specified by a given DN // using a given password. function doBind($userDN, $password) { global $xoopsConfig; $this->bound = false; $this->error = null; if(!$this->conn) { if(!$this->connect()) { return false; } } ldap_bind($this->conn, $userDN, $password); if(ldap_errno($this->conn) != 0) { $userDN .= " LDAP Server: " . $xoopsConfig['ldapserver']; return $this->returnLDAPFailure("Bind DN: " . $userDN); } $this->bound = true; return true; } // Do authentication for the admin function bindAdmin() { global $xoopsConfig; return $this->doBind($xoopsConfig['ldapadmin'], $xoopsConfig['ldapadminpass']); }
So happy Xoopsing
Greetz Predator