Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
与Win Server 2008 R2标准AD的LDAP绑定失败_Ldap_Bind - Fatal编程技术网

与Win Server 2008 R2标准AD的LDAP绑定失败

与Win Server 2008 R2标准AD的LDAP绑定失败,ldap,bind,Ldap,Bind,该环境是一台运行Win server 2008 R2标准的单服务器,SP1带有Apache2.2和PHP5.3.19 我有一个PHP脚本,它尝试将LDAP绑定到Win Server 2008 R2 Active Directory,但无论我尝试了何种变体,都会失败。我在每个步骤中都加入了大量的回音以查看结果,我发现ldap_connect总是可以连接。我可以把全部垃圾放在URL中,它永远不会失败。我的PHP脚本的最新迭代执行匿名绑定,然后执行ldap_搜索,结果失败 以下是脚本实际域、用户和ps

该环境是一台运行Win server 2008 R2标准的单服务器,SP1带有Apache2.2和PHP5.3.19

我有一个PHP脚本,它尝试将LDAP绑定到Win Server 2008 R2 Active Directory,但无论我尝试了何种变体,都会失败。我在每个步骤中都加入了大量的回音以查看结果,我发现ldap_connect总是可以连接。我可以把全部垃圾放在URL中,它永远不会失败。我的PHP脚本的最新迭代执行匿名绑定,然后执行ldap_搜索,结果失败

以下是脚本实际域、用户和pswd已更改:

<?php

    define(LDAP_OPT_DIAGNOSTIC_MESSAGE, 0x0032);

    ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
    echo "<br>LDAP set debug level: " . ldap_errno($ad) . ' ' . ldap_error($ad);

    $LDAPhost = 'ldap://myDomain.com';
    $LDAPport = '3268';
    $ad = ldap_connect($LDAPhost, $LDAPport);
    echo "<br>LDAP connect to $LDAPhost: " . ldap_errno($ad) . ' ' . ldap_error($ad);

    if ($ad) {

        ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
        echo "<br>LDAP set protocol to version 3: " . ldap_errno($ad) . ' ' . ldap_error($ad);

        ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
        echo "<br>LDAP set referrals to 0: " . ldap_errno($ad) . ' ' . ldap_error($ad);

        $bind = ldap_bind($ad);
        echo "<br>LDAP bind: " . ldap_errno($ad) . ' ' . ldap_error($ad);

        $baseDN = 'CN=Users,DC=myDomain,DC=com';
        $filter = '(objectClass=*)';
        $search = ldap_search($ad, $baseDN, $filter);
        echo "<br>LDAP search $baseDN $filter: " . ldap_errno($ad) . ' ' . ldap_error($ad);

        if ($rec = ldap_get_entries($ad, $search)) {
            echo "<br>LDAP get entries: " . ldap_errno($ad) . ' ' . ldap_error($ad);

            for ($i = 0; $i < $rec["count"]; $i++) {

                echo "<br>$rec[0]['uid'][0]";
                echo "<br>$rec[0]['givenname'][0]";

            }

        } else {
            echo '<br>Record not found.';
        }

        ldap_close($ad);
    } else {
        echo '<br><br>Could not connect.';
    }
?>
使用Windows LDP.exe实用程序,我能够使用测试中使用的相同用户/pswd凭据进行绑定

我想知道到底应该把什么作为基本DN,即ldap_bind将这些值与什么进行比较?Active Directory中有什么东西吗?登记处有什么东西吗?还有别的吗


搜索这些东西会找到很多例子,但没有一个适合我。有什么想法吗?

您需要的基本DN是广告中的有效DN。如何找到基本DN?您需要查看rootDSE,看看namingContexts属性是怎么说的

如果您有一个带有ldapsearch的Unix设备,则可以执行以下操作: ldapsearch-x-h mydomain.com-p3268 | less查看namingContexts值是什么


默认情况下,AD通常有4个namingContexts值。没有一个广告盒来做一个快速测试。许多GUI LDAP工具可以让您连接并查看rootDSE,或者使用GUI方式查看它

需要注意的一件事是,如果基本DN似乎不起作用,并且您确信一切,请尝试使用2003格式的用户名:user@domain而不是DN。似乎存在这样一个问题:从2003控制器迁移到2008控制器的域可能在使用PHP LDAP函数绑定时遇到问题。我没有完整的细节,因为我仍在探索它,但2003格式在2008 R2域控制器上工作。下面是测试中使用的基本函数示例

# $ldapconn = a valid connection
# $username = a username in the format 'username@domain'
# #password = the password for the above user

function ad_auth($ldapconn,$username,$password){
    ldap_set_option ($ldapconn, LDAP_OPT_REFERRALS, 0);
    ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
    try {
        $ldap_bind = ldap_bind($ldapconn, $username, $password);
    } catch (Exception $e){
        # Your error code
    }
    return $ldap_bind;
}
用法:$rs=ad_auth$ldapconn、$username、$password


如果我找到原因,我会把它贴出来。

好的,到目前为止还不错。我在一个Windows机器上,所以我使用了ldp.exe,已连接,它显示了以下内容:抱歉,被中断:namingContexts 5:DC=myDomain,DC=com;CN=Configuration,DC=myDomain,DC=com;CN=Schema,CN=Configuration,DC=myDomain,DC=com;DC=DomainDnsZones,DC=myDomain,DC=com;DC=ForestDnsZones,DC=myDomain,DC=com;我的基本DN使用什么来查看用户?@P.Dow所以你的基本DN是:DC=myDomain,DC=com
# $ldapconn = a valid connection
# $username = a username in the format 'username@domain'
# #password = the password for the above user

function ad_auth($ldapconn,$username,$password){
    ldap_set_option ($ldapconn, LDAP_OPT_REFERRALS, 0);
    ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
    try {
        $ldap_bind = ldap_bind($ldapconn, $username, $password);
    } catch (Exception $e){
        # Your error code
    }
    return $ldap_bind;
}