summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/smtpd/mda.c26
-rw-r--r--usr.sbin/smtpd/mta.c13
-rw-r--r--usr.sbin/smtpd/mta_session.c15
-rw-r--r--usr.sbin/smtpd/queue.c15
-rw-r--r--usr.sbin/smtpd/smtpd.h3
-rw-r--r--usr.sbin/smtpd/util.c24
6 files changed, 44 insertions, 52 deletions
diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c
index 8dcaafbb314..b949a54c2ec 100644
--- a/usr.sbin/smtpd/mda.c
+++ b/usr.sbin/smtpd/mda.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mda.c,v 1.74 2012/09/20 09:27:49 eric Exp $ */
+/* $OpenBSD: mda.c,v 1.75 2012/09/21 12:33:32 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -55,10 +55,10 @@ static void
mda_imsg(struct imsgev *iev, struct imsg *imsg)
{
char output[128], *error, *parent_error;
+ char stat[MAX_LINE_SIZE];
struct deliver deliver;
struct mda_session *s;
struct delivery_mda *d_mda;
- struct mailaddr *maddr;
struct envelope *ep;
FILE *fp;
uint16_t msg;
@@ -215,30 +215,12 @@ mda_imsg(struct imsgev *iev, struct imsg *imsg)
if (error) {
msg = IMSG_QUEUE_DELIVERY_TEMPFAIL;
envelope_set_errormsg(&s->msg, "%s", error);
+ snprintf(stat, sizeof stat, "Error (%s)", error);
}
imsg_compose_event(env->sc_ievs[PROC_QUEUE], msg,
0, 0, -1, &s->msg, sizeof s->msg);
- /*
- * XXX: which struct path gets used for logging depends
- * on whether lka did aliases or .forward processing;
- * lka may need to be changed to present data in more
- * unified way.
- */
- if (s->msg.rule.r_action == A_MAILDIR ||
- s->msg.rule.r_action == A_MBOX)
- maddr = &s->msg.dest;
- else
- maddr = &s->msg.rcpt;
-
- /* log status */
- if (error && asprintf(&error, "Error (%s)", error) < 0)
- fatal("mda: asprintf");
- log_info("%016" PRIx64 ": to=<%s@%s>, delay=%s, stat=%s",
- s->msg.id, maddr->user, maddr->domain,
- duration_to_text(time(NULL) - s->msg.creation),
- error ? error : "Sent");
- free(error);
+ log_envelope(&s->msg, NULL, error ? stat : "Delivered");
/* destroy session */
LIST_REMOVE(s, entry);
diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c
index e0aa972fd2b..96592722e59 100644
--- a/usr.sbin/smtpd/mta.c
+++ b/usr.sbin/smtpd/mta.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mta.c,v 1.142 2012/09/18 14:23:01 eric Exp $ */
+/* $OpenBSD: mta.c,v 1.143 2012/09/21 12:33:32 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -516,15 +516,12 @@ mta_route_drain(struct mta_route *route)
static void
mta_envelope_done(struct mta_task *task, struct envelope *e, const char *status)
{
+ char relay[MAX_LINE_SIZE];
+
envelope_set_errormsg(e, "%s", status);
- log_info("%016" PRIx64 ": to=<%s@%s>, delay=%s, relay=%s, stat=%s (%s)",
- e->id, e->dest.user,
- e->dest.domain,
- duration_to_text(time(NULL) - e->creation),
- task->route->hostname,
- mta_response_status(e->errorline),
- mta_response_text(e->errorline));
+ snprintf(relay, sizeof relay, "relay=%s, ", task->route->hostname);
+ log_envelope(e, relay, e->errorline);
imsg_compose_event(env->sc_ievs[PROC_QUEUE],
mta_response_delivery(e->errorline), 0, 0, -1, e, sizeof(*e));
diff --git a/usr.sbin/smtpd/mta_session.c b/usr.sbin/smtpd/mta_session.c
index 3ca6fc0cf95..029ddbb6ef8 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.16 2012/09/11 16:24:28 eric Exp $ */
+/* $OpenBSD: mta_session.c,v 1.17 2012/09/21 12:33:32 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -853,18 +853,17 @@ mta_status(struct mta_session *s, int connerr, const char *fmt, ...)
static void
mta_envelope_done(struct mta_task *task, struct envelope *e, const char *status)
{
- struct mta_host *host = TAILQ_FIRST(&task->session->hosts);
+ struct mta_host *host = TAILQ_FIRST(&task->session->hosts);
+ char relay[MAX_LINE_SIZE], stat[MAX_LINE_SIZE];
envelope_set_errormsg(e, "%s", status);
- log_info("%016" PRIx64 ": to=<%s@%s>, delay=%s, relay=%s [%s], stat=%s (%s)",
- e->id, e->dest.user,
- e->dest.domain,
- duration_to_text(time(NULL) - e->creation),
- host->fqdn,
- ss_to_text(&host->sa),
+ snprintf(relay, sizeof relay, "relay=%s [%s], ",
+ host->fqdn, ss_to_text(&host->sa));
+ snprintf(stat, sizeof stat, "%s (%s)",
mta_response_status(e->errorline),
mta_response_text(e->errorline));
+ log_envelope(e, relay, stat);
imsg_compose_event(env->sc_ievs[PROC_QUEUE],
mta_response_delivery(e->errorline), 0, 0, -1, e, sizeof(*e));
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c
index 817c0910ec3..6713f8ffee0 100644
--- a/usr.sbin/smtpd/queue.c
+++ b/usr.sbin/smtpd/queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue.c,v 1.136 2012/09/19 18:20:36 eric Exp $ */
+/* $OpenBSD: queue.c,v 1.137 2012/09/21 12:33:32 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -146,12 +146,7 @@ queue_imsg(struct imsgev *iev, struct imsg *imsg)
id = *(uint64_t*)(imsg->data);
if (queue_envelope_load(id, &evp) == 0)
errx(1, "cannot load evp:%016" PRIx64, id);
- envelope_set_errormsg(&evp, "Removed by administrator");
- log_info("%016" PRIx64 ": to=<%s@%s>, delay=%s, stat=%s",
- evp.id, evp.dest.user,
- evp.dest.domain,
- duration_to_text(time(NULL) - evp.creation),
- evp.errorline);
+ log_envelope(&evp, NULL, "Removed by administrator");
queue_envelope_delete(&evp);
return;
@@ -160,12 +155,8 @@ queue_imsg(struct imsgev *iev, struct imsg *imsg)
if (queue_envelope_load(id, &evp) == 0)
errx(1, "cannot load evp:%016" PRIx64, id);
envelope_set_errormsg(&evp, "Envelope expired");
- log_info("%016" PRIx64 ": to=<%s@%s>, delay=%s, stat=%s",
- evp.id, evp.dest.user,
- evp.dest.domain,
- duration_to_text(time(NULL) - evp.creation),
- evp.errorline);
queue_bounce(&evp);
+ log_envelope(&evp, NULL, evp.errorline);
queue_envelope_delete(&evp);
return;
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index c2b55f48b81..add6f8220c1 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.362 2012/09/21 10:22:29 eric Exp $ */
+/* $OpenBSD: smtpd.h,v 1.363 2012/09/21 12:33:32 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -1203,3 +1203,4 @@ void *xmalloc(size_t, const char *);
void *xcalloc(size_t, size_t, const char *);
char *xstrdup(const char *, const char *);
void *xmemdup(const void *, size_t, const char *);
+void log_envelope(const struct envelope *, const char *, const char *);
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index 5e7d818bcc3..6f583396443 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.80 2012/09/21 10:22:29 eric Exp $ */
+/* $OpenBSD: util.c,v 1.81 2012/09/21 12:33:32 eric Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -1029,3 +1029,25 @@ temp_inet_net_pton_ipv6(const char *src, void *dst, size_t size)
return bits;
}
+
+void
+log_envelope(const struct envelope *evp, const char *extra, const char *status)
+{
+ char rcpt[MAX_LINE_SIZE];
+
+ rcpt[0] = '\0';
+ if (strcmp(evp->rcpt.user, evp->dest.user) ||
+ strcmp(evp->rcpt.domain, evp->dest.domain))
+ snprintf(rcpt, sizeof rcpt, "rcpt=<%s@%s>, ",
+ evp->rcpt.user, evp->rcpt.domain);
+
+ if (extra == NULL)
+ extra = "";
+
+ log_info("%016" PRIx64 ": to=<%s@%s>, %sdelay=%s, %sstat=%s",
+ evp->id, evp->dest.user, evp->dest.domain,
+ rcpt,
+ duration_to_text(time(NULL) - evp->creation),
+ extra,
+ status);
+}