diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2012-10-10 19:39:12 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2012-10-10 19:39:12 +0000 |
commit | 91b1663a227f50b0e2e3a33752e6a2a2ed57e4ef (patch) | |
tree | bb6e65be42a2ecea51b0f1b40a8ebe42a6dab305 /usr.sbin/smtpd | |
parent | 4881fc2ea8c947fb0e71efc909f73db75e1e91c1 (diff) |
teach smtpctl how to display envelopes and messages using their id.
this allows an admin to inspect the queue without having to manually
extract bucket and find the path to an envelope or message.
diff by Sunil Nimmagadda <sunil@poolp.org>
ok eric@, chl@ and I
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/parser.c | 16 | ||||
-rw-r--r-- | usr.sbin/smtpd/parser.h | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpctl.8 | 8 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpctl.c | 79 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/util.c | 19 |
6 files changed, 112 insertions, 17 deletions
diff --git a/usr.sbin/smtpd/parser.c b/usr.sbin/smtpd/parser.c index ca18395157e..6c61abfdd20 100644 --- a/usr.sbin/smtpd/parser.c +++ b/usr.sbin/smtpd/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.27 2012/08/30 22:06:00 gilles Exp $ */ +/* $OpenBSD: parser.c,v 1.28 2012/10/10 19:39:11 gilles Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -54,6 +54,8 @@ static const struct token t_pause[]; static const struct token t_remove[]; static const struct token t_resume[]; static const struct token t_log[]; +static const struct token t_show_envelope[]; +static const struct token t_show_message[]; static const struct token t_main[] = { {KEYWORD, "schedule-id", NONE, t_schedule_id}, @@ -81,6 +83,18 @@ static const struct token t_schedule_id[] = { static const struct token t_show[] = { {KEYWORD, "queue", SHOW_QUEUE, NULL}, {KEYWORD, "stats", SHOW_STATS, NULL}, + {KEYWORD, "envelope", NONE, t_show_envelope}, + {KEYWORD, "message", SHOW_MESSAGE, t_show_message}, + {ENDTOKEN, "", NONE, NULL} +}; + +static const struct token t_show_envelope[] = { + {VARIABLE, "evpid", SHOW_ENVELOPE, NULL}, + {ENDTOKEN, "", NONE, NULL} +}; + +static const struct token t_show_message[] = { + {VARIABLE, "evpid", SHOW_MESSAGE, NULL}, {ENDTOKEN, "", NONE, NULL} }; diff --git a/usr.sbin/smtpd/parser.h b/usr.sbin/smtpd/parser.h index 31a9780f3ea..c6fb452a8dc 100644 --- a/usr.sbin/smtpd/parser.h +++ b/usr.sbin/smtpd/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.21 2012/08/30 22:06:00 gilles Exp $ */ +/* $OpenBSD: parser.h,v 1.22 2012/10/10 19:39:11 gilles Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -27,6 +27,8 @@ enum actions { SHOW_QUEUE, SHOW_STATS, SHOW_SIZES, + SHOW_ENVELOPE, + SHOW_MESSAGE, PAUSE_MDA, PAUSE_MTA, PAUSE_SMTP, diff --git a/usr.sbin/smtpd/smtpctl.8 b/usr.sbin/smtpd/smtpctl.8 index e2ee4bee7ca..f74a9ad78a5 100644 --- a/usr.sbin/smtpd/smtpctl.8 +++ b/usr.sbin/smtpd/smtpctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: smtpctl.8,v 1.27 2012/04/07 14:11:11 jmc Exp $ +.\" $OpenBSD: smtpctl.8,v 1.28 2012/10/10 19:39:11 gilles Exp $ .\" .\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> .\" @@ -14,7 +14,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: April 7 2012 $ +.Dd $Mdocdate: October 10 2012 $ .Dt SMTPCTL 8 .Os .Sh NAME @@ -60,6 +60,10 @@ Marks all envelopes as ready for immediate delivery. .It Cm schedule-id Ar envelope-id | message-id Marks a single envelope, or all envelopes with the same message ID, as ready for immediate delivery. +.It Cm show envelope Ar envelope-id +Displays envelope's content for the given ID. +.It Cm show message Ar envelope-id +Displays message content for the given ID. .It Cm show queue Displays information concerning envelopes that are currently in a queue. diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c index 67148ec8443..4cca0dc058c 100644 --- a/usr.sbin/smtpd/smtpctl.c +++ b/usr.sbin/smtpd/smtpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpctl.c,v 1.91 2012/09/19 20:08:53 eric Exp $ */ +/* $OpenBSD: smtpctl.c,v 1.92 2012/10/10 19:39:11 gilles Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -42,6 +42,10 @@ #include "parser.h" #include "log.h" +#define PATH_CAT "/bin/cat" +#define PATH_GZCAT "/bin/gzcat" +#define PATH_QUEUE "/queue" + void usage(void); static void setup_env(struct smtpd *); static int show_command_output(struct imsg *); @@ -49,6 +53,9 @@ static void show_stats_output(void); static void show_queue(int); static void show_queue_envelope(struct envelope *, int); static void getflag(uint *, int, char *, char *, size_t); +static void display(const char *); +static void show_envelope(const char *); +static void show_message(const char *); int proctype; struct imsgbuf *ibuf; @@ -124,6 +131,12 @@ main(int argc, char *argv[]) case SHOW_QUEUE: show_queue(0); break; + case SHOW_ENVELOPE: + show_envelope(res->data); + break; + case SHOW_MESSAGE: + show_message(res->data); + break; default: goto connected; } @@ -161,17 +174,8 @@ connected: case SCHEDULE: case REMOVE: { uint64_t ulval; - char *ep; - - errno = 0; - ulval = strtoull(res->data, &ep, 16); - if (res->data[0] == '\0' || *ep != '\0') - errx(1, "invalid msgid/evpid"); - if (errno == ERANGE && ulval == ULLONG_MAX) - errx(1, "invalid msgid/evpid"); - if (ulval == 0) - errx(1, "invalid msgid/evpid"); + ulval = strtoevpid(res->data); if (res->action == SCHEDULE) imsg_compose(ibuf, IMSG_SCHEDULER_SCHEDULE, 0, 0, -1, &ulval, sizeof(ulval)); @@ -465,3 +469,56 @@ getflag(uint *bitmap, int bit, char *bitstr, char *buf, size_t len) strlcat(buf, ",", len); } } + +static void +display(const char *s) +{ + arglist args; + char *cmd; + + if (env->sc_queue_flags & QUEUE_COMPRESS) + cmd = PATH_GZCAT; + else + cmd = PATH_CAT; + + bzero(&args, sizeof(args)); + addargs(&args, "%s", cmd); + addargs(&args, "%s", s); + execvp(cmd, args.list); + errx(1, "execvp"); +} + +static void +show_envelope(const char *s) +{ + char buf[MAXPATHLEN]; + uint64_t evpid; + + evpid = strtoevpid(s); + if (! bsnprintf(buf, sizeof(buf), "%s%s/%02x/%08x%s/%016" PRIx64, + PATH_SPOOL, + PATH_QUEUE, + evpid_to_msgid(evpid) & 0xff, + evpid_to_msgid(evpid), + PATH_ENVELOPES, evpid)) + errx(1, "unable to retrieve envelope"); + + display(buf); +} + +static void +show_message(const char *s) +{ + char buf[MAXPATHLEN]; + uint32_t msgid; + + msgid = evpid_to_msgid(strtoevpid(s)); + if (! bsnprintf(buf, sizeof(buf), "%s%s/%02x/%08x/message", + PATH_SPOOL, + PATH_QUEUE, + msgid & 0xff, + msgid)) + errx(1, "unable to retrieve message"); + + display(buf); +} diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index eb2953ec413..782473adba2 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.383 2012/10/10 18:02:37 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.384 2012/10/10 19:39:11 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -1175,6 +1175,7 @@ void log_envelope(const struct envelope *, const char *, const char *); void session_socket_blockmode(int, enum blockmodes); void session_socket_no_linger(int); int session_socket_error(int); +uint64_t strtoevpid(const char *); /* waitq.c */ int waitq_wait(void *, void (*)(void *, void *, void *), void *); diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c index 54e1d575df0..5f00474ee21 100644 --- a/usr.sbin/smtpd/util.c +++ b/usr.sbin/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.86 2012/10/07 15:46:38 chl Exp $ */ +/* $OpenBSD: util.c,v 1.87 2012/10/10 19:39:11 gilles Exp $ */ /* * Copyright (c) 2000,2001 Markus Friedl. All rights reserved. @@ -1095,3 +1095,20 @@ log_envelope(const struct envelope *evp, const char *extra, const char *status) extra, status); } + +uint64_t +strtoevpid(const char *s) +{ + uint64_t ulval; + char *ep; + + errno = 0; + ulval = strtoull(s, &ep, 16); + if (s[0] == '\0' || *ep != '\0') + errx(1, "invalid msgid/evpid"); + if (errno == ERANGE && ulval == ULLONG_MAX) + errx(1, "invalid msgid/evpid"); + if (ulval == 0) + errx(1, "invalid msgid/evpid"); + return (ulval); +} |