diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2009-07-28 13:53:52 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2009-07-28 13:53:52 +0000 |
commit | 54c933b3d9857cc7108849e2fb675c65f23995fa (patch) | |
tree | 068027f0adde7bd1a0da5e832f55aad19d84adbb /usr.sbin/smtpd | |
parent | dcdbe6fb29453ec226f52503e0290c48720b33b9 (diff) |
add missing bit to correctly spot loops in all cases.
at the moment we only break out of the loop, but do not generate
mailer daemon, this will come soon.
ok pyr@, tested by me with help from gui at iroqwa dot org
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/store.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/usr.sbin/smtpd/store.c b/usr.sbin/smtpd/store.c index d96e32a71f4..1d901084cff 100644 --- a/usr.sbin/smtpd/store.c +++ b/usr.sbin/smtpd/store.c @@ -1,4 +1,4 @@ -/* $OpenBSD: store.c,v 1.19 2009/06/05 21:55:40 jacekm Exp $ */ +/* $OpenBSD: store.c,v 1.20 2009/07/28 13:53:51 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -26,6 +26,7 @@ #include <netinet/in.h> #include <arpa/inet.h> +#include <ctype.h> #include <err.h> #include <errno.h> #include <event.h> @@ -37,15 +38,16 @@ #include "smtpd.h" -int file_copy(FILE *, FILE *, enum action_type); +int file_copy(FILE *, FILE *, struct path *, enum action_type); int -file_copy(FILE *dest, FILE *src, enum action_type type) +file_copy(FILE *dest, FILE *src, struct path *path, enum action_type type) { char *buf, *lbuf; size_t len; char *escape; - + int inheaders = 1; + lbuf = NULL; while ((buf = fgetln(src, &len))) { if (buf[len - 1] == '\n') { @@ -61,6 +63,18 @@ file_copy(FILE *dest, FILE *src, enum action_type type) buf = lbuf; } + /* If we are NOT dealing with a mailer daemon copy, we have + * 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 && + strchr(buf, ':') == NULL && !isspace(*buf)) { + if (fprintf(dest, "X-OpenSMTPD-Loop: %s@%s\n", + path->user, path->domain) == -1) + return 0; + inheaders = 0; + } + if (type == A_MBOX) { escape = buf; while (*escape == '>') @@ -160,7 +174,8 @@ store_write_daemon(struct batch *batchp, struct message *messagep) if (fprintf(mboxfp, "Below is a copy of the original message:\n\n") == -1) goto bad; - if (! file_copy(mboxfp, messagefp, messagep->recipient.rule.r_action)) + if (! file_copy(mboxfp, messagefp, NULL, + messagep->recipient.rule.r_action)) goto bad; fflush(mboxfp); @@ -193,7 +208,8 @@ store_write_message(struct batch *batchp, struct message *messagep) if (messagefp == NULL) goto bad; - if (! file_copy(mboxfp, messagefp, messagep->recipient.rule.r_action)) + if (! file_copy(mboxfp, messagefp, &messagep->session_rcpt, + messagep->recipient.rule.r_action)) goto bad; fflush(mboxfp); |