当前位置: 首页 > 知识库问答 >
问题:

ldap身份验证失败,php ldap\u connect出现错误49/52f

梁丘柏
2023-03-14

首先,我的证书经过100次测试。

我的PHP代码:

$ldapurl = "IP_ADDRESS";
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
$ldapconn = ldap_connect($ldapurl) or die ("no con"); 
ldap_set_option($ldapconn,LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
$dn = "user@domain.local";
$ps = 'Password';
$ldapbind = @ldap_bind($ldapconn,$dn,$ps);

我可以以匿名身份成功绑定,但当我添加用户和密码时,绑定失败。

LDAP调试:

ldap_init: trying c:\openldap\sysconf\ldap.conf
ldap_init: HOME env is NULL
ldap_init: trying ldaprc
ldap_init: LDAPCONF env is NULL
ldap_init: LDAPRC env is NULL
ldap_create
ldap_url_parse_ext(ldap://192.168.17.2:389)
ldap_sasl_bind_s
ldap_sasl_bind
ldap_send_initial_request
ldap_new_connection 1 1 0
ldap_int_open_connection
ldap_connect_to_host: TCP 192.168.17.2:389
ldap_new_socket: 500
ldap_prepare_socket: 500
ldap_connect_to_host: Trying 192.168.17.2:389
ldap_pvt_connect: fd: 500 tm: -1 async: 0
attempting to connect:
connect success
ldap_open_defconn: successful
ldap_send_server_request
ldap_result ld 14BADDF0 msgid 1
wait4msg ld 14BADDF0 msgid 1 (infinite timeout)
wait4msg continue ld 14BADDF0 msgid 1 all 1
** ld 14BADDF0 Connections:
* host: 192.168.17.2  port: 389  (default)
  refcnt: 2  status: Connected
  last used: Wed Mar 20 12:55:22 2019


** ld 14BADDF0 Outstanding Requests:
 * msgid 1,  origid 1, status InProgress
   outstanding referrals 0, parent count 0
  ld 14BADDF0 request count 1 (abandoned 0)
** ld 14BADDF0 Response Queue:
   Empty
  ld 14BADDF0 response count 0
ldap_chkResponseList ld 14BADDF0 msgid 1 all 1
ldap_chkResponseList returns ld 14BADDF0 NULL
ldap_int_select
read1msg: ld 14BADDF0 msgid 1 all 1
read1msg: ld 14BADDF0 msgid 1 message type bind
read1msg: ld 14BADDF0 0 new referrals
read1msg:  mark request completed, ld 14BADDF0 msgid 1
request done: ld 14BADDF0 msgid 1
res_errno: 49, res_error: <80090308: LdapErr: DSID-0C0903D3, comment: AcceptSecurityContext error, data 52f, v3839>, res_matched: <>
ldap_free_request (origid 1, msgid 1)
ldap_parse_result
ldap_msgfree
ldap_err2string
ldap_free_connection 1 1
ldap_send_unbind
ldap_free_connection: actually freed

错误代码为49/52F

Account Restrictions are preventing this user from signing in. 

但是我对这个用户没有任何限制。我已经成功地从控制台将自己连接到AD上。

我已经尝试了$dn=“cn=用户,dc=域,dc=本地”或其他组合,但没有成功

共有1个答案

侯池暝
2023-03-14

请尝试此代码,我刚刚使用过它。它对我有用:

$ldap_password = 'password';
$ldap_username = 'email_address';
$ldap_connection = @ldap_connect(IP address);
if (FALSE === $ldap_connection){
    echo 'Uh-oh, something is wrong...';
}

// We have to set this option for the version of Active Directory we are using.
@ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version');
@ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, 0); // We need this for doing an LDAP search.
$ad_users = [];
if (@ldap_bind($ldap_connection, $ldap_username, $ldap_password)){ 
    $ldap_base_dn = 'DC=domain,DC=com';
    $search_filter = '(&(objectCategory=person)(samaccountname=*))';
    $attributes = array();
    $attributes[] = 'givenname';
    $attributes[] = 'mail';
    $attributes[] = 'samaccountname';
    $attributes[] = 'sn';
    $result = @ldap_search($ldap_connection, $ldap_base_dn, $search_filter, $attributes);   

    if ($result){
        $entries = @ldap_get_entries($ldap_connection, $result);

        for ($x=0; $x<$entries['count']; $x++){
            if (!empty($entries[$x]['givenname'][0]) &&
                 !empty($entries[$x]['mail'][0]) &&
                 !empty($entries[$x]['samaccountname'][0]) &&
                 !empty($entries[$x]['sn'][0]) &&
                 'Shop' !== $entries[$x]['sn'][0] &&
                 'Account' !== $entries[$x]['sn'][0]){
                $ad_users[strtoupper(trim($entries[$x]['samaccountname'][0]))] = array('email' => strtolower(trim($entries[$x]['mail'][0])),'first_name' => trim($entries[$x]['givenname'][0]),'last_name' => trim($entries[$x]['sn'][0]));
            }
        }
    }
    ldap_unbind($ldap_connection); // Clean up after ourselves.
}

echo "Retrieved ". count($ad_users) ." Active Directory users\n";
echo '<pre>';print_r($ad_users);echo '</pre>';
 类似资料:
  • 问题内容: 我正在尝试通过FTP SITE代理访问FTP服务器以绕过防火墙,因为我知道我的用户名/密码正确,因为可以使用FileZilla进行连接。我尝试使用,但没有用。码: 给我这个错误: 我尝试过的事情: 使用备用构造函数。 拆下 使用just ,不使用FTPProxyConnector 设置连接器之前进行身份验证,反之亦然。 但是,当我仅使用Authenticator时,会收到不同的错误提示

  • 我正在尝试从Ldap服务器对用户进行身份验证。 以下是我的Ldap用户: 我的管理员的路径是cn=admin,dc=ldap,dc=agem,dc=com 我错过了什么?

  • 我有一个问题,通过mongo shell连接到MongoDB地图集,即使我已经做了一切正确的和三重检查数据用户名和密码,包括我的IP在白名单中,更改库名测试,并尝试在同一行中添加-密码 `$mongo“mongodbsrv://cluster******.mongodb。net/test”--用户名admin--密码admin MongoDB shell v4.4.6版连接到:mongodb://

  • Tweepy API请求twitter return me Twitter错误响应:状态代码=401。 这是我的实际代码: 我曾试图用tweepy软件包删除推文,并获得了所有必需的密钥。镊子包装不起作用吗?有人能帮我解决这个问题吗。

  • 我正在尝试使用smtplib在python 2.7中发送邮件。下面的代码非常简单: 现在当我执行下面的代码时,我不断得到这个异常:

  • 我使用Presto Cli测试ldap,下面是以下命令: 它不要求密码,我能够连接到Presto集群,并能够运行查询。为什么LDAP身份验证对此没有任何帮助?