diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2009-01-28 11:27:58 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2009-01-28 11:27:58 +0000 |
commit | ebb732384bddc5061d44a9e0ca37bd3f7309c100 (patch) | |
tree | d460ab46ed08764e972ba3cc389aad60853e4567 | |
parent | 5d5cfafd03740303c0423b06ea2336373d820235 (diff) |
add a struct path to struct message so that we can keep track of the RCPT
provided recipient even after aliases/forwards expansion, we'll need this
for loop detection.
message id and uid being MAXPATHLEN long is a waste, define MAX_ID_SIZE
which is currently set to 64 (but can probably be further reduced) and
make sure that structures and the few strlcpy's use the right define.
original idea by jacekm@ a while ago
-rw-r--r-- | usr.sbin/smtpd/aliases.c | 6 | ||||
-rw-r--r-- | usr.sbin/smtpd/enqueue.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/mta.c | 7 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue.c | 10 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_shared.c | 10 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtp_session.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 12 |
7 files changed, 31 insertions, 22 deletions
diff --git a/usr.sbin/smtpd/aliases.c b/usr.sbin/smtpd/aliases.c index 4301549657a..f6ff982853c 100644 --- a/usr.sbin/smtpd/aliases.c +++ b/usr.sbin/smtpd/aliases.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aliases.c,v 1.14 2009/01/07 00:26:30 gilles Exp $ */ +/* $OpenBSD: aliases.c,v 1.15 2009/01/28 11:27:57 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -364,8 +364,8 @@ alias_is_address(struct alias *alias, char *line, size_t len) /* scan pre @ for disallowed chars */ *domain++ = '\0'; - strlcpy(alias->u.path.user, line, MAXPATHLEN); - strlcpy(alias->u.path.domain, domain, MAXPATHLEN); + strlcpy(alias->u.path.user, line, MAX_LOCALPART_SIZE); + strlcpy(alias->u.path.domain, domain, MAX_DOMAINPART_SIZE); while (*line) { char allowedset[] = "!#$%*/?|^{}`~&'+-=_."; diff --git a/usr.sbin/smtpd/enqueue.c b/usr.sbin/smtpd/enqueue.c index e8c0470eeb4..0eb5cd47b3d 100644 --- a/usr.sbin/smtpd/enqueue.c +++ b/usr.sbin/smtpd/enqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: enqueue.c,v 1.3 2009/01/28 00:19:27 gilles Exp $ */ +/* $OpenBSD: enqueue.c,v 1.4 2009/01/28 11:27:57 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -159,6 +159,8 @@ enqueue_add_recipient(struct message *messagep, char *recipient) return 0; } + message.session_rcpt = message.recipient; + mr.ss.ss_family = AF_INET6; mr.ss.ss_len = sizeof(ssin6); ssin6 = (struct sockaddr_in6 *)&mr.ss; diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c index 3432a27daf2..febbd17c2bd 100644 --- a/usr.sbin/smtpd/mta.c +++ b/usr.sbin/smtpd/mta.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta.c,v 1.13 2009/01/12 19:56:27 jacekm Exp $ */ +/* $OpenBSD: mta.c,v 1.14 2009/01/28 11:27:57 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -667,7 +667,10 @@ mta_reply_handler(struct bufferevent *bev, void *arg) "localhost", "localhost", "127.0.0.1", "", batchp->message_id); - evbuffer_add_printf(batchp->bev->output, "X-OpenSMTPD: experiment\r\n"); + TAILQ_FOREACH(messagep, &batchp->messages, entry) { + evbuffer_add_printf(batchp->bev->output, "X-Delivered-To: %s@%s\r\n", + messagep->session_rcpt.user, messagep->session_rcpt.domain); + } if (batchp->type & T_DAEMON_BATCH) { evbuffer_add_printf(batchp->bev->output, diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c index f1b41c8d800..2accb62fdb7 100644 --- a/usr.sbin/smtpd/queue.c +++ b/usr.sbin/smtpd/queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue.c,v 1.48 2009/01/27 22:48:29 gilles Exp $ */ +/* $OpenBSD: queue.c,v 1.49 2009/01/28 11:27:57 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -119,7 +119,7 @@ queue_dispatch_control(int sig, short event, void *p) ss.id = messagep->session_id; ss.code = 250; - bzero(ss.u.msgid, MAXPATHLEN); + bzero(ss.u.msgid, MAX_ID_SIZE); if (! enqueue_create_layout(ss.u.msgid)) ss.code = 421; @@ -217,7 +217,7 @@ queue_dispatch_smtp(int sig, short event, void *p) messagep = imsg.data; ss.id = messagep->session_id; ss.code = 250; - bzero(ss.u.msgid, MAXPATHLEN); + bzero(ss.u.msgid, MAX_ID_SIZE); if (! queue_create_incoming_layout(ss.u.msgid)) ss.code = 421; @@ -786,10 +786,10 @@ int queue_load_envelope(struct message *messagep, char *evpid) { char pathname[MAXPATHLEN]; - char msgid[MAXPATHLEN]; + char msgid[MAX_ID_SIZE]; FILE *fp; - if (strlcpy(msgid, evpid, MAXPATHLEN) >= MAXPATHLEN) + if (strlcpy(msgid, evpid, MAX_ID_SIZE) >= MAX_ID_SIZE) fatalx("queue_load_envelope: truncation"); *strrchr(msgid, '.') = '\0'; diff --git a/usr.sbin/smtpd/queue_shared.c b/usr.sbin/smtpd/queue_shared.c index 75c85cb711e..917108dc896 100644 --- a/usr.sbin/smtpd/queue_shared.c +++ b/usr.sbin/smtpd/queue_shared.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue_shared.c,v 1.1 2009/01/27 22:54:01 gilles Exp $ */ +/* $OpenBSD: queue_shared.c,v 1.2 2009/01/28 11:27:57 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -52,8 +52,8 @@ queue_create_layout_message(char *queuepath, char *message_id) fatal("queue_create_layout_message: mkdtemp"); } - if (strlcpy(message_id, rootdir + strlen(queuepath) + 1, MAXPATHLEN) - >= MAXPATHLEN) + if (strlcpy(message_id, rootdir + strlen(queuepath) + 1, MAX_ID_SIZE) + >= MAX_ID_SIZE) fatalx("queue_create_layout_message: truncation"); if (! bsnprintf(evpdir, MAXPATHLEN, "%s%s", rootdir, PATH_ENVELOPES)) @@ -115,8 +115,8 @@ again: fatal("queue_record_incoming_envelope: fdopen"); message->creation = time(NULL); - if (strlcpy(message->message_uid, strrchr(evpname, '/') + 1, MAXPATHLEN) - >= MAXPATHLEN) + if (strlcpy(message->message_uid, strrchr(evpname, '/') + 1, MAX_ID_SIZE) + >= MAX_ID_SIZE) fatalx("queue_record_incoming_envelope: truncation"); if (fwrite(message, sizeof (struct message), 1, fp) != 1) { diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c index a1ca0cb1b74..32a9e4b3573 100644 --- a/usr.sbin/smtpd/smtp_session.c +++ b/usr.sbin/smtpd/smtp_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtp_session.c,v 1.40 2009/01/12 19:56:27 jacekm Exp $ */ +/* $OpenBSD: smtp_session.c,v 1.41 2009/01/28 11:27:57 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -457,6 +457,8 @@ session_rfc5321_rcpt_handler(struct session *s, char *args) return 1; } + s->s_msg.session_rcpt = mr.path; + mr.id = s->s_msg.id; s->s_state = S_RCPTREQUEST; mr.ss = s->s_ss; diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 44aeed5d1ca..d058f99f6d9 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.48 2009/01/27 22:48:29 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.49 2009/01/28 11:27:57 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -27,6 +27,7 @@ #define MAX_LINE_SIZE 1024 #define MAX_LOCALPART_SIZE 65 #define MAX_DOMAINPART_SIZE MAXHOSTNAMELEN +#define MAX_ID_SIZE 64 /* return and forward path size */ #define MAX_PATH_SIZE 256 @@ -414,13 +415,14 @@ struct message { u_int64_t session_id; u_int64_t batch_id; - char message_id[MAXPATHLEN]; - char message_uid[MAXPATHLEN]; + char message_id[MAX_ID_SIZE]; + char message_uid[MAX_ID_SIZE]; char session_helo[MAXHOSTNAMELEN]; char session_hostname[MAXHOSTNAMELEN]; char session_errorline[MAX_LINE_SIZE]; struct sockaddr_storage session_ss; + struct path session_rcpt; struct path sender; struct path recipient; @@ -483,7 +485,7 @@ struct batch { u_int8_t state; struct smtpd *env; - char message_id[MAXPATHLEN]; + char message_id[MAX_ID_SIZE]; char hostname[MAXHOSTNAMELEN]; char errorline[MAX_LINE_SIZE]; @@ -622,7 +624,7 @@ struct submit_status { int code; union submit_path { struct path path; - char msgid[MAXPATHLEN]; + char msgid[MAX_ID_SIZE]; char errormsg[MAX_LINE_SIZE]; } u; enum message_flags flags; |