diff --git a/lib/Net/LDAP3.php b/lib/Net/LDAP3.php --- a/lib/Net/LDAP3.php +++ b/lib/Net/LDAP3.php @@ -334,14 +334,16 @@ 'nsDS5ReplicaBindDN', 'nsDS5ReplicaCredentials', 'nsDS5ReplicaTransportInfo', - 'nsDS5ReplicaBindMethod', - 'nsDS5ReplicaHost', - 'nsDS5ReplicaPort' + 'nsDS5ReplicaBindMethod' ); + list($host, $port) = strpos($replicate_to_host, ':') !== false ? explode(':', $replicate_to_host) : array($replicate_to_host, 389); + $replica_agreement_attrs = $ldap->get_entry_attributes($replica_agreement_tpl_dn, $attrs); $replica_agreement_attrs['cn'] = array_shift(explode('.', $replicate_to_host)) . str_replace(array('dc=',','), array('_',''), $domain_root_dn); $replica_agreement_attrs['nsDS5ReplicaRoot'] = $domain_root_dn; + $replica_agreement_attrs['nsDS5ReplicaHost'] = $host; + $replica_agreement_attrs['nsDS5ReplicaPort'] = $port; $replica_agreement_dn = "cn=" . $replica_agreement_attrs['cn'] . "," . $new_replica_dn; $this->_debug("Adding $replica_agreement_dn to $replica_host with attributes: " . var_export($replica_agreement_attrs, true)); @@ -1091,7 +1093,9 @@ $ldap->connect(); $ldap->bind($this->_current_bind_dn, $this->_current_bind_pw); - $result = $ldap->search($root_dn, '(objectclass=nsds5replicationagreement)', 'sub', array('nsds5replicahost')); + $host_attrs = array('nsds5replicahost', 'nsds5replicaport'); + + $result = $ldap->search($root_dn, '(objectclass=nsds5replicationagreement)', 'sub', $host_attrs); if (!$result) { $this->_debug("No replicas configured"); @@ -1101,8 +1105,9 @@ $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']; + $host = $attrs['nsds5replicahost'] . ':' . !empty($attrs['nsds5replicaport']) ? $attrs['nsds5replicaport'] : 389; + if (!in_array($host, $replica_hosts)) { + $replica_hosts[] = $host; } } @@ -1119,7 +1124,7 @@ $ldap->connect(); $ldap->bind($this->_current_bind_dn, $this->_current_bind_pw); - $result = $ldap->search($root_dn, '(objectclass=nsds5replicationagreement)', 'sub', array('nsds5replicahost')); + $result = $ldap->search($root_dn, '(objectclass=nsds5replicationagreement)', 'sub', $host_attrs); if (!$result) { $this->_debug("No replicas configured on $replica_host"); $ldap->close(); @@ -1127,8 +1132,9 @@ } foreach ($result->entries(true) as $dn => $attrs) { - if (!in_array($attrs['nsds5replicahost'], $replica_hosts)) { - $replica_hosts[] = $attrs['nsds5replicahost']; + $host = $attrs['nsds5replicahost'] . ':' . !empty($attrs['nsds5replicaport']) ? $attrs['nsds5replicaport'] : 389; + if (!in_array($host, $replica_hosts)) { + $replica_hosts[] = $host; } }