【问题标题】:PHP 5.3.5 ldap_search(): Search: Can't contact LDAP serverPHP 5.3.5 ldap_search():搜索:无法联系 LDAP 服务器
【发布时间】:2011-10-11 02:27:28
【问题描述】:

我有一个 LDAP PHP 类,它适用于我们公司的所有其他 PHP 安装。但是,由于我从 SuSE 更改为 Ubuntu 11.04,因此代码停止工作。 PHP版本是5.3.5。

我尝试连接到我们的 LDAP 服务器。连接到它后,我尝试运行 ldap_search。它失败并显示错误消息“ldap_search():搜索:无法联系 LDAP 服务器”。 我使用wireshark查看了流量,可以看到php和ldap之间发生了通信,可惜没有发生连接。

感谢您的意见, 乌韦

这是我使用的代码:

class ldap{
    private $ldap_conn;
    private $ldaphost;
    private $ldapport;

    public function __construct ()
    {
      $this->ldaphost = 'ldaps://ourserver.co.nz';  // obviously a fake name 
      $this->ldapport = 636;
      $this->ldap_conn = ldap_connect($this->ldaphost, $this->ldapport) or die("Could not connect to $this->ldaphost");
    }

    public function signin ($username,$password, $applicationName)
    {
        $dn = "o=MY_COM";
        $filter="(cn=$username)";

        $justthese = array("dn","fullname", "mail");

        $sr=ldap_search($this->ldap_conn, $dn, $filter, $justthese);

        $people = ldap_get_entries($this->ldapconn, $sr);

        if (!$people || count($people) == 0 || $people['count'] == 0)
        {  //Nothing found, quit.
            return AUTH_ERROR_NO_DN;
        }

        $dn = ($people[0]['dn']);

        if (($dn!='')&&($password!=''))
        {
            $loginStatus = @ldap_bind($this->ldapconn, $dn, $password);
            if ($loginStatus)
            {
                $fullname = $people[0]['fullname'][0];
                if ($fullname=='')
                {
                    $fullname =$dn;
                }
                $user = array(
                  'logged_in_dn'  => $dn,
                  'password'      => $password,
                  'username'      => $fullname,
                  'cn'            => $username,
                  'mail'          => $people[0]['mail'][0],
                  'status'        => 'AUTHENTICATED'
                  );
            } else
            {
                $user = array(
                  'status'=> array('AUTH_ERROR_WRONG_PASSWORD'),
                  'details'       => array(             
                    'logged_in_dn'  => '',
                    'password'      => '',
                    'username'      => '',
                    'cn'            => '',
                    'mail'          => '',
                    'status'        => 'AUTHENTICATED'
                    )
                  );    
            }
        } else
        {
                $user = array(
                  'status'=> array('AUTH_ERROR_NO_DN'),
                  'details'       => array(             
                    'logged_in_dn'  => '',
                    'password'      => '',
                    'username'      => '',
                    'cn'            => '',
                    'mail'          => '',
                    'status'        => 'AUTHENTICATED'
                    )
                  );    
        }
        return $user;
    }

这是执行方法的单元测试: 类 unit_ldapConnectTest 扩展 TadPhpUnitTestCase

{

  function testLdapconnection () {  
  $ldap = new LDAP();
  $user = $ldap->signin('myname','password','');


  }
}

【问题讨论】:

  • 您的 SSL 配置是否正确?
  • 您使用的是哪个目录服务器产品?

标签: php ubuntu ldap


【解决方案1】:

可能是 LDAP 版本问题。

在您致电ldap_connect 后,请致电:

ldap_set_option($this->ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多