diff options
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/bounce.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 5 | ||||
-rw-r--r-- | usr.sbin/smtpd/store.c | 46 |
3 files changed, 12 insertions, 43 deletions
diff --git a/usr.sbin/smtpd/bounce.c b/usr.sbin/smtpd/bounce.c index d9ceb5a03d0..add6d442087 100644 --- a/usr.sbin/smtpd/bounce.c +++ b/usr.sbin/smtpd/bounce.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bounce.c,v 1.3 2009/08/06 14:16:37 gilles Exp $ */ +/* $OpenBSD: bounce.c,v 1.4 2009/08/06 14:27:41 gilles Exp $ */ /* * Copyright (c) 2009 Gilles Chehade <gilles@openbsd.org> @@ -151,7 +151,7 @@ bounce_session_switch(struct smtpd *env, FILE *fp, enum session_state *state, ch fprintf(fp, "\r\n"); fprintf(fp, "Below is a copy of the original message:\r\n\r\n"); - if (! file_copy_session(env, fp, srcfp)) { + if (! file_copy(fp, srcfp, NULL, 0, 1)) { return 0; } diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index f62491f1379..0af1e79ebca 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.132 2009/08/06 14:12:48 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.133 2009/08/06 14:27:41 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -873,8 +873,7 @@ void session_bufferevent_new(struct session *); SPLAY_PROTOTYPE(sessiontree, session, s_nodes, session_cmp); /* store.c */ -int -file_copy_session(struct smtpd *, FILE *, FILE *); +int file_copy(FILE *, FILE *, struct path *, enum action_type, int); int store_write_header(struct batch *, struct message *, FILE *, int); int store_write_message(struct batch *, struct message *); int store_write_daemon(struct batch *, struct message *); diff --git a/usr.sbin/smtpd/store.c b/usr.sbin/smtpd/store.c index 9e50c2460a0..b9cf478cf70 100644 --- a/usr.sbin/smtpd/store.c +++ b/usr.sbin/smtpd/store.c @@ -1,4 +1,4 @@ -/* $OpenBSD: store.c,v 1.21 2009/08/06 13:40:45 gilles Exp $ */ +/* $OpenBSD: store.c,v 1.22 2009/08/06 14:27:41 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -38,39 +38,8 @@ #include "smtpd.h" -int file_copy(FILE *, FILE *, struct path *, enum action_type); - -int -file_copy_session(struct smtpd *env, FILE *dest, FILE *src) -{ - char *buf, *lbuf; - size_t len; - - lbuf = NULL; - while ((buf = fgetln(src, &len))) { - if (buf[len - 1] == '\n') { - buf[len - 1] = '\0'; - len--; - } - else { - /* EOF without EOL, copy and add the NUL */ - if ((lbuf = malloc(len + 1)) == NULL) - err(1, NULL); - memcpy(lbuf, buf, len); - lbuf[len] = '\0'; - buf = lbuf; - } - - if (fprintf(dest, "%s\r\n", buf) != (int)len + 2) - return 0; - } - free(lbuf); - - return 1; -} - int -file_copy(FILE *dest, FILE *src, struct path *path, enum action_type type) +file_copy(FILE *dest, FILE *src, struct path *path, enum action_type type, int session) { char *buf, *lbuf; size_t len; @@ -96,7 +65,7 @@ file_copy(FILE *dest, FILE *src, struct path *path, enum action_type type) * path set to the original recipient. In that case, we can * add the X-OpenSMTPD-Loop header to help loop detection. */ - if (path != NULL && inheaders && + if (!session && path != NULL && inheaders && strchr(buf, ':') == NULL && !isspace(*buf)) { if (fprintf(dest, "X-OpenSMTPD-Loop: %s@%s\n", path->user, path->domain) == -1) @@ -104,7 +73,7 @@ file_copy(FILE *dest, FILE *src, struct path *path, enum action_type type) inheaders = 0; } - if (type == A_MBOX) { + if (!session && type == A_MBOX) { escape = buf; while (*escape == '>') ++escape; @@ -114,12 +83,13 @@ file_copy(FILE *dest, FILE *src, struct path *path, enum action_type type) } } - if (fprintf(dest, "%s\n", buf) != (int)len + 1) + if (fprintf(dest, "%s%s", buf, session ? "\r\n" : "\n") != + (int)len + (session ? 2 : 1)) return 0; } free(lbuf); - if (type == A_MBOX) { + if (!session && type == A_MBOX) { if (fprintf(dest, "\n") != 1) return 0; } @@ -142,7 +112,7 @@ store_write_message(struct batch *batchp, struct message *messagep) goto bad; if (! file_copy(mboxfp, messagefp, &messagep->session_rcpt, - messagep->recipient.rule.r_action)) + messagep->recipient.rule.r_action, 0)) goto bad; fflush(mboxfp); |