diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2011-04-14 23:26:17 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2011-04-14 23:26:17 +0000 |
commit | 42141c14a76c8180e90413d4125b4c7f6c4f4da9 (patch) | |
tree | 6c92dca9e9739e4f068b7f24e1ca3614ee8f30fd /usr.sbin | |
parent | 2641531408e91b374d3bc048faf07da3cf7281e4 (diff) |
- implement missing operations for fsqueue:
fsqueue_envelope_create(), fsqueue_message_purge()
- kill deprecated functions in queue_shared.c
At this point fsqueue backend is almost complete, all that is left to do is
to move the qwalk() API inside the queue_backend API, then make sure smtpd
is no longer calling anything queue related directly.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/queue.c | 27 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_backend.c | 8 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_fsqueue.c | 97 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_shared.c | 150 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 9 |
5 files changed, 118 insertions, 173 deletions
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c index 34fae8cee9e..c18ab232e48 100644 --- a/usr.sbin/smtpd/queue.c +++ b/usr.sbin/smtpd/queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue.c,v 1.97 2011/04/14 22:36:09 gilles Exp $ */ +/* $OpenBSD: queue.c,v 1.98 2011/04/14 23:26:16 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -40,14 +40,7 @@ void queue_imsg(struct smtpd *, struct imsgev *, struct imsg *); void queue_pass_to_runner(struct smtpd *, struct imsgev *, struct imsg *); __dead void queue_shutdown(void); void queue_sig_handler(int, short, void *); -void queue_purge(char *); - -int queue_create_layout_message(char *, char *); -void queue_delete_layout_message(char *, char *); -int queue_record_layout_envelope(char *, struct message *); -int queue_remove_layout_envelope(char *, struct message *); -int queue_commit_layout_message(char *, struct message *); -int queue_open_layout_messagefile(char *, struct message *); +void queue_purge(struct smtpd *, enum queue_kind, char *); void queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg) @@ -77,9 +70,9 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg) case IMSG_QUEUE_REMOVE_MESSAGE: if (m->flags & F_MESSAGE_ENQUEUED) - enqueue_delete_message(m->message_id); + queue_message_purge(env, Q_ENQUEUE, m->message_id); else - queue_delete_incoming_message(m->message_id); + queue_message_purge(env, Q_INCOMING, m->message_id); return; case IMSG_QUEUE_COMMIT_MESSAGE: @@ -136,9 +129,9 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg) /* Write to disk */ if (m->flags & F_MESSAGE_ENQUEUED) - ret = enqueue_record_envelope(m); + ret = queue_envelope_create(env, Q_ENQUEUE, m); else - ret = queue_record_incoming_envelope(m); + ret = queue_envelope_create(env, Q_INCOMING, m); if (ret == 0) { ss.code = 421; @@ -315,8 +308,8 @@ queue(struct smtpd *env) config_pipes(env, peers, nitems(peers)); config_peers(env, peers, nitems(peers)); - queue_purge(PATH_INCOMING); - queue_purge(PATH_ENQUEUE); + queue_purge(env, Q_INCOMING, PATH_INCOMING); + queue_purge(env, Q_ENQUEUE, PATH_ENQUEUE); if (event_dispatch() < 0) fatal("event_dispatch"); @@ -326,7 +319,7 @@ queue(struct smtpd *env) } void -queue_purge(char *queuepath) +queue_purge(struct smtpd *env, enum queue_kind qkind, char *queuepath) { char path[MAXPATHLEN]; struct qwalk *q; @@ -334,7 +327,7 @@ queue_purge(char *queuepath) q = qwalk_new(queuepath); while (qwalk(q, path)) - queue_delete_layout_message(queuepath, basename(path)); + queue_message_purge(env, qkind, basename(path)); qwalk_close(q); } diff --git a/usr.sbin/smtpd/queue_backend.c b/usr.sbin/smtpd/queue_backend.c index ac677521882..5d8a588055c 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.6 2011/04/14 20:11:08 gilles Exp $ */ +/* $OpenBSD: queue_backend.c,v 1.7 2011/04/14 23:26:16 gilles Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -84,6 +84,12 @@ queue_message_commit(struct smtpd *env, enum queue_kind qkind, char *msgid) } int +queue_message_purge(struct smtpd *env, enum queue_kind qkind, char *msgid) +{ + return env->sc_queue->message(env, qkind, QOP_PURGE, msgid); +} + +int queue_message_fd_r(struct smtpd *env, enum queue_kind qkind, char *msgid) { return env->sc_queue->message(env, qkind, QOP_FD_R, msgid); diff --git a/usr.sbin/smtpd/queue_fsqueue.c b/usr.sbin/smtpd/queue_fsqueue.c index f3b42da93ab..947f0cce7c8 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.5 2011/04/14 22:36:09 gilles Exp $ */ +/* $OpenBSD: queue_fsqueue.c,v 1.6 2011/04/14 23:26:16 gilles Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -45,9 +45,12 @@ static int fsqueue_envelope_load(struct smtpd *, enum queue_kind, struct message static int fsqueue_envelope_update(struct smtpd *, enum queue_kind, struct message *); static int fsqueue_envelope_delete(struct smtpd *, enum queue_kind, struct message *); +static int fsqueue_message_create(struct smtpd *, enum queue_kind, char *); +static int fsqueue_message_commit(struct smtpd *, enum queue_kind, char *); static int fsqueue_message_fd_r(struct smtpd *, enum queue_kind, char *); static int fsqueue_message_fd_rw(struct smtpd *, enum queue_kind, char *); static int fsqueue_message_delete(struct smtpd *, enum queue_kind, char *); +static int fsqueue_message_purge(struct smtpd *, enum queue_kind, char *); int fsqueue_init(struct smtpd *); int fsqueue_message(struct smtpd *, enum queue_kind, @@ -95,6 +98,72 @@ fsqueue_hash(char *msgid) } static int +fsqueue_envelope_create(struct smtpd *env, enum queue_kind qkind, + struct message *envelope) +{ + char evpname[MAXPATHLEN]; + FILE *fp; + int fd; + + fp = NULL; + +again: + if (! bsnprintf(evpname, sizeof(evpname), "%s/%s%s/%s.%qu", + fsqueue_getpath(qkind), envelope->message_id, + PATH_ENVELOPES, envelope->message_id, + (u_int64_t)arc4random())) + fatalx("fsqueue_envelope_create: snprintf"); + + fd = open(evpname, O_WRONLY|O_CREAT|O_EXCL, 0600); + if (fd == -1) { + if (errno == EEXIST) + goto again; + if (errno == ENOSPC || errno == ENFILE) + goto tempfail; + fatal("fsqueue_envelope_create: open"); + } + + fp = fdopen(fd, "w"); + if (fp == NULL) + fatal("fsqueue_envelope_create: fdopen"); + + envelope->creation = time(NULL); + if (strlcpy(envelope->message_uid, strrchr(evpname, '/') + 1, + sizeof(envelope->message_uid)) >= sizeof(envelope->message_uid)) + fatalx("fsqueue_envelope_create: truncation"); + + if (qkind == Q_BOUNCE) { + envelope->lasttry = 0; + envelope->retry = 0; + } + + if (fwrite(envelope, sizeof (struct message), 1, fp) != 1) { + if (errno == ENOSPC) + goto tempfail; + fatal("fsqueue_envelope_create: write"); + } + + if (! safe_fclose(fp)) { + fp = NULL; + fd = -1; + goto tempfail; + } + + return 1; + +tempfail: + unlink(evpname); + if (fp) + fclose(fp); + else if (fd != -1) + close(fd); + envelope->creation = 0; + envelope->message_uid[0] = '\0'; + + return 0; +} + +static int fsqueue_envelope_load(struct smtpd *env, enum queue_kind qkind, struct message *envelope) { @@ -380,6 +449,27 @@ fsqueue_message_delete(struct smtpd *env, enum queue_kind qkind, char *msgid) return 1; } +static int +fsqueue_message_purge(struct smtpd *env, enum queue_kind qkind, char *msgid) +{ + char rootdir[MAXPATHLEN]; + char purgedir[MAXPATHLEN]; + + if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%s", + fsqueue_getpath(qkind), msgid)) + fatalx("fsqueue_message_purge: snprintf"); + + if (! bsnprintf(purgedir, sizeof(purgedir), "%s/%s", + fsqueue_getpath(Q_PURGE), msgid)) + fatalx("fsqueue_message_purge: snprintf"); + + if (rename(rootdir, purgedir) == -1) + fatal("fsqueue_message_purge: rename"); + + return 1; +} + + int fsqueue_init(struct smtpd *env) { @@ -529,6 +619,9 @@ fsqueue_message(struct smtpd *env, enum queue_kind qkind, case QOP_FD_RW: return fsqueue_message_fd_rw(env, qkind, msgid); + case QOP_PURGE: + return fsqueue_message_purge(env, qkind, msgid); + default: fatalx("queue_fsqueue_message: unsupported operation."); } @@ -542,7 +635,7 @@ fsqueue_envelope(struct smtpd *env, enum queue_kind qkind, { switch (qop) { case QOP_CREATE: - return 0; + return fsqueue_envelope_create(env, qkind, envelope); case QOP_DELETE: return fsqueue_envelope_delete(env, qkind, envelope); diff --git a/usr.sbin/smtpd/queue_shared.c b/usr.sbin/smtpd/queue_shared.c index 47b73b44fa1..654b06e0b6c 100644 --- a/usr.sbin/smtpd/queue_shared.c +++ b/usr.sbin/smtpd/queue_shared.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue_shared.c,v 1.41 2011/04/14 22:36:09 gilles Exp $ */ +/* $OpenBSD: queue_shared.c,v 1.42 2011/04/14 23:26:16 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -58,134 +58,6 @@ int walk_queue(struct qwalk *, char *); void display_envelope(struct message *, int); void getflag(u_int *, int, char *, char *, size_t); -void -queue_delete_layout_message(char *queuepath, char *msgid) -{ - char rootdir[MAXPATHLEN]; - char purgedir[MAXPATHLEN]; - - if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%s", queuepath, msgid)) - fatalx("snprintf"); - - if (! bsnprintf(purgedir, sizeof(purgedir), "%s/%s", PATH_PURGE, msgid)) - fatalx("snprintf"); - - if (rename(rootdir, purgedir) == -1) - fatal("queue_delete_layout_message: rename"); -} - -int -queue_record_layout_envelope(char *queuepath, struct message *message) -{ - char evpname[MAXPATHLEN]; - FILE *fp; - int fd; - - fp = NULL; - -again: - if (! bsnprintf(evpname, sizeof(evpname), "%s/%s%s/%s.%qu", queuepath, - message->message_id, PATH_ENVELOPES, message->message_id, - (u_int64_t)arc4random())) - fatalx("queue_record_incoming_envelope: snprintf"); - - fd = open(evpname, O_WRONLY|O_CREAT|O_EXCL, 0600); - if (fd == -1) { - if (errno == EEXIST) - goto again; - if (errno == ENOSPC || errno == ENFILE) - goto tempfail; - fatal("queue_record_incoming_envelope: open"); - } - - fp = fdopen(fd, "w"); - if (fp == NULL) - fatal("queue_record_incoming_envelope: fdopen"); - - message->creation = time(NULL); - if (strlcpy(message->message_uid, strrchr(evpname, '/') + 1, - sizeof(message->message_uid)) >= sizeof(message->message_uid)) - fatalx("queue_record_incoming_envelope: truncation"); - - if (fwrite(message, sizeof (struct message), 1, fp) != 1) { - if (errno == ENOSPC) - goto tempfail; - fatal("queue_record_incoming_envelope: write"); - } - - if (! safe_fclose(fp)) { - fp = NULL; - fd = -1; - goto tempfail; - } - - return 1; - -tempfail: - unlink(evpname); - if (fp) - fclose(fp); - else if (fd != -1) - close(fd); - message->creation = 0; - message->message_uid[0] = '\0'; - - return 0; -} - -int -queue_remove_layout_envelope(char *queuepath, struct message *message) -{ - char pathname[MAXPATHLEN]; - - if (! bsnprintf(pathname, sizeof(pathname), "%s/%s%s/%s", queuepath, - message->message_id, PATH_ENVELOPES, message->message_uid)) - fatal("queue_remove_incoming_envelope: snprintf"); - - if (unlink(pathname) == -1) - fatal("queue_remove_incoming_envelope: unlink"); - - return 1; -} - -void -enqueue_delete_message(char *msgid) -{ - queue_delete_layout_message(PATH_ENQUEUE, msgid); -} - -int -enqueue_record_envelope(struct message *message) -{ - return queue_record_layout_envelope(PATH_ENQUEUE, message); -} - -int -enqueue_remove_envelope(struct message *message) -{ - return queue_remove_layout_envelope(PATH_ENQUEUE, message); -} - -void -bounce_delete_message(char *msgid) -{ - queue_delete_layout_message(PATH_BOUNCE, msgid); -} - -int -bounce_record_envelope(struct message *message) -{ - message->lasttry = 0; - message->retry = 0; - return queue_record_layout_envelope(PATH_BOUNCE, message); -} - -int -bounce_remove_envelope(struct message *message) -{ - return queue_remove_layout_envelope(PATH_BOUNCE, message); -} - int bounce_record_message(struct smtpd *env, struct message *messagep, struct message *mbounce) { @@ -205,31 +77,13 @@ bounce_record_message(struct smtpd *env, struct message *messagep, struct messag return 0; strlcpy(mbounce->message_id, msgid, sizeof(mbounce->message_id)); - if (! bounce_record_envelope(mbounce)) + if (! queue_envelope_create(env, Q_BOUNCE, mbounce)) return 0; return queue_message_commit(env, Q_BOUNCE, msgid); } void -queue_delete_incoming_message(char *msgid) -{ - queue_delete_layout_message(PATH_INCOMING, msgid); -} - -int -queue_record_incoming_envelope(struct message *message) -{ - return queue_record_layout_envelope(PATH_INCOMING, message); -} - -int -queue_remove_incoming_envelope(struct message *message) -{ - return queue_remove_layout_envelope(PATH_INCOMING, message); -} - -void queue_message_update(struct smtpd *env, struct message *messagep) { messagep->flags &= ~F_MESSAGE_PROCESSING; diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 452ffd92134..3a11fe34341 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.212 2011/04/14 22:46:38 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.213 2011/04/14 23:26:16 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -926,7 +926,8 @@ enum queue_op { QOP_COMMIT, QOP_LOAD, QOP_FD_R, - QOP_FD_RW + QOP_FD_RW, + QOP_PURGE }; struct queue_backend { @@ -1060,6 +1061,7 @@ int queue_message_delete(struct smtpd *, enum queue_kind, char *); int queue_message_commit(struct smtpd *, enum queue_kind, char *); int queue_message_fd_r(struct smtpd *, enum queue_kind, char *); int queue_message_fd_rw(struct smtpd *, enum queue_kind, char *); +int queue_message_purge(struct smtpd *, enum queue_kind, char *); int queue_envelope_create(struct smtpd *, enum queue_kind, struct message *); int queue_envelope_delete(struct smtpd *, enum queue_kind, @@ -1070,11 +1072,8 @@ int queue_envelope_update(struct smtpd *, enum queue_kind, struct message *); - - /* queue_shared.c */ int queue_create_layout_message(char *, char *); -void queue_delete_layout_message(char *, char *); int queue_record_layout_envelope(char *, struct message *); int queue_remove_layout_envelope(char *, struct message *); int queue_commit_layout_message(char *, struct message *); |