diff options
-rw-r--r-- | usr.sbin/smtpd/enqueue.c | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/usr.sbin/smtpd/enqueue.c b/usr.sbin/smtpd/enqueue.c index 05a4880021b..6e5cf24aab1 100644 --- a/usr.sbin/smtpd/enqueue.c +++ b/usr.sbin/smtpd/enqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: enqueue.c,v 1.60 2012/08/23 13:16:02 todd Exp $ */ +/* $OpenBSD: enqueue.c,v 1.61 2012/08/23 16:10:19 todd Exp $ */ /* * Copyright (c) 2005 Henning Brauer <henning@bulabula.org> @@ -30,6 +30,7 @@ #include <inttypes.h> #include <pwd.h> #include <signal.h> +#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -50,6 +51,7 @@ static char *qualify_addr(char *); static void rcpt_add(char *); static int open_connection(void); static void get_responses(FILE *, int); +static int send_line(FILE *, int, char *, ...); enum headerfields { HDR_NONE, @@ -259,53 +261,53 @@ enqueue(int argc, char *argv[]) /* banner */ get_responses(fout, 1); - fprintf(fout, "EHLO localhost\n"); + send_line(fout, verbose, "EHLO localhost\n"); get_responses(fout, 1); - fprintf(fout, "MAIL FROM: <%s>\n", msg.from); + send_line(fout, verbose, "MAIL FROM: <%s>\n", msg.from); get_responses(fout, 1); for (i = 0; i < msg.rcpt_cnt; i++) { - fprintf(fout, "RCPT TO: <%s>\n", msg.rcpts[i]); + send_line(fout, verbose, "RCPT TO: <%s>\n", msg.rcpts[i]); get_responses(fout, 1); } - fprintf(fout, "DATA\n"); + send_line(fout, verbose, "DATA\n"); get_responses(fout, 1); /* add From */ if (!msg.saw_from) - fprintf(fout, "From: %s%s<%s>\n", + send_line(fout, 0, "From: %s%s<%s>\n", msg.fromname ? msg.fromname : "", msg.fromname ? " " : "", msg.from); /* add Date */ if (!msg.saw_date) - fprintf(fout, "Date: %s\n", time_to_text(timestamp)); + send_line(fout, 0, "Date: %s\n", time_to_text(timestamp)); /* add Message-Id */ if (!msg.saw_msgid) - fprintf(fout, "Message-Id: <%"PRIu64".enqueue@%s>\n", + send_line(fout, 0, "Message-Id: <%"PRIu64".enqueue@%s>\n", generate_uid(), host); if (msg.need_linesplit) { /* we will always need to mime encode for long lines */ if (!msg.saw_mime_version) - fprintf(fout, "MIME-Version: 1.0\n"); + send_line(fout, 0, "MIME-Version: 1.0\n"); if (!msg.saw_content_type) - fprintf(fout, "Content-Type: text/plain; charset=unknown-8bit\n"); + send_line(fout, 0, "Content-Type: text/plain; charset=unknown-8bit\n"); if (!msg.saw_content_disposition) - fprintf(fout, "Content-Disposition: inline\n"); + send_line(fout, 0, "Content-Disposition: inline\n"); if (!msg.saw_content_transfer_encoding) - fprintf(fout, "Content-Transfer-Encoding: quoted-printable\n"); + send_line(fout, 0, "Content-Transfer-Encoding: quoted-printable\n"); } if (!msg.saw_user_agent) - fprintf(fout, "User-Agent: OpenSMTPD enqueuer (Demoosh)\n"); + send_line(fout, 0, "User-Agent: OpenSMTPD enqueuer (Demoosh)\n"); /* add separating newline */ if (noheader) - fprintf(fout, "\n"); + send_line(fout, 0, "\n"); else inheaders = 1; @@ -328,7 +330,7 @@ enqueue(int argc, char *argv[]) line = buf; if (msg.saw_content_transfer_encoding || noheader || inheaders || !msg.need_linesplit) { - fprintf(fout, "%.*s", (int)len, line); + send_line(fout, 0, "%.*s", (int)len, line); if (inheaders && buf[0] == '\n') inheaders = 0; continue; @@ -342,16 +344,16 @@ enqueue(int argc, char *argv[]) } else { qp_encoded_write(fout, line, LINESPLIT - 2 - dotted); - fprintf(fout, "=\n"); + send_line(fout, 0, "=\n"); line += LINESPLIT - 2 - dotted; len -= LINESPLIT - 2 - dotted; } } while (len); } - fprintf(fout, ".\n"); + send_line(fout, verbose, ".\n"); get_responses(fout, 1); - fprintf(fout, "QUIT\n"); + send_line(fout, verbose, "QUIT\n"); get_responses(fout, 1); fclose(fp); @@ -388,7 +390,7 @@ get_responses(FILE *fin, int n) errx(1, "bad response"); if (verbose) - printf(">>> %.*s", (int)len, buf); + printf("<<< %.*s", (int)len, buf); if (buf[3] == '-') continue; @@ -398,6 +400,22 @@ get_responses(FILE *fin, int n) } } +static int +send_line(FILE *fp, int v, char *fmt, ...) +{ + int ret; + va_list ap; + + if (v) + printf(">>> "); + va_start(ap, fmt); + ret = vfprintf(fp, fmt, ap); + if (v) + ret = vprintf(fmt, ap); + va_end(ap); + return (ret); +} + static void build_from(char *fake_from, struct passwd *pw) { @@ -488,7 +506,7 @@ parse_message(FILE *fin, int get_from, int tflag, FILE *fout) header_seen = 1; if (cur != HDR_BCC) { - fprintf(fout, "%.*s", (int)len, buf); + send_line(fout, 0, "%.*s", (int)len, buf); if (buf[len - 1] != '\n') fputc('\n', fout); if (ferror(fout)) |