Exemplo n.º 1
0
 public function list_replicas()
 {
     $this->_debug("Finding replicas for this server.");
     // Search any host that is a replica for the current host
     $replica_hosts = $this->config_get('replica_hosts', array());
     $root_dn = $this->config_get('config_root_dn');
     if (!empty($replica_hosts)) {
         return $replica_hosts;
     }
     $ldap = new Net_LDAP3($this->config);
     $ldap->connect();
     $ldap->bind($this->_current_bind_dn, $this->_current_bind_pw);
     $result = $ldap->search($root_dn, '(objectclass=nsds5replicationagreement)', 'sub', array('nsds5replicahost'));
     if (!$result) {
         $this->_debug("No replicas configured");
         return $replica_hosts;
     }
     $this->_debug("Replication agreements found: " . var_export($result->entries(true), true));
     foreach ($result->entries(true) as $dn => $attrs) {
         if (!in_array($attrs['nsds5replicahost'], $replica_hosts)) {
             $replica_hosts[] = $attrs['nsds5replicahost'];
         }
     }
     // $replica_hosts now holds the IDs of servers we are currently NOT
     // connected to. We might need this later in order to set
     $this->_server_id_not = $replica_hosts;
     $this->_debug("So far, we have the following replicas: " . var_export($replica_hosts, true));
     $ldap->close();
     foreach ($replica_hosts as $replica_host) {
         $ldap->config_set('hosts', array($replica_host));
         $ldap->connect();
         $ldap->bind($this->_current_bind_dn, $this->_current_bind_pw);
         $result = $ldap->search($root_dn, '(objectclass=nsds5replicationagreement)', 'sub', array('nsds5replicahost'));
         if (!$result) {
             $this->_debug("No replicas configured on {$replica_host}");
             $ldap->close();
             continue;
         }
         foreach ($result->entries(true) as $dn => $attrs) {
             if (!in_array($attrs['nsds5replicahost'], $replica_hosts)) {
                 $replica_hosts[] = $attrs['nsds5replicahost'];
             }
         }
         $ldap->close();
     }
     $this->config_set('replica_hosts', $replica_hosts);
     return $replica_hosts;
 }
Exemplo n.º 2
0
 /**
  * Get a specific LDAP entry, identified by its DN
  *
  * @param string $dn Record identifier
  *
  * @return array Hash array
  */
 function get_entry($dn)
 {
     return parent::get_entry($dn, $this->attributes);
 }
Exemplo n.º 3
0
 /**
  * Find domain by name
  */
 private function find_domain($domain)
 {
     $ckey = 'domain::' . $domain;
     /*
             // use memcache
             if ($domain = $this->get_cache_data($ckey)) {
                 return $domain;
             }
     */
     $domain_base_dn = $this->conf->get('ldap', 'domain_base_dn');
     $domain_filter = $this->conf->get('ldap', 'domain_filter');
     $domain_name_attribute = $this->conf->get('ldap', 'domain_name_attribute');
     if (empty($domain_name_attribute)) {
         $domain_name_attribute = 'associateddomain';
     }
     $name_filter = $domain_name_attribute . "=" . Net_LDAP3::quote_string($domain);
     $domain_filter = "(&" . $domain_filter . "(" . $name_filter . "))";
     if ($result = $this->ldap->search($domain_base_dn, $domain_filter, 'sub', array($domain_name_attribute))) {
         $result = $result->entries(true);
         // root domain
         $domain = current($result);
         $domain = current((array) $domain[$domain_name_attribute]);
         /*
                     // cache domain DN
                     $this->set_cache_data($ckey, $domain);
         */
         return $domain;
     }
 }
 /**
  * Get a specific LDAP entry, identified by its DN
  *
  * @param string $dn Record identifier
  * @param array  $attributes Attributes to return
  *
  * @return array Hash array
  */
 function get_entry($dn, $attributes = array())
 {
     return parent::get_entry($dn, !empty($attributes) ? $attributes : $this->attributes);
 }
Exemplo n.º 5
0
 /**
  * Wrapper for ldap_get_entries()
  *
  * @param bool $normalize Optionally normalize the entries to a list of hash arrays
  *
  * @return array List of LDAP entries
  */
 public function entries($normalize = false)
 {
     $entries = ldap_get_entries($this->conn, $this->result);
     if ($normalize) {
         return Net_LDAP3::normalize_result($entries);
     }
     return $entries;
 }