diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2010-09-20 09:01:10 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2010-09-20 09:01:10 +0000 |
commit | 9feee62d0b62c714e04df3d67ee185bfaaebe345 (patch) | |
tree | 13b36f5e768431566c80226f55334d55789d6055 | |
parent | ac8cc5a944e921b496c2176be5598b782444ec41 (diff) |
- fix a regression caused by latest commit (long story made short: do not
attempt to expand the local delivery buffer when relaying mail, it was
kind of ok before but no longer is)
- use the same buffer for local deliveries to files and commands
tested by jmc@ and I
-rw-r--r-- | usr.sbin/smtpd/lka.c | 34 | ||||
-rw-r--r-- | usr.sbin/smtpd/parse.y | 26 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 7 |
4 files changed, 37 insertions, 34 deletions
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c index 646bcfb8db3..2b6ef76815f 100644 --- a/usr.sbin/smtpd/lka.c +++ b/usr.sbin/smtpd/lka.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka.c,v 1.117 2010/09/12 22:38:31 gilles Exp $ */ +/* $OpenBSD: lka.c,v 1.118 2010/09/20 09:01:09 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -379,13 +379,13 @@ lka_expand(char *buf, size_t len, struct path *path, struct path *sender) size_t ret, lret = 0; struct passwd *pw; - bzero(r.r_value.path, MAXPATHLEN); - pbuf = r.r_value.path; + bzero(r.r_value.buffer, MAX_RULEBUFFER_LEN); + pbuf = r.r_value.buffer; ret = 0; - for (p = path->rule.r_value.path; *p != '\0'; + for (p = path->rule.r_value.buffer; *p != '\0'; ++p, len -= lret, pbuf += lret, ret += lret) { - if (p == path->rule.r_value.path && *p == '~') { + if (p == path->rule.r_value.buffer && *p == '~') { if (*(p + 1) == '/' || *(p + 1) == '\0') { pw = getpwnam(path->pw_name); if (pw == NULL) @@ -475,7 +475,7 @@ copy: } /* + 1 to include the NUL byte. */ - memcpy(path->rule.r_value.path, r.r_value.path, ret + 1); + memcpy(path->rule.r_value.buffer, r.r_value.buffer, ret + 1); return ret; } @@ -526,9 +526,9 @@ lka_resolve_node(struct smtpd *env, char *tag, struct path *path, struct expandn log_debug("lka_resolve_node: node is filter: %s", expnode->u.filter); path->rule.r_action = A_EXT; - strlcpy(path->rule.r_value.command, expnode->u.filter + 2, - sizeof(path->rule.r_value.command)); - path->rule.r_value.command[strlen(path->rule.r_value.command) - 1] = '\0'; + strlcpy(path->rule.r_value.buffer, expnode->u.filter + 2, + sizeof(path->rule.r_value.buffer)); + path->rule.r_value.buffer[strlen(path->rule.r_value.buffer) - 1] = '\0'; break; case EXPAND_ADDRESS: @@ -678,12 +678,16 @@ lka_queue_append(struct smtpd *env, struct lkasession *s, int status) /* send next item to queue */ message = s->message; - log_debug("lka_expand: before: [%s]", path->rule.r_value.path); - ret = lka_expand(path->rule.r_value.path, sizeof(path->rule.r_value.path), path, &message.sender); - log_debug("lka_expand: after: [%s]", path->rule.r_value.path); - if (! ret) { - log_debug("lka_expand: returned failure."); - return 0; + if (path->rule.r_action != A_RELAY && + path->rule.r_action != A_RELAYVIA) { + log_debug("lka_expand: before: [%s]", path->rule.r_value.buffer); + ret = lka_expand(path->rule.r_value.buffer, + sizeof(path->rule.r_value.buffer), path, &message.sender); + log_debug("lka_expand: after: [%s]", path->rule.r_value.buffer); + if (! ret) { + log_debug("lka_expand: returned failure."); + return 0; + } } message.recipient = *path; diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y index 8967292b4bb..10fe04f1b63 100644 --- a/usr.sbin/smtpd/parse.y +++ b/usr.sbin/smtpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.65 2010/09/08 23:32:27 gilles Exp $ */ +/* $OpenBSD: parse.y,v 1.66 2010/09/20 09:01:09 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -805,33 +805,33 @@ user : USER STRING { action : DELIVER TO MAILDIR user { rule->r_user = $4; rule->r_action = A_MAILDIR; - if (strlcpy(rule->r_value.path, "~/Maildir", - sizeof(rule->r_value.path)) >= - sizeof(rule->r_value.path)) + if (strlcpy(rule->r_value.buffer, "~/Maildir", + sizeof(rule->r_value.buffer)) >= + sizeof(rule->r_value.buffer)) fatal("pathname too long"); } | DELIVER TO MAILDIR STRING user { rule->r_user = $5; rule->r_action = A_MAILDIR; - if (strlcpy(rule->r_value.path, $4, - sizeof(rule->r_value.path)) >= - sizeof(rule->r_value.path)) + if (strlcpy(rule->r_value.buffer, $4, + sizeof(rule->r_value.buffer)) >= + sizeof(rule->r_value.buffer)) fatal("pathname too long"); free($4); } | DELIVER TO MBOX { rule->r_action = A_MBOX; - if (strlcpy(rule->r_value.path, _PATH_MAILDIR "/%u", - sizeof(rule->r_value.path)) - >= sizeof(rule->r_value.path)) + if (strlcpy(rule->r_value.buffer, _PATH_MAILDIR "/%u", + sizeof(rule->r_value.buffer)) + >= sizeof(rule->r_value.buffer)) fatal("pathname too long"); } | DELIVER TO MDA STRING user { rule->r_user = $5; rule->r_action = A_EXT; - if (strlcpy(rule->r_value.command, $4, - sizeof(rule->r_value.command)) - >= sizeof(rule->r_value.command)) + if (strlcpy(rule->r_value.buffer, $4, + sizeof(rule->r_value.buffer)) + >= sizeof(rule->r_value.buffer)) fatal("command too long"); free($4); } diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c index d6984717704..a5a38a335ca 100644 --- a/usr.sbin/smtpd/queue.c +++ b/usr.sbin/smtpd/queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue.c,v 1.89 2010/07/23 22:23:24 gilles Exp $ */ +/* $OpenBSD: queue.c,v 1.90 2010/09/20 09:01:09 gilles Exp $ */ /* * Copyright (c) 2008-2010 Jacek Masiulaniec <jacekm@dobremiasto.net> @@ -239,7 +239,7 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg) strlcat(aux, "|", sizeof aux); strlcat(aux, m->recipient.pw_name, sizeof aux); strlcat(aux, "|", sizeof aux); - strlcat(aux, m->recipient.rule.r_value.path, sizeof aux); + strlcat(aux, m->recipient.rule.r_value.buffer, sizeof aux); break; case A_FILENAME: diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index c5008d42b21..ff74870100b 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.193 2010/06/10 19:34:51 chl Exp $ */ +/* $OpenBSD: smtpd.h,v 1.194 2010/09/20 09:01:09 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -40,6 +40,7 @@ /* return and forward path size */ #define MAX_PATH_SIZE 256 +#define MAX_RULEBUFFER_LEN 256 #define SMTPD_EXPIRE (4 * 24 * 60 * 60) #define SMTPD_USER "_smtpd" @@ -302,10 +303,8 @@ struct rule { struct cond r_condition; enum action_type r_action; union rule_dest { - char path[MAXPATHLEN]; + char buffer[MAX_RULEBUFFER_LEN]; struct relayhost relayhost; -#define MAXCOMMANDLEN 256 - char command[MAXCOMMANDLEN]; } r_value; char *r_user; |