From 94010cad00060918e872cf96b4feed6bf9bf34c3 Mon Sep 17 00:00:00 2001 From: Gilles Chehade Date: Tue, 28 Jul 2009 22:03:56 +0000 Subject: introduce daemon_record_message() and needed glue in queue_shared.c to atomically create a mailer daemon out of a message. it is unreferenced for now, this commit makes no functional change. --- usr.sbin/smtpd/queue_shared.c | 73 ++++++++++++++++++++++++++++++++++++++++++- usr.sbin/smtpd/runner.c | 4 +-- usr.sbin/smtpd/smtpd.c | 4 +-- usr.sbin/smtpd/smtpd.h | 9 +++++- 4 files changed, 84 insertions(+), 6 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/smtpd/queue_shared.c b/usr.sbin/smtpd/queue_shared.c index e8923e4966f..f36715ad716 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.18 2009/05/10 11:29:40 jacekm Exp $ */ +/* $OpenBSD: queue_shared.c,v 1.19 2009/07/28 22:03:55 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -266,6 +266,77 @@ enqueue_open_messagefile(struct message *message) return queue_open_layout_messagefile(PATH_ENQUEUE, message); } +int +daemon_create_layout(char *msgid, struct message *message) +{ + char msgpath[MAXPATHLEN]; + char lnkpath[MAXPATHLEN]; + + if (! queue_create_layout_message(PATH_DAEMON, 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_DAEMON, msgid)) + return 0; + + if (link(msgpath, lnkpath) == -1) + fatal("link"); + + return 1; +} + +void +daemon_delete_message(char *msgid) +{ + queue_delete_layout_message(PATH_DAEMON, msgid); +} + +int +daemon_record_envelope(struct message *message) +{ + return queue_record_layout_envelope(PATH_DAEMON, message); +} + +int +daemon_remove_envelope(struct message *message) +{ + return queue_remove_layout_envelope(PATH_DAEMON, message); +} + +int +daemon_commit_message(struct message *message) +{ + return queue_commit_layout_message(PATH_DAEMON, message); +} + +int +daemon_record_message(struct message *messagep) +{ + char msgid[MAX_ID_SIZE]; + struct message mdaemon; + + if (messagep->type == T_DAEMON_MESSAGE) { + log_debug("mailer daemons loop detected !"); + return 0; + } + + mdaemon = *messagep; + mdaemon.type |= T_DAEMON_MESSAGE; + + if (! daemon_create_layout(msgid, messagep)) + return 0; + + strlcpy(mdaemon.message_id, msgid, sizeof(mdaemon.message_id)); + if (! daemon_record_envelope(&mdaemon)) + return 0; + + return daemon_commit_message(&mdaemon); +} int queue_create_incoming_layout(char *msgid) diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c index 6f4ce9f2b8c..16847cd4fe6 100644 --- a/usr.sbin/smtpd/runner.c +++ b/usr.sbin/smtpd/runner.c @@ -1,4 +1,4 @@ -/* $OpenBSD: runner.c,v 1.53 2009/06/29 10:11:07 martynas Exp $ */ +/* $OpenBSD: runner.c,v 1.54 2009/07/28 22:03:55 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -587,7 +587,7 @@ runner_process_queue(struct smtpd *env) continue; if (runner_check_loop(&message)) { - log_debug("TODO: generate mailer daemon"); + /*daemon_record_message(&message);*/ queue_remove_envelope(&message); continue; } diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index 1f691892b68..77d04ac6c47 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.77 2009/07/28 21:12:26 jsg Exp $ */ +/* $OpenBSD: smtpd.c,v 1.78 2009/07/28 22:03:55 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -1011,7 +1011,7 @@ setup_spool(uid_t uid, gid_t gid) char *paths[] = { PATH_INCOMING, PATH_ENQUEUE, PATH_QUEUE, PATH_RUNQUEUE, PATH_RUNQUEUELOW, PATH_RUNQUEUEHIGH, PATH_PURGE, - PATH_OFFLINE }; + PATH_OFFLINE, PATH_DAEMON }; char pathname[MAXPATHLEN]; struct stat sb; int ret; diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 2e39b9c76b3..1df044dc33e 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.129 2009/06/26 11:48:00 okan Exp $ */ +/* $OpenBSD: smtpd.h,v 1.130 2009/07/28 22:03:55 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -76,6 +76,7 @@ #define PATH_RUNQUEUELOW "/runqueue-low" #define PATH_OFFLINE "/offline" +#define PATH_DAEMON "/daemon" /* number of MX records to lookup */ #define MAX_MX_COUNT 10 @@ -808,6 +809,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 daemon_create_layout(char *, struct message *); +void daemon_delete_message(char *); +int daemon_record_envelope(struct message *); +int daemon_remove_envelope(struct message *); +int daemon_commit_message(struct message *); +int daemon_record_message(struct message *); int queue_create_incoming_layout(char *); void queue_delete_incoming_message(char *); int queue_record_incoming_envelope(struct message *); -- cgit v1.2.3