summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd/smtpd.c
diff options
context:
space:
mode:
authorGilles Chehade <gilles@cvs.openbsd.org>2009-05-20 14:29:45 +0000
committerGilles Chehade <gilles@cvs.openbsd.org>2009-05-20 14:29:45 +0000
commitbc25feea06c53f00f0d6f4c0cc46d680abef8057 (patch)
tree867ebdef0a941cf7d60314ae3eb148d7634fa894 /usr.sbin/smtpd/smtpd.c
parent4ca8ef671d2dcbf4a29531ed0b75fb9144a8be32 (diff)
first step towards configuration reload in smtpd, smtpctl reload will parse
the configuration file again and replace current configuration with new one in all processes. what we don't support yet is graceful restart, clients in sessions at the moment of the reload will have a temp failure thrown at 'em which is ok RFC-wise but which we will try to improve anyway. tested with various setups, "diff reads good" jacekm@
Diffstat (limited to 'usr.sbin/smtpd/smtpd.c')
-rw-r--r--usr.sbin/smtpd/smtpd.c54
1 files changed, 50 insertions, 4 deletions
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index b688f61ac80..2ed5eaa0549 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.61 2009/05/19 22:54:46 gilles Exp $ */
+/* $OpenBSD: smtpd.c,v 1.62 2009/05/20 14:29:44 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -53,6 +53,8 @@
__dead void usage(void);
void parent_shutdown(void);
void parent_send_config(int, short, void *);
+void parent_send_config_listeners(struct smtpd *);
+void parent_send_config_ruleset(struct smtpd *, int);
void parent_dispatch_lka(int, short, void *);
void parent_dispatch_mda(int, short, void *);
void parent_dispatch_mfa(int, short, void *);
@@ -131,10 +133,17 @@ parent_shutdown(void)
void
parent_send_config(int fd, short event, void *p)
{
- struct smtpd *env = p;
- struct iovec iov[3];
+ parent_send_config_listeners(p);
+ parent_send_config_ruleset(p, PROC_MFA);
+ parent_send_config_ruleset(p, PROC_LKA);
+}
+
+void
+parent_send_config_listeners(struct smtpd *env)
+{
struct listener *l;
struct ssl *s;
+ struct iovec iov[3];
log_debug("parent_send_config: configuring smtp");
imsg_compose(env->sc_ibufs[PROC_SMTP], IMSG_CONF_START,
@@ -162,6 +171,35 @@ parent_send_config(int fd, short event, void *p)
}
void
+parent_send_config_ruleset(struct smtpd *env, int proc)
+{
+ struct rule *r;
+ struct cond *cond;
+ struct map *m;
+
+ log_debug("parent_send_config_ruleset: reloading rules and maps");
+ imsg_compose(env->sc_ibufs[proc], IMSG_CONF_START,
+ 0, 0, -1, NULL, 0);
+
+ TAILQ_FOREACH(r, env->sc_rules, r_entry) {
+ imsg_compose(env->sc_ibufs[proc], IMSG_CONF_RULE,
+ 0, 0, -1, r, sizeof(*r));
+ TAILQ_FOREACH(cond, &r->r_conditions, c_entry) {
+ imsg_compose(env->sc_ibufs[proc], IMSG_CONF_CONDITION,
+ 0, 0, -1, cond, sizeof(*cond));
+ }
+ }
+
+ TAILQ_FOREACH(m, env->sc_maps, m_entry) {
+ imsg_compose(env->sc_ibufs[proc], IMSG_CONF_MAP,
+ 0, 0, -1, m, sizeof(*m));
+ }
+
+ imsg_compose(env->sc_ibufs[proc], IMSG_CONF_END,
+ 0, 0, -1, NULL, 0);
+}
+
+void
parent_dispatch_lka(int fd, short event, void *p)
{
struct smtpd *env = p;
@@ -452,7 +490,7 @@ parent_dispatch_smtp(int fd, short event, void *p)
switch (imsg.hdr.type) {
case IMSG_PARENT_SEND_CONFIG: {
- parent_send_config(-1, -1, env);
+ parent_send_config_listeners(env);
break;
}
case IMSG_PARENT_AUTHENTICATE: {
@@ -594,6 +632,14 @@ parent_dispatch_control(int sig, short event, void *p)
break;
switch (imsg.hdr.type) {
+ case IMSG_CONF_RELOAD: {
+ parent_send_config_ruleset(env, PROC_MFA);
+ parent_send_config_ruleset(env, PROC_LKA);
+ imsg_compose(env->sc_ibufs[PROC_SMTP],
+ IMSG_CONF_RELOAD, 0, 0, -1, NULL, 0);
+ imsg_compose(ibuf, IMSG_CONF_RELOAD, 0, 0, -1, NULL, 0);
+ break;
+ }
case IMSG_STATS: {
struct stats *s = imsg.data;