From 81367f8ade64c2f379780d33a7cbfa4e42d89465 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 13 Aug 2015 03:23:43 +0000 Subject: [PATCH] fixed a bug of not getting an email address when ldap_auth_mode is 2 --- codepot/src/codepot/models/ldaploginmodel.php | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/codepot/src/codepot/models/ldaploginmodel.php b/codepot/src/codepot/models/ldaploginmodel.php index 898fb0f5..2eb8a812 100644 --- a/codepot/src/codepot/models/ldaploginmodel.php +++ b/codepot/src/codepot/models/ldaploginmodel.php @@ -94,6 +94,7 @@ class LdapLoginModel extends LoginModel { $e = @ldap_get_entries($ldap, $r); if ($e !== FALSE && count($e) > 0 && + array_key_exists(0, $e) && array_key_exists(CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME, $e[0])) { $email = $e[0][CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME][0]; @@ -132,7 +133,47 @@ class LdapLoginModel extends LoginModel return FALSE; } - $f_userid = $this->formatString (CODEPOT_LDAP_USERID_FORMAT, $userid, ''); + if (CODEPOT_LDAP_AUTH_MODE == 2) + { + $f_basedn = $this->formatString (CODEPOT_LDAP_USERID_SEARCH_BASE, $userid, ''); + $f_filter = $this->formatString (CODEPOT_LDAP_USERID_SEARCH_FILTER, $userid, ''); + + $sr = @ldap_search ($ldap, $f_basedn, $f_filter, array("dn")); + if ($sr === FALSE) + { + $this->setErrorMessage (ldap_error ($ldap)); + ldap_close ($ldap); + return FALSE; + } + + $ec = @ldap_count_entries ($ldap, $sr); + if ($ec === FALSE) + { + $this->setErrorMessage (ldap_error ($ldap)); + ldap_close ($ldap); + return FALSE; + } + + if ($ec <= 0) + { + $this->setErrorMessage ('No such user'); + ldap_close ($ldap); + return FALSE; + } + + if (($fe = @ldap_first_entry ($ldap, $sr)) === FALSE || + ($f_userid = ldap_get_dn ($ldap, $fe)) === FALSE) + { + $this->setErrorMessage (ldap_error ($ldap)); + ldap_close ($ldap); + return FALSE; + } + } + else + { + $f_userid = $this->formatString (CODEPOT_LDAP_USERID_FORMAT, $userid, ''); + } + $email = ''; if (CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME != '') @@ -143,6 +184,7 @@ class LdapLoginModel extends LoginModel { $e = @ldap_get_entries($ldap, $r); if ($e !== FALSE && count($e) > 0 && + array_key_exists(0, $e) && array_key_exists(CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME, $e[0])) { $email = $e[0][CODEPOT_LDAP_MAIL_ATTRIBUTE_NAME][0]; @@ -150,7 +192,6 @@ class LdapLoginModel extends LoginModel } } - //@ldap_unbind ($ldap); @ldap_close ($ldap);