Exemple #1
0
 /**
  * tries to determine a base dn from User DN or LDAP Host
  * @return WizardResult|false WizardResult on success, false otherwise
  */
 public function guessBaseDN()
 {
     if (!$this->checkRequirements(array('ldapHost', 'ldapPort'))) {
         return false;
     }
     //check whether a DN is given in the agent name (99.9% of all cases)
     $base = null;
     $i = stripos($this->configuration->ldapAgentName, 'dc=');
     if ($i !== false) {
         $base = substr($this->configuration->ldapAgentName, $i);
         if ($this->testBaseDN($base)) {
             $this->applyFind('ldap_base', $base);
             return $this->result;
         }
     }
     //this did not help :(
     //Let's see whether we can parse the Host URL and convert the domain to
     //a base DN
     $helper = new Helper();
     $domain = $helper->getDomainFromURL($this->configuration->ldapHost);
     if (!$domain) {
         return false;
     }
     $dparts = explode('.', $domain);
     while (count($dparts) > 0) {
         $base2 = 'dc=' . implode(',dc=', $dparts);
         if ($base !== $base2 && $this->testBaseDN($base2)) {
             $this->applyFind('ldap_base', $base2);
             return $this->result;
         }
         array_shift($dparts);
     }
     return false;
 }