diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php index bf02ba1..481deb9 100644 --- a/lib/Auth/LDAP.php +++ b/lib/Auth/LDAP.php @@ -483,11 +483,74 @@ class LDAP extends Net_LDAP3 { return $this->modify_entry($domain_dn, $domain[$domain_dn], $attributes); } + # used for deleting domains completely + private function delete_recursive($dn) + { + //searching for sub entries, but not scope sub, just one level + $this->config_set('return_attributes', array('*')); + $result = $this->search($dn, '(objectclass=*)', 'one'); + + if ($result != null) { + $entries = $result->entries(true); + + foreach (array_keys($entries) as $subdn){ + if ($this->delete_recursive($subdn) === false) { + return false; + } + } + } + + if ($this->entry_delete($dn) === false) { + $this->_log(LOG_DEBUG, "Auth::LDAP::delete_recursive() cannot delete ".$dn); + return false; + } + + return true; + } + public function domain_delete($domain) { $base_dn = $this->conf->get('ldap', 'domain_base_dn'); + + $domainObj = $this->domain_info($domain); + + if (empty($domainObj)) { + return false; + } + + $domain_name = $domainObj[key($domainObj)]["associateddomain"]; + $inetdomainbasedn = $this->_standard_root_dn($domain_name); + + # delete role kolab-admin + if ($this->delete_entry("cn=kolab-admin,".$inetdomainbasedn) === false) { + $this->_log(LOG_DEBUG, "Auth::LDAP::domain_delete() problem deleting cn=kolab-admin,".$inetdomainbasedn); + return false; + } + # delete dc=example,dc=org and all elements below as well + if ($this->delete_recursive($inetdomainbasedn) === false) { + $this->_log(LOG_DEBUG, "Auth::LDAP::domain_delete() problem deleting ".$inetdomainbasedn); + return false; + } + # only deletes associateddomain=example.org,cn=kolab,cn=config + if ($this->entry_delete($domain, array(), $base_dn) === false) { + $this->_log(LOG_DEBUG, "Auth::LDAP::domain_delete() problem deleting ".$domain); + return false; + } - return $this->entry_delete($domain, array(), $base_dn); + $dn = "cn=" . str_replace('.', '_', $domain_name) . ",cn=ldbm database,cn=plugins,cn=config"; + if ($this->delete_recursive($dn) === false) { + $this->_log(LOG_DEBUG, "Auth::LDAP::domain_delete() problem deleting $dn"); + return false; + } + + $cn = str_replace(array(',', '='), array('\2C', '\3D'), $inetdomainbasedn); + $dn = "cn=" . $cn . ",cn=mapping tree,cn=config"; + if ($this->delete_recursive($dn) === false) { + $this->_log(LOG_DEBUG, "Auth::LDAP::domain_delete() problem deleting $dn"); + return false; + } + + return true; } public function domain_find_by_attribute($attribute)