X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2Fauth%2FAuth_ldap.class.php;h=f99d752a064ab8e8d26a0e1357a6732b7b506e4d;hb=c8144edb537a2447d78cda4a2e6c53616a63c876;hp=25d375bc992379c6570e20d9396dbafdc08e1390;hpb=806dde3c7931d1a0d13c4f0469013a79e6198dcc;p=timetracker.git diff --git a/WEB-INF/lib/auth/Auth_ldap.class.php b/WEB-INF/lib/auth/Auth_ldap.class.php index 25d375bc..f99d752a 100644 --- a/WEB-INF/lib/auth/Auth_ldap.class.php +++ b/WEB-INF/lib/auth/Auth_ldap.class.php @@ -51,7 +51,7 @@ class Auth_ldap extends Auth { var $params; - function Auth_ldap($params) + function __construct($params) { $this->params = $params; if (isset($GLOBALS['smarty'])) { @@ -65,7 +65,7 @@ class Auth_ldap extends Auth { foreach ($illegal as $id => $char) { $legal[$id] = "\\".$char; } - $str = str_replace($illegal, $legal,$str); //replace them + $str = str_replace($illegal, $legal, $str); //replace them return $str; } @@ -78,6 +78,13 @@ class Auth_ldap extends Auth { */ 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!'); } @@ -105,15 +112,14 @@ class Auth_ldap extends Auth { } // We need to handle Windows AD and OpenLDAP differently. - if ($this->params['type'] != 'openldap') { + if ($this->params['type'] == 'ad') { - // check if the user specified full login + // Check if user specified full login. if (strpos($login, '@') === false) { - // append default domain + // Append default domain. $login .= '@' . $this->params['default_domain']; } - if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { echo '$login='; var_dump($login); echo '
'; } @@ -131,10 +137,10 @@ class Auth_ldap extends Auth { } if ($member_of) { - // get groups + // Get groups the user is a member of from AD LDAP server. - $filter = 'samaccountname='.Auth_ldap::ldap_escape($login); - $fields = array('samaccountname', 'mail', 'memberof', 'department', 'displayname', 'telephonenumber', 'primarygroupid'); + $filter = 'userPrincipalName='.Auth_ldap::ldap_escape($login); + $fields = array('memberof'); $sr = @ldap_search($lc, $this->params['base_dn'], $filter, $fields); if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { @@ -142,7 +148,6 @@ class Auth_ldap extends Auth { echo 'ldap_error()='; echo ldap_error($lc); echo '
'; } - // if search failed it's likely that account is disabled if (!$sr) { ldap_unbind($lc); return false; @@ -162,8 +167,7 @@ class Auth_ldap extends Auth { $groups = array(); - // extract group names from - // assuming the groups are in format: CN=,... + // Extract group names. Assume the groups are in format: CN=,... for ($i = 0; $i < @$entries[0]['memberof']['count']; $i++) { $grp = $entries[0]['memberof'][$i]; $grp_fields = explode(',', $grp); @@ -174,8 +178,8 @@ class Auth_ldap extends Auth { echo '$member_of'; var_dump($member_of); echo '
'; }; - // check for group membership - foreach ($member_of as $check_grp) { + // Check for group membership. + foreach ($member_of as $check_grp) { if (!in_array($check_grp, $groups)) { ldap_unbind($lc); return false; @@ -184,9 +188,10 @@ class Auth_ldap extends Auth { } ldap_unbind($lc); - return array('login' => $login, 'data' => $entries, 'member_of' => $groups); - } else { + } + + if ($this->params['type'] == 'openldap') { // Assuming OpenLDAP server. $login_oldap = 'uid='.$login.','.$this->params['base_dn']; @@ -214,6 +219,7 @@ class Auth_ldap extends Auth { } if ($member_of) { + // TODO: Fix this for OpenLDAP, as samaccountname has nothing to do with it. // get groups $filter = 'samaccountname='.Auth_ldap::ldap_escape($login_oldap); @@ -255,7 +261,7 @@ class Auth_ldap extends Auth { if (defined('AUTH_DEBUG') && isTrue(AUTH_DEBUG)) { echo '$member_of'; var_dump($member_of); echo '
'; - }; + } // check for group membership foreach ($member_of as $check_grp) { @@ -270,6 +276,9 @@ class Auth_ldap extends Auth { return array('login' => $login, 'data' => $entries, 'member_of' => $groups); } + + // Server type is neither 'ad' or 'openldap'. + return false; } function isPasswordExternal() {