diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2013-01-28 11:09:54 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2013-01-28 11:09:54 +0000 |
commit | b97566628d975a6e56cc36855b136476f7a78c41 (patch) | |
tree | 28fba00b6a3fabbf5db13569e27513f0bbc29592 | |
parent | 2a154b9855cdf3974923e42aca27c54c9d31b215 (diff) |
- introduce 'smtpctl trace lookup' to trace lookup process
- improve logging of the transfer process
trace by me, logging by eric
-rw-r--r-- | usr.sbin/smtpd/lka.c | 16 | ||||
-rw-r--r-- | usr.sbin/smtpd/lka_session.c | 48 | ||||
-rw-r--r-- | usr.sbin/smtpd/mta.c | 7 | ||||
-rw-r--r-- | usr.sbin/smtpd/mta_session.c | 25 | ||||
-rw-r--r-- | usr.sbin/smtpd/parser.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/parser.h | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpctl.8 | 6 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpctl.c | 10 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 11 |
10 files changed, 81 insertions, 54 deletions
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c index 3ce7406ec0f..5d79e9b9809 100644 --- a/usr.sbin/smtpd/lka.c +++ b/usr.sbin/smtpd/lka.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka.c,v 1.147 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: lka.c,v 1.148 2013/01/28 11:09:53 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -661,8 +661,7 @@ lka_authenticate(const char *tablename, const char *user, const char *password) struct credentials *creds; int r; - log_debug("debug: lka: authenticating for %s:%s", tablename, user); - + log_trace(TRACE_LOOKUP, "lookup: authenticating for %s:%s", tablename, user); table = table_findbyname(tablename); if (table == NULL) { log_warnx("warn: could not find table %s needed for authentication", @@ -738,8 +737,7 @@ lka_userinfo(const char *tablename, const char *username, struct userinfo *res) struct userinfo *info; struct table *table; - log_debug("debug: looking up userinfo %s:%s", tablename, username); - + log_trace(TRACE_LOOKUP, "lookup: userinfo %s:%s", tablename, username); table = table_findbyname(tablename); if (table == NULL) { log_warnx("warn: cannot find user table %s", tablename); @@ -770,8 +768,7 @@ lka_addrname(const char *tablename, const struct sockaddr *sa, source = sa_to_text(sa); - log_debug("debug: looking up helo %s:%s", tablename, source); - + log_trace(TRACE_LOOKUP, "lookup: helo %s:%s", tablename, source); table = table_findbyname(tablename); if (table == NULL) { log_warnx("warn: cannot find helo table %s", tablename); @@ -830,9 +827,8 @@ lka_X509_verify(struct ca_vrfy_req_msg *vrfy, x509_tmp = x509_tmp2 = NULL; } } - if (! ca_X509_verify(x509, x509_chain, CAfile, NULL, &errstr)) { - log_debug("debug: lka_X509_verify: failure: %s", errstr); - } + if (! ca_X509_verify(x509, x509_chain, CAfile, NULL, &errstr)) + log_trace(TRACE_LOOKUP, "lookup: X509 verify: %s", errstr); else ret = 1; diff --git a/usr.sbin/smtpd/lka_session.c b/usr.sbin/smtpd/lka_session.c index e044c23042c..5b4f09fcf53 100644 --- a/usr.sbin/smtpd/lka_session.c +++ b/usr.sbin/smtpd/lka_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka_session.c,v 1.51 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: lka_session.c,v 1.52 2013/01/28 11:09:53 gilles Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@poolp.org> @@ -114,14 +114,14 @@ lka_session_forward_reply(struct forward_req *fwreq, int fd) switch (fwreq->status) { case 0: /* permanent failure while lookup ~/.forward */ - log_debug("debug: lka: opening .forward failed for user %s", + log_trace(TRACE_LOOKUP, "lookup: ~/.forward failed for user %s", fwreq->user); lks->error = LKA_PERMFAIL; break; case 1: if (fd == -1) { - log_debug("debug: lka: no .forward for user %s, just deliver", - fwreq->user); + log_trace(TRACE_LOOKUP, "lookup: no .forward for " + "user %s, just deliver", fwreq->user); lka_submit(lks, rule, xn); } else { @@ -132,8 +132,8 @@ lka_session_forward_reply(struct forward_req *fwreq, int fd) /* forwards_get() will close the descriptor no matter what */ if (! forwards_get(fd, &lks->expand)) { - log_debug("debug: lka: temporary forward error for user %s", - fwreq->user); + log_trace(TRACE_LOOKUP, "lookup: temporary " + "forward error for user %s", fwreq->user); lks->error = LKA_TEMPFAIL; } } @@ -167,7 +167,8 @@ lka_resume(struct lka_session *lks) /* delivery list is empty, reject */ if (TAILQ_FIRST(&lks->deliverylist) == NULL) { - log_debug("debug: lka_done: expanded to empty delivery list"); + log_trace(TRACE_LOOKUP, "lookup: lka_done: expanded to empty " + "delivery list"); lks->error = LKA_PERMFAIL; } error: @@ -213,7 +214,7 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) struct userinfo *tu = NULL; if (xn->depth >= EXPAND_DEPTH) { - log_debug("debug: lka_expand: node too deep."); + log_trace(TRACE_LOOKUP, "lookup: lka_expand: node too deep."); lks->error = LKA_PERMFAIL; return; } @@ -225,7 +226,9 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) break; case EXPAND_ADDRESS: - log_debug("debug: lka_expand: address: %s@%s [depth=%d]", + + log_trace(TRACE_LOOKUP, "lookup: lka_expand: address: %s@%s " + "[depth=%d]", xn->u.mailaddr.user, xn->u.mailaddr.domain, xn->depth); /* Pass the node through the ruleset */ @@ -252,12 +255,12 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) &lks->expand, &xn->u.mailaddr); if (r == -1) { lks->error = LKA_TEMPFAIL; - log_debug("debug: lka_expand: " + log_trace(TRACE_LOOKUP, "lookup: lka_expand: " "error in virtual alias lookup"); } else if (r == 0) { lks->error = LKA_PERMFAIL; - log_debug("debug: lka_expand: " + log_trace(TRACE_LOOKUP, "lookup: lka_expand: " "no aliases for virtual"); } } @@ -274,11 +277,12 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) break; case EXPAND_USERNAME: - log_debug("debug: lka_expand: username: %s [depth=%d]", - xn->u.user, xn->depth); + log_trace(TRACE_LOOKUP, "lookup: lka_expand: username: %s " + "[depth=%d]", xn->u.user, xn->depth); if (xn->sameuser) { - log_debug("debug: lka_expand: same user, submitting"); + log_trace(TRACE_LOOKUP, "lookup: lka_expand: same " + "user, submitting"); lka_submit(lks, rule, xn); break; } @@ -291,7 +295,7 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) r = aliases_get(rule->r_mapping, &lks->expand, xn->u.user); if (r == -1) { - log_debug("debug: lka_expand: " + log_trace(TRACE_LOOKUP, "lookup: lka_expand: " "error in alias lookup"); lks->error = LKA_TEMPFAIL; } @@ -301,7 +305,7 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) /* A username should not exceed the size of a system user */ if (strlen(xn->u.user) >= sizeof fwreq.user) { - log_debug("debug: lka_expand: " + log_trace(TRACE_LOOKUP, "lookup: lka_expand: " "user-part too long to be a system user"); lks->error = LKA_PERMFAIL; break; @@ -309,13 +313,13 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) r = table_lookup(rule->r_users, xn->u.user, K_USERINFO, (void **)&tu); if (r == -1) { - log_debug("debug: lka_expand: " + log_trace(TRACE_LOOKUP, "lookup: lka_expand: " "backend error while searching user"); lks->error = LKA_TEMPFAIL; break; } if (r == 0) { - log_debug("debug: lka_expand: " + log_trace(TRACE_LOOKUP, "lookup: lka_expand: " "user-part does not match system user"); lks->error = LKA_PERMFAIL; break; @@ -336,14 +340,14 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn) break; case EXPAND_FILENAME: - log_debug("debug: lka_expand: filename: %s [depth=%d]", - xn->u.buffer, xn->depth); + log_trace(TRACE_LOOKUP, "lookup: lka_expand: filename: %s " + "[depth=%d]", xn->u.buffer, xn->depth); lka_submit(lks, rule, xn); break; case EXPAND_FILTER: - log_debug("debug: lka_expand: filter: %s [depth=%d]", - xn->u.buffer, xn->depth); + log_trace(TRACE_LOOKUP, "lookup: lka_expand: filter: %s " + "[depth=%d]", xn->u.buffer, xn->depth); lka_submit(lks, rule, xn); break; } diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c index 881ac1bb42f..2e740692513 100644 --- a/usr.sbin/smtpd/mta.c +++ b/usr.sbin/smtpd/mta.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta.c,v 1.149 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: mta.c,v 1.150 2013/01/28 11:09:53 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -491,16 +491,13 @@ mta_source_error(struct mta_relay *relay, struct mta_route *route, const char *e * Also, we need a timeout on that. */ void -mta_route_error(struct mta_relay *relay, struct mta_route *route, const char *e) +mta_route_error(struct mta_relay *relay, struct mta_route *route) { route->dst->nerror++; if (route->dst->flags & HOST_IGNORE) return; - log_info("smtp-out: Error on route %s: %s", - mta_route_to_text(route), e); - if (route->dst->nerror > MAXERROR_PER_HOST) { log_info("smtp-out: Too many errors on host %s: ignoring this MX", mta_host_to_text(route->dst)); diff --git a/usr.sbin/smtpd/mta_session.c b/usr.sbin/smtpd/mta_session.c index cb253ebd458..be5a3c89a0e 100644 --- a/usr.sbin/smtpd/mta_session.c +++ b/usr.sbin/smtpd/mta_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mta_session.c,v 1.27 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: mta_session.c,v 1.28 2013/01/28 11:09:53 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -443,8 +443,10 @@ mta_connect(struct mta_session *s) schema = "smtps://"; else schema = "smtp://"; - log_debug("debug: mta: %p: connecting to %s%s:%i (%s)", - s, schema, sa_to_text(sa), portno, s->route->dst->ptrname); + + log_info("smtp-out: Connecting to %s%s:%i (%s) on session" + " %016"PRIx64"...", schema, sa_to_text(s->route->dst->sa), + portno, s->route->dst->ptrname, s->id); mta_enter_state(s, MTA_INIT); iobuf_xinit(&s->iobuf, 0, 0, "mta_connect"); @@ -794,8 +796,8 @@ mta_io(struct io *io, int evt) schema = "smtps://"; else schema = "smtp://"; - log_debug("debug: mta: %p: connected to %s%s (%s)", - s, schema, sa_to_text(s->route->dst->sa), s->route->dst->ptrname); + + log_info("smtp-out: Connected on session %016"PRIx64, s->id); if (s->use_smtps) { io_set_write(io); @@ -867,6 +869,9 @@ mta_io(struct io *io, int evt) goto nextline; if (s->state == MTA_QUIT) { + log_info("smtp-out: Closing session %016"PRIx64 + ": %i message%s sent.", s->id, s->msgcount, + (s->msgcount > 1) ? "s" : ""); mta_free(s); return; } @@ -1031,7 +1036,15 @@ mta_error(struct mta_session *s, const char *fmt, ...) fatal("mta: vasprintf"); va_end(ap); - mta_route_error(s->relay, s->route, error); + if (s->msgcount) + log_info("smtp-out: Error on session %016"PRIx64 + " after %i message%s sent: %s", s->id, s->msgcount, + (s->msgcount > 1) ? "s" : "", error); + else + log_info("smtp-out: Error on session %016"PRIx64 ": %s", + s->id, error); + + mta_route_error(s->relay, s->route); if (s->task) mta_flush_task(s, IMSG_DELIVERY_TEMPFAIL, error); diff --git a/usr.sbin/smtpd/parser.c b/usr.sbin/smtpd/parser.c index 0765f595410..5ed8250638d 100644 --- a/usr.sbin/smtpd/parser.c +++ b/usr.sbin/smtpd/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.31 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: parser.c,v 1.32 2013/01/28 11:09:53 gilles Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -146,6 +146,7 @@ static const struct token t_trace[] = { {KEYWORD, "transfer", LOG_TRACE_MTA, NULL}, {KEYWORD, "bounce", LOG_TRACE_BOUNCE, NULL}, {KEYWORD, "scheduler", LOG_TRACE_SCHEDULER, NULL}, + {KEYWORD, "lookup", LOG_TRACE_LOOKUP, NULL}, {KEYWORD, "stat", LOG_TRACE_STAT, NULL}, {KEYWORD, "rules", LOG_TRACE_RULES, NULL}, {KEYWORD, "msg-size", LOG_TRACE_IMSG_SIZE, NULL}, @@ -161,6 +162,7 @@ static const struct token t_untrace[] = { {KEYWORD, "transfer", LOG_UNTRACE_MTA, NULL}, {KEYWORD, "bounce", LOG_UNTRACE_BOUNCE, NULL}, {KEYWORD, "scheduler", LOG_UNTRACE_SCHEDULER, NULL}, + {KEYWORD, "lookup", LOG_UNTRACE_LOOKUP, NULL}, {KEYWORD, "stat", LOG_UNTRACE_STAT, NULL}, {KEYWORD, "rules", LOG_UNTRACE_RULES, NULL}, {KEYWORD, "msg-size", LOG_UNTRACE_IMSG_SIZE, NULL}, diff --git a/usr.sbin/smtpd/parser.h b/usr.sbin/smtpd/parser.h index a87d96a4181..3d90d02ea56 100644 --- a/usr.sbin/smtpd/parser.h +++ b/usr.sbin/smtpd/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.24 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: parser.h,v 1.25 2013/01/28 11:09:53 gilles Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -43,6 +43,7 @@ enum actions { LOG_TRACE_MTA, LOG_TRACE_BOUNCE, LOG_TRACE_SCHEDULER, + LOG_TRACE_LOOKUP, LOG_TRACE_STAT, LOG_TRACE_RULES, LOG_TRACE_IMSG_SIZE, @@ -54,6 +55,7 @@ enum actions { LOG_UNTRACE_MTA, LOG_UNTRACE_BOUNCE, LOG_UNTRACE_SCHEDULER, + LOG_UNTRACE_LOOKUP, LOG_UNTRACE_STAT, LOG_UNTRACE_RULES, LOG_UNTRACE_IMSG_SIZE, diff --git a/usr.sbin/smtpd/smtpctl.8 b/usr.sbin/smtpd/smtpctl.8 index 2cfa7138234..926946332b6 100644 --- a/usr.sbin/smtpd/smtpctl.8 +++ b/usr.sbin/smtpd/smtpctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: smtpctl.8,v 1.38 2013/01/26 14:13:25 jmc Exp $ +.\" $OpenBSD: smtpctl.8,v 1.39 2013/01/28 11:09:53 gilles Exp $ .\" .\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> .\" Copyright (c) 2012 Gilles Chehade <gilles@poolp.org> @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 26 2013 $ +.Dd $Mdocdate: January 28 2013 $ .Dt SMTPCTL 8 .Os .Sh NAME @@ -180,6 +180,8 @@ bounce .It scheduler .It +lookup (aliases/virtual/forward expansion) +.It stat .It rules (matched by incoming sessions) diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c index 8c6992750c9..cc218ee9155 100644 --- a/usr.sbin/smtpd/smtpctl.c +++ b/usr.sbin/smtpd/smtpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpctl.c,v 1.99 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: smtpctl.c,v 1.100 2013/01/28 11:09:53 gilles Exp $ */ /* * Copyright (c) 2006 Gilles Chehade <gilles@poolp.org> @@ -306,6 +306,7 @@ main(int argc, char *argv[]) case LOG_TRACE_MTA: case LOG_TRACE_BOUNCE: case LOG_TRACE_SCHEDULER: + case LOG_TRACE_LOOKUP: case LOG_TRACE_STAT: case LOG_TRACE_RULES: case LOG_TRACE_IMSG_SIZE: @@ -323,6 +324,7 @@ main(int argc, char *argv[]) case LOG_UNTRACE_MTA: case LOG_UNTRACE_BOUNCE: case LOG_UNTRACE_SCHEDULER: + case LOG_UNTRACE_LOOKUP: case LOG_UNTRACE_STAT: case LOG_UNTRACE_RULES: case LOG_UNTRACE_IMSG_SIZE: @@ -376,6 +378,7 @@ main(int argc, char *argv[]) case LOG_TRACE_MTA: case LOG_TRACE_BOUNCE: case LOG_TRACE_SCHEDULER: + case LOG_TRACE_LOOKUP: case LOG_TRACE_STAT: case LOG_TRACE_RULES: case LOG_TRACE_IMSG_SIZE: @@ -387,6 +390,7 @@ main(int argc, char *argv[]) case LOG_UNTRACE_MTA: case LOG_UNTRACE_BOUNCE: case LOG_UNTRACE_SCHEDULER: + case LOG_UNTRACE_LOOKUP: case LOG_UNTRACE_STAT: case LOG_UNTRACE_RULES: case LOG_UNTRACE_IMSG_SIZE: @@ -846,6 +850,10 @@ trace_convert(uint32_t trace) case LOG_UNTRACE_SCHEDULER: return TRACE_SCHEDULER; + case LOG_TRACE_LOOKUP: + case LOG_UNTRACE_LOOKUP: + return TRACE_LOOKUP; + case LOG_TRACE_STAT: case LOG_UNTRACE_STAT: return TRACE_STAT; diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index 272c7018f3d..cb294174f1d 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.184 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: smtpd.c,v 1.185 2013/01/28 11:09:53 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -652,6 +652,8 @@ main(int argc, char *argv[]) verbose |= TRACE_BOUNCE; else if (!strcmp(optarg, "scheduler")) verbose |= TRACE_SCHEDULER; + else if (!strcmp(optarg, "lookup")) + verbose |= TRACE_LOOKUP; else if (!strcmp(optarg, "stat")) verbose |= TRACE_STAT; else if (!strcmp(optarg, "rules")) diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 97fab2d30ca..186265be527 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.398 2013/01/26 09:37:23 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.399 2013/01/28 11:09:53 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -577,9 +577,10 @@ struct smtpd { #define TRACE_MTA 0x0020 #define TRACE_BOUNCE 0x0040 #define TRACE_SCHEDULER 0x0080 -#define TRACE_STAT 0x0100 -#define TRACE_RULES 0x0200 -#define TRACE_IMSGSIZE 0x0400 +#define TRACE_LOOKUP 0x0100 +#define TRACE_STAT 0x0200 +#define TRACE_RULES 0x0400 +#define TRACE_IMSGSIZE 0x0800 #define PROFILE_TOSTAT 0x0001 #define PROFILE_IMSG 0x0002 @@ -1189,7 +1190,7 @@ void m_get_envelope(struct msg *, struct envelope *); /* mta.c */ pid_t mta(void); void mta_route_ok(struct mta_relay *, struct mta_route *); -void mta_route_error(struct mta_relay *, struct mta_route *, const char *); +void mta_route_error(struct mta_relay *, struct mta_route *); void mta_route_collect(struct mta_relay *, struct mta_route *); void mta_source_error(struct mta_relay *, struct mta_route *, const char *); void mta_delivery(struct envelope *, const char *, int, const char *); |