diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2011-04-14 22:36:10 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2011-04-14 22:36:10 +0000 |
commit | 8aa9805c6c6a07e2e443192c06997db291ce8f9f (patch) | |
tree | 022eb9addce61e7a4d44d85c893f3070da1123e5 /usr.sbin | |
parent | aa8d852e3859a12cf274f2a0baf898ec4c4e2138 (diff) |
- implement fsqueue_message_create() and fsqueue_message_commit()
- change a few prototypes to allow bounce messages to use the
queue_backend API until it gets merged in
- kill functions of the queue API that have been deprecated
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/queue.c | 10 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_fsqueue.c | 102 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_shared.c | 137 | ||||
-rw-r--r-- | usr.sbin/smtpd/ramqueue.c | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/runner.c | 6 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 6 |
6 files changed, 116 insertions, 149 deletions
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c index 8669ae231ae..34fae8cee9e 100644 --- a/usr.sbin/smtpd/queue.c +++ b/usr.sbin/smtpd/queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue.c,v 1.96 2011/04/14 21:53:45 gilles Exp $ */ +/* $OpenBSD: queue.c,v 1.97 2011/04/14 22:36:09 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -66,9 +66,9 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg) ss.code = 250; bzero(ss.u.msgid, sizeof ss.u.msgid); if (m->flags & F_MESSAGE_ENQUEUED) - ret = enqueue_create_layout(ss.u.msgid); + ret = queue_message_create(env, Q_ENQUEUE, ss.u.msgid); else - ret = queue_create_incoming_layout(ss.u.msgid); + ret = queue_message_create(env, Q_INCOMING, ss.u.msgid); if (ret == 0) ss.code = 421; imsg_compose_event(iev, IMSG_QUEUE_CREATE_MESSAGE, 0, 0, -1, @@ -85,12 +85,12 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg) case IMSG_QUEUE_COMMIT_MESSAGE: ss.id = m->session_id; if (m->flags & F_MESSAGE_ENQUEUED) { - if (enqueue_commit_message(m)) + if (queue_message_commit(env, Q_ENQUEUE, m->message_id)) env->stats->queue.inserts_local++; else ss.code = 421; } else { - if (queue_commit_incoming_message(m)) + if (queue_message_commit(env, Q_INCOMING, m->message_id)) env->stats->queue.inserts_remote++; else ss.code = 421; diff --git a/usr.sbin/smtpd/queue_fsqueue.c b/usr.sbin/smtpd/queue_fsqueue.c index b81963f94cd..f3b42da93ab 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.4 2011/04/14 21:53:46 gilles Exp $ */ +/* $OpenBSD: queue_fsqueue.c,v 1.5 2011/04/14 22:36:09 gilles Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -207,6 +207,99 @@ fsqueue_envelope_delete(struct smtpd *env, enum queue_kind qkind, } static int +fsqueue_message_create(struct smtpd *env, enum queue_kind qkind, char *msgid) +{ + char rootdir[MAXPATHLEN]; + char evpdir[MAXPATHLEN]; + char *queuepath = fsqueue_getpath(qkind); + char msgpath[MAXPATHLEN]; + char lnkpath[MAXPATHLEN]; + char msgid_save[MAX_ID_SIZE]; + + strlcpy(msgid_save, msgid, sizeof(msgid_save)); + + if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%d.XXXXXXXXXXXXXXXX", + queuepath, time(NULL))) + fatalx("fsqueue_message_create: snprintf"); + + if (mkdtemp(rootdir) == NULL) { + if (errno == ENOSPC) { + bzero(msgid, MAX_ID_SIZE); + return 0; + } + fatal("fsqueue_message_create: mkdtemp"); + } + + if (strlcpy(msgid, rootdir + strlen(queuepath) + 1, MAX_ID_SIZE) + >= MAX_ID_SIZE) + fatalx("fsqueue_message_create: truncation"); + + if (! bsnprintf(evpdir, sizeof(evpdir), "%s%s", rootdir, + PATH_ENVELOPES)) + fatalx("fsqueue_message_create: snprintf"); + + if (mkdir(evpdir, 0700) == -1) { + if (errno == ENOSPC) { + rmdir(rootdir); + bzero(msgid, MAX_ID_SIZE); + return 0; + } + fatal("fsqueue_message_create: mkdir"); + } + + if (qkind == Q_BOUNCE) { + if (! bsnprintf(msgpath, sizeof(msgpath), "%s/%d/%s/message", + fsqueue_getpath(Q_QUEUE), + queue_hash(msgid_save), msgid_save)) + return 0; + + if (! bsnprintf(lnkpath, sizeof(lnkpath), "%s/%s/message", + fsqueue_getpath(Q_BOUNCE), msgid)) + return 0; + + if (link(msgpath, lnkpath) == -1) + fatal("link"); + } + + return 1; +} + +static int +fsqueue_message_commit(struct smtpd *env, enum queue_kind qkind, char *msgid) +{ + char rootdir[MAXPATHLEN]; + char queuedir[MAXPATHLEN]; + + if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%s", + fsqueue_getpath(qkind), msgid)) + fatal("fsqueue_message_commit: snprintf"); + + if (! bsnprintf(queuedir, sizeof(queuedir), "%s/%d", + fsqueue_getpath(Q_QUEUE), fsqueue_hash(msgid))) + fatal("fsqueue_message_commit: snprintf"); + + if (mkdir(queuedir, 0700) == -1) { + if (errno == ENOSPC) + return 0; + if (errno != EEXIST) + fatal("fsqueue_message_commit: mkdir"); + } + + if (strlcat(queuedir, "/", sizeof(queuedir)) >= sizeof(queuedir) || + strlcat(queuedir, msgid, sizeof(queuedir)) >= + sizeof(queuedir)) + fatalx("fsqueue_message_commit: truncation"); + + if (rename(rootdir, queuedir) == -1) { + if (errno == ENOSPC) + return 0; + fatal("fsqueue_message_commit: rename"); + } + + return 1; +} + +static int fsqueue_message_fd_r(struct smtpd *env, enum queue_kind qkind, char *msgid) { int fd; @@ -225,7 +318,6 @@ fsqueue_message_fd_r(struct smtpd *env, enum queue_kind qkind, char *msgid) fatal("fsqueue_message_fd_r: snprintf"); } - log_debug("pathname: %s", pathname); if ((fd = open(pathname, O_RDONLY)) == -1) fatal("fsqueue_message_fd_r: open"); @@ -241,7 +333,7 @@ fsqueue_message_fd_rw(struct smtpd *env, enum queue_kind qkind, char *msgid) fsqueue_getpath(qkind), msgid)) fatal("fsqueue_message_fd_rw: snprintf"); - log_debug("path: %s", pathname); + return open(pathname, O_CREAT|O_EXCL|O_RDWR, 0600); } @@ -423,13 +515,13 @@ fsqueue_message(struct smtpd *env, enum queue_kind qkind, { switch (qop) { case QOP_CREATE: - return 0; + return fsqueue_message_create(env, qkind, msgid); case QOP_DELETE: return fsqueue_message_delete(env, qkind, msgid); case QOP_COMMIT: - return 0; + return fsqueue_message_commit(env, qkind, msgid); case QOP_FD_R: return fsqueue_message_fd_r(env, qkind, msgid); diff --git a/usr.sbin/smtpd/queue_shared.c b/usr.sbin/smtpd/queue_shared.c index 2a7a736c186..47b73b44fa1 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.40 2011/04/14 22:00:26 gilles Exp $ */ +/* $OpenBSD: queue_shared.c,v 1.41 2011/04/14 22:36:09 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -58,43 +58,6 @@ int walk_queue(struct qwalk *, char *); void display_envelope(struct message *, int); void getflag(u_int *, int, char *, char *, size_t); -int -queue_create_layout_message(char *queuepath, char *message_id) -{ - char rootdir[MAXPATHLEN]; - char evpdir[MAXPATHLEN]; - - if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%d.XXXXXXXXXXXXXXXX", - queuepath, time(NULL))) - fatalx("queue_create_layout_message: snprintf"); - - if (mkdtemp(rootdir) == NULL) { - if (errno == ENOSPC) { - bzero(message_id, MAX_ID_SIZE); - return 0; - } - fatal("queue_create_layout_message: mkdtemp"); - } - - if (strlcpy(message_id, rootdir + strlen(queuepath) + 1, MAX_ID_SIZE) - >= MAX_ID_SIZE) - fatalx("queue_create_layout_message: truncation"); - - if (! bsnprintf(evpdir, sizeof(evpdir), "%s%s", rootdir, - PATH_ENVELOPES)) - fatalx("queue_create_layout_message: snprintf"); - - if (mkdir(evpdir, 0700) == -1) { - if (errno == ENOSPC) { - rmdir(rootdir); - bzero(message_id, MAX_ID_SIZE); - return 0; - } - fatal("queue_create_layout_message: mkdir"); - } - return 1; -} - void queue_delete_layout_message(char *queuepath, char *msgid) { @@ -185,47 +148,6 @@ queue_remove_layout_envelope(char *queuepath, struct message *message) return 1; } -int -queue_commit_layout_message(char *queuepath, struct message *messagep) -{ - char rootdir[MAXPATHLEN]; - char queuedir[MAXPATHLEN]; - - if (! bsnprintf(rootdir, sizeof(rootdir), "%s/%s", queuepath, - messagep->message_id)) - fatal("queue_commit_message_incoming: snprintf"); - - if (! bsnprintf(queuedir, sizeof(queuedir), "%s/%d", PATH_QUEUE, - queue_hash(messagep->message_id))) - fatal("queue_commit_message_incoming: snprintf"); - - if (mkdir(queuedir, 0700) == -1) { - if (errno == ENOSPC) - return 0; - if (errno != EEXIST) - fatal("queue_commit_message_incoming: mkdir"); - } - - if (strlcat(queuedir, "/", sizeof(queuedir)) >= sizeof(queuedir) || - strlcat(queuedir, messagep->message_id, sizeof(queuedir)) >= - sizeof(queuedir)) - fatalx("queue_commit_incoming_message: truncation"); - - if (rename(rootdir, queuedir) == -1) { - if (errno == ENOSPC) - return 0; - fatal("queue_commit_message_incoming: rename"); - } - - return 1; -} - -int -enqueue_create_layout(char *msgid) -{ - return queue_create_layout_message(PATH_ENQUEUE, msgid); -} - void enqueue_delete_message(char *msgid) { @@ -244,36 +166,6 @@ enqueue_remove_envelope(struct message *message) return queue_remove_layout_envelope(PATH_ENQUEUE, message); } -int -enqueue_commit_message(struct message *message) -{ - return queue_commit_layout_message(PATH_ENQUEUE, message); -} - -int -bounce_create_layout(char *msgid, struct message *message) -{ - char msgpath[MAXPATHLEN]; - char lnkpath[MAXPATHLEN]; - - if (! queue_create_layout_message(PATH_BOUNCE, msgid)) - return 0; - - if (! bsnprintf(msgpath, sizeof(msgpath), "%s/%d/%s/message", - PATH_QUEUE, queue_hash(message->message_id), - message->message_id)) - return 0; - - if (! bsnprintf(lnkpath, sizeof(lnkpath), "%s/%s/message", - PATH_BOUNCE, msgid)) - return 0; - - if (link(msgpath, lnkpath) == -1) - fatal("link"); - - return 1; -} - void bounce_delete_message(char *msgid) { @@ -295,13 +187,7 @@ bounce_remove_envelope(struct message *message) } int -bounce_commit_message(struct message *message) -{ - return queue_commit_layout_message(PATH_BOUNCE, message); -} - -int -bounce_record_message(struct message *messagep, struct message *mbounce) +bounce_record_message(struct smtpd *env, struct message *messagep, struct message *mbounce) { char msgid[MAX_ID_SIZE]; @@ -314,20 +200,15 @@ bounce_record_message(struct message *messagep, struct message *mbounce) mbounce->type = T_BOUNCE_MESSAGE; mbounce->status &= ~S_MESSAGE_PERMFAILURE; - if (! bounce_create_layout(msgid, messagep)) + strlcpy(msgid, messagep->message_id, sizeof(msgid)); + if (! queue_message_create(env, Q_BOUNCE, msgid)) return 0; strlcpy(mbounce->message_id, msgid, sizeof(mbounce->message_id)); if (! bounce_record_envelope(mbounce)) return 0; - return bounce_commit_message(mbounce); -} - -int -queue_create_incoming_layout(char *msgid) -{ - return queue_create_layout_message(PATH_INCOMING, msgid); + return queue_message_commit(env, Q_BOUNCE, msgid); } void @@ -348,12 +229,6 @@ queue_remove_incoming_envelope(struct message *message) return queue_remove_layout_envelope(PATH_INCOMING, message); } -int -queue_commit_incoming_message(struct message *message) -{ - return queue_commit_layout_message(PATH_INCOMING, message); -} - void queue_message_update(struct smtpd *env, struct message *messagep) { @@ -367,7 +242,7 @@ queue_message_update(struct smtpd *env, struct message *messagep) messagep->sender.user[0] != '\0') { struct message bounce; - bounce_record_message(messagep, &bounce); + bounce_record_message(env, messagep, &bounce); } queue_envelope_delete(env, Q_QUEUE, messagep); return; diff --git a/usr.sbin/smtpd/ramqueue.c b/usr.sbin/smtpd/ramqueue.c index 8e98de29dc0..db57552935a 100644 --- a/usr.sbin/smtpd/ramqueue.c +++ b/usr.sbin/smtpd/ramqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ramqueue.c,v 1.2 2011/04/14 20:11:08 gilles Exp $ */ +/* $OpenBSD: ramqueue.c,v 1.3 2011/04/14 22:36:09 gilles Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -215,7 +215,7 @@ ramqueue_expire(struct smtpd *env, struct message *envelope, time_t curtm) message_set_errormsg(envelope, "message expired after sitting in queue for %d days", envelope->expire / 60 / 60 / 24); - bounce_record_message(envelope, &bounce); + bounce_record_message(env, envelope, &bounce); ramqueue_insert(&env->sc_rqueue, &bounce, time(NULL)); queue_envelope_delete(env, Q_QUEUE, envelope); return 1; diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c index 22b13ee81cc..b5f873c1f7a 100644 --- a/usr.sbin/smtpd/runner.c +++ b/usr.sbin/smtpd/runner.c @@ -1,4 +1,4 @@ -/* $OpenBSD: runner.c,v 1.98 2011/04/14 21:53:46 gilles Exp $ */ +/* $OpenBSD: runner.c,v 1.99 2011/04/14 22:36:09 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -98,7 +98,7 @@ runner_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg) if (m->type != T_BOUNCE_MESSAGE && m->sender.user[0] != '\0') { - bounce_record_message(m, &bounce); + bounce_record_message(env, m, &bounce); ramqueue_insert(&env->sc_rqueue, &bounce, time(NULL)); runner_setup_events(env); } @@ -367,7 +367,7 @@ runner_process_envelope(struct smtpd *env, struct ramqueue_envelope *rq_evp, tim struct message bounce; message_set_errormsg(&envelope, "loop has been detected"); - bounce_record_message(&envelope, &bounce); + bounce_record_message(env, &envelope, &bounce); ramqueue_insert(&env->sc_rqueue, &bounce, time(NULL)); runner_setup_events(env); queue_envelope_delete(env, Q_QUEUE, &envelope); diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 67ca4e3c1fb..fd46dd6c4ad 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.210 2011/04/14 20:11:08 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.211 2011/04/14 22:36:09 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -1085,12 +1085,12 @@ int enqueue_record_envelope(struct message *); int enqueue_remove_envelope(struct message *); int enqueue_commit_message(struct message *); int enqueue_open_messagefile(struct message *); -int bounce_create_layout(char *, struct message *); +int bounce_create_layout(struct smtpd *, char *, struct message *); void bounce_delete_message(char *); int bounce_record_envelope(struct message *); int bounce_remove_envelope(struct message *); int bounce_commit_message(struct message *); -int bounce_record_message(struct message *, struct message *); +int bounce_record_message(struct smtpd *, struct message *, struct message *); int queue_create_incoming_layout(char *); void queue_delete_incoming_message(char *); int queue_record_incoming_envelope(struct message *); |