summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/smtpd/config.c16
-rw-r--r--usr.sbin/smtpd/mta.c4
-rw-r--r--usr.sbin/smtpd/parse.y25
-rw-r--r--usr.sbin/smtpd/smtp.c32
-rw-r--r--usr.sbin/smtpd/smtpd.c8
-rw-r--r--usr.sbin/smtpd/smtpd.h6
-rw-r--r--usr.sbin/smtpd/ssl.c10
7 files changed, 62 insertions, 39 deletions
diff --git a/usr.sbin/smtpd/config.c b/usr.sbin/smtpd/config.c
index 19a60e45d7f..6bed7d4ae25 100644
--- a/usr.sbin/smtpd/config.c
+++ b/usr.sbin/smtpd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.6 2009/05/24 14:38:56 jacekm Exp $ */
+/* $OpenBSD: config.c,v 1.7 2009/06/02 22:23:35 gilles Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -63,11 +63,12 @@ purge_config(struct smtpd *env, u_int8_t what)
struct ssl *s;
if (what & PURGE_LISTENERS) {
- while ((l = TAILQ_FIRST(&env->sc_listeners)) != NULL) {
- TAILQ_REMOVE(&env->sc_listeners, l, entry);
+ while ((l = TAILQ_FIRST(env->sc_listeners)) != NULL) {
+ TAILQ_REMOVE(env->sc_listeners, l, entry);
free(l);
}
- TAILQ_INIT(&env->sc_listeners);
+ free(env->sc_listeners);
+ env->sc_listeners = NULL;
}
if (what & PURGE_MAPS) {
while ((m = TAILQ_FIRST(env->sc_maps)) != NULL) {
@@ -93,13 +94,14 @@ purge_config(struct smtpd *env, u_int8_t what)
env->sc_rules = NULL;
}
if (what & PURGE_SSL) {
- while ((s = SPLAY_ROOT(&env->sc_ssl)) != NULL) {
- SPLAY_REMOVE(ssltree, &env->sc_ssl, s);
+ while ((s = SPLAY_ROOT(env->sc_ssl)) != NULL) {
+ SPLAY_REMOVE(ssltree, env->sc_ssl, s);
free(s->ssl_cert);
free(s->ssl_key);
free(s);
}
- SPLAY_INIT(&env->sc_ssl);
+ free(env->sc_ssl);
+ env->sc_ssl = NULL;
}
}
diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c
index 6b4a8539927..a203744f325 100644
--- a/usr.sbin/smtpd/mta.c
+++ b/usr.sbin/smtpd/mta.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mta.c,v 1.55 2009/06/01 13:20:56 jacekm Exp $ */
+/* $OpenBSD: mta.c,v 1.56 2009/06/02 22:23:35 gilles Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -129,7 +129,7 @@ mta_dispatch_parent(int sig, short event, void *p)
(sizeof(*s) + s->ssl_cert_len))) == NULL)
fatal(NULL);
- SPLAY_INSERT(ssltree, &env->sc_ssl, s);
+ SPLAY_INSERT(ssltree, env->sc_ssl, s);
break;
}
case IMSG_CONF_END:
diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index fb2f09dd9f9..02930931d19 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.36 2009/05/30 23:53:41 gilles Exp $ */
+/* $OpenBSD: parse.y,v 1.37 2009/06/02 22:23:35 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -278,9 +278,9 @@ main : QUEUE INTERVAL interval {
}
}
- if (! interface($3, cert, &conf->sc_listeners,
+ if (! interface($3, cert, conf->sc_listeners,
MAX_LISTEN, $4, flags)) {
- if (host($3, cert, &conf->sc_listeners,
+ if (host($3, cert, conf->sc_listeners,
MAX_LISTEN, $4, flags) <= 0) {
yyerror("invalid virtual ip or interface: %s", $3);
free($6);
@@ -1272,10 +1272,25 @@ parse_config(struct smtpd *x_conf, const char *filename, int opts)
free(conf->sc_maps);
return 0;
}
+ if ((conf->sc_listeners = calloc(1, sizeof(*conf->sc_listeners))) == NULL) {
+ log_warn("cannot allocate memory");
+ free(conf->sc_maps);
+ free(conf->sc_rules);
+ return 0;
+ }
+ if ((conf->sc_ssl = calloc(1, sizeof(*conf->sc_ssl))) == NULL) {
+ log_warn("cannot allocate memory");
+ free(conf->sc_maps);
+ free(conf->sc_rules);
+ free(conf->sc_listeners);
+ return 0;
+ }
if ((m = calloc(1, sizeof(*m))) == NULL) {
log_warn("cannot allocate memory");
free(conf->sc_maps);
free(conf->sc_rules);
+ free(conf->sc_listeners);
+ free(conf->sc_ssl);
return 0;
}
@@ -1285,11 +1300,11 @@ parse_config(struct smtpd *x_conf, const char *filename, int opts)
map = NULL;
rule = NULL;
- TAILQ_INIT(&conf->sc_listeners);
+ TAILQ_INIT(conf->sc_listeners);
TAILQ_INIT(conf->sc_maps);
TAILQ_INIT(conf->sc_rules);
+ SPLAY_INIT(conf->sc_ssl);
SPLAY_INIT(&conf->sc_sessions);
- SPLAY_INIT(&conf->sc_ssl);
conf->sc_qintval.tv_sec = SMTPD_QUEUE_INTERVAL;
conf->sc_qintval.tv_usec = 0;
diff --git a/usr.sbin/smtpd/smtp.c b/usr.sbin/smtpd/smtp.c
index f2e83c240e7..b3e97d5a843 100644
--- a/usr.sbin/smtpd/smtp.c
+++ b/usr.sbin/smtpd/smtp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp.c,v 1.54 2009/06/01 14:38:45 jacekm Exp $ */
+/* $OpenBSD: smtp.c,v 1.55 2009/06/02 22:23:36 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -109,8 +109,8 @@ smtp_dispatch_parent(int sig, short event, void *p)
s->s_l = NULL;
s->s_msg.status |= S_MESSAGE_TEMPFAILURE;
}
-
- smtp_disable_events(env);
+ if (env->sc_listeners)
+ smtp_disable_events(env);
imsg_compose(ibuf, IMSG_PARENT_SEND_CONFIG, 0, 0, -1,
NULL, 0);
break;
@@ -119,6 +119,12 @@ smtp_dispatch_parent(int sig, short event, void *p)
if (env->sc_flags & SMTPD_CONFIGURING)
break;
env->sc_flags |= SMTPD_CONFIGURING;
+
+ if ((env->sc_listeners = calloc(1, sizeof(*env->sc_listeners))) == NULL)
+ fatal("smtp_dispatch_parent: calloc");
+ if ((env->sc_ssl = calloc(1, sizeof(*env->sc_ssl))) == NULL)
+ fatal("smtp_dispatch_parent: calloc");
+ TAILQ_INIT(env->sc_listeners);
break;
case IMSG_CONF_SSL: {
struct ssl *s;
@@ -141,7 +147,7 @@ smtp_dispatch_parent(int sig, short event, void *p)
(sizeof(*s) + s->ssl_cert_len))) == NULL)
fatal(NULL);
- SPLAY_INSERT(ssltree, &env->sc_ssl, s);
+ SPLAY_INSERT(ssltree, env->sc_ssl, s);
break;
}
case IMSG_CONF_LISTENER: {
@@ -163,10 +169,10 @@ smtp_dispatch_parent(int sig, short event, void *p)
if (l->flags & F_SSL)
if ((l->ssl = SPLAY_FIND(ssltree,
- &env->sc_ssl, &key)) == NULL)
+ env->sc_ssl, &key)) == NULL)
fatal("parent and smtp desynchronized");
- TAILQ_INSERT_TAIL(&env->sc_listeners, l, entry);
+ TAILQ_INSERT_TAIL(env->sc_listeners, l, entry);
break;
}
case IMSG_CONF_END:
@@ -630,7 +636,6 @@ smtp(struct smtpd *env)
config_pipes(env, peers, nitems(peers));
config_peers(env, peers, nitems(peers));
- smtp_setup_events(env);
event_dispatch();
smtp_shutdown();
@@ -642,7 +647,7 @@ smtp_setup_events(struct smtpd *env)
{
struct listener *l;
- TAILQ_FOREACH(l, &env->sc_listeners, entry) {
+ TAILQ_FOREACH(l, env->sc_listeners, entry) {
log_debug("smtp_setup_events: listen on %s port %d flags 0x%01x"
" cert \"%s\"", ss_to_text(&l->ss), ntohs(l->port),
l->flags, l->ssl_cert_name);
@@ -663,13 +668,14 @@ smtp_disable_events(struct smtpd *env)
struct listener *l;
log_debug("smtp_disable_events: closing listening sockets");
- while ((l = TAILQ_FIRST(&env->sc_listeners)) != NULL) {
- TAILQ_REMOVE(&env->sc_listeners, l, entry);
+ while ((l = TAILQ_FIRST(env->sc_listeners)) != NULL) {
+ TAILQ_REMOVE(env->sc_listeners, l, entry);
event_del(&l->ev);
close(l->fd);
free(l);
}
- TAILQ_INIT(&env->sc_listeners);
+ free(env->sc_listeners);
+ env->sc_listeners = NULL;
}
void
@@ -680,7 +686,7 @@ smtp_pause(struct smtpd *env)
log_debug("smtp_pause: pausing listening sockets");
env->sc_opts |= SMTPD_SMTP_PAUSED;
- TAILQ_FOREACH(l, &env->sc_listeners, entry)
+ TAILQ_FOREACH(l, env->sc_listeners, entry)
event_del(&l->ev);
}
@@ -692,7 +698,7 @@ smtp_resume(struct smtpd *env)
log_debug("smtp_resume: resuming listening sockets");
env->sc_opts &= ~SMTPD_SMTP_PAUSED;
- TAILQ_FOREACH(l, &env->sc_listeners, entry)
+ TAILQ_FOREACH(l, env->sc_listeners, entry)
event_add(&l->ev, NULL);
}
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index 6d1ed99425b..d59ae8b6b59 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.71 2009/06/01 18:24:01 deraadt Exp $ */
+/* $OpenBSD: smtpd.c,v 1.72 2009/06/02 22:23:36 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -136,7 +136,7 @@ parent_send_config_listeners(struct smtpd *env)
imsg_compose(env->sc_ibufs[PROC_SMTP], IMSG_CONF_START,
0, 0, -1, NULL, 0);
- SPLAY_FOREACH(s, ssltree, &env->sc_ssl) {
+ SPLAY_FOREACH(s, ssltree, env->sc_ssl) {
if (!(s->flags & F_SCERT))
continue;
@@ -151,7 +151,7 @@ parent_send_config_listeners(struct smtpd *env)
iov, nitems(iov));
}
- TAILQ_FOREACH(l, &env->sc_listeners, entry) {
+ TAILQ_FOREACH(l, env->sc_listeners, entry) {
if ((l->fd = socket(l->ss.ss_family, SOCK_STREAM, 0)) == -1)
fatal("socket");
opt = 1;
@@ -177,7 +177,7 @@ parent_send_config_client_certs(struct smtpd *env)
imsg_compose(env->sc_ibufs[PROC_MTA], IMSG_CONF_START,
0, 0, -1, NULL, 0);
- SPLAY_FOREACH(s, ssltree, &env->sc_ssl) {
+ SPLAY_FOREACH(s, ssltree, env->sc_ssl) {
if (!(s->flags & F_CCERT))
continue;
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index f81e7af22da..4ffeb3cca9f 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.121 2009/06/01 18:24:01 deraadt Exp $ */
+/* $OpenBSD: smtpd.h,v 1.122 2009/06/02 22:23:36 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -675,12 +675,12 @@ struct smtpd {
char *sc_title[PROC_COUNT];
struct passwd *sc_pw;
char sc_hostname[MAXHOSTNAMELEN];
- TAILQ_HEAD(listenerlist, listener) sc_listeners;
+ TAILQ_HEAD(listenerlist, listener) *sc_listeners;
TAILQ_HEAD(maplist, map) *sc_maps, *sc_maps_reload;
TAILQ_HEAD(rulelist, rule) *sc_rules, *sc_rules_reload;
SPLAY_HEAD(sessiontree, session) sc_sessions;
SPLAY_HEAD(msgtree, message) sc_messages;
- SPLAY_HEAD(ssltree, ssl) sc_ssl;
+ SPLAY_HEAD(ssltree, ssl) *sc_ssl;
SPLAY_HEAD(batchtree, batch) batch_queue;
SPLAY_HEAD(childtree, child) children;
diff --git a/usr.sbin/smtpd/ssl.c b/usr.sbin/smtpd/ssl.c
index 9cfd78dcdc9..f5e98c4ad82 100644
--- a/usr.sbin/smtpd/ssl.c
+++ b/usr.sbin/smtpd/ssl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssl.c,v 1.18 2009/06/01 18:02:41 jacekm Exp $ */
+/* $OpenBSD: ssl.c,v 1.19 2009/06/02 22:23:36 gilles Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -349,7 +349,7 @@ ssl_load_certfile(struct smtpd *env, const char *name, u_int8_t flags)
return -1;
}
- s = SPLAY_FIND(ssltree, &env->sc_ssl, &key);
+ s = SPLAY_FIND(ssltree, env->sc_ssl, &key);
if (s != NULL) {
s->flags |= flags;
return 0;
@@ -385,7 +385,7 @@ ssl_load_certfile(struct smtpd *env, const char *name, u_int8_t flags)
return (-1);
}
- SPLAY_INSERT(ssltree, &env->sc_ssl, s);
+ SPLAY_INSERT(ssltree, env->sc_ssl, s);
return (0);
}
@@ -415,7 +415,7 @@ ssl_setup(struct smtpd *env, struct listener *l)
>= sizeof(key.ssl_name))
fatal("ssl_setup: certificate name truncated");
- if ((l->ssl = SPLAY_FIND(ssltree, &env->sc_ssl, &key)) == NULL)
+ if ((l->ssl = SPLAY_FIND(ssltree, env->sc_ssl, &key)) == NULL)
fatal("ssl_setup: certificate tree corrupted");
l->ssl_ctx = ssl_ctx_create();
@@ -576,7 +576,7 @@ ssl_client_init(struct session *s)
sizeof(key.ssl_name)) >= sizeof(key.ssl_name))
log_warnx("warning: certificate name too long: %s",
s->batch->rule.r_value.relayhost.cert);
- else if ((ssl = SPLAY_FIND(ssltree, &s->s_env->sc_ssl,
+ else if ((ssl = SPLAY_FIND(ssltree, s->s_env->sc_ssl,
&key)) == NULL)
log_warnx("warning: failed to find client "
"certificate: %s", key.ssl_name);