Logo Search packages:      
Sourcecode: davical version File versions  Download package

ldapDrivers::__construct ( config )

Initializes the LDAP connection

array$configThe configuration data

Definition at line 43 of file drivers_ldap.php.

Referenced by ldapDrivers().

      global $c;
          $c->messages[] = i18n("drivers_ldap : function ldap_connect not defined, check your php_ldap module");
          return ;

      //Set LDAP protocol version
      if (isset($config['protocolVersion']))
          ldap_set_option($this->connect, LDAP_OPT_PROTOCOL_VERSION, $config['protocolVersion']);
      if (isset($config['optReferrals']))
          ldap_set_option($this->connect, LDAP_OPT_REFERRALS, $config['optReferrals']);

      if ($port)
          $this->connect=ldap_connect($host, $port);

      if (! $this->connect){
          $c->messages[] = sprintf(i18n( "drivers_ldap : Unable to connect to LDAP with port %s on host %s"), $port,$host );
          return ;

      dbg_error_log( "LDAP", "drivers_ldap : Connected to LDAP server %s",$host );

      // Start TLS if desired (requires protocol version 3)
      if (isset($config['startTLS'])) {
        if (!ldap_set_option($this->connect, LDAP_OPT_PROTOCOL_VERSION, 3)) {
          $c->messages[] = sprintf(i18n( "drivers_ldap : Failed to set LDAP to use protocol version 3, TLS not supported") );
        if (!ldap_start_tls($this->connect)) {
          $c->messages[] = sprintf(i18n( "drivers_ldap : Could not start TLS: ldap_start_tls() failed") );

      //Set the search scope to be used, default to subtree.
      if (!isset($config['scope'])) $config['scope'] = 'subtree';
      switch (strtolower($config['scope'])) {
      case "base":
        $this->ldap_query_one = ldap_read;
        $this->ldap_query_all = ldap_read;
      case "onelevel":
        $this->ldap_query_one = ldap_list;
        $this->ldap_query_all = ldap_search;
        $this->ldap_query_one = ldap_search;
        $this->ldap_query_all = ldap_search;

      //connect as root
      if (!ldap_bind($this->connect,$config['bindDN'],$config['passDN'])){
          $bindDN = isset($config['bindDN']) ? $config['bindDN'] : 'anonymous';
          $passDN = isset($config['passDN']) ? $config['passDN'] : 'anonymous';
          dbg_error_log( "LDAP", i18n('drivers_ldap : Failed to bind to host %1$s on port %2$s with bindDN of %3$s'), $host, $port, $bindDN );
          $c->messages[] = i18n( 'drivers_ldap : Unable to bind to LDAP - check your configuration for bindDN and passDN, and that your LDAP server is reachable');
          return ;
      $this->valid = true;
      //root to start search
      $this->baseDNUsers  = is_string($config['baseDNUsers']) ? array($config['baseDNUsers']) : $config['baseDNUsers'];
      $this->filterUsers  = $config['filterUsers'];
      $this->baseDNGroups = $config['baseDNGroups'];
      $this->filterGroups = $config['filterGroups'];

Here is the caller graph for this function:

Generated by  Doxygen 1.6.0   Back to index