the ldap auth doesn't seem to be working with openldap. The reason seems to be that not the user DN is used for binding to the ldap, but the entered userid (eg. just "uid=xxxx". This works for Windows AD, but not for any other LDAP server out there (they require a LDAP bind with the DN). Windows AD also supports binding with the DN, so I changed some code for this to work. Hereunder you can find the unified diff (for 2.6.4, but it should apply against later versions as well):
Code: Select all
diff -ru phpmyfaq-2.6.4.orig/inc/Ldap.php phpmyfaq-2.6.4/inc/Ldap.php
--- phpmyfaq-2.6.4.orig/inc/Ldap.php 2010-04-18 11:30:58.000000000 +0200
+++ phpmyfaq-2.6.4/inc/Ldap.php 2010-05-26 11:28:50.000000000 +0200
@@ -121,6 +121,10 @@
return $this->getLdapData($username, 'mail');
}
+ public function getDn($username)
+ {
+ return $this->getLdapDn($username);
+ }
/**
* Returns the user's full name from LDAP
*
@@ -129,7 +133,7 @@
*/
public function getCompleteName($username)
{
- return $this->getLdapData($username, "name");
+ return $this->getLdapData($username, 'name');
}
/**
@@ -183,4 +187,26 @@
return $values[0];
}
-}
\ No newline at end of file
+ private function getLdapDn ($username)
+ {
+ global $PMF_LDAP;
+
+ $filter = "(" . $PMF_LDAP['ldap_mapping']['username'] . "=" . $username . ")";
+ $sr = ldap_search($this->ds, $this->base, $filter);
+
+ if (!$sr) {
+ $this->errno = ldap_errno($this->ds);
+ $this->error = 'Unable to search for "' . $username . '" (Error: ' . ldap_error($this->ds) . ')';
+ }
+
+ $entryId = ldap_first_entry($this->ds, $sr);
+
+ if (!$entryId) {
+ $this->errno = ldap_errno($this->ds);
+ $this->error = 'Cannot get the value(s). Error: ' . ldap_error($this->ds);
+ }
+
+ return ldap_get_dn($this->ds, $entryId);
+ }
+
+}
diff -ru phpmyfaq-2.6.4.orig/inc/PMF_Auth/AuthLdap.php phpmyfaq-2.6.4/inc/PMF_Auth/AuthLdap.php
--- phpmyfaq-2.6.4.orig/inc/PMF_Auth/AuthLdap.php 2010-04-18 11:30:58.000000000 +0200
+++ phpmyfaq-2.6.4/inc/PMF_Auth/AuthLdap.php 2010-05-26 11:24:16.000000000 +0200
@@ -137,7 +137,19 @@
if (array_key_exists('domain', $optionalData)) {
$bindLogin = $optionalData['domain']."\\".$login;
}
- }
+ } else {
+ $this->ldap = new PMF_Ldap($PMF_LDAP['ldap_server'],
+ $PMF_LDAP['ldap_port'],
+ $PMF_LDAP['ldap_base'],
+ $PMF_LDAP['ldap_user'],
+ $PMF_LDAP['ldap_password']);
+
+ if ($this->ldap->error) {
+ $this->errors[] = $this->ldap->error;
+ }
+ $bindLogin = $this->ldap->getDn($login);
+
+ }
$this->ldap = new PMF_Ldap($PMF_LDAP['ldap_server'],
$PMF_LDAP['ldap_port'],
@@ -165,4 +177,4 @@
return $this->ldap->getCompleteName($login);
}
-}
\ No newline at end of file
+}
Franky