diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2011-04-14 21:53:47 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2011-04-14 21:53:47 +0000 |
commit | 1dfda728514d3dfa5392aaba1e10de003909639e (patch) | |
tree | 1548848951e6ac789341b133c5c573d9617b792b | |
parent | 31f310c8229e9d38537aeee483beecd845fcd8c6 (diff) |
fsqueue now provides fsqueue_message_fd_r() and fsqueue_message_fd_rw() to
obtain a read{-only,/write} descriptor to the message file.
make sure smtpd uses the new API everywhere it needs a fd, and kill the
many functions that were used until now.
-rw-r--r-- | usr.sbin/smtpd/bounce.c | 5 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue.c | 8 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_fsqueue.c | 56 | ||||
-rw-r--r-- | usr.sbin/smtpd/queue_shared.c | 45 | ||||
-rw-r--r-- | usr.sbin/smtpd/runner.c | 12 |
5 files changed, 63 insertions, 63 deletions
diff --git a/usr.sbin/smtpd/bounce.c b/usr.sbin/smtpd/bounce.c index 9bea66eb241..7889f10f36b 100644 --- a/usr.sbin/smtpd/bounce.c +++ b/usr.sbin/smtpd/bounce.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bounce.c,v 1.27 2011/04/14 20:11:08 gilles Exp $ */ +/* $OpenBSD: bounce.c,v 1.28 2011/04/14 21:53:45 gilles Exp $ */ /* * Copyright (c) 2009 Gilles Chehade <gilles@openbsd.org> @@ -55,7 +55,8 @@ bounce_session(struct smtpd *env, int fd, struct message *messagep) FILE *msgfp = NULL; /* get message content */ - if ((msgfd = queue_open_message_file(messagep->message_id)) == -1) + if ((msgfd = queue_message_fd_r(env, Q_QUEUE, + messagep->message_id)) == -1) goto fail; msgfp = fdopen(msgfd, "r"); if (msgfp == NULL) diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c index c9515bc6bc6..8669ae231ae 100644 --- a/usr.sbin/smtpd/queue.c +++ b/usr.sbin/smtpd/queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: queue.c,v 1.95 2011/04/13 20:53:18 gilles Exp $ */ +/* $OpenBSD: queue.c,v 1.96 2011/04/14 21:53:45 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -106,9 +106,9 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg) case IMSG_QUEUE_MESSAGE_FILE: ss.id = m->session_id; if (m->flags & F_MESSAGE_ENQUEUED) - fd = enqueue_open_messagefile(m); + fd = queue_message_fd_rw(env, Q_ENQUEUE, m->message_id); else - fd = queue_open_incoming_message_file(m); + fd = queue_message_fd_rw(env, Q_INCOMING, m->message_id); if (fd == -1) ss.code = 421; imsg_compose_event(iev, IMSG_QUEUE_MESSAGE_FILE, 0, 0, fd, @@ -170,7 +170,7 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg) switch (imsg->hdr.type) { case IMSG_QUEUE_MESSAGE_FD: rq_batch = imsg->data; - fd = queue_open_message_file(rq_batch->m_id); + fd = queue_message_fd_r(env, Q_QUEUE, rq_batch->m_id); imsg_compose_event(iev, IMSG_QUEUE_MESSAGE_FD, 0, 0, fd, rq_batch, sizeof *rq_batch); return; diff --git a/usr.sbin/smtpd/queue_fsqueue.c b/usr.sbin/smtpd/queue_fsqueue.c index be4ce0b7176..b81963f94cd 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.3 2011/04/14 21:14:20 gilles Exp $ */ +/* $OpenBSD: queue_fsqueue.c,v 1.4 2011/04/14 21:53:46 gilles Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -26,6 +26,7 @@ #include <err.h> #include <errno.h> #include <event.h> +#include <fcntl.h> #include <imsg.h> #include <libgen.h> #include <pwd.h> @@ -44,6 +45,8 @@ 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_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 *); int fsqueue_init(struct smtpd *); @@ -60,7 +63,7 @@ fsqueue_getpath(enum queue_kind kind) return (PATH_INCOMING); case Q_ENQUEUE: - return (PATH_INCOMING); + return (PATH_ENQUEUE); case Q_QUEUE: return (PATH_QUEUE); @@ -120,7 +123,7 @@ fsqueue_envelope_load(struct smtpd *env, enum queue_kind qkind, return 1; } -int +static int fsqueue_envelope_update(struct smtpd *env, enum queue_kind qkind, struct message *envelope) { @@ -175,7 +178,7 @@ tempfail: return 0; } -int +static int fsqueue_envelope_delete(struct smtpd *env, enum queue_kind qkind, struct message *envelope) { @@ -203,7 +206,46 @@ fsqueue_envelope_delete(struct smtpd *env, enum queue_kind qkind, return 1; } -int +static int +fsqueue_message_fd_r(struct smtpd *env, enum queue_kind qkind, char *msgid) +{ + int fd; + char pathname[MAXPATHLEN]; + u_int16_t hval; + + if (qkind == Q_ENQUEUE || qkind == Q_INCOMING) { + if (! bsnprintf(pathname, sizeof(pathname), "%s/%s/message", + fsqueue_getpath(qkind), msgid)) + fatal("fsqueue_message_fd_r: snprintf"); + } + else { + hval = fsqueue_hash(msgid); + if (! bsnprintf(pathname, sizeof(pathname), "%s/%d/%s/message", + fsqueue_getpath(qkind), hval, 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"); + + return fd; +} + +static int +fsqueue_message_fd_rw(struct smtpd *env, enum queue_kind qkind, char *msgid) +{ + char pathname[MAXPATHLEN]; + + if (! bsnprintf(pathname, sizeof(pathname), "%s/%s/message", + 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); +} + +static int fsqueue_message_delete(struct smtpd *env, enum queue_kind qkind, char *msgid) { char rootdir[MAXPATHLEN]; @@ -390,10 +432,10 @@ fsqueue_message(struct smtpd *env, enum queue_kind qkind, return 0; case QOP_FD_R: - return 0; + return fsqueue_message_fd_r(env, qkind, msgid); case QOP_FD_RW: - return 0; + return fsqueue_message_fd_rw(env, qkind, msgid); default: fatalx("queue_fsqueue_message: unsupported operation."); diff --git a/usr.sbin/smtpd/queue_shared.c b/usr.sbin/smtpd/queue_shared.c index 1d8f1c415ef..0c14d9e4e57 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.38 2011/04/14 20:11:08 gilles Exp $ */ +/* $OpenBSD: queue_shared.c,v 1.39 2011/04/14 21:53:46 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -227,18 +227,6 @@ queue_commit_layout_message(char *queuepath, struct message *messagep) } int -queue_open_layout_messagefile(char *queuepath, struct message *messagep) -{ - char pathname[MAXPATHLEN]; - - if (! bsnprintf(pathname, sizeof(pathname), "%s/%s/message", queuepath, - messagep->message_id)) - fatal("queue_open_incoming_message_file: snprintf"); - - return open(pathname, O_CREAT|O_EXCL|O_RDWR, 0600); -} - -int enqueue_create_layout(char *msgid) { return queue_create_layout_message(PATH_ENQUEUE, msgid); @@ -269,12 +257,6 @@ enqueue_commit_message(struct message *message) } int -enqueue_open_messagefile(struct message *message) -{ - return queue_open_layout_messagefile(PATH_ENQUEUE, message); -} - -int bounce_create_layout(char *msgid, struct message *message) { char msgpath[MAXPATHLEN]; @@ -378,31 +360,6 @@ queue_commit_incoming_message(struct message *message) return queue_commit_layout_message(PATH_INCOMING, message); } -int -queue_open_incoming_message_file(struct message *message) -{ - return queue_open_layout_messagefile(PATH_INCOMING, message); -} - -int -queue_open_message_file(char *msgid) -{ - int fd; - char pathname[MAXPATHLEN]; - u_int16_t hval; - - hval = queue_hash(msgid); - - if (! bsnprintf(pathname, sizeof(pathname), "%s/%d/%s/message", - PATH_QUEUE, hval, msgid)) - fatal("queue_open_message_file: snprintf"); - - if ((fd = open(pathname, O_RDONLY)) == -1) - fatal("queue_open_message_file: open"); - - return fd; -} - void queue_message_update(struct smtpd *env, struct message *messagep) { diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c index fb8e185f0ab..22b13ee81cc 100644 --- a/usr.sbin/smtpd/runner.c +++ b/usr.sbin/smtpd/runner.c @@ -1,4 +1,4 @@ -/* $OpenBSD: runner.c,v 1.97 2011/04/14 20:11:08 gilles Exp $ */ +/* $OpenBSD: runner.c,v 1.98 2011/04/14 21:53:46 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -56,7 +56,7 @@ void runner_process_batch(struct smtpd *, struct ramqueue_envelope *, time_t); void runner_purge_run(void); void runner_purge_message(char *); -int runner_check_loop(struct message *); +int runner_check_loop(struct smtpd *, struct message *); int runner_force_message_to_ramqueue(struct ramqueue *, char *); @@ -363,7 +363,7 @@ runner_process_envelope(struct smtpd *env, struct ramqueue_envelope *rq_evp, tim return 0; } - if (runner_check_loop(&envelope)) { + if (runner_check_loop(env, &envelope)) { struct message bounce; message_set_errormsg(&envelope, "loop has been detected"); @@ -421,7 +421,7 @@ runner_process_batch(struct smtpd *env, struct ramqueue_envelope *rq_evp, time_t &envelope)) return; envelope.lasttry = curtm; - fd = queue_open_message_file(envelope.message_id); + fd = queue_message_fd_r(env, Q_QUEUE, rq_evp->batch->m_id); imsg_compose_event(env->sc_ievs[PROC_QUEUE], IMSG_MDA_SESS_NEW, PROC_MDA, 0, fd, &envelope, sizeof envelope); @@ -585,7 +585,7 @@ delroot: } int -runner_check_loop(struct message *messagep) +runner_check_loop(struct smtpd *env, struct message *messagep) { int fd; FILE *fp; @@ -595,7 +595,7 @@ runner_check_loop(struct message *messagep) int ret = 0; int rcvcount = 0; - fd = queue_open_message_file(messagep->message_id); + fd = queue_message_fd_r(env, Q_QUEUE, messagep->message_id); if ((fp = fdopen(fd, "r")) == NULL) fatal("fdopen"); |