From: jung Date: Sun, 18 Oct 2015 18:59:51 +0000 (+0000) Subject: fix lmtp delivery regressions introduced in previous: X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ec2f453b95eb8c20f6418ebd69c83eed0cb25c1f;p=openbsd fix lmtp delivery regressions introduced in previous: - strip \r\n and add them explicitly to all DATA lines - fix DATA termination - add missing QUIT command (and check for reply) - remove free() and fclose() and use exit(3) instead of _exit(2) to handle cleanup ok sunil gilles --- diff --git a/usr.sbin/smtpd/delivery_lmtp.c b/usr.sbin/smtpd/delivery_lmtp.c index 2a6f1792979..52b01be071f 100644 --- a/usr.sbin/smtpd/delivery_lmtp.c +++ b/usr.sbin/smtpd/delivery_lmtp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: delivery_lmtp.c,v 1.10 2015/10/17 16:07:03 sunil Exp $ */ +/* $OpenBSD: delivery_lmtp.c,v 1.11 2015/10/18 18:59:51 jung Exp $ */ /* * Copyright (c) 2013 Ashish SHUKLA @@ -149,18 +149,23 @@ lmtp_open(struct deliver *deliver) if (lmtp_cmd(&buf, &sz, '3', fp, "DATA") != 0) errx(1, "Invalid DATA reply: %s", buf); - while ((len = getline(&buf, &sz, stdin)) != -1) - if (fprintf(fp, "%s%s", buf[0] == '.' ? "." : "", buf) < 0) + while ((len = getline(&buf, &sz, stdin)) != -1) { + if (len >= 2 && buf[len - 2] == '\r') + buf[len - 2] = '\0'; + else if (buf[len - 1] == '\n') + buf[len - 1] = '\0'; + + if (fprintf(fp, "%s%s\r\n", buf[0] == '.' ? "." : "", buf) < 0) errx(1, "fprintf failed"); + } - free(buf); - if (fprintf(fp, ".\r\n") < 0) - errx(1, "fprintf failed"); - - if (fclose(fp) != 0) - err(1, "fclose"); + if (lmtp_cmd(&buf, &sz, '2', fp, ".") != 0) + errx(1, "Delivery error: %s", buf); + + if (lmtp_cmd(&buf, &sz, '2', fp, "QUIT") != 0) + errx(1, "Error on QUIT: %s", buf); - _exit(0); + exit(0); } static int