diff options
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/control.c | 41 | ||||
-rw-r--r-- | usr.sbin/smtpd/parser.c | 9 | ||||
-rw-r--r-- | usr.sbin/smtpd/parser.h | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/runner.c | 61 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpctl.c | 29 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 9 |
6 files changed, 129 insertions, 23 deletions
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c index dae67ae6aae..53d94339755 100644 --- a/usr.sbin/smtpd/control.c +++ b/usr.sbin/smtpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.45 2010/01/03 14:37:37 chl Exp $ */ +/* $OpenBSD: control.c,v 1.46 2010/01/10 16:42:35 gilles Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -363,6 +363,27 @@ control_dispatch_ext(int fd, short event, void *arg) imsg_compose_event(env->sc_ievs[PROC_RUNNER], IMSG_RUNNER_SCHEDULE, 0, 0, -1, s, sizeof(*s)); break; } + + case IMSG_RUNNER_REMOVE: { + struct remove *s = imsg.data; + + if (euid) + goto badcred; + + if (IMSG_DATA_SIZE(&imsg) != sizeof(*s)) + goto badcred; + + s->fd = fd; + + if (! valid_message_id(s->mid) && ! valid_message_uid(s->mid)) { + imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1, + NULL, 0); + break; + } + + imsg_compose_event(env->sc_ievs[PROC_RUNNER], IMSG_RUNNER_REMOVE, 0, 0, -1, s, sizeof(*s)); + break; + } /* case IMSG_CONF_RELOAD: { struct reload r; @@ -766,6 +787,24 @@ control_dispatch_runner(int sig, short event, void *p) imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0); break; } + case IMSG_RUNNER_REMOVE: { + struct remove *s = imsg.data; + struct ctl_conn *c; + + IMSG_SIZE_CHECK(s); + + if ((c = control_connbyfd(s->fd)) == NULL) { + log_warn("control_dispatch_runner: fd %d not found", s->fd); + imsg_free(&imsg); + return; + } + + if (s->ret) + imsg_compose_event(&c->iev, IMSG_CTL_OK, 0, 0, -1, NULL, 0); + else + imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0); + break; + } default: log_warnx("control_dispatch_runner: got imsg %d", imsg.hdr.type); diff --git a/usr.sbin/smtpd/parser.c b/usr.sbin/smtpd/parser.c index e76e63f0295..055ba67d07f 100644 --- a/usr.sbin/smtpd/parser.c +++ b/usr.sbin/smtpd/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.10 2010/01/03 14:37:37 chl Exp $ */ +/* $OpenBSD: parser.c,v 1.11 2010/01/10 16:42:35 gilles Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -61,6 +61,7 @@ static const struct token t_show[]; static const struct token t_pause[]; static const struct token t_resume[]; static const struct token t_schedule[]; +static const struct token t_remove[]; static const struct token t_log[]; static const struct token t_main[] = { @@ -71,6 +72,7 @@ static const struct token t_main[] = { {KEYWORD, "resume", NONE, t_resume}, {KEYWORD, "stop", SHUTDOWN, NULL}, {KEYWORD, "schedule", SCHEDULE, t_schedule}, + {KEYWORD, "remove", REMOVE, t_remove}, {KEYWORD, "log", NONE, t_log}, {ENDTOKEN, "", NONE, NULL} }; @@ -101,6 +103,11 @@ static const struct token t_schedule[] = { {ENDTOKEN, "", NONE, NULL} }; +static const struct token t_remove[] = { + {VARIABLE, "message id/uid", REMOVE, NULL}, + {ENDTOKEN, "", NONE, NULL} +}; + static const struct token t_log[] = { {KEYWORD, "verbose", LOG_VERBOSE, NULL}, {KEYWORD, "brief", LOG_BRIEF, NULL}, diff --git a/usr.sbin/smtpd/parser.h b/usr.sbin/smtpd/parser.h index 39f0a7b74ad..5a9b56c9c04 100644 --- a/usr.sbin/smtpd/parser.h +++ b/usr.sbin/smtpd/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.9 2010/01/03 14:37:37 chl Exp $ */ +/* $OpenBSD: parser.h,v 1.10 2010/01/10 16:42:35 gilles Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -22,6 +22,7 @@ enum actions { RELOAD, MONITOR, SCHEDULE, + REMOVE, LOG_VERBOSE, LOG_BRIEF, SHOW_QUEUE, diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c index 4f541e5978e..a2f9b1ac808 100644 --- a/usr.sbin/smtpd/runner.c +++ b/usr.sbin/smtpd/runner.c @@ -1,4 +1,4 @@ -/* $OpenBSD: runner.c,v 1.77 2010/01/03 14:37:37 chl Exp $ */ +/* $OpenBSD: runner.c,v 1.78 2010/01/10 16:42:35 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -83,6 +83,9 @@ struct batch *batch_lookup(struct smtpd *, struct message *); int runner_force_envelope_schedule(char *); int runner_force_message_schedule(char *); +int runner_force_envelope_remove(char *); +int runner_force_message_remove(char *); + void runner_sig_handler(int sig, short event, void *p) { @@ -214,6 +217,20 @@ runner_dispatch_control(int sig, short event, void *p) imsg_compose_event(iev, IMSG_RUNNER_SCHEDULE, 0, 0, -1, s, sizeof(*s)); break; } + case IMSG_RUNNER_REMOVE: { + struct remove *s = imsg.data; + + IMSG_SIZE_CHECK(s); + + s->ret = 0; + if (valid_message_uid(s->mid)) + s->ret = runner_force_envelope_remove(s->mid); + else if (valid_message_id(s->mid)) + s->ret = runner_force_message_remove(s->mid); + + imsg_compose_event(iev, IMSG_RUNNER_REMOVE, 0, 0, -1, s, sizeof(*s)); + break; + } default: log_warnx("runner_dispatch_control: got imsg %d", imsg.hdr.type); @@ -930,6 +947,48 @@ runner_force_message_schedule(char *mid) return 1; } + +int +runner_force_envelope_remove(char *mid) +{ + struct message message; + + if (! queue_load_envelope(&message, mid)) + return 0; + + if (! message.flags & (F_MESSAGE_PROCESSING|F_MESSAGE_SCHEDULED)) + return 0; + + if (! queue_remove_envelope(&message)) + return 0; + + return 1; +} + +int +runner_force_message_remove(char *mid) +{ + char path[MAXPATHLEN]; + DIR *dirp; + struct dirent *dp; + + if (! bsnprintf(path, MAXPATHLEN, "%s/%d/%s/envelopes", + PATH_QUEUE, queue_hash(mid), mid)) + return 0; + + dirp = opendir(path); + if (dirp == NULL) + return 0; + + while ((dp = readdir(dirp)) != NULL) { + if (valid_message_uid(dp->d_name)) + runner_force_envelope_remove(dp->d_name); + } + closedir(dirp); + + return 1; +} + void runner_purge_run(void) { diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c index 93d32fd13a5..c81e9da9ce0 100644 --- a/usr.sbin/smtpd/smtpctl.c +++ b/usr.sbin/smtpd/smtpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpctl.c,v 1.45 2010/01/03 14:37:37 chl Exp $ */ +/* $OpenBSD: smtpctl.c,v 1.46 2010/01/10 16:42:35 gilles Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -48,23 +48,6 @@ __dead void usage(void); int show_command_output(struct imsg*); int show_stats_output(struct imsg *); -/* -struct imsgname { - int type; - char *name; - void (*func)(struct imsg *); -}; - -struct imsgname imsgs[] = { - { IMSG_CTL_SHUTDOWN, "stop", NULL }, - { IMSG_CONF_RELOAD, "reload", NULL }, - { 0, NULL, NULL } -}; -struct imsgname imsgunknown = { - -1, "<unknown>", NULL -}; -*/ - int proctype; struct imsgbuf *ibuf; @@ -189,6 +172,15 @@ connected: imsg_compose(ibuf, IMSG_RUNNER_SCHEDULE, 0, 0, -1, &s, sizeof (s)); break; } + case REMOVE: { + struct remove s; + + s.fd = -1; + bzero(s.mid, sizeof (s.mid)); + strlcpy(s.mid, res->data, sizeof (s.mid)); + imsg_compose(ibuf, IMSG_RUNNER_REMOVE, 0, 0, -1, &s, sizeof (s)); + break; + } case MONITOR: /* XXX */ break; @@ -224,6 +216,7 @@ connected: /* case RELOAD:*/ case SHUTDOWN: case SCHEDULE: + case REMOVE: case PAUSE_MDA: case PAUSE_MTA: case PAUSE_SMTP: diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 8b1fe8bdba1..7e7c4fee1e9 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.167 2010/01/03 14:37:37 chl Exp $ */ +/* $OpenBSD: smtpd.h,v 1.168 2010/01/10 16:42:35 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -157,6 +157,7 @@ enum imsg_type { IMSG_RUNNER_UPDATE_ENVELOPE, IMSG_RUNNER_STATS, IMSG_RUNNER_SCHEDULE, + IMSG_RUNNER_REMOVE, IMSG_BATCH_CREATE, IMSG_BATCH_APPEND, @@ -700,6 +701,12 @@ struct sched { int ret; }; +struct remove { + int fd; + char mid[MAX_ID_SIZE]; + int ret; +}; + struct reload { int fd; int ret; |