From 5d7fe8bb641e1ea14271925709460931ee4b9a19 Mon Sep 17 00:00:00 2001 From: Simon Schubert Date: Thu, 16 Jul 2009 14:08:22 +0200 Subject: [PATCH] dma: clean up network code - free memory where necessary - don't just abort without error message - don't bounce if we want to defer the message --- libexec/dma/crypto.c | 11 +++++++---- libexec/dma/net.c | 16 +++++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/libexec/dma/crypto.c b/libexec/dma/crypto.c index 348b8a1701..58094bc022 100644 --- a/libexec/dma/crypto.c +++ b/libexec/dma/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/libexec/dma/net.c b/libexec/dma/net.c index d9af3541b0..649e35c6e2 100644 --- a/libexec/dma/net.c +++ b/libexec/dma/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:" -- 2.41.0