diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2018-12-06 12:32:12 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2018-12-06 12:32:12 +0000 |
commit | 1ef9b7048da97b4c486b3fdcc56ee7830e89c77e (patch) | |
tree | e482bc850fd7735af3fc8d0816bbb034d4833c50 | |
parent | 4961b2a4b6cbd2d39c117a2f14c35a634fa7190e (diff) |
in mda variables expansions, do not consider empty strings as errors since
an empty %{sender} is really a mailer-daemon and not an error
reported and initial diff by Lauri Tirkkonen <lotheac@iki.fi>
commit is a revised version of the diff based on a discussion with eric@
-rw-r--r-- | usr.sbin/smtpd/mda_unpriv.c | 10 | ||||
-rw-r--r-- | usr.sbin/smtpd/mda_variables.c | 54 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 4 |
3 files changed, 34 insertions, 34 deletions
diff --git a/usr.sbin/smtpd/mda_unpriv.c b/usr.sbin/smtpd/mda_unpriv.c index e519d4c26e5..59c899416af 100644 --- a/usr.sbin/smtpd/mda_unpriv.c +++ b/usr.sbin/smtpd/mda_unpriv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mda_unpriv.c,v 1.3 2018/12/02 11:34:21 gilles Exp $ */ +/* $OpenBSD: mda_unpriv.c,v 1.4 2018/12/06 12:32:11 gilles Exp $ */ /* * Copyright (c) 2018 Gilles Chehade <gilles@poolp.org> @@ -56,8 +56,8 @@ mda_unpriv(struct dispatcher *dsp, struct deliver *deliver, >= sizeof (mda_exec)) errx(1, "mda command line too long"); - if (! mda_expand_format(mda_exec, sizeof mda_exec, deliver, - &deliver->userinfo, NULL)) + if (mda_expand_format(mda_exec, sizeof mda_exec, deliver, + &deliver->userinfo, NULL) == -1) errx(1, "mda command line could not be expanded"); mda_command = mda_exec; @@ -90,8 +90,8 @@ mda_unpriv(struct dispatcher *dsp, struct deliver *deliver, >= sizeof (mda_wrapper)) errx(1, "mda command line too long"); - if (! mda_expand_format(mda_wrapper, sizeof mda_wrapper, deliver, - &deliver->userinfo, mda_command)) + if (mda_expand_format(mda_wrapper, sizeof mda_wrapper, deliver, + &deliver->userinfo, mda_command) == -1) errx(1, "mda command line could not be expanded"); mda_command = mda_wrapper; } diff --git a/usr.sbin/smtpd/mda_variables.c b/usr.sbin/smtpd/mda_variables.c index a23112c71e8..03052e21554 100644 --- a/usr.sbin/smtpd/mda_variables.c +++ b/usr.sbin/smtpd/mda_variables.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mda_variables.c,v 1.4 2018/06/15 08:57:17 gilles Exp $ */ +/* $OpenBSD: mda_variables.c,v 1.5 2018/12/06 12:32:11 gilles Exp $ */ /* * Copyright (c) 2011-2017 Gilles Chehade <gilles@poolp.org> @@ -36,9 +36,9 @@ #define EXPAND_DEPTH 10 -size_t mda_expand_format(char *, size_t, const struct deliver *, +ssize_t mda_expand_format(char *, size_t, const struct deliver *, const struct userinfo *, const char *); -static size_t mda_expand_token(char *, size_t, const char *, +static ssize_t mda_expand_token(char *, size_t, const char *, const struct deliver *, const struct userinfo *, const char *); static int mod_lowercase(char *, size_t); static int mod_uppercase(char *, size_t); @@ -56,7 +56,7 @@ static struct modifiers { #define MAXTOKENLEN 128 -static size_t +static ssize_t mda_expand_token(char *dest, size_t len, const char *token, const struct deliver *dlv, const struct userinfo *ui, const char *mda_command) { @@ -75,14 +75,14 @@ mda_expand_token(char *dest, size_t len, const char *token, mods = NULL; if (strlcpy(rtoken, token, sizeof rtoken) >= sizeof rtoken) - return 0; + return -1; /* token[x[:y]] -> extracts optional x and y, converts into offsets */ if ((lbracket = strchr(rtoken, '[')) && (rbracket = strchr(rtoken, ']'))) { /* ] before [ ... or empty */ if (rbracket < lbracket || rbracket - lbracket <= 1) - return 0; + return -1; *lbracket = *rbracket = '\0'; content = lbracket + 1; @@ -102,7 +102,7 @@ mda_expand_token(char *dest, size_t len, const char *token, } } if (errstr) - return 0; + return -1; /* token:mod_1,mod_2,mod_n -> extract modifiers */ mods = strchr(rbracket + 1, ':'); @@ -115,7 +115,7 @@ mda_expand_token(char *dest, size_t len, const char *token, if (!strcasecmp("sender", rtoken)) { if (snprintf(tmp, sizeof tmp, "%s@%s", dlv->sender.user, dlv->sender.domain) >= (int)sizeof tmp) - return 0; + return -1; if (strcmp(tmp, "@") == 0) (void)strlcpy(tmp, "", sizeof tmp); string = tmp; @@ -123,7 +123,7 @@ mda_expand_token(char *dest, size_t len, const char *token, else if (!strcasecmp("rcpt", rtoken)) { if (snprintf(tmp, sizeof tmp, "%s@%s", dlv->rcpt.user, dlv->rcpt.domain) >= (int)sizeof tmp) - return 0; + return -1; if (strcmp(tmp, "@") == 0) (void)strlcpy(tmp, "", sizeof tmp); string = tmp; @@ -131,7 +131,7 @@ mda_expand_token(char *dest, size_t len, const char *token, else if (!strcasecmp("dest", rtoken)) { if (snprintf(tmp, sizeof tmp, "%s@%s", dlv->dest.user, dlv->dest.domain) >= (int)sizeof tmp) - return 0; + return -1; if (strcmp(tmp, "@") == 0) (void)strlcpy(tmp, "", sizeof tmp); string = tmp; @@ -161,17 +161,17 @@ mda_expand_token(char *dest, size_t len, const char *token, else if (!strcasecmp("mbox.from", rtoken)) { if (snprintf(tmp, sizeof tmp, "%s@%s", dlv->sender.user, dlv->sender.domain) >= (int)sizeof tmp) - return 0; + return -1; if (strcmp(tmp, "@") == 0) (void)strlcpy(tmp, "MAILER-DAEMON", sizeof tmp); string = tmp; } else - return 0; + return -1; if (string != tmp) { if (strlcpy(tmp, string, sizeof tmp) >= sizeof tmp) - return 0; + return -1; string = tmp; } @@ -187,12 +187,12 @@ mda_expand_token(char *dest, size_t len, const char *token, break; } if (!token_modifiers[i].f(tmp, sizeof tmp)) - return 0; /* modifier error */ + return -1; /* modifier error */ break; } } if ((size_t)i == nitems(token_modifiers)) - return 0; /* modifier not found */ + return -1; /* modifier not found */ } while ((mods = sep) != NULL); } @@ -208,7 +208,7 @@ mda_expand_token(char *dest, size_t len, const char *token, /* begin offset beyond end of string */ if (begoff >= i) - return 0; + return -1; /* end offset beyond end of string, make it end of string */ if (endoff >= i) @@ -225,13 +225,13 @@ mda_expand_token(char *dest, size_t len, const char *token, /* check that final offsets are valid */ if (begoff < 0 || endoff < 0 || endoff < begoff) - return 0; + return -1; endoff += 1; /* end offset is inclusive */ /* check that substring does not exceed destination buffer length */ i = endoff - begoff; if ((size_t)i + 1 >= len) - return 0; + return -1; string += begoff; for (; i; i--) { @@ -244,19 +244,19 @@ mda_expand_token(char *dest, size_t len, const char *token, } -size_t +ssize_t mda_expand_format(char *buf, size_t len, const struct deliver *dlv, const struct userinfo *ui, const char *mda_command) { char tmpbuf[EXPAND_BUFFER], *ptmp, *pbuf, *ebuf; char exptok[EXPAND_BUFFER]; - size_t exptoklen; + ssize_t exptoklen; char token[MAXTOKENLEN]; size_t ret, tmpret; if (len < sizeof tmpbuf) { log_warnx("mda_expand_format: tmp buffer < rule buffer"); - return 0; + return -1; } memset(tmpbuf, 0, sizeof tmpbuf); @@ -308,12 +308,12 @@ mda_expand_format(char *buf, size_t len, const struct deliver *dlv, exptoklen = mda_expand_token(exptok, sizeof exptok, token, dlv, ui, mda_command); - if (exptoklen == 0) - return 0; + if (exptoklen == -1) + return -1; /* writing expanded token at ptmp will overflow tmpbuf */ - if (sizeof (tmpbuf) - (ptmp - tmpbuf) <= exptoklen) - return 0; + if (sizeof (tmpbuf) - (ptmp - tmpbuf) <= (size_t)exptoklen) + return -1; memcpy(ptmp, exptok, exptoklen); pbuf = ebuf + 1; @@ -321,10 +321,10 @@ mda_expand_format(char *buf, size_t len, const struct deliver *dlv, tmpret = exptoklen; } if (ret >= sizeof tmpbuf) - return 0; + return -1; if ((ret = strlcpy(buf, tmpbuf, len)) >= len) - return 0; + return -1; return ret; } diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index a653888f4e1..0ea27ea86a6 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.576 2018/12/06 12:09:50 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.577 2018/12/06 12:32:11 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -1352,7 +1352,7 @@ void mda_unpriv(struct dispatcher *, struct deliver *, const char *, const char /* mda_variables.c */ -size_t mda_expand_format(char *, size_t, const struct deliver *, +ssize_t mda_expand_format(char *, size_t, const struct deliver *, const struct userinfo *, const char *); |