fixed RDN change and moving to other DNs

This commit is contained in:
Roland Gruber 2011-12-03 18:23:08 +00:00
parent 952fff7947
commit b5e6e5f34a
2 changed files with 32 additions and 4 deletions

View File

@ -821,4 +821,28 @@ function isObfuscatedText($text) {
} }
} }
/**
* Extracts the RDN attribute name from a given DN.
*
* @param String $dn DN
* @return String RDN attribute name
*/
function extractRDNAttribute($dn) {
if ($dn == null) return null;
$parts = explode("=", substr($dn, 0, strpos($dn, ',')));
return $parts[0];
}
/**
* Extracts the DN suffix from a given DN.
* E.g. ou=people,dc=test,dc=com will result in dc=test,dc=com.
*
* @param String $dn DN
* @return String DN suffix
*/
function extractDNSuffix($dn) {
if ($dn == null) return null;
return substr($dn, strpos($dn, ',')+1);
}
?> ?>

View File

@ -669,7 +669,7 @@ class accountContainer {
/** DN suffix of the account */ /** DN suffix of the account */
public $dnSuffix; public $dnSuffix;
/** DN suffix of account when it was loaded */ /** DN of account when it was loaded */
public $dn_orig; public $dn_orig;
/** RDN attribute of this account */ /** RDN attribute of this account */
@ -1381,11 +1381,10 @@ class accountContainer {
if (!$entry) { if (!$entry) {
return array(array("ERROR", _("Unable to load LDAP entry:") . " " . htmlspecialchars($dn), ldap_error($_SESSION['ldap']->server()))); return array(array("ERROR", _("Unable to load LDAP entry:") . " " . htmlspecialchars($dn), ldap_error($_SESSION['ldap']->server())));
} }
$this->dnSuffix = substr($dn, strpos($dn, ',')+1); $this->dnSuffix = extractDNSuffix($dn);
$this->dn_orig = $dn; $this->dn_orig = $dn;
// extract RDN // extract RDN
$this->rdn = explode("=", substr($dn, 0, strpos($dn, ','))); $this->rdn = extractRDNAttribute($dn);
$this->rdn = $this->rdn[0];
$attr = ldap_get_attributes($_SESSION['ldap']->server(), $entry); $attr = ldap_get_attributes($_SESSION['ldap']->server(), $entry);
$attr = array($attr); $attr = array($attr);
cleanLDAPResult($attr); cleanLDAPResult($attr);
@ -1579,6 +1578,11 @@ class accountContainer {
unset($attributes[$this->dn_orig]); unset($attributes[$this->dn_orig]);
} }
} }
elseif (!$this->isNewAccount && (($this->dnSuffix != extractDNSuffix($this->dn_orig)) || ($this->rdn != extractRDNAttribute($this->rdn)))) {
$this->finalDN = $this->rdn . '=' . $attributes[$this->dn_orig]['notchanged'][$this->rdn][0] . ',' . $this->dnSuffix;
$attributes[$this->finalDN] = $attributes[$this->dn_orig];
unset($attributes[$this->dn_orig]);
}
// pre modify actions // pre modify actions
$prePostModifyAttributes = array(); $prePostModifyAttributes = array();
if (isset($attributes[$this->finalDN]) && is_array($attributes[$this->finalDN])) { if (isset($attributes[$this->finalDN]) && is_array($attributes[$this->finalDN])) {