*/
function authenticate($login, $password)
{
+ // Special handling for admin@localhost - authenticate against db, not ldap.
+ // It is a fallback mechanism when admin account in LDAP directory does not exist or is misconfigured.
+ if ($login == 'admin@localhost') {
+ import('auth.Auth_db');
+ return Auth_db::authenticate($login, $password);
+ }
+
if (!function_exists('ldap_bind')) {
die ('php_ldap extension not loaded!');
}
}
if (!$lc) return false;
-
+
ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($lc, LDAP_OPT_REFERRALS, 0);
if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) {
ldap_set_option($lc, LDAP_OPT_DEBUG_LEVEL, 7);
}
-
+
// We need to handle Windows AD and OpenLDAP differently.
if ($this->params['type'] != 'openldap') {
-
+
// check if the user specified full login
if (strpos($login, '@') === false) {
// append default domain
}
$lb = @ldap_bind($lc, $login, $password);
-
+
if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) {
echo '$lb='; var_dump($lb); echo '<br />';
echo 'ldap_error()='; echo ldap_error($lc); echo '<br />';
return false;
}
- if ($member_of) {
+ if ($member_of) {
// get groups
$filter = 'samaccountname='.Auth_ldap::ldap_escape($login);
ldap_unbind($lc);
- // handle special case - admin account, strip domain part
- if (strpos($login, 'admin@') !== false) {
- $login = substr($login, 0, 5);
- }
-
return array('login' => $login, 'data' => $entries, 'member_of' => $groups);
} else {
-
+
// Assuming OpenLDAP server.
$login_oldap = 'uid='.$login.','.$this->params['base_dn'];
if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) {
echo '$login_oldap='; var_dump($login_oldap); echo '<br />';
}
-
+
// check if the user specified full login
if (strpos($login, '@') === false) {
// append default domain
}
$lb = @ldap_bind($lc, $login_oldap, $password);
-
+
if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) {
echo '$lb='; var_dump($lb); echo '<br />';
echo 'ldap_error()='; echo ldap_error($lc); echo '<br />';
return false;
}
- if ($member_of) {
+ if ($member_of) {
// get groups
$filter = 'samaccountname='.Auth_ldap::ldap_escape($login_oldap);
ldap_unbind($lc);
- // handle special case - admin account, strip domain part
- if (strpos($login, 'admin@') !== false) {
- $login = substr($login, 0, 5);
- }
-
return array('login' => $login, 'data' => $entries, 'member_of' => $groups);
}
}
function isPasswordExternal() {
return true;
}
-}
\ No newline at end of file
+}