summaryrefslogtreecommitdiffstats
path: root/usr.sbin/smtpd/queue_backend.c
diff options
context:
space:
mode:
authorgilles <gilles@openbsd.org>2011-10-23 09:30:06 +0000
committergilles <gilles@openbsd.org>2011-10-23 09:30:06 +0000
commit148c595199db36e6e1828873912dd8a66f8f5d3f (patch)
tree9e69aef1bf11f7f30f562c44e8841f75ccbd4cc0 /usr.sbin/smtpd/queue_backend.c
parentTry to resolve relative paths for loadb and saveb (first using client (diff)
downloadwireguard-openbsd-148c595199db36e6e1828873912dd8a66f8f5d3f.tar.xz
wireguard-openbsd-148c595199db36e6e1828873912dd8a66f8f5d3f.zip
fsqueue no longer stores envelopes by dumping the structure, instead use a
couple of load/dump functions to convert to and from a human readable fmt. while at it kill struct delivery and merge back its fields to the envelope. this basically means we shouldn't require users to flush their queues every time we make a change to struct envelope. work is not done, but we're at a better state than the binary fsqueue so we'll improve it in-tree. has been running on my own box for the last 12 hours or so ok eric@, chl@
Diffstat (limited to 'usr.sbin/smtpd/queue_backend.c')
-rw-r--r--usr.sbin/smtpd/queue_backend.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/usr.sbin/smtpd/queue_backend.c b/usr.sbin/smtpd/queue_backend.c
index d86033126ff..1095a591fe3 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.11 2011/05/16 21:05:52 gilles Exp $ */
+/* $OpenBSD: queue_backend.c,v 1.12 2011/10/23 09:30:07 gilles Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -23,6 +23,7 @@
#include <sys/socket.h>
#include <sys/stat.h>
+#include <ctype.h>
#include <event.h>
#include <imsg.h>
#include <libgen.h>
@@ -35,12 +36,13 @@
#include "smtpd.h"
#include "log.h"
+static int envelope_validate(struct envelope *);
+
/* fsqueue backend */
int fsqueue_init(void);
int fsqueue_message(enum queue_kind, enum queue_op, u_int32_t *);
int fsqueue_envelope(enum queue_kind, enum queue_op , struct envelope *);
-
struct queue_backend queue_backends[] = {
{ QT_FS,
fsqueue_init,
@@ -114,8 +116,10 @@ queue_envelope_delete(enum queue_kind qkind, struct envelope *ep)
int
queue_envelope_load(enum queue_kind qkind, u_int64_t evpid, struct envelope *ep)
{
- ep->delivery.id = evpid;
- return env->sc_queue->envelope(qkind, QOP_LOAD, ep);
+ ep->id = evpid;
+ if (env->sc_queue->envelope(qkind, QOP_LOAD, ep))
+ return envelope_validate(ep);
+ return 0;
}
int
@@ -123,3 +127,30 @@ queue_envelope_update(enum queue_kind qkind, struct envelope *ep)
{
return env->sc_queue->envelope(qkind, QOP_UPDATE, ep);
}
+
+static int
+envelope_validate(struct envelope *ep)
+{
+ if (ep->version != SMTPD_ENVELOPE_VERSION)
+ return 0;
+
+ if ((ep->id & 0xffffffff) == 0 ||
+ ((ep->id >> 32) & 0xffffffff) == 0)
+ return 0;
+
+ if (ep->helo[0] == '\0')
+ return 0;
+
+ if (ep->hostname[0] == '\0')
+ return 0;
+
+ if (ep->errorline[0] != '\0') {
+ if (! isdigit(ep->errorline[0]) ||
+ ! isdigit(ep->errorline[1]) ||
+ ! isdigit(ep->errorline[2]) ||
+ ep->errorline[3] != ' ')
+ return 0;
+ }
+
+ return 1;
+}