From ff4af074503894250d1b3648e230343be84940ec Mon Sep 17 00:00:00 2001 From: Michael Hierweck Date: Fri, 15 Sep 2017 08:45:34 +0200 Subject: [PATCH] Fix edge cases. Ignore postmap errors. --- .../de/hsadmin/mods/dom/DomainModuleImpl.java | 9 ++++--- .../mods/dom/DomainProcessorFactory.java | 27 ++++++++++--------- .../email/EMailAddressProcessorFactory.java | 27 ++++++++++--------- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java index 9459d4c..af97ce3 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java @@ -231,12 +231,15 @@ public class DomainModuleImpl extends AbstractModuleImpl { throw new HSAdminException("invalid domain option: " + opt.getName() + " for wildcard subdomain"); } if ("backupmxforexternalmx".equals(opt.getName())) { - final Query query = em.createQuery("SELECT e FROM EMailAddress e WHERE e.domain = :domname"); + final Query query = em.createQuery( + "SELECT e FROM " + EMailAddress.class.getAnnotation(javax.persistence.Entity.class).name() + + " e WHERE e.domain = :domname"); query.setParameter("domname", updatedDom.getName()); if (!query.getResultList().isEmpty()) { - throw new HSAdminException("domain option backupmaxforexternalmx may not be activated when email addresses exist"); + throw new HSAdminException( + "domain option backupmaxforexternalmx may not be activated when email addresses exist"); } - } + } } needsWriteAccessOn(oldDom, "update"); return super.update(existingEntity); diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index b6d3505..2a13752 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -149,7 +149,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory { final String inetAddr = pac.getCurINetAddr().getInetAddr(); final CompoundProcessor cp = new CompoundProcessor( createPostgreyConfiguration(em), - new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains", + new ShellProcessor("postmap -r -i /etc/postfix-mailin/relaydomains || true", dom.getName() + " anything\n" + "." + dom.getName() + " anything\n")); final Query query = em.createQuery("SELECT d FROM Domains d WHERE d.domainoptions.name = :option AND d.name = :domname"); @@ -157,22 +157,22 @@ public class DomainProcessorFactory implements EntityProcessorFactory { query.setParameter("option", "backupmxforexternalmx"); if (query.getResultList().isEmpty()) { cp.appendProcessor( - new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport", + new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients || true", + "@" + dom.getName() + "\n") + ); + cp.appendProcessor( + new ShellProcessor("postmap -r -i /etc/postfix-mailin/transport || true", dom.getName() + " smtp:" + inetAddr + ":225\n" + "." + dom.getName() + " smtp:" + inetAddr + ":225\n") - ); - cp.appendProcessor( - new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients", - "@" + dom.getName() + "\n") - ); + ); } else { cp.appendProcessor( - new ShellProcessor("postmap -d - /etc/postfix-mailin/transport", + new ShellProcessor("postmap -d - /etc/postfix-mailin/transport || true", dom.getName() + "\n" + "." + dom.getName() + "\n") ); cp.appendProcessor( - new ShellProcessor("postmap -r -i /etc/postfix-mailin/relayrecipients", + new ShellProcessor("postmap -r -i /etc/postfix-mailin/relayrecipients || true", "@" + dom.getName() + " anything\n") ); } @@ -204,11 +204,12 @@ public class DomainProcessorFactory implements EntityProcessorFactory { private Processor createMailinUnsetupProcessor(EntityManager em, Domain dom) throws ProcessorException { final CompoundProcessor mailQueueProcessor = new CompoundProcessor(createPostgreyConfiguration(em)); - mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients", - dom.getName() + "\n" + - "." + dom.getName() + "\n" + + mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/relaydomains || true", + dom.getName() + "\n" + + "." + dom.getName() + "\n")); + mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients || true", "@" + dom.getName() + "\n")); - mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/transports", + mailQueueProcessor.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/transports || true", dom.getName() + "\n" + "." + dom.getName() + "\n")); return mailQueueProcessor; diff --git a/hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java b/hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java index 19efe5c..35aef57 100644 --- a/hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/email/EMailAddressProcessorFactory.java @@ -16,22 +16,22 @@ import de.hsadmin.core.util.Config; public class EMailAddressProcessorFactory implements EntityProcessorFactory { public Processor createCreateProcessor(EntityManager em, T entity) { - // TODO: combine both keys in a single call (optimization) CompoundProcessor cp = new CompoundProcessor(); EMailAddress email = (EMailAddress) entity; - if (emailAddressCount(em, email) == 1) { - // first email address added - cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual", - email.getFullDomain() + " -")); + if (emailAddressCount(em, email) > 0) { + // first email address added (but the initial email addresses are created at once) + cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual || true", + email.getFullDomain() + " -\n" + + "." + email.getFullDomain() + " -\n")); } - cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual", - email.getEMailAddress() + " " + email.getTarget())); + cp.appendProcessor(new ShellProcessor("postmap -r -i /etc/postfix-mailin/virtual || true", + email.getEMailAddress() + " " + email.getTarget() + "\n")); WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp); Config config = Config.getInstance(); for (String queueName : config.getProperty("queues.mail").split(",")) { waitingTasksProcessor.appendProcessor(queueName, - new ShellProcessor("postmap -r -i /etc/postfix-mailin/relayrecipients", - email.getEMailAddress() + " anything"), + new ShellProcessor("postmap -r -i /etc/postfix-mailin/relayrecipients || true", + email.getEMailAddress() + " anything\n"), "Add to relayrecipients"); } return waitingTasksProcessor; @@ -48,16 +48,17 @@ public class EMailAddressProcessorFactory implements EntityProcessorFactory { EMailAddress email = (EMailAddress) entity; if (emailAddressCount(em, email) == 0) { // last email address removed - cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual", - email.getFullDomain() + "\n")); + cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual || true", + email.getFullDomain() + "\n" + + "." + email.getFullDomain() + "\n")); } - cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual", + cp.appendProcessor(new ShellProcessor("postmap -d - /etc/postfix-mailin/virtual || true", email.getEMailAddress() + "\n")); Config config = Config.getInstance(); WaitingTasksProcessor waitingTasksProcessor = new WaitingTasksProcessor(cp); for (String queueName : config.getProperty("queues.mail").split(",")) { waitingTasksProcessor.appendProcessor(queueName, - new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients", + new ShellProcessor("postmap -d - /etc/postfix-mailin/relayrecipients || true", email.getEMailAddress() + "\n"), "Remove from relayrecipients"); }