]> git.ipfire.org Git - people/ms/dma.git/blobdiff - net.c
dma - Fix security hole (#46)
[people/ms/dma.git] / net.c
diff --git a/net.c b/net.c
index 985c5393ac2ce073c1e2e406261cf73c459c362b..47ee928494215be68c5dec48ee04cb2ce95da9a2 100644 (file)
--- a/net.c
+++ b/net.c
@@ -1,4 +1,5 @@
 /*
+ * Copyright (c) 2008-2014, Simon Schubert <2@0x2c.org>.
  * Copyright (c) 2008 The DragonFly Project.  All rights reserved.
  *
  * This code is derived from software contributed to The DragonFly Project
@@ -256,7 +257,7 @@ smtp_login(int fd, char *login, char* password)
                return (0);
        } else if (res == -2) {
        /*
-        * If the return code is -2, then then the login attempt failed, 
+        * If the return code is -2, then then the login attempt failed,
         * do not try other login mechanisms
         */
                return (1);
@@ -371,11 +372,13 @@ deliver_to_host(struct qitem *it, struct mx_hostentry *host)
                       host->host, host->addr, c, neterr); \
                snprintf(errmsg, sizeof(errmsg), "%s [%s] did not like our %s:\n%s", \
                         host->host, host->addr, c, neterr); \
-               return (-1); \
+               error = -1; \
+               goto out; \
        } else if (res != exp) { \
                syslog(LOG_NOTICE, "remote delivery deferred: %s [%s] failed after %s: %s", \
                       host->host, host->addr, c, neterr); \
-               return (1); \
+               error = 1; \
+               goto out; \
        }
 
        /* Check first reply from remote host */
@@ -425,7 +428,8 @@ deliver_to_host(struct qitem *it, struct mx_hostentry *host)
                        syslog(LOG_ERR, "remote delivery failed:"
                                        " SMTP login failed: %m");
                        snprintf(errmsg, sizeof(errmsg), "SMTP login to %s failed", host->host);
-                       return (-1);
+                       error = -1;
+                       goto out;
                }
                /* SMTP login is not available, so try without */
                else if (error > 0) {
@@ -493,17 +497,6 @@ deliver_remote(struct qitem *it)
        int port;
        int error = 1, smarthost = 0;
 
-       host = strrchr(it->addr, '@');
-       /* Should not happen */
-       if (host == NULL) {
-               snprintf(errmsg, sizeof(errmsg), "Internal error: badly formed address %s",
-                   it->addr);
-               return(-1);
-       } else {
-               /* Step over the @ */
-               host++;
-       }
-
        port = SMTP_PORT;
 
        /* Smarthost support? */
@@ -512,11 +505,23 @@ deliver_remote(struct qitem *it)
                port = config.port;
                syslog(LOG_INFO, "using smarthost (%s:%i)", host, port);
                smarthost = 1;
+       } else {
+               host = strrchr(it->addr, '@');
+               /* Should not happen */
+               if (host == NULL) {
+                       snprintf(errmsg, sizeof(errmsg), "Internal error: badly formed address %s",
+                                it->addr);
+                       return(-1);
+               } else {
+                       /* Step over the @ */
+                       host++;
+               }
        }
 
        error = dns_get_mx_list(host, port, &hosts, smarthost);
        if (error) {
-               syslog(LOG_NOTICE, "remote delivery %s: DNS failure (%s)",
+               snprintf(errmsg, sizeof(errmsg), "DNS lookup failure: host %s not found", host);
+               syslog(LOG_NOTICE, "remote delivery %s: DNS lookup failure: host %s not found",
                       error < 0 ? "failed" : "deferred",
                       host);
                return (error);