summaryrefslogtreecommitdiffstats
path: root/usr.sbin/smtpd/queue_backend.c
diff options
context:
space:
mode:
authorgilles <gilles@openbsd.org>2011-11-15 23:06:39 +0000
committergilles <gilles@openbsd.org>2011-11-15 23:06:39 +0000
commit7b5d776d6d9ea7ce6d100cdd9266cbd9d04c8ed5 (patch)
tree7f1170e1ebd7e6e7431fde7be04d61f5f86633bf /usr.sbin/smtpd/queue_backend.c
parentDisable LESSHISTFILE by default, requested by deraadt. (diff)
downloadwireguard-openbsd-7b5d776d6d9ea7ce6d100cdd9266cbd9d04c8ed5.tar.xz
wireguard-openbsd-7b5d776d6d9ea7ce6d100cdd9266cbd9d04c8ed5.zip
Qwalk, our API to linearly walk over the persistent queue, did not take the
queue_backend into account and assumed a filesystem with a specific layout. This commit does plenty of things: - make qwalk an abstraction in the queue_backend API, and impose queue drivers to implement qwalk_open(), qwalk() and qwalk_close(); - move previous qwalk_open(), qwalk() and qwalk_close() to the fsqueue driver since they were fsqueue specific ... - make qwalk API work with msgid/evpid instead of pathnames since we're going to use the queue_backend API to load envelopes by evpid anyway; - makes smtpd use *solely* the queue_backend API when manipulating the queue. pathnames were removed from smtpd.h and moved into the fsqueue which means we can now store a queue anywhere ... as long as we write the ten functions or so required for a queue driver ;-) ok eric@, ok chl@
Diffstat (limited to 'usr.sbin/smtpd/queue_backend.c')
-rw-r--r--usr.sbin/smtpd/queue_backend.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/usr.sbin/smtpd/queue_backend.c b/usr.sbin/smtpd/queue_backend.c
index 564baf47496..94c6a4b4b59 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.13 2011/10/23 13:03:04 gilles Exp $ */
+/* $OpenBSD: queue_backend.c,v 1.14 2011/11/15 23:06:39 gilles Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -42,12 +42,19 @@ static int envelope_validate(struct envelope *);
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 *);
+void *fsqueue_qwalk_new(enum queue_kind, u_int32_t);
+int fsqueue_qwalk(void *, u_int64_t *);
+void fsqueue_qwalk_close(void *);
+
struct queue_backend queue_backends[] = {
{ QT_FS,
fsqueue_init,
fsqueue_message,
- fsqueue_envelope }
+ fsqueue_envelope,
+ fsqueue_qwalk_new,
+ fsqueue_qwalk,
+ fsqueue_qwalk_close }
};
struct queue_backend *
@@ -110,6 +117,7 @@ queue_message_fd_rw(enum queue_kind qkind, u_int32_t msgid)
int
queue_envelope_create(enum queue_kind qkind, struct envelope *ep)
{
+ ep->id >>= 32;
return env->sc_queue->envelope(qkind, QOP_CREATE, ep);
}
@@ -134,6 +142,57 @@ queue_envelope_update(enum queue_kind qkind, struct envelope *ep)
return env->sc_queue->envelope(qkind, QOP_UPDATE, ep);
}
+void *
+qwalk_new(enum queue_kind kind, u_int32_t msgid)
+{
+ return env->sc_queue->qwalk_new(kind, msgid);
+}
+
+int
+qwalk(void *hdl, u_int64_t *evpid)
+{
+ return env->sc_queue->qwalk(hdl, evpid);
+}
+
+void
+qwalk_close(void *hdl)
+{
+ return env->sc_queue->qwalk_close(hdl);
+}
+
+u_int32_t
+queue_generate_msgid(void)
+{
+ u_int32_t msgid;
+
+again:
+ msgid = arc4random_uniform(0xffffffff);
+ if (msgid == 0)
+ goto again;
+
+ return msgid;
+}
+
+u_int64_t
+queue_generate_evpid(u_int32_t msgid)
+{
+ u_int32_t rnd;
+ u_int64_t evpid;
+
+again:
+ rnd = arc4random_uniform(0xffffffff);
+ if (rnd == 0)
+ goto again;
+
+ evpid = msgid;
+ evpid <<= 32;
+ evpid |= rnd;
+
+ return evpid;
+}
+
+
+/**/
static int
envelope_validate(struct envelope *ep)
{