diff options
author | Joerg Jung <jung@cvs.openbsd.org> | 2015-10-18 18:59:52 +0000 |
---|---|---|
committer | Joerg Jung <jung@cvs.openbsd.org> | 2015-10-18 18:59:52 +0000 |
commit | b3e0fdf5e752830505212cd72f0e90fbb7157293 (patch) | |
tree | 106203446dcd01b761a282dc2371a8da015c1814 | |
parent | 265f08543b2938b9f8d5d94ecc2d0024309384cc (diff) |
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 |