use of com.zimbra.cs.ldap.SearchLdapOptions in project zm-mailbox by Zimbra.
the class LdapProvisioning method deleteDomainInternal.
public void deleteDomainInternal(ZLdapContext zlc, String zimbraId) throws ServiceException {
// TODO: should only allow a domain delete to succeed if there are no people
// if there aren't, we need to delete the people trees first, then delete the domain.
LdapDomain domain = null;
String acctBaseDn = null;
String dynGroupsBaseDn = null;
try {
// bypass the cached Domain data, in case a subdomain exists and deletion
// of the domain transforms into attribute removal, in which case attributes
// might be missing from a stale cached Domain object
domain = (LdapDomain) getDomainByIdInternal(zimbraId, zlc, GetFromDomainCacheOption.NEGATIVE);
if (domain == null) {
throw AccountServiceException.NO_SUCH_DOMAIN(zimbraId);
}
String name = domain.getName();
// delete account base DN
acctBaseDn = mDIT.domainDNToAccountBaseDN(domain.getDN());
if (!acctBaseDn.equals(domain.getDN())) {
try {
zlc.deleteEntry(acctBaseDn);
} catch (LdapEntryNotFoundException e) {
ZimbraLog.account.info("entry %s not found", acctBaseDn);
}
}
// delete dynamic groups base DN
dynGroupsBaseDn = mDIT.domainDNToDynamicGroupsBaseDN(domain.getDN());
if (!dynGroupsBaseDn.equals(domain.getDN())) {
try {
zlc.deleteEntry(dynGroupsBaseDn);
} catch (LdapEntryNotFoundException e) {
ZimbraLog.account.info("entry %s not found", dynGroupsBaseDn);
}
}
try {
zlc.deleteEntry(domain.getDN());
domainCache.remove(domain);
} catch (LdapContextNotEmptyException e) {
// remove from cache before nuking all attrs
domainCache.remove(domain);
// assume subdomains exist and turn into plain dc object
Map<String, Object> attrs = new HashMap<String, Object>();
List<String> objClasses = new ArrayList<String>();
objClasses.addAll(Arrays.asList("zimbraDomain", "amavisAccount", "DKIM"));
attrs.put("-" + A_objectClass, objClasses);
// remove all zimbra attrs
for (String key : domain.getAttrs(false).keySet()) {
if (key.startsWith("zimbra") || key.startsWith("amavis") || key.startsWith("DKIM"))
attrs.put(key, "");
}
// cannot invoke callback here. If another domain attr is added in a callback,
// e.g. zimbraDomainStatus would add zimbraMailStatus, then we will get a LDAP
// schema violation naming error(zimbraDomain is removed, thus there cannot be
// any zimbraAttrs left) and the modify will fail.
modifyAttrs(domain, attrs, false, false);
// necessary to remove the cached object re-created/refreshed by
// refreshEntry() down the line from modifyAttrs()?
domainCache.remove(domain);
}
String defaultDomain = getConfig().getAttr(A_zimbraDefaultDomainName, null);
if (name.equalsIgnoreCase(defaultDomain)) {
try {
Map<String, String> attrs = new HashMap<String, String>();
attrs.put(A_zimbraDefaultDomainName, "");
modifyAttrs(getConfig(), attrs);
} catch (Exception e) {
ZimbraLog.account.warn("unable to remove config attr:" + A_zimbraDefaultDomainName, e);
}
}
} catch (LdapContextNotEmptyException e) {
// get a few entries to include in the error message
int maxEntriesToGet = 5;
final String doNotReportThisDN = acctBaseDn;
final StringBuilder sb = new StringBuilder();
sb.append(" (remaining entries: ");
SearchLdapOptions.SearchLdapVisitor visitor = new SearchLdapOptions.SearchLdapVisitor() {
@Override
public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) {
if (!dn.equals(doNotReportThisDN)) {
sb.append("[" + dn + "] ");
}
}
};
SearchLdapOptions searchOptions = new SearchLdapOptions(acctBaseDn, filterFactory.anyEntry(), new String[] { Provisioning.A_objectClass }, maxEntriesToGet, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
try {
zlc.searchPaged(searchOptions);
} catch (LdapSizeLimitExceededException lslee) {
// quietly ignore
} catch (ServiceException se) {
ZimbraLog.account.warn("unable to get sample entries in non-empty domain " + domain.getName() + " for reporting", se);
}
sb.append("...)");
throw AccountServiceException.DOMAIN_NOT_EMPTY(domain.getName() + sb.toString(), e);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to purge domain: " + zimbraId, e);
}
}
use of com.zimbra.cs.ldap.SearchLdapOptions in project zm-mailbox by Zimbra.
the class LdapProvisioning method searchLdapObjects.
private void searchLdapObjects(String base, ZLdapFilter filter, String[] returnAttrs, SearchDirectoryOptions opts, NamedEntry.Visitor visitor) throws ServiceException {
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.get(opts.getOnMaster()), opts.getUseConnPool(), LdapUsage.SEARCH);
SearchObjectsVisitor searchObjectsVisitor = new SearchObjectsVisitor(this, zlc, visitor, opts.getMaxResults(), opts.getMakeObjectOpt(), returnAttrs);
SearchLdapOptions searchObjectsOptions = new SearchLdapOptions(base, filter, returnAttrs, opts.getMaxResults(), null, ZSearchScope.SEARCH_SCOPE_SUBTREE, searchObjectsVisitor);
searchObjectsOptions.setUseControl(opts.isUseControl());
searchObjectsOptions.setManageDSAit(opts.isManageDSAit());
zlc.searchPaged(searchObjectsOptions);
} catch (LdapSizeLimitExceededException e) {
throw AccountServiceException.TOO_MANY_SEARCH_RESULTS("too many search results returned", e);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to list all objects", e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.ldap.SearchLdapOptions in project zm-mailbox by Zimbra.
the class BUG_18277 method getAllDomainOrGlobalAdmins.
private void getAllDomainOrGlobalAdmins(Set<String> domainAdminIds, Set<String> globalAdminIds) throws ServiceException {
LdapDIT dit = prov.getDIT();
String[] returnAttrs = new String[] { Provisioning.A_objectClass, Provisioning.A_zimbraId, Provisioning.A_zimbraIsAdminAccount, Provisioning.A_zimbraIsDomainAdminAccount, Provisioning.A_zimbraIsDelegatedAdminAccount };
String configBranchBaseDn = dit.configBranchBaseDN();
String base = dit.mailBranchBaseDN();
String query = "(&(objectclass=zimbraAccount)(|(zimbraIsDomainAdminAccount=TRUE)(zimbraIsAdminAccount=TRUE)))";
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
Bug18277Visitor visitor = new Bug18277Visitor(this, configBranchBaseDn, domainAdminIds, globalAdminIds);
SearchLdapOptions searchOpts = new SearchLdapOptions(base, getFilter(query), returnAttrs, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
zlc.searchPaged(searchOpts);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to list all objects", e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.ldap.SearchLdapOptions in project zm-mailbox by Zimbra.
the class BUG_29978 method doUpgrade.
/**
* for each domain, if domain has zimbraPublicServiceHostname, and that zPSH has a
* corresponding zimbraServer, then set public service port/protocol on domain from
* that zimbraServer.
*/
@Override
void doUpgrade() throws ServiceException {
List<Server> servers = prov.getAllServers();
String query = genQuery(servers);
String[] bases = prov.getDIT().getSearchBases(Provisioning.SD_DOMAIN_FLAG);
String[] attrs = new String[] { Provisioning.A_objectClass, Provisioning.A_zimbraId, Provisioning.A_zimbraDomainName, Provisioning.A_zimbraPublicServiceHostname, Provisioning.A_zimbraPublicServiceProtocol, Provisioning.A_zimbraPublicServicePort };
ZLdapContext zlc = null;
Bug29978Visitor visitor = new Bug29978Visitor(this, zlc, servers);
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
for (String base : bases) {
// should really have one base, but iterate thought the arrya anyway
if (verbose) {
printer.println("LDAP search base: " + base);
printer.println("LDAP search query: " + query);
printer.println();
}
SearchLdapOptions searchOpts = new SearchLdapOptions(base, getFilter(query), attrs, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
zlc.searchPaged(searchOpts);
}
} finally {
LdapClient.closeContext(zlc);
visitor.reportStat();
}
}
use of com.zimbra.cs.ldap.SearchLdapOptions in project zm-mailbox by Zimbra.
the class BUG_57866 method upgradeGalSyncAccounts.
private void upgradeGalSyncAccounts(ZLdapContext zlc) throws ServiceException {
LdapDIT dit = prov.getDIT();
String[] returnAttrs = new String[] { Provisioning.A_zimbraGalAccountId };
String base = dit.mailBranchBaseDN();
String query = "(&(objectclass=zimbraDomain)(zimbraGalAccountId=*))";
final Set<String> galAcctIds = new HashSet<String>();
SearchLdapVisitor visitor = new SearchLdapVisitor(false) {
@Override
public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
try {
String acctId;
acctId = ldapAttrs.getAttrString(Provisioning.A_zimbraGalAccountId);
if (acctId != null) {
galAcctIds.add(acctId);
}
} catch (ServiceException e) {
printer.printStackTrace("unsble to search domains for GAL sync accounts", e);
}
}
};
SearchLdapOptions searchOpts = new SearchLdapOptions(base, getFilter(query), returnAttrs, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
zlc.searchPaged(searchOpts);
for (String galAcctId : galAcctIds) {
printer.format("Checking GAL sync account %s\n", galAcctId);
Account acct = prov.get(AccountBy.id, galAcctId);
setIsSystemAccount(zlc, acct);
}
}
Aggregations