|
Line
Link Here
|
| 0 |
-- a/ldap.php2010-09-13 18:15:43 +0300 |
0 |
++ b/ldap.php2010-09-13 18:15:50 +0300 |
|
Lines 22-31
Link Here
|
| 22 |
// Building user DN |
22 |
// Building user DN |
| 23 |
if ($userDN = $rcmail->config->get('password_ldap_userDN_mask')) { |
23 |
if ($userDN = $rcmail->config->get('password_ldap_userDN_mask')) { |
| 24 |
$userDN = substitute_vars($userDN); |
24 |
$userDN = substitute_vars($userDN); |
|
|
25 |
if (strstr($rcmail->config->get('password_ldap_userDN_mask'), '*')){ |
| 26 |
if ($rcmail->config->get('password_ldap_host') == NULL){ |
| 27 |
$ldapHost = "localhost"; |
| 28 |
} else { |
| 29 |
$ldapHost = $rcmail->config->get('password_ldap_host'); |
| 30 |
} |
| 31 |
if ($rcmail->config->get('password_ldap_port') == NULL){ |
| 32 |
$ldapPort = 389; |
| 33 |
} else { |
| 34 |
$ldapPort = $rcmail->config->get('password_ldap_port'); |
| 35 |
} |
| 36 |
$ds = ldap_connect($ldapHost, $ldapPort); |
| 37 |
if (!$ds){ |
| 38 |
return PASSWORD_CONNECT_ERROR; |
| 39 |
} |
| 40 |
$br = ldap_bind($ds); |
| 41 |
if (!$br){ |
| 42 |
return PASSWORD_CONNECT_ERROR; |
| 43 |
} |
| 44 |
$nameParts = explode('@', $_SESSION['username']); |
| 45 |
$ldapFilter = "(uid=$nameParts[0])"; |
| 46 |
$ldapAttr = array("dn"); |
| 47 |
$sr = ldap_search($ds, $rcmail->config->get('password_ldap_basedn'), $ldapFilter, $ldapAttr); |
| 48 |
if ($sr){ |
| 49 |
$ldapRes = ldap_get_entries($ds, $sr); |
| 50 |
$userDN = $ldapRes[0]["dn"]; |
| 51 |
} else { |
| 52 |
return PASSWORD_CONNECT_ERROR; |
| 53 |
} |
| 54 |
ldap_close($ds); |
| 55 |
} else { |
| 56 |
$userDN = str_replace('%login', $_SESSION['username'], $rcmail->config->get('password_ldap_userDN_mask')); |
| 57 |
} |
| 25 |
} else { |
58 |
} else { |
| 26 |
$userDN = search_userdn($rcmail); |
59 |
$userDN = search_userdn($rcmail); |
| 27 |
} |
60 |
} |
| 28 |
|
|
|
| 29 |
if (empty($userDN)) { |
61 |
if (empty($userDN)) { |
| 30 |
return PASSWORD_CONNECT_ERROR; |
62 |
return PASSWORD_CONNECT_ERROR; |
| 31 |
} |
63 |
} |