]> git.ipfire.org Git - people/ms/dma.git/commitdiff
dma: clean up network code
authorSimon Schubert <corecode@dragonflybsd.org>
Thu, 16 Jul 2009 12:08:22 +0000 (14:08 +0200)
committerSimon Schubert <corecode@dragonflybsd.org>
Thu, 16 Jul 2009 14:13:08 +0000 (16:13 +0200)
- free memory where necessary
- don't just abort without error message
- don't bounce if we want to defer the message

crypto.c
net.c

index 348b8a170198b10114c08d1f22cce36d54e89c58..58094bc02288dd0f16fd47ac8f2033985656eee0 100644 (file)
--- a/crypto.c
+++ b/crypto.c
@@ -266,7 +266,7 @@ smtp_auth_md5(struct qitem *it, int fd, char *login, char *password)
        /* Send AUTH command according to RFC 2554 */
        send_remote_command(fd, "AUTH CRAM-MD5");
        if (read_remote(fd, sizeof(buffer), buffer) != 3) {
-               syslog(LOG_INFO, "%s: smarthost authentification:"
+               syslog(LOG_DEBUG, "%s: smarthost authentification:"
                       " AUTH cram-md5 not available: %s", it->queueid,
                       neterr);
                /* if cram-md5 is not available */
@@ -276,6 +276,7 @@ smtp_auth_md5(struct qitem *it, int fd, char *login, char *password)
        /* skip 3 char status + 1 char space */
        base64_decode(buffer + 4, temp);
        hmac_md5(temp, strlen(temp), password, strlen(password), digest);
+       free(temp);
 
        ascii_digest[32] = 0;
        for (i = 0; i < 16; i++) {
@@ -286,15 +287,17 @@ smtp_auth_md5(struct qitem *it, int fd, char *login, char *password)
        /* prepare answer */
        snprintf(buffer, BUF_SIZE, "%s %s", login, ascii_digest);
 
-       /* temp will be allocated inside base64_encode again */
-       free(temp);
        /* encode answer */
        len = base64_encode(buffer, strlen(buffer), &temp);
-       if (len <= 0)
+       if (len < 0) {
+               syslog(LOG_ERR, "%s: can not encode auth reply: %m",
+                      it->queueid);
                return (-1);
+       }
 
        /* send answer */
        send_remote_command(fd, "%s", temp);
+       free(temp);
        if (read_remote(fd, 0, NULL) != 2) {
                syslog(LOG_WARNING, "%s: remote delivery deferred:"
                                " AUTH cram-md5 failed: %s", it->queueid,
diff --git a/net.c b/net.c
index d9af3541b00c5b0a6ba99c8728b2725eba852a1d..649e35c6e2d4458ef27889db4fc11853ab03762f 100644 (file)
--- a/net.c
+++ b/net.c
@@ -206,7 +206,7 @@ smtp_login(struct qitem *it, int fd, char *login, char* password)
         * If the return code is -2, then then the login attempt failed, 
         * do not try other login mechanisms
         */
-               return (-1);
+               return (1);
        }
 
        if ((config->features & INSECURE) != 0 ||
@@ -221,10 +221,15 @@ smtp_login(struct qitem *it, int fd, char *login, char* password)
                }
 
                len = base64_encode(login, strlen(login), &temp);
-               if (len <= 0)
-                       return (-1);
+               if (len < 0) {
+encerr:
+                       syslog(LOG_ERR, "%s: can not encode auth reply: %m",
+                              it->queueid);
+                       return (1);
+               }
 
                send_remote_command(fd, "%s", temp);
+               free(temp);
                if (read_remote(fd, 0, NULL) != 3) {
                        syslog(LOG_NOTICE, "%s: remote delivery deferred:"
                                        " AUTH login failed: %s", it->queueid,
@@ -233,10 +238,11 @@ smtp_login(struct qitem *it, int fd, char *login, char* password)
                }
 
                len = base64_encode(password, strlen(password), &temp);
-               if (len <= 0)
-                       return (-1);
+               if (len < 0)
+                       goto encerr;
 
                send_remote_command(fd, "%s", temp);
+               free(temp);
                res = read_remote(fd, 0, NULL);
                if (res == 5) {
                        syslog(LOG_NOTICE, "%s: remote delivery failed:"