LDAP:某些用户的PHP代码身份验证问题

时间:2014-08-20 16:45:39

标签: php codeigniter ldap ldapconnection

你好朋友我在我的php应用程序中使用此功能它在Windows服务器上工作得很好,客户要求将服务器更改为Linux服务器奇怪的是它正确地验证了一些用户并且不与其他用户连接并且搜索没问题,但第二次绑定对某些用户不起作用

    function authLDAP($username, $pass, $dn) {

        $ldap['server'] = 'x.local'; 
        if (empty($dn)) {
            $ldap['user'] = 'organization\\user';
            $ldap['pass'] = 'xxxxxxx';
        } else {
            $ldap['user'] = $dn;
            $ldap['pass'] = $pass;
        }

        $ldap['base_dn'] = "OU=QU, DC=Qassimu, DC=local";

        $ds = ldap_connect($ldap['server']);
        ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
        $bind = ldap_bind($ds, $ldap['user'], $ldap['pass']);

        $filter = "(SamAccountname=$username)";

        $sr = ldap_search($ds, $ldap['base_dn'], $filter, array('*'));

        $rows = ldap_get_entries($ds, $sr);
        if (empty($dn) and !empty($rows[0]['dn'])) {
 // check user authintcation ..
            return $this->authLDAP($username, $pass, $rows[0]['dn']);
        } elseif ($rows[0]['samaccountname'][0] == $username) { 
// // first LDAP binding    
            return true;
        } else {
            return false;
        }
    }

0 个答案:

没有答案