summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2011-10-23 13:03:06 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2011-10-23 13:03:06 +0000
commit65956c605e4eb81c91c2183d39efa1a5e7724dc5 (patch)
treed5058cf91be89a3a218fe8f9a08c376431a01603
parenta2e8f7c8d86fcb928a98de9604202a601d1bd4ac (diff)
introduce Q_CORRUPT and queue_backend operation to move a message from
schedule queue to corrupt queue upon envelope loading failure. tested by me, ok eric@
-rw-r--r--usr.sbin/smtpd/queue_backend.c8
-rw-r--r--usr.sbin/smtpd/queue_fsqueue.c40
-rw-r--r--usr.sbin/smtpd/queue_fsqueue_ascii.c10
-rw-r--r--usr.sbin/smtpd/ramqueue.c7
-rw-r--r--usr.sbin/smtpd/smtpd.h10
5 files changed, 57 insertions, 18 deletions
diff --git a/usr.sbin/smtpd/queue_backend.c b/usr.sbin/smtpd/queue_backend.c
index 1095a591fe3..564baf47496 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.12 2011/10/23 09:30:07 gilles Exp $ */
+/* $OpenBSD: queue_backend.c,v 1.13 2011/10/23 13:03:04 gilles Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -90,6 +90,12 @@ queue_message_purge(enum queue_kind qkind, u_int32_t msgid)
}
int
+queue_message_corrupt(enum queue_kind qkind, u_int32_t msgid)
+{
+ return env->sc_queue->message(qkind, QOP_CORRUPT, &msgid);
+}
+
+int
queue_message_fd_r(enum queue_kind qkind, u_int32_t msgid)
{
return env->sc_queue->message(qkind, QOP_FD_R, &msgid);
diff --git a/usr.sbin/smtpd/queue_fsqueue.c b/usr.sbin/smtpd/queue_fsqueue.c
index f0c7361d7ce..44f8c0ab0c5 100644
--- a/usr.sbin/smtpd/queue_fsqueue.c
+++ b/usr.sbin/smtpd/queue_fsqueue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_fsqueue.c,v 1.14 2011/10/23 09:30:07 gilles Exp $ */
+/* $OpenBSD: queue_fsqueue.c,v 1.15 2011/10/23 13:03:05 gilles Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -51,6 +51,7 @@ static int fsqueue_message_fd_r(enum queue_kind, u_int32_t);
static int fsqueue_message_fd_rw(enum queue_kind, u_int32_t);
static int fsqueue_message_delete(enum queue_kind, u_int32_t);
static int fsqueue_message_purge(enum queue_kind, u_int32_t);
+static int fsqueue_message_corrupt(enum queue_kind, u_int32_t);
int fsqueue_init(void);
int fsqueue_message(enum queue_kind, enum queue_op, u_int32_t *);
@@ -81,6 +82,9 @@ fsqueue_getpath(enum queue_kind kind)
case Q_BOUNCE:
return (PATH_BOUNCE);
+ case Q_CORRUPT:
+ return (PATH_CORRUPT);
+
default:
fatalx("queue_fsqueue_getpath: unsupported queue kind.");
}
@@ -162,6 +166,7 @@ fsqueue_envelope_load(enum queue_kind qkind, struct envelope *ep)
{
char pathname[MAXPATHLEN];
FILE *fp;
+ int ret;
if (! bsnprintf(pathname, sizeof(pathname), "%s/%03x/%08x%s/%016llx",
fsqueue_getpath(qkind),
@@ -176,10 +181,11 @@ fsqueue_envelope_load(enum queue_kind qkind, struct envelope *ep)
return 0;
fatal("fsqueue_envelope_load: fopen");
}
- if (! fsqueue_load_envelope_ascii(fp, ep))
- fatal("fsqueue_load_envelope_ascii: fread");
+ ret = fsqueue_load_envelope_ascii(fp, ep);
+
fclose(fp);
- return 1;
+
+ return ret;
}
static int
@@ -457,13 +463,34 @@ fsqueue_message_purge(enum queue_kind qkind, u_int32_t msgid)
return 1;
}
+static int
+fsqueue_message_corrupt(enum queue_kind qkind, u_int32_t msgid)
+{
+ char rootdir[MAXPATHLEN];
+ char corruptdir[MAXPATHLEN];
+
+ if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%03x/%08x",
+ fsqueue_getpath(qkind), msgid & 0xfff, msgid))
+ fatalx("fsqueue_message_corrupt: snprintf");
+
+ if (! bsnprintf(corruptdir, sizeof(corruptdir), "%s/%08x",
+ fsqueue_getpath(Q_CORRUPT), msgid))
+ fatalx("fsqueue_message_corrupt: snprintf");
+
+ if (rename(rootdir, corruptdir) == -1)
+ fatalx("fsqueue_message_corrupt: rename");
+
+ return 1;
+}
+
int
fsqueue_init(void)
{
unsigned int n;
char *paths[] = { PATH_INCOMING, PATH_ENQUEUE, PATH_QUEUE,
- PATH_PURGE, PATH_OFFLINE, PATH_BOUNCE };
+ PATH_PURGE, PATH_OFFLINE, PATH_BOUNCE,
+ PATH_CORRUPT };
char pathname[MAXPATHLEN];
struct stat sb;
int ret;
@@ -609,6 +636,9 @@ fsqueue_message(enum queue_kind qkind, enum queue_op qop, u_int32_t *msgid)
case QOP_PURGE:
return fsqueue_message_purge(qkind, *msgid);
+ case QOP_CORRUPT:
+ return fsqueue_message_corrupt(qkind, *msgid);
+
default:
fatalx("queue_fsqueue_message: unsupported operation.");
}
diff --git a/usr.sbin/smtpd/queue_fsqueue_ascii.c b/usr.sbin/smtpd/queue_fsqueue_ascii.c
index 1c7c78ddd5e..fb49089aa7e 100644
--- a/usr.sbin/smtpd/queue_fsqueue_ascii.c
+++ b/usr.sbin/smtpd/queue_fsqueue_ascii.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_fsqueue_ascii.c,v 1.1 2011/10/23 09:30:07 gilles Exp $ */
+/* $OpenBSD: queue_fsqueue_ascii.c,v 1.2 2011/10/23 13:03:05 gilles Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -729,19 +729,15 @@ fsqueue_load_envelope_ascii(FILE *fp, struct envelope *ep)
buf++;
ret = ascii_load_handlers[i].hdl(ep, buf);
- if (ret == 0) {
- log_debug("### CHOKED ON: %s", buf);
+ if (ret == 0)
goto err;
- }
break;
}
}
/* unknown keyword */
- if (i == n) {
- log_debug("### CHOKED ON: %s", buf);
+ if (i == n)
goto err;
- }
}
free(lbuf);
diff --git a/usr.sbin/smtpd/ramqueue.c b/usr.sbin/smtpd/ramqueue.c
index aba38b5560f..6290c42115a 100644
--- a/usr.sbin/smtpd/ramqueue.c
+++ b/usr.sbin/smtpd/ramqueue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ramqueue.c,v 1.20 2011/10/23 09:30:07 gilles Exp $ */
+/* $OpenBSD: ramqueue.c,v 1.21 2011/10/23 13:03:05 gilles Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -154,8 +154,11 @@ ramqueue_load(struct ramqueue *rqueue, time_t *nsched)
if ((evpid = filename_to_evpid(basename(path))) == 0)
continue;
- if (! queue_envelope_load(Q_QUEUE, evpid, &envelope))
+ if (! queue_envelope_load(Q_QUEUE, evpid, &envelope)) {
+ log_debug("failed to load envelope");
+ queue_message_corrupt(Q_QUEUE, evpid_to_msgid(evpid));
continue;
+ }
if (ramqueue_expire(&envelope, curtm))
continue;
ramqueue_insert(rqueue, &envelope, curtm);
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 0824231361a..ffcedc34859 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.243 2011/10/23 09:30:07 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.244 2011/10/23 13:03:05 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -69,6 +69,7 @@
#define PATH_INCOMING "/incoming"
#define PATH_QUEUE "/queue"
#define PATH_PURGE "/purge"
+#define PATH_CORRUPT "/corrupt"
#define PATH_MESSAGE "/message"
#define PATH_ENVELOPES "/envelopes"
@@ -900,7 +901,8 @@ enum queue_kind {
Q_QUEUE,
Q_PURGE,
Q_OFFLINE,
- Q_BOUNCE
+ Q_BOUNCE,
+ Q_CORRUPT
};
enum queue_op {
@@ -912,7 +914,8 @@ enum queue_op {
QOP_LOAD,
QOP_FD_R,
QOP_FD_RW,
- QOP_PURGE
+ QOP_PURGE,
+ QOP_CORRUPT,
};
struct queue_backend {
@@ -1079,6 +1082,7 @@ int queue_message_commit(enum queue_kind, u_int32_t);
int queue_message_fd_r(enum queue_kind, u_int32_t);
int queue_message_fd_rw(enum queue_kind, u_int32_t);
int queue_message_purge(enum queue_kind, u_int32_t);
+int queue_message_corrupt(enum queue_kind, u_int32_t);
int queue_envelope_create(enum queue_kind, struct envelope *);
int queue_envelope_delete(enum queue_kind, struct envelope *);
int queue_envelope_load(enum queue_kind, u_int64_t, struct envelope *);