summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2009-07-28 22:03:56 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2009-07-28 22:03:56 +0000
commit94010cad00060918e872cf96b4feed6bf9bf34c3 (patch)
tree432c6cb4ccc27d828f25fdb137ff0d9510d6eeab /usr.sbin
parent5a8b485770b64f31116865b644c971a7626b4301 (diff)
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.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/smtpd/queue_shared.c73
-rw-r--r--usr.sbin/smtpd/runner.c4
-rw-r--r--usr.sbin/smtpd/smtpd.c4
-rw-r--r--usr.sbin/smtpd/smtpd.h9
4 files changed, 84 insertions, 6 deletions
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 <gilles@openbsd.org>
@@ -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 <gilles@openbsd.org>
@@ -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 <gilles@openbsd.org>
@@ -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 <gilles@openbsd.org>
@@ -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 *);