summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/control.c4
-rw-r--r--usr.sbin/smtpd/queue.c11
-rw-r--r--usr.sbin/smtpd/queue_backend.c15
-rw-r--r--usr.sbin/smtpd/queue_fs.c47
-rw-r--r--usr.sbin/smtpd/smtpctl.86
-rw-r--r--usr.sbin/smtpd/smtpctl.c28
-rw-r--r--usr.sbin/smtpd/smtpd-api.h3
-rw-r--r--usr.sbin/smtpd/smtpd.c3
-rw-r--r--usr.sbin/smtpd/smtpd.h6
9 files changed, 112 insertions, 11 deletions
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c
index 2a0dec52f8c..3b8a41962cd 100644
--- a/usr.sbin/smtpd/control.c
+++ b/usr.sbin/smtpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.107 2015/10/29 10:25:36 sunil Exp $ */
+/* $OpenBSD: control.c,v 1.108 2015/11/05 09:14:31 sunil Exp $ */
/*
* Copyright (c) 2012 Gilles Chehade <gilles@poolp.org>
@@ -118,6 +118,7 @@ control_imsg(struct mproc *p, struct imsg *imsg)
case IMSG_CTL_LIST_ENVELOPES:
case IMSG_CTL_DISCOVER_EVPID:
case IMSG_CTL_DISCOVER_MSGID:
+ case IMSG_CTL_UNCORRUPT_MSGID:
c = tree_get(&ctl_conns, imsg->hdr.peerid);
if (c == NULL)
return;
@@ -811,6 +812,7 @@ control_dispatch_ext(struct mproc *p, struct imsg *imsg)
return;
case IMSG_CTL_DISCOVER_MSGID:
+ case IMSG_CTL_UNCORRUPT_MSGID:
if (c->euid)
goto badcred;
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c
index dbe12312660..4977994ffb8 100644
--- a/usr.sbin/smtpd/queue.c
+++ b/usr.sbin/smtpd/queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue.c,v 1.170 2015/10/29 10:25:36 sunil Exp $ */
+/* $OpenBSD: queue.c,v 1.171 2015/11/05 09:14:31 sunil Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -546,6 +546,15 @@ queue_imsg(struct mproc *p, struct imsg *imsg)
tv.tv_usec = 10;
evtimer_add(&wi->ev, &tv);
return;
+
+ case IMSG_CTL_UNCORRUPT_MSGID:
+ m_msg(&m, imsg);
+ m_get_msgid(&m, &msgid);
+ m_end(&m);
+ ret = queue_message_uncorrupt(msgid);
+ m_compose(p_control, imsg->hdr.type, imsg->hdr.peerid,
+ 0, -1, &ret, sizeof ret);
+ return;
}
}
diff --git a/usr.sbin/smtpd/queue_backend.c b/usr.sbin/smtpd/queue_backend.c
index 590f6c888af..21e704527af 100644
--- a/usr.sbin/smtpd/queue_backend.c
+++ b/usr.sbin/smtpd/queue_backend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_backend.c,v 1.58 2015/11/05 08:59:23 sunil Exp $ */
+/* $OpenBSD: queue_backend.c,v 1.59 2015/11/05 09:14:31 sunil Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
@@ -65,6 +65,7 @@ static int (*handler_message_commit)(uint32_t, const char*);
static int (*handler_message_delete)(uint32_t);
static int (*handler_message_fd_r)(uint32_t);
static int (*handler_message_corrupt)(uint32_t);
+static int (*handler_message_uncorrupt)(uint32_t);
static int (*handler_envelope_create)(uint32_t, const char *, size_t, uint64_t *);
static int (*handler_envelope_delete)(uint64_t);
static int (*handler_envelope_update)(uint64_t, const char *, size_t);
@@ -298,6 +299,12 @@ queue_message_corrupt(uint32_t msgid)
}
int
+queue_message_uncorrupt(uint32_t msgid)
+{
+ return handler_message_uncorrupt(msgid);
+}
+
+int
queue_message_fd_r(uint32_t msgid)
{
int fdin = -1, fdout = -1, fd = -1;
@@ -780,6 +787,12 @@ queue_api_on_message_corrupt(int(*cb)(uint32_t))
}
void
+queue_api_on_message_uncorrupt(int(*cb)(uint32_t))
+{
+ handler_message_uncorrupt = cb;
+}
+
+void
queue_api_on_envelope_create(int(*cb)(uint32_t, const char *, size_t, uint64_t *))
{
handler_envelope_create = cb;
diff --git a/usr.sbin/smtpd/queue_fs.c b/usr.sbin/smtpd/queue_fs.c
index 4063b477843..7ebfb8be25f 100644
--- a/usr.sbin/smtpd/queue_fs.c
+++ b/usr.sbin/smtpd/queue_fs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_fs.c,v 1.10 2015/10/29 10:25:36 sunil Exp $ */
+/* $OpenBSD: queue_fs.c,v 1.11 2015/11/05 09:14:31 sunil Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
@@ -239,6 +239,50 @@ again:
}
static int
+queue_fs_message_uncorrupt(uint32_t msgid)
+{
+ struct stat sb;
+ char bucketdir[PATH_MAX];
+ char queuedir[PATH_MAX];
+ char corruptdir[PATH_MAX];
+
+ fsqueue_message_corrupt_path(msgid, corruptdir, sizeof(corruptdir));
+ if (stat(corruptdir, &sb) == -1) {
+ log_warnx("warn: queue-fs: stat %s failed", corruptdir);
+ return (0);
+ }
+
+ fsqueue_message_path(msgid, queuedir, sizeof(queuedir));
+ if (stat(queuedir, &sb) == 0) {
+ log_warnx("warn: queue-fs: %s already exists", queuedir);
+ return (0);
+ }
+
+ if (! bsnprintf(bucketdir, sizeof bucketdir, "%s/%02x", PATH_QUEUE,
+ (msgid & 0xff000000) >> 24)) {
+ log_warnx("warn: queue-fs: path too long");
+ return (0);
+ }
+
+ /* create the bucket */
+ if (mkdir(bucketdir, 0700) == -1) {
+ if (errno == ENOSPC)
+ return (0);
+ if (errno != EEXIST) {
+ log_warn("warn: queue-fs: mkdir");
+ return (0);
+ }
+ }
+
+ if (rename(corruptdir, queuedir) == -1) {
+ log_warn("warn: queue-fs: rename");
+ return (0);
+ }
+
+ return (1);
+}
+
+static int
queue_fs_envelope_create(uint32_t msgid, const char *buf, size_t len,
uint64_t *evpid)
{
@@ -712,6 +756,7 @@ queue_fs_init(struct passwd *pw, int server, const char *conf)
queue_api_on_message_delete(queue_fs_message_delete);
queue_api_on_message_fd_r(queue_fs_message_fd_r);
queue_api_on_message_corrupt(queue_fs_message_corrupt);
+ queue_api_on_message_uncorrupt(queue_fs_message_uncorrupt);
queue_api_on_envelope_create(queue_fs_envelope_create);
queue_api_on_envelope_delete(queue_fs_envelope_delete);
queue_api_on_envelope_update(queue_fs_envelope_update);
diff --git a/usr.sbin/smtpd/smtpctl.8 b/usr.sbin/smtpd/smtpctl.8
index a7ca06300e6..05446eeb744 100644
--- a/usr.sbin/smtpd/smtpctl.8
+++ b/usr.sbin/smtpd/smtpctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: smtpctl.8,v 1.53 2015/10/29 10:25:36 sunil Exp $
+.\" $OpenBSD: smtpctl.8,v 1.54 2015/11/05 09:14:31 sunil 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: October 29 2015 $
+.Dd $Mdocdate: November 5 2015 $
.Dt SMTPCTL 8
.Os
.Sh NAME
@@ -280,6 +280,8 @@ mproc
.It
all
.El
+.It Cm uncorrupt Ar message-id
+Move all envelopes with the given message ID from corrupt bucket back to queue.
.It Cm unprofile Ar subsystem
Disables real-time profiling of
.Ar subsystem .
diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
index d190a8e9096..bc3f5fd01a4 100644
--- a/usr.sbin/smtpd/smtpctl.c
+++ b/usr.sbin/smtpd/smtpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpctl.c,v 1.135 2015/10/29 10:25:36 sunil Exp $ */
+/* $OpenBSD: smtpctl.c,v 1.136 2015/11/05 09:14:31 sunil Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@@ -942,6 +942,31 @@ do_discover(int argc, struct parameter *argv)
return (0);
}
+static int
+do_uncorrupt(int argc, struct parameter *argv)
+{
+ uint32_t msgid;
+ int ret;
+
+ if (ibuf == NULL && !srv_connect())
+ errx(1, "smtpd doesn't seem to be running");
+
+ msgid = argv[0].u.u_msgid;
+ srv_send(IMSG_CTL_UNCORRUPT_MSGID, &msgid, sizeof msgid);
+ srv_recv(IMSG_CTL_UNCORRUPT_MSGID);
+
+ if (rlen == 0) {
+ srv_end();
+ return (0);
+ } else {
+ srv_read(&ret, sizeof ret);
+ srv_end();
+ }
+
+ printf("command %s\n", ret ? "succeeded" : "failed");
+ return (0);
+}
+
int
main(int argc, char **argv)
{
@@ -1016,6 +1041,7 @@ main(int argc, char **argv)
cmd_install("show status", do_show_status);
cmd_install("stop", do_stop);
cmd_install("trace <str>", do_trace);
+ cmd_install("uncorrupt <msgid>", do_uncorrupt);
cmd_install("unprofile <str>", do_unprofile);
cmd_install("untrace <str>", do_untrace);
cmd_install("update table <str>", do_update_table);
diff --git a/usr.sbin/smtpd/smtpd-api.h b/usr.sbin/smtpd/smtpd-api.h
index 98b15b29b75..3359df2dff0 100644
--- a/usr.sbin/smtpd/smtpd-api.h
+++ b/usr.sbin/smtpd/smtpd-api.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd-api.h,v 1.23 2015/10/29 10:25:36 sunil Exp $ */
+/* $OpenBSD: smtpd-api.h,v 1.24 2015/11/05 09:14:31 sunil Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@@ -351,6 +351,7 @@ void queue_api_on_message_commit(int(*)(uint32_t, const char*));
void queue_api_on_message_delete(int(*)(uint32_t));
void queue_api_on_message_fd_r(int(*)(uint32_t));
void queue_api_on_message_corrupt(int(*)(uint32_t));
+void queue_api_on_message_uncorrupt(int(*)(uint32_t));
void queue_api_on_envelope_create(int(*)(uint32_t, const char *, size_t, uint64_t *));
void queue_api_on_envelope_delete(int(*)(uint64_t));
void queue_api_on_envelope_update(int(*)(uint64_t, const char *, size_t));
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index 93d6b3eb49e..f8f47e19969 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.253 2015/10/29 10:25:36 sunil Exp $ */
+/* $OpenBSD: smtpd.c,v 1.254 2015/11/05 09:14:31 sunil Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -1425,6 +1425,7 @@ imsg_to_str(int type)
CASE(IMSG_CTL_VERBOSE);
CASE(IMSG_CTL_DISCOVER_EVPID);
CASE(IMSG_CTL_DISCOVER_MSGID);
+ CASE(IMSG_CTL_UNCORRUPT_MSGID);
CASE(IMSG_CTL_SMTP_SESSION);
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 42316a94846..35ec79af471 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.483 2015/10/29 10:25:36 sunil Exp $ */
+/* $OpenBSD: smtpd.h,v 1.484 2015/11/05 09:14:31 sunil Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -152,7 +152,7 @@ union lookup {
* Bump IMSG_VERSION whenever a change is made to enum imsg_type.
* This will ensure that we can never use a wrong version of smtpctl with smtpd.
*/
-#define IMSG_VERSION 13
+#define IMSG_VERSION 14
enum imsg_type {
IMSG_NONE,
@@ -193,6 +193,7 @@ enum imsg_type {
IMSG_CTL_VERBOSE,
IMSG_CTL_DISCOVER_EVPID,
IMSG_CTL_DISCOVER_MSGID,
+ IMSG_CTL_UNCORRUPT_MSGID,
IMSG_CTL_SMTP_SESSION,
@@ -1302,6 +1303,7 @@ int queue_message_commit(uint32_t);
int queue_message_fd_r(uint32_t);
int queue_message_fd_rw(uint32_t);
int queue_message_corrupt(uint32_t);
+int queue_message_uncorrupt(uint32_t);
int queue_envelope_create(struct envelope *);
int queue_envelope_delete(uint64_t);
int queue_envelope_load(uint64_t, struct envelope *);