diff options
author | 2015-10-18 18:59:51 +0000 | |
---|---|---|
committer | 2015-10-18 18:59:51 +0000 | |
commit | ec2f453b95eb8c20f6418ebd69c83eed0cb25c1f (patch) | |
tree | 77192561d48d79d1e7e3b95a7bc4c41e46d2c5f3 | |
parent | Move more EXTERN-defined globals from sh.h. (diff) | |
download | wireguard-openbsd-ec2f453b95eb8c20f6418ebd69c83eed0cb25c1f.tar.xz wireguard-openbsd-ec2f453b95eb8c20f6418ebd69c83eed0cb25c1f.zip |
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
-rw-r--r-- | usr.sbin/smtpd/delivery_lmtp.c | 25 |
1 files changed, 15 insertions, 10 deletions
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 <ashish.is@lostca.se> @@ -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 |