summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2011-05-01 12:57:12 +0000
committerEric Faurot <eric@cvs.openbsd.org>2011-05-01 12:57:12 +0000
commitc451ba908723902ef2bf2ef658ed29e304a28fe1 (patch)
treefde86e74ac869a4d88d3612616972d38e0aa5861
parenta98e9bb7b03360436119edd88230330b78dac64f (diff)
the smtpd env is meant to be global, so do not pass it all around.
discussed with and ok gilles@
-rw-r--r--usr.sbin/smtpd/aliases.c38
-rw-r--r--usr.sbin/smtpd/bounce.c16
-rw-r--r--usr.sbin/smtpd/config.c15
-rw-r--r--usr.sbin/smtpd/control.c41
-rw-r--r--usr.sbin/smtpd/dns.c31
-rw-r--r--usr.sbin/smtpd/lka.c129
-rw-r--r--usr.sbin/smtpd/makemap.c17
-rw-r--r--usr.sbin/smtpd/map.c10
-rw-r--r--usr.sbin/smtpd/mda.c26
-rw-r--r--usr.sbin/smtpd/mfa.c36
-rw-r--r--usr.sbin/smtpd/mta.c59
-rw-r--r--usr.sbin/smtpd/parse.y28
-rw-r--r--usr.sbin/smtpd/queue.c72
-rw-r--r--usr.sbin/smtpd/queue_backend.c54
-rw-r--r--usr.sbin/smtpd/queue_fsqueue.c82
-rw-r--r--usr.sbin/smtpd/queue_shared.c20
-rw-r--r--usr.sbin/smtpd/ramqueue.c39
-rw-r--r--usr.sbin/smtpd/ruleset.c12
-rw-r--r--usr.sbin/smtpd/runner.c98
-rw-r--r--usr.sbin/smtpd/smtp.c76
-rw-r--r--usr.sbin/smtpd/smtp_session.c56
-rw-r--r--usr.sbin/smtpd/smtpctl.c4
-rw-r--r--usr.sbin/smtpd/smtpd.c158
-rw-r--r--usr.sbin/smtpd/smtpd.h116
-rw-r--r--usr.sbin/smtpd/ssl.c28
25 files changed, 615 insertions, 646 deletions
diff --git a/usr.sbin/smtpd/aliases.c b/usr.sbin/smtpd/aliases.c
index f416f530860..26b631d0f64 100644
--- a/usr.sbin/smtpd/aliases.c
+++ b/usr.sbin/smtpd/aliases.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aliases.c,v 1.41 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: aliases.c,v 1.42 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -41,18 +41,18 @@ static int alias_is_filename(struct expandnode *, char *, size_t);
static int alias_is_include(struct expandnode *, char *, size_t);
int
-aliases_exist(struct smtpd *env, objid_t mapid, char *username)
+aliases_exist(objid_t mapid, char *username)
{
struct map *map;
struct map_alias *map_alias;
char buf[MAX_LOCALPART_SIZE];
- map = map_find(env, mapid);
+ map = map_find(mapid);
if (map == NULL)
return 0;
lowercase(buf, username, sizeof(buf));
- map_alias = map_lookup(env, mapid, buf, K_ALIAS);
+ map_alias = map_lookup(mapid, buf, K_ALIAS);
if (map_alias == NULL)
return 0;
@@ -67,7 +67,7 @@ aliases_exist(struct smtpd *env, objid_t mapid, char *username)
}
int
-aliases_get(struct smtpd *env, objid_t mapid, struct expandtree *expandtree, char *username)
+aliases_get(objid_t mapid, struct expandtree *expandtree, char *username)
{
struct map *map;
struct map_alias *map_alias;
@@ -75,12 +75,12 @@ aliases_get(struct smtpd *env, objid_t mapid, struct expandtree *expandtree, cha
char buf[MAX_LOCALPART_SIZE];
size_t nbaliases;
- map = map_find(env, mapid);
+ map = map_find(mapid);
if (map == NULL)
return 0;
lowercase(buf, username, sizeof(buf));
- map_alias = map_lookup(env, mapid, buf, K_ALIAS);
+ map_alias = map_lookup(mapid, buf, K_ALIAS);
if (map_alias == NULL)
return 0;
@@ -103,18 +103,18 @@ aliases_get(struct smtpd *env, objid_t mapid, struct expandtree *expandtree, cha
}
int
-aliases_vdomain_exists(struct smtpd *env, objid_t mapid, char *hostname)
+aliases_vdomain_exists(objid_t mapid, char *hostname)
{
struct map *map;
struct map_virtual *map_virtual;
char buf[MAXHOSTNAMELEN];
- map = map_find(env, mapid);
+ map = map_find(mapid);
if (map == NULL)
return 0;
lowercase(buf, hostname, sizeof(buf));
- map_virtual = map_lookup(env, mapid, buf, K_VIRTUAL);
+ map_virtual = map_lookup(mapid, buf, K_VIRTUAL);
if (map_virtual == NULL)
return 0;
@@ -128,14 +128,14 @@ aliases_vdomain_exists(struct smtpd *env, objid_t mapid, char *hostname)
}
int
-aliases_virtual_exist(struct smtpd *env, objid_t mapid, struct path *path)
+aliases_virtual_exist(objid_t mapid, struct path *path)
{
struct map *map;
struct map_virtual *map_virtual;
char buf[MAX_LINE_SIZE];
char *pbuf = buf;
- map = map_find(env, mapid);
+ map = map_find(mapid);
if (map == NULL)
return 0;
@@ -144,10 +144,10 @@ aliases_virtual_exist(struct smtpd *env, objid_t mapid, struct path *path)
return 0;
lowercase(buf, buf, sizeof(buf));
- map_virtual = map_lookup(env, mapid, buf, K_VIRTUAL);
+ map_virtual = map_lookup(mapid, buf, K_VIRTUAL);
if (map_virtual == NULL) {
pbuf = strchr(buf, '@');
- map_virtual = map_lookup(env, mapid, pbuf, K_VIRTUAL);
+ map_virtual = map_lookup(mapid, pbuf, K_VIRTUAL);
}
if (map_virtual == NULL)
return 0;
@@ -160,8 +160,8 @@ aliases_virtual_exist(struct smtpd *env, objid_t mapid, struct path *path)
}
int
-aliases_virtual_get(struct smtpd *env, objid_t mapid,
- struct expandtree *expandtree, struct path *path)
+aliases_virtual_get(objid_t mapid, struct expandtree *expandtree,
+ struct path *path)
{
struct map *map;
struct map_virtual *map_virtual;
@@ -170,7 +170,7 @@ aliases_virtual_get(struct smtpd *env, objid_t mapid,
char *pbuf = buf;
int nbaliases;
- map = map_find(env, mapid);
+ map = map_find(mapid);
if (map == NULL)
return 0;
@@ -179,10 +179,10 @@ aliases_virtual_get(struct smtpd *env, objid_t mapid,
return 0;
lowercase(buf, buf, sizeof(buf));
- map_virtual = map_lookup(env, mapid, buf, K_VIRTUAL);
+ map_virtual = map_lookup(mapid, buf, K_VIRTUAL);
if (map_virtual == NULL) {
pbuf = strchr(buf, '@');
- map_virtual = map_lookup(env, mapid, pbuf, K_VIRTUAL);
+ map_virtual = map_lookup(mapid, pbuf, K_VIRTUAL);
}
if (map_virtual == NULL)
return 0;
diff --git a/usr.sbin/smtpd/bounce.c b/usr.sbin/smtpd/bounce.c
index f48c3d22256..ff3bed8100b 100644
--- a/usr.sbin/smtpd/bounce.c
+++ b/usr.sbin/smtpd/bounce.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bounce.c,v 1.30 2011/04/17 11:39:22 gilles Exp $ */
+/* $OpenBSD: bounce.c,v 1.31 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2009 Gilles Chehade <gilles@openbsd.org>
@@ -42,12 +42,11 @@ struct client_ctx {
struct event ev;
struct envelope m;
struct smtp_client *pcb;
- struct smtpd *env;
FILE *msgfp;
};
int
-bounce_session(struct smtpd *env, int fd, struct envelope *m)
+bounce_session(int fd, struct envelope *m)
{
struct client_ctx *cc = NULL;
int msgfd = -1;
@@ -58,7 +57,7 @@ bounce_session(struct smtpd *env, int fd, struct envelope *m)
msgid = evpid_to_msgid(m->evpid);
/* get message content */
- if ((msgfd = queue_message_fd_r(env, Q_QUEUE, msgid)) == -1)
+ if ((msgfd = queue_message_fd_r(Q_QUEUE, msgid)) == -1)
goto fail;
msgfp = fdopen(msgfd, "r");
if (msgfp == NULL)
@@ -68,7 +67,6 @@ bounce_session(struct smtpd *env, int fd, struct envelope *m)
if ((cc = calloc(1, sizeof(*cc))) == NULL)
goto fail;
cc->pcb = client_init(fd, msgfp, env->sc_hostname, 1);
- cc->env = env;
cc->m = *m;
cc->msgfp = msgfp;
@@ -150,18 +148,18 @@ bounce_event(int fd, short event, void *p)
out:
if (*ep == '2')
- queue_envelope_delete(cc->env, Q_QUEUE, &cc->m);
+ queue_envelope_delete(Q_QUEUE, &cc->m);
else {
if (*ep == '5' || *ep == '6')
cc->m.status = S_MESSAGE_PERMFAILURE;
else
cc->m.status = S_MESSAGE_TEMPFAILURE;
message_set_errormsg(&cc->m, "%s", ep);
- queue_message_update(cc->env, &cc->m);
+ queue_message_update(&cc->m);
}
- cc->env->stats->runner.active--;
- cc->env->stats->runner.bounces_active--;
+ env->stats->runner.active--;
+ env->stats->runner.bounces_active--;
client_close(cc->pcb);
fclose(cc->msgfp);
free(cc);
diff --git a/usr.sbin/smtpd/config.c b/usr.sbin/smtpd/config.c
index 6858f05677b..4e0368189a7 100644
--- a/usr.sbin/smtpd/config.c
+++ b/usr.sbin/smtpd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.14 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: config.c,v 1.15 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -45,17 +45,17 @@ is_peer(struct peer *p, enum smtp_proc_type peer, u_int peercount)
}
void
-unconfigure(struct smtpd *env)
+unconfigure(void)
{
}
void
-configure(struct smtpd *env)
+configure(void)
{
}
void
-purge_config(struct smtpd *env, u_int8_t what)
+purge_config(u_int8_t what)
{
struct listener *l;
struct map *m;
@@ -104,7 +104,7 @@ purge_config(struct smtpd *env, u_int8_t what)
}
void
-init_pipes(struct smtpd *env)
+init_pipes(void)
{
int i;
int j;
@@ -149,7 +149,7 @@ init_pipes(struct smtpd *env)
}
void
-config_pipes(struct smtpd *env, struct peer *p, u_int peercount)
+config_pipes(struct peer *p, u_int peercount)
{
u_int i;
u_int j;
@@ -184,7 +184,7 @@ config_pipes(struct smtpd *env, struct peer *p, u_int peercount)
}
void
-config_peers(struct smtpd *env, struct peer *p, u_int peercount)
+config_peers(struct peer *p, u_int peercount)
{
int count;
u_int src;
@@ -212,7 +212,6 @@ config_peers(struct smtpd *env, struct peer *p, u_int peercount)
env->sc_ievs[dst][count].events = EV_READ;
env->sc_ievs[dst][count].proc = dst;
env->sc_ievs[dst][count].data = &env->sc_ievs[dst][count];
- env->sc_ievs[dst][count].env = env;
event_set(&(env->sc_ievs[dst][count].ev),
env->sc_ievs[dst][count].ibuf.fd,
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c
index 8134aa0ce00..28800a90f64 100644
--- a/usr.sbin/smtpd/control.c
+++ b/usr.sbin/smtpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.57 2011/04/13 20:53:18 gilles Exp $ */
+/* $OpenBSD: control.c,v 1.58 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -47,21 +47,21 @@ struct {
int fd;
} control_state;
-void control_imsg(struct smtpd *, struct imsgev *, struct imsg *);
+void control_imsg(struct imsgev *, struct imsg *);
__dead void control_shutdown(void);
int control_init(void);
-void control_listen(struct smtpd *);
+void control_listen(void);
void control_cleanup(void);
void control_accept(int, short, void *);
struct ctl_conn *control_connbyfd(int);
-void control_close(struct smtpd *, int);
+void control_close(int);
void control_sig_handler(int, short, void *);
void control_dispatch_ext(int, short, void *);
struct ctl_connlist ctl_conns;
void
-control_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
+control_imsg(struct imsgev *iev, struct imsg *imsg)
{
struct ctl_conn *c;
struct reload *reload;
@@ -111,7 +111,7 @@ control_sig_handler(int sig, short event, void *p)
pid_t
-control(struct smtpd *env)
+control(void)
{
struct sockaddr_un sun;
int fd;
@@ -136,7 +136,7 @@ control(struct smtpd *env)
return (pid);
}
- purge_config(env, PURGE_EVERYTHING);
+ purge_config(PURGE_EVERYTHING);
pw = env->sc_pw;
@@ -187,8 +187,8 @@ control(struct smtpd *env)
imsg_callback = control_imsg;
event_init();
- signal_set(&ev_sigint, SIGINT, control_sig_handler, env);
- signal_set(&ev_sigterm, SIGTERM, control_sig_handler, env);
+ signal_set(&ev_sigint, SIGINT, control_sig_handler, NULL);
+ signal_set(&ev_sigterm, SIGTERM, control_sig_handler, NULL);
signal_add(&ev_sigint, NULL);
signal_add(&ev_sigterm, NULL);
signal(SIGPIPE, SIG_IGN);
@@ -196,9 +196,9 @@ control(struct smtpd *env)
TAILQ_INIT(&ctl_conns);
- config_pipes(env, peers, nitems(peers));
- config_peers(env, peers, nitems(peers));
- control_listen(env);
+ config_pipes(peers, nitems(peers));
+ config_peers(peers, nitems(peers));
+ control_listen();
if (event_dispatch() < 0)
fatal("event_dispatch");
@@ -215,7 +215,7 @@ control_shutdown(void)
}
void
-control_listen(struct smtpd *env)
+control_listen(void)
{
int avail = availdesc();
@@ -224,7 +224,7 @@ control_listen(struct smtpd *env)
avail--;
event_set(&control_state.ev, control_state.fd, EV_READ|EV_PERSIST,
- control_accept, env);
+ control_accept, NULL);
event_add(&control_state.ev, NULL);
/* guarantee 2 fds to each accepted client */
@@ -246,7 +246,6 @@ control_accept(int listenfd, short event, void *arg)
socklen_t len;
struct sockaddr_un sun;
struct ctl_conn *c;
- struct smtpd *env = arg;
len = sizeof(sun);
if ((connfd = accept(listenfd, (struct sockaddr *)&sun, &len)) == -1) {
@@ -262,9 +261,8 @@ control_accept(int listenfd, short event, void *arg)
imsg_init(&c->iev.ibuf, connfd);
c->iev.handler = control_dispatch_ext;
c->iev.events = EV_READ;
- c->iev.data = env;
event_set(&c->iev.ev, c->iev.ibuf.fd, c->iev.events,
- c->iev.handler, env);
+ c->iev.handler, NULL);
event_add(&c->iev.ev, NULL);
TAILQ_INSERT_TAIL(&ctl_conns, c, entry);
@@ -292,7 +290,7 @@ control_connbyfd(int fd)
}
void
-control_close(struct smtpd *env, int fd)
+control_close(int fd)
{
struct ctl_conn *c;
@@ -320,7 +318,6 @@ void
control_dispatch_ext(int fd, short event, void *arg)
{
struct ctl_conn *c;
- struct smtpd *env = arg;
struct imsg imsg;
int n;
uid_t euid;
@@ -336,21 +333,21 @@ control_dispatch_ext(int fd, short event, void *arg)
if (event & EV_READ) {
if ((n = imsg_read(&c->iev.ibuf)) == -1 || n == 0) {
- control_close(env, fd);
+ control_close(fd);
return;
}
}
if (event & EV_WRITE) {
if (msgbuf_write(&c->iev.ibuf.w) < 0) {
- control_close(env, fd);
+ control_close(fd);
return;
}
}
for (;;) {
if ((n = imsg_get(&c->iev.ibuf, &imsg)) == -1) {
- control_close(env, fd);
+ control_close(fd);
return;
}
diff --git a/usr.sbin/smtpd/dns.c b/usr.sbin/smtpd/dns.c
index d3fc88b959b..b6bd5a13a3b 100644
--- a/usr.sbin/smtpd/dns.c
+++ b/usr.sbin/smtpd/dns.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dns.c,v 1.40 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: dns.c,v 1.41 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -37,8 +37,8 @@
#include "smtpd.h"
#include "log.h"
-static struct dnssession *dnssession_init(struct smtpd *, struct dns *);
-static void dnssession_destroy(struct smtpd *, struct dnssession *);
+static struct dnssession *dnssession_init(struct dns *);
+static void dnssession_destroy(struct dnssession *);
static void dnssession_mx_insert(struct dnssession *, const char *, int);
static void dns_asr_event_set(struct dnssession *, struct asr_result *);
static void dns_asr_handler(int, short, void *);
@@ -53,7 +53,7 @@ struct asr *asr = NULL;
*/
void
-dns_query_host(struct smtpd *env, char *host, int port, u_int64_t id)
+dns_query_host(char *host, int port, u_int64_t id)
{
struct dns query;
@@ -67,7 +67,7 @@ dns_query_host(struct smtpd *env, char *host, int port, u_int64_t id)
}
void
-dns_query_mx(struct smtpd *env, char *host, int port, u_int64_t id)
+dns_query_mx(char *host, int port, u_int64_t id)
{
struct dns query;
@@ -81,7 +81,7 @@ dns_query_mx(struct smtpd *env, char *host, int port, u_int64_t id)
}
void
-dns_query_ptr(struct smtpd *env, struct sockaddr_storage *ss, u_int64_t id)
+dns_query_ptr(struct sockaddr_storage *ss, u_int64_t id)
{
struct dns query;
@@ -95,7 +95,7 @@ dns_query_ptr(struct smtpd *env, struct sockaddr_storage *ss, u_int64_t id)
/* LKA interface */
void
-dns_async(struct smtpd *env, struct imsgev *asker, int type, struct dns *query)
+dns_async(struct imsgev *asker, int type, struct dns *query)
{
struct dnssession *dnssession;
@@ -104,10 +104,9 @@ dns_async(struct smtpd *env, struct imsgev *asker, int type, struct dns *query)
goto noasr;
}
- query->env = env;
query->type = type;
query->asker = asker;
- dnssession = dnssession_init(env, query);
+ dnssession = dnssession_init(query);
switch (type) {
case IMSG_DNS_HOST:
@@ -140,7 +139,7 @@ dns_async(struct smtpd *env, struct imsgev *asker, int type, struct dns *query)
}
env->stats->lka.queries_failure++;
- dnssession_destroy(env, dnssession);
+ dnssession_destroy(dnssession);
noasr:
query->error = EAI_AGAIN;
if (type != IMSG_DNS_PTR)
@@ -240,10 +239,10 @@ next:
if (dnssession->mxcurrent == dnssession->mxarraysz) {
query->error = (dnssession->mxfound) ? 0 : EAI_NONAME;
if (query->error)
- query->env->stats->lka.queries_failure++;
+ env->stats->lka.queries_failure++;
imsg_compose_event(query->asker, IMSG_DNS_HOST_END, 0,
0, -1, query, sizeof(*query));
- dnssession_destroy(query->env, dnssession);
+ dnssession_destroy(dnssession);
return;
}
mx = dnssession->mxarray + dnssession->mxcurrent++;
@@ -287,17 +286,17 @@ dns_asr_dispatch_cname(struct dnssession *dnssession)
break;
case ASR_DONE:
/* This is necessarily an error */
- query->env->stats->lka.queries_failure++;
+ env->stats->lka.queries_failure++;
query->error = ar.ar_err;
break;
}
imsg_compose_event(query->asker, IMSG_DNS_PTR, 0, 0, -1, query,
sizeof(*query));
- dnssession_destroy(query->env, dnssession);
+ dnssession_destroy(dnssession);
}
static struct dnssession *
-dnssession_init(struct smtpd *env, struct dns *query)
+dnssession_init(struct dns *query)
{
struct dnssession *dnssession;
@@ -318,7 +317,7 @@ dnssession_init(struct smtpd *env, struct dns *query)
}
static void
-dnssession_destroy(struct smtpd *env, struct dnssession *dnssession)
+dnssession_destroy(struct dnssession *dnssession)
{
env->stats->lka.queries_active--;
SPLAY_REMOVE(dnstree, &env->dns_sessions, dnssession);
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c
index 027c6dbb1b9..f36a783693e 100644
--- a/usr.sbin/smtpd/lka.c
+++ b/usr.sbin/smtpd/lka.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka.c,v 1.125 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: lka.c,v 1.126 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -41,28 +41,28 @@
#include "smtpd.h"
#include "log.h"
-struct rule *ruleset_match(struct smtpd *, char *, struct path *, struct sockaddr_storage *);
-static void lka_imsg(struct smtpd *, struct imsgev *, struct imsg *);
+struct rule *ruleset_match(char *, struct path *, struct sockaddr_storage *);
+static void lka_imsg(struct imsgev *, struct imsg *);
static void lka_shutdown(void);
static void lka_sig_handler(int, short, void *);
-static void lka_expand_pickup(struct smtpd *, struct lkasession *);
-static int lka_expand_resume(struct smtpd *, struct lkasession *);
-static int lka_resolve_node(struct smtpd *, char *, struct path *, struct expandnode *);
-static int lka_verify_mail(struct smtpd *, struct path *);
-static int lka_resolve_path(struct smtpd *, struct lkasession *, struct path *);
-static struct lkasession *lka_session_init(struct smtpd *, struct submit_status *);
-static void lka_request_forwardfile(struct smtpd *, struct lkasession *, char *);
+static void lka_expand_pickup(struct lkasession *);
+static int lka_expand_resume(struct lkasession *);
+static int lka_resolve_node(char *, struct path *, struct expandnode *);
+static int lka_verify_mail(struct path *);
+static int lka_resolve_path(struct lkasession *, struct path *);
+static struct lkasession *lka_session_init(struct submit_status *);
+static void lka_request_forwardfile(struct lkasession *, char *);
static void lka_clear_expandtree(struct expandtree *);
static void lka_clear_deliverylist(struct deliverylist *);
static int lka_encode_credentials(char *, size_t, struct map_secret *);
static size_t lka_expand(char *, size_t, struct path *, struct path *);
-static void lka_rcpt_action(struct smtpd *, char *, struct path *);
-static void lka_session_destroy(struct smtpd *, struct lkasession *);
-static void lka_expansion_done(struct smtpd *, struct lkasession *);
-static void lka_session_fail(struct smtpd *, struct lkasession *, struct submit_status *);
+static void lka_rcpt_action(char *, struct path *);
+static void lka_session_destroy(struct lkasession *);
+static void lka_expansion_done(struct lkasession *);
+static void lka_session_fail(struct lkasession *, struct submit_status *);
static void
-lka_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
+lka_imsg(struct imsgev *iev, struct imsg *imsg)
{
struct lkasession skey;
struct submit_status *ss;
@@ -77,7 +77,7 @@ lka_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
if (imsg->hdr.type == IMSG_DNS_HOST || imsg->hdr.type == IMSG_DNS_MX ||
imsg->hdr.type == IMSG_DNS_PTR) {
- dns_async(env, iev, imsg->hdr.type, imsg->data);
+ dns_async(iev, imsg->hdr.type, imsg->data);
return;
}
@@ -90,7 +90,7 @@ lka_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
ss->u.path.domain[0] == '\0')
ss->code = 250;
else
- if (lka_verify_mail(env, &ss->u.path))
+ if (lka_verify_mail(&ss->u.path))
ss->code = 250;
imsg_compose_event(iev, IMSG_LKA_MAIL, 0, 0, -1, ss,
sizeof *ss);
@@ -99,8 +99,7 @@ lka_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_LKA_RULEMATCH:
ss = imsg->data;
ss->code = 530;
- rule = ruleset_match(env, ss->msg.tag, &ss->u.path,
- &ss->ss);
+ rule = ruleset_match(ss->msg.tag, &ss->u.path, &ss->ss);
if (rule) {
ss->code = 250;
ss->u.path.rule = *rule;
@@ -113,11 +112,11 @@ lka_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
ss = imsg->data;
ss->code = 250;
path = &ss->u.path;
- s = lka_session_init(env, ss);
- if (! lka_resolve_path(env, s, path))
- lka_session_fail(env, s, ss);
+ s = lka_session_init(ss);
+ if (! lka_resolve_path(s, path))
+ lka_session_fail(s, ss);
else
- lka_expand_pickup(env, s);
+ lka_expand_pickup(s);
return;
}
}
@@ -128,10 +127,10 @@ lka_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
struct map_secret *map_secret;
secret = imsg->data;
- map = map_find(env, secret->secmapid);
+ map = map_find(secret->secmapid);
if (map == NULL)
fatalx("lka: secrets map not found");
- map_secret = map_lookup(env, map->m_id, secret->host, K_SECRET);
+ map_secret = map_lookup(map->m_id, secret->host, K_SECRET);
log_debug("lka: %s secret lookup (%d)", secret->host,
map_secret != NULL);
secret->secret[0] = '\0';
@@ -182,7 +181,7 @@ lka_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
rule = TAILQ_LAST(env->sc_rules_reload, rulelist);
tmp = env->sc_maps;
env->sc_maps = env->sc_maps_reload;
- rule->r_sources = map_findbyname(env, imsg->data);
+ rule->r_sources = map_findbyname(imsg->data);
if (rule->r_sources == NULL)
fatalx("lka: maps inconsistency");
env->sc_maps = tmp;
@@ -199,9 +198,9 @@ lka_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_CONF_END:
if (env->sc_rules)
- purge_config(env, PURGE_RULES);
+ purge_config(PURGE_RULES);
if (env->sc_maps)
- purge_config(env, PURGE_MAPS);
+ purge_config(PURGE_MAPS);
env->sc_rules = env->sc_rules_reload;
env->sc_maps = env->sc_maps_reload;
return;
@@ -225,7 +224,7 @@ lka_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
}
close(imsg->fd);
s->path.flags |= F_PATH_FORWARDED;
- lka_expand_pickup(env, s);
+ lka_expand_pickup(s);
} else {
if (fwreq->status) {
/* .forward not present */
@@ -233,12 +232,12 @@ lka_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
strlcpy(path->pw_name, fwreq->pw_name,
sizeof path->pw_name);
TAILQ_INSERT_TAIL(&s->deliverylist, path, entry);
- lka_expand_pickup(env, s);
+ lka_expand_pickup(s);
} else {
/* opening .forward failed */
s->ss.code = 530;
s->flags |= F_ERROR;
- lka_expand_pickup(env, s);
+ lka_expand_pickup(s);
}
}
return;
@@ -281,7 +280,7 @@ lka_shutdown(void)
}
pid_t
-lka(struct smtpd *env)
+lka(void)
{
pid_t pid;
struct passwd *pw;
@@ -307,7 +306,7 @@ lka(struct smtpd *env)
return (pid);
}
- purge_config(env, PURGE_EVERYTHING);
+ purge_config(PURGE_EVERYTHING);
pw = env->sc_pw;
@@ -323,9 +322,9 @@ lka(struct smtpd *env)
event_init();
SPLAY_INIT(&env->lka_sessions);
- signal_set(&ev_sigint, SIGINT, lka_sig_handler, env);
- signal_set(&ev_sigterm, SIGTERM, lka_sig_handler, env);
- signal_set(&ev_sigchld, SIGCHLD, lka_sig_handler, env);
+ signal_set(&ev_sigint, SIGINT, lka_sig_handler, NULL);
+ signal_set(&ev_sigterm, SIGTERM, lka_sig_handler, NULL);
+ signal_set(&ev_sigchld, SIGCHLD, lka_sig_handler, NULL);
signal_add(&ev_sigint, NULL);
signal_add(&ev_sigterm, NULL);
signal_add(&ev_sigchld, NULL);
@@ -338,8 +337,8 @@ lka(struct smtpd *env)
*/
fdlimit(1.0);
- config_pipes(env, peers, nitems(peers));
- config_peers(env, peers, nitems(peers));
+ config_pipes(peers, nitems(peers));
+ config_peers(peers, nitems(peers));
if (event_dispatch() < 0)
fatal("event_dispatch");
@@ -349,7 +348,7 @@ lka(struct smtpd *env)
}
int
-lka_verify_mail(struct smtpd *env, struct path *path)
+lka_verify_mail(struct path *path)
{
return 1;
}
@@ -464,7 +463,7 @@ copy:
}
int
-lka_resolve_node(struct smtpd *env, char *tag, struct path *path, struct expandnode *expnode)
+lka_resolve_node(char *tag, struct path *path, struct expandnode *expnode)
{
struct path psave = *path;
@@ -494,7 +493,7 @@ lka_resolve_node(struct smtpd *env, char *tag, struct path *path, struct expandn
log_debug("lka_resolve_node: resolved to address: %s@%s",
path->user, path->domain);
- lka_rcpt_action(env, tag, path);
+ lka_rcpt_action(tag, path);
break;
case EXPAND_FILENAME:
@@ -526,7 +525,7 @@ lka_resolve_node(struct smtpd *env, char *tag, struct path *path, struct expandn
sizeof(path->domain)) >= sizeof(path->domain))
return 0;
- lka_rcpt_action(env, tag, path);
+ lka_rcpt_action(tag, path);
break;
case EXPAND_INVALID:
case EXPAND_INCLUDE:
@@ -538,7 +537,7 @@ lka_resolve_node(struct smtpd *env, char *tag, struct path *path, struct expandn
}
void
-lka_expand_pickup(struct smtpd *env, struct lkasession *lkasession)
+lka_expand_pickup(struct lkasession *lkasession)
{
int ret;
@@ -550,7 +549,7 @@ lka_expand_pickup(struct smtpd *env, struct lkasession *lkasession)
while (! (lkasession->flags & F_ERROR) &&
! lkasession->pending && lkasession->iterations < 5) {
++lkasession->iterations;
- ret = lka_expand_resume(env, lkasession);
+ ret = lka_expand_resume(lkasession);
if (ret == -1) {
lkasession->ss.code = 530;
lkasession->flags |= F_ERROR;
@@ -563,11 +562,11 @@ lka_expand_pickup(struct smtpd *env, struct lkasession *lkasession)
if (lkasession->pending)
return;
- lka_expansion_done(env, lkasession);
+ lka_expansion_done(lkasession);
}
int
-lka_expand_resume(struct smtpd *env, struct lkasession *lkasession)
+lka_expand_resume(struct lkasession *lkasession)
{
u_int8_t done = 1;
struct expandnode *expnode = NULL;
@@ -583,7 +582,7 @@ lka_expand_resume(struct smtpd *env, struct lkasession *lkasession)
done = 0;
/* convert node to path, then inherit flags from lkasession */
- if (! lka_resolve_node(env, lkasession->message.tag, &path, expnode))
+ if (! lka_resolve_node(lkasession->message.tag, &path, expnode))
return -1;
path.flags = lkasessionpath->flags;
@@ -591,7 +590,7 @@ lka_expand_resume(struct smtpd *env, struct lkasession *lkasession)
* we need to dup because path may be added to the deliverylist.
*/
pathp = path_dup(&path);
- if (! lka_resolve_path(env, lkasession, pathp))
+ if (! lka_resolve_path(lkasession, pathp))
return -1;
/* decrement refcount on this node and flag it as processed */
@@ -612,7 +611,7 @@ lka_expand_resume(struct smtpd *env, struct lkasession *lkasession)
}
void
-lka_expansion_done(struct smtpd *env, struct lkasession *lkasession)
+lka_expansion_done(struct lkasession *lkasession)
{
struct envelope message;
struct path *path;
@@ -631,21 +630,21 @@ lka_expansion_done(struct smtpd *env, struct lkasession *lkasession)
lka_expand(path->rule.r_value.buffer,
sizeof(path->rule.r_value.buffer), path, &message.sender);
message.recipient = *path;
- queue_submit_envelope(env, &message);
+ queue_submit_envelope(&message);
TAILQ_REMOVE(&lkasession->deliverylist, path, entry);
free(path);
}
- queue_commit_envelopes(env, &message);
+ queue_commit_envelopes(&message);
done:
lka_clear_expandtree(&lkasession->expandtree);
lka_clear_deliverylist(&lkasession->deliverylist);
- lka_session_destroy(env, lkasession);
+ lka_session_destroy(lkasession);
}
int
-lka_resolve_path(struct smtpd *env, struct lkasession *lkasession, struct path *path)
+lka_resolve_path(struct lkasession *lkasession, struct path *path)
{
if (IS_RELAY(*path)) {
path = path_dup(path);
@@ -668,9 +667,9 @@ lka_resolve_path(struct smtpd *env, struct lkasession *lkasession, struct path *
if (sep != NULL)
*sep = '\0';
- if (aliases_exist(env, path->rule.r_amap, username)) {
+ if (aliases_exist(path->rule.r_amap, username)) {
path->flags |= F_PATH_ALIAS;
- if (! aliases_get(env, path->rule.r_amap,
+ if (! aliases_get(path->rule.r_amap,
&lkasession->expandtree, path->user))
return 0;
return 1;
@@ -690,14 +689,14 @@ lka_resolve_path(struct smtpd *env, struct lkasession *lkasession, struct path *
if (path->flags & F_PATH_FORWARDED)
TAILQ_INSERT_TAIL(&lkasession->deliverylist, path, entry);
else
- lka_request_forwardfile(env, lkasession, path->pw_name);
+ lka_request_forwardfile(lkasession, path->pw_name);
return 1;
}
case C_VDOM: {
- if (aliases_virtual_exist(env, path->rule.r_condition.c_map, path)) {
+ if (aliases_virtual_exist(path->rule.r_condition.c_map, path)) {
path->flags |= F_PATH_VIRTUAL;
- if (! aliases_virtual_get(env, path->rule.r_condition.c_map,
+ if (! aliases_virtual_get(path->rule.r_condition.c_map,
&lkasession->expandtree, path))
return 0;
return 1;
@@ -712,7 +711,7 @@ lka_resolve_path(struct smtpd *env, struct lkasession *lkasession, struct path *
}
static void
-lka_rcpt_action(struct smtpd *env, char *tag, struct path *path)
+lka_rcpt_action(char *tag, struct path *path)
{
struct rule *r;
@@ -720,7 +719,7 @@ lka_rcpt_action(struct smtpd *env, char *tag, struct path *path)
(void)strlcpy(path->domain, env->sc_hostname,
sizeof (path->domain));
- r = ruleset_match(env, tag, path, NULL);
+ r = ruleset_match(tag, path, NULL);
if (r == NULL) {
path->rule.r_action = A_RELAY;
return;
@@ -786,7 +785,7 @@ lka_encode_credentials(char *dst, size_t size, struct map_secret *map_secret)
}
static struct lkasession *
-lka_session_init(struct smtpd *env, struct submit_status *ss)
+lka_session_init(struct submit_status *ss)
{
struct lkasession *lkasession;
@@ -807,23 +806,23 @@ lka_session_init(struct smtpd *env, struct submit_status *ss)
}
static void
-lka_session_fail(struct smtpd *env, struct lkasession *lkasession, struct submit_status *ss)
+lka_session_fail(struct lkasession *lkasession, struct submit_status *ss)
{
ss->code = 530;
imsg_compose_event(env->sc_ievs[PROC_MFA], IMSG_LKA_RCPT, 0, 0, -1,
ss, sizeof(*ss));
- lka_session_destroy(env, lkasession);
+ lka_session_destroy(lkasession);
}
static void
-lka_session_destroy(struct smtpd *env, struct lkasession *lkasession)
+lka_session_destroy(struct lkasession *lkasession)
{
SPLAY_REMOVE(lkatree, &env->lka_sessions, lkasession);
free(lkasession);
}
static void
-lka_request_forwardfile(struct smtpd *env, struct lkasession *lkasession, char *username)
+lka_request_forwardfile(struct lkasession *lkasession, char *username)
{
struct forward_req fwreq;
diff --git a/usr.sbin/smtpd/makemap.c b/usr.sbin/smtpd/makemap.c
index 864cf660f0b..b8d92d1a7fb 100644
--- a/usr.sbin/smtpd/makemap.c
+++ b/usr.sbin/smtpd/makemap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: makemap.c,v 1.29 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: makemap.c,v 1.30 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -58,6 +58,8 @@ char *source;
char *oflag;
int dbputs;
+struct smtpd *env = NULL;
+
enum program {
P_MAKEMAP,
P_NEWALIASES
@@ -73,13 +75,13 @@ enum output_type {
* Stub functions so that makemap compiles using minimum object files.
*/
void
-purge_config(struct smtpd *env, u_int8_t what)
+purge_config(u_int8_t what)
{
bzero(env, sizeof(struct smtpd));
}
int
-ssl_load_certfile(struct smtpd *env, const char *name, u_int8_t flags)
+ssl_load_certfile(const char *name, u_int8_t flags)
{
return (0);
}
@@ -92,6 +94,9 @@ main(int argc, char *argv[])
char *opts;
char *conf;
int ch;
+ struct smtpd smtpd;
+
+ env = &smtpd;
log_init(1);
@@ -383,15 +388,15 @@ error:
char *
conf_aliases(char *cfgpath)
{
- struct smtpd env;
+ struct smtpd smtpd;
struct map *map;
char *path;
char *p;
- if (parse_config(&env, cfgpath, 0))
+ if (parse_config(&smtpd, cfgpath, 0))
exit(1);
- map = map_findbyname(&env, "aliases");
+ map = map_findbyname("aliases");
if (map == NULL)
return (PATH_ALIASES);
diff --git a/usr.sbin/smtpd/map.c b/usr.sbin/smtpd/map.c
index 96caaabacb1..4ce5a3c1943 100644
--- a/usr.sbin/smtpd/map.c
+++ b/usr.sbin/smtpd/map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: map.c,v 1.22 2010/11/28 14:35:58 gilles Exp $ */
+/* $OpenBSD: map.c,v 1.23 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -35,7 +35,7 @@ struct map_backend *map_backend_lookup(enum map_src);
struct map_parser *map_parser_lookup(enum map_kind);
struct map *
-map_findbyname(struct smtpd *env, const char *name)
+map_findbyname(const char *name)
{
struct map *m;
@@ -47,7 +47,7 @@ map_findbyname(struct smtpd *env, const char *name)
}
struct map *
-map_find(struct smtpd *env, objid_t id)
+map_find(objid_t id)
{
struct map *m;
@@ -59,7 +59,7 @@ map_find(struct smtpd *env, objid_t id)
}
void *
-map_lookup(struct smtpd *env, objid_t mapid, char *key, enum map_kind kind)
+map_lookup(objid_t mapid, char *key, enum map_kind kind)
{
void *hdl = NULL;
char *result = NULL;
@@ -69,7 +69,7 @@ map_lookup(struct smtpd *env, objid_t mapid, char *key, enum map_kind kind)
struct map_backend *backend = NULL;
struct map_parser *parser = NULL;
- map = map_find(env, mapid);
+ map = map_find(mapid);
if (map == NULL)
return NULL;
diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c
index 7626b9ed229..012095d2bb1 100644
--- a/usr.sbin/smtpd/mda.c
+++ b/usr.sbin/smtpd/mda.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mda.c,v 1.54 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: mda.c,v 1.55 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -36,17 +36,17 @@
#include "smtpd.h"
#include "log.h"
-static void mda_imsg(struct smtpd *, struct imsgev *, struct imsg *);
+static void mda_imsg(struct imsgev *, struct imsg *);
static void mda_shutdown(void);
static void mda_sig_handler(int, short, void *);
static void mda_store(struct mda_session *);
static void mda_store_event(int, short, void *);
-static struct mda_session *mda_lookup(struct smtpd *, u_int32_t);
+static struct mda_session *mda_lookup(u_int32_t);
u_int32_t mda_id;
static void
-mda_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
+mda_imsg(struct imsgev *iev, struct imsg *imsg)
{
char output[128], *error, *parent_error;
struct deliver deliver;
@@ -121,7 +121,7 @@ mda_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
if (iev->proc == PROC_PARENT) {
switch (imsg->hdr.type) {
case IMSG_PARENT_FORK_MDA:
- s = mda_lookup(env, imsg->hdr.peerid);
+ s = mda_lookup(imsg->hdr.peerid);
if (imsg->fd < 0)
fatalx("mda: fd pass fail");
@@ -131,7 +131,7 @@ mda_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
return;
case IMSG_MDA_DONE:
- s = mda_lookup(env, imsg->hdr.peerid);
+ s = mda_lookup(imsg->hdr.peerid);
/*
* Grab last line of mda stdout/stderr if available.
@@ -263,7 +263,7 @@ mda_shutdown(void)
}
pid_t
-mda(struct smtpd *env)
+mda(void)
{
pid_t pid;
struct passwd *pw;
@@ -285,7 +285,7 @@ mda(struct smtpd *env)
return (pid);
}
- purge_config(env, PURGE_EVERYTHING);
+ purge_config(PURGE_EVERYTHING);
pw = env->sc_pw;
@@ -307,15 +307,15 @@ mda(struct smtpd *env)
imsg_callback = mda_imsg;
event_init();
- signal_set(&ev_sigint, SIGINT, mda_sig_handler, env);
- signal_set(&ev_sigterm, SIGTERM, mda_sig_handler, env);
+ signal_set(&ev_sigint, SIGINT, mda_sig_handler, NULL);
+ signal_set(&ev_sigterm, SIGTERM, mda_sig_handler, NULL);
signal_add(&ev_sigint, NULL);
signal_add(&ev_sigterm, NULL);
signal(SIGPIPE, SIG_IGN);
signal(SIGHUP, SIG_IGN);
- config_pipes(env, peers, nitems(peers));
- config_peers(env, peers, nitems(peers));
+ config_pipes(peers, nitems(peers));
+ config_peers(peers, nitems(peers));
if (event_dispatch() < 0)
fatal("event_dispatch");
@@ -389,7 +389,7 @@ mda_store_event(int fd, short event, void *p)
}
static struct mda_session *
-mda_lookup(struct smtpd *env, u_int32_t id)
+mda_lookup(u_int32_t id)
{
struct mda_session *s;
diff --git a/usr.sbin/smtpd/mfa.c b/usr.sbin/smtpd/mfa.c
index d1bda911ecc..945227f591f 100644
--- a/usr.sbin/smtpd/mfa.c
+++ b/usr.sbin/smtpd/mfa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mfa.c,v 1.57 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: mfa.c,v 1.58 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -34,25 +34,25 @@
#include "smtpd.h"
#include "log.h"
-static void mfa_imsg(struct smtpd *, struct imsgev *, struct imsg *);
+static void mfa_imsg(struct imsgev *, struct imsg *);
static void mfa_shutdown(void);
static void mfa_sig_handler(int, short, void *);
-static void mfa_test_mail(struct smtpd *, struct envelope *);
-static void mfa_test_rcpt(struct smtpd *, struct envelope *);
-static void mfa_test_rcpt_resume(struct smtpd *, struct submit_status *);
+static void mfa_test_mail(struct envelope *);
+static void mfa_test_rcpt(struct envelope *);
+static void mfa_test_rcpt_resume(struct submit_status *);
static int mfa_strip_source_route(char *, size_t);
static void
-mfa_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
+mfa_imsg(struct imsgev *iev, struct imsg *imsg)
{
if (iev->proc == PROC_SMTP) {
switch (imsg->hdr.type) {
case IMSG_MFA_MAIL:
- mfa_test_mail(env, imsg->data);
+ mfa_test_mail(imsg->data);
return;
case IMSG_MFA_RCPT:
- mfa_test_rcpt(env, imsg->data);
+ mfa_test_rcpt(imsg->data);
return;
}
}
@@ -67,7 +67,7 @@ mfa_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
return;
case IMSG_LKA_RULEMATCH:
- mfa_test_rcpt_resume(env, imsg->data);
+ mfa_test_rcpt_resume(imsg->data);
return;
}
}
@@ -105,7 +105,7 @@ mfa_shutdown(void)
pid_t
-mfa(struct smtpd *env)
+mfa(void)
{
pid_t pid;
struct passwd *pw;
@@ -129,7 +129,7 @@ mfa(struct smtpd *env)
return (pid);
}
- purge_config(env, PURGE_EVERYTHING);
+ purge_config(PURGE_EVERYTHING);
pw = env->sc_pw;
@@ -149,15 +149,15 @@ mfa(struct smtpd *env)
imsg_callback = mfa_imsg;
event_init();
- signal_set(&ev_sigint, SIGINT, mfa_sig_handler, env);
- signal_set(&ev_sigterm, SIGTERM, mfa_sig_handler, env);
+ signal_set(&ev_sigint, SIGINT, mfa_sig_handler, NULL);
+ signal_set(&ev_sigterm, SIGTERM, mfa_sig_handler, NULL);
signal_add(&ev_sigint, NULL);
signal_add(&ev_sigterm, NULL);
signal(SIGPIPE, SIG_IGN);
signal(SIGHUP, SIG_IGN);
- config_pipes(env, peers, nitems(peers));
- config_peers(env, peers, nitems(peers));
+ config_pipes(peers, nitems(peers));
+ config_peers(peers, nitems(peers));
if (event_dispatch() < 0)
fatal("event_dispatch");
@@ -167,7 +167,7 @@ mfa(struct smtpd *env)
}
void
-mfa_test_mail(struct smtpd *env, struct envelope *m)
+mfa_test_mail(struct envelope *m)
{
struct submit_status ss;
@@ -202,7 +202,7 @@ accept:
}
static void
-mfa_test_rcpt(struct smtpd *env, struct envelope *m)
+mfa_test_rcpt(struct envelope *m)
{
struct submit_status ss;
@@ -233,7 +233,7 @@ refuse:
}
static void
-mfa_test_rcpt_resume(struct smtpd *env, struct submit_status *ss) {
+mfa_test_rcpt_resume(struct submit_status *ss) {
if (ss->code != 250) {
imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_MFA_RCPT, 0, 0, -1, ss,
sizeof(*ss));
diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c
index d8f53754168..07deac0507a 100644
--- a/usr.sbin/smtpd/mta.c
+++ b/usr.sbin/smtpd/mta.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mta.c,v 1.104 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: mta.c,v 1.105 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -38,10 +38,10 @@
#include "client.h"
#include "log.h"
-static void mta_imsg(struct smtpd *, struct imsgev *, struct imsg *);
+static void mta_imsg(struct imsgev *, struct imsg *);
static void mta_shutdown(void);
static void mta_sig_handler(int, short, void *);
-static struct mta_session *mta_lookup(struct smtpd *, u_int64_t);
+static struct mta_session *mta_lookup(u_int64_t);
static void mta_enter_state(struct mta_session *, int, void *);
static void mta_pickup(struct mta_session *, void *);
static void mta_event(int, short, void *);
@@ -53,7 +53,7 @@ static void mta_connect_done(int, short, void *);
static void mta_request_datafd(struct mta_session *);
static void
-mta_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
+mta_imsg(struct imsgev *iev, struct imsg *imsg)
{
struct ramqueue_batch *rq_batch;
struct mta_session *s;
@@ -73,7 +73,6 @@ mta_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
fatal(NULL);
s->id = rq_batch->b_id;
s->state = MTA_INIT;
- s->env = env;
s->batch = rq_batch;
/* establish host name */
@@ -128,7 +127,7 @@ mta_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_BATCH_APPEND:
m = imsg->data;
- s = mta_lookup(env, m->batch_id);
+ s = mta_lookup(m->batch_id);
m = malloc(sizeof *m);
if (m == NULL)
fatal(NULL);
@@ -146,12 +145,12 @@ mta_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_BATCH_CLOSE:
rq_batch = imsg->data;
- mta_pickup(mta_lookup(env, rq_batch->b_id), NULL);
+ mta_pickup(mta_lookup(rq_batch->b_id), NULL);
return;
case IMSG_QUEUE_MESSAGE_FD:
rq_batch = imsg->data;
- mta_pickup(mta_lookup(env, rq_batch->b_id), &imsg->fd);
+ mta_pickup(mta_lookup(rq_batch->b_id), &imsg->fd);
return;
}
}
@@ -160,12 +159,12 @@ mta_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
switch (imsg->hdr.type) {
case IMSG_LKA_SECRET:
secret = imsg->data;
- mta_pickup(mta_lookup(env, secret->id), secret->secret);
+ mta_pickup(mta_lookup(secret->id), secret->secret);
return;
case IMSG_DNS_HOST:
dns = imsg->data;
- s = mta_lookup(env, dns->id);
+ s = mta_lookup(dns->id);
relay = calloc(1, sizeof *relay);
if (relay == NULL)
fatal(NULL);
@@ -175,12 +174,12 @@ mta_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_DNS_HOST_END:
dns = imsg->data;
- mta_pickup(mta_lookup(env, dns->id), &dns->error);
+ mta_pickup(mta_lookup(dns->id), &dns->error);
return;
case IMSG_DNS_PTR:
dns = imsg->data;
- s = mta_lookup(env, dns->id);
+ s = mta_lookup(dns->id);
relay = TAILQ_FIRST(&s->relays);
if (dns->error)
strlcpy(relay->fqdn, "<unknown>",
@@ -258,7 +257,7 @@ mta_shutdown(void)
}
pid_t
-mta(struct smtpd *env)
+mta(void)
{
pid_t pid;
@@ -282,7 +281,7 @@ mta(struct smtpd *env)
}
ssl_init();
- purge_config(env, PURGE_EVERYTHING);
+ purge_config(PURGE_EVERYTHING);
pw = env->sc_pw;
if (chroot(pw->pw_dir) == -1)
@@ -301,17 +300,17 @@ mta(struct smtpd *env)
imsg_callback = mta_imsg;
event_init();
- signal_set(&ev_sigint, SIGINT, mta_sig_handler, env);
- signal_set(&ev_sigterm, SIGTERM, mta_sig_handler, env);
+ signal_set(&ev_sigint, SIGINT, mta_sig_handler, NULL);
+ signal_set(&ev_sigterm, SIGTERM, mta_sig_handler, NULL);
signal_add(&ev_sigint, NULL);
signal_add(&ev_sigterm, NULL);
signal(SIGPIPE, SIG_IGN);
signal(SIGHUP, SIG_IGN);
- config_pipes(env, peers, nitems(peers));
- config_peers(env, peers, nitems(peers));
+ config_pipes(peers, nitems(peers));
+ config_peers(peers, nitems(peers));
- ramqueue_init(env, &env->sc_rqueue);
+ ramqueue_init(&env->sc_rqueue);
SPLAY_INIT(&env->mta_sessions);
if (event_dispatch() < 0)
@@ -322,7 +321,7 @@ mta(struct smtpd *env)
}
static struct mta_session *
-mta_lookup(struct smtpd *env, u_int64_t id)
+mta_lookup(u_int64_t id)
{
struct mta_session key, *res;
@@ -353,7 +352,7 @@ mta_enter_state(struct mta_session *s, int newstate, void *p)
secret.id = s->id;
secret.secmapid = s->secmapid;
strlcpy(secret.host, s->host, sizeof(secret.host));
- imsg_compose_event(s->env->sc_ievs[PROC_LKA], IMSG_LKA_SECRET,
+ imsg_compose_event(env->sc_ievs[PROC_LKA], IMSG_LKA_SECRET,
0, 0, -1, &secret, sizeof(secret));
break;
@@ -362,9 +361,9 @@ mta_enter_state(struct mta_session *s, int newstate, void *p)
* Lookup MX record.
*/
if (s->flags & MTA_FORCE_MX)
- dns_query_host(s->env, s->host, s->port, s->id);
+ dns_query_host(s->host, s->port, s->id);
else
- dns_query_mx(s->env, s->host, 0, s->id);
+ dns_query_mx(s->host, 0, s->id);
break;
case MTA_DATA:
@@ -433,7 +432,7 @@ mta_enter_state(struct mta_session *s, int newstate, void *p)
* Lookup PTR record of the connected host.
*/
relay = TAILQ_FIRST(&s->relays);
- dns_query_ptr(s->env, &relay->sa, s->id);
+ dns_query_ptr(&relay->sa, s->id);
break;
case MTA_PROTOCOL:
@@ -442,14 +441,14 @@ mta_enter_state(struct mta_session *s, int newstate, void *p)
*/
log_debug("mta: entering smtp phase");
- pcb = client_init(s->fd, s->datafp, s->env->sc_hostname, 1);
+ pcb = client_init(s->fd, s->datafp, env->sc_hostname, 1);
/* lookup SSL certificate */
if (s->cert) {
struct ssl key, *res;
strlcpy(key.ssl_name, s->cert, sizeof(key.ssl_name));
- res = SPLAY_FIND(ssltree, s->env->sc_ssl, &key);
+ res = SPLAY_FIND(ssltree, env->sc_ssl, &key);
if (res == NULL) {
client_close(pcb);
s->pcb = NULL;
@@ -502,11 +501,11 @@ mta_enter_state(struct mta_session *s, int newstate, void *p)
while ((m = TAILQ_FIRST(&s->recipients)))
mta_message_done(s, m);
- imsg_compose_event(s->env->sc_ievs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_BATCH_DONE, 0, 0, -1, NULL, 0);
/* deallocate resources */
- SPLAY_REMOVE(mtatree, &s->env->mta_sessions, s);
+ SPLAY_REMOVE(mtatree, &env->mta_sessions, s);
while ((relay = TAILQ_FIRST(&s->relays))) {
TAILQ_REMOVE(&s->relays, relay, entry);
free(relay);
@@ -722,7 +721,7 @@ mta_message_done(struct mta_session *s, struct envelope *m)
m->status = S_MESSAGE_TEMPFAILURE;
break;
}
- imsg_compose_event(s->env->sc_ievs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_MESSAGE_UPDATE, 0, 0, -1, m, sizeof(*m));
TAILQ_REMOVE(&s->recipients, m, entry);
free(m);
@@ -744,7 +743,7 @@ mta_request_datafd(struct mta_session *s)
rq_batch.b_id = s->id;
rq_batch.msgid = evpid_to_msgid(m->evpid);
- imsg_compose_event(s->env->sc_ievs[PROC_QUEUE], IMSG_QUEUE_MESSAGE_FD,
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE], IMSG_QUEUE_MESSAGE_FD,
0, 0, -1, &rq_batch, sizeof(rq_batch));
}
diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y
index c07f3f1318b..8bf87d1874b 100644
--- a/usr.sbin/smtpd/parse.y
+++ b/usr.sbin/smtpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.72 2010/11/28 14:35:58 gilles Exp $ */
+/* $OpenBSD: parse.y,v 1.73 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -280,7 +280,7 @@ expire : EXPIRE STRING {
credentials : AUTH STRING {
struct map *m;
- if ((m = map_findbyname(conf, $2)) == NULL) {
+ if ((m = map_findbyname($2)) == NULL) {
yyerror("no such map: %s", $2);
free($2);
YYERROR;
@@ -338,7 +338,7 @@ main : QUEUE INTERVAL interval {
if ($7)
flags |= F_AUTH;
- if ($5 && ssl_load_certfile(conf, cert, F_SCERT) < 0) {
+ if ($5 && ssl_load_certfile(cert, F_SCERT) < 0) {
yyerror("cannot load certificate: %s", cert);
free($8);
free($6);
@@ -685,7 +685,7 @@ mapref : STRING {
| MAP STRING {
struct map *m;
- if ((m = map_findbyname(conf, $2)) == NULL) {
+ if ((m = map_findbyname($2)) == NULL) {
yyerror("no such map: %s", $2);
free($2);
YYERROR;
@@ -718,7 +718,7 @@ condition : NETWORK mapref {
struct map *m;
if ($3) {
- if ((m = map_findbyname(conf, $3)) == NULL) {
+ if ((m = map_findbyname($3)) == NULL) {
yyerror("no such map: %s", $3);
free($3);
YYERROR;
@@ -736,7 +736,7 @@ condition : NETWORK mapref {
struct cond *c;
struct map *m;
- if ((m = map_findbyname(conf, $2)) == NULL) {
+ if ((m = map_findbyname($2)) == NULL) {
yyerror("no such map: %s", $2);
free($2);
YYERROR;
@@ -756,7 +756,7 @@ condition : NETWORK mapref {
struct mapel *me;
if ($2) {
- if ((m = map_findbyname(conf, $2)) == NULL) {
+ if ((m = map_findbyname($2)) == NULL) {
yyerror("no such map: %s", $2);
free($2);
YYERROR;
@@ -906,7 +906,7 @@ action : DELIVER TO MAILDIR user {
}
if ($6 != NULL) {
- if (ssl_load_certfile(conf, $6, F_CCERT) < 0) {
+ if (ssl_load_certfile($6, F_CCERT) < 0) {
yyerror("cannot load certificate: %s",
$6);
free($6);
@@ -981,13 +981,13 @@ from : FROM mapref {
| FROM LOCAL {
struct map *m;
- m = map_findbyname(conf, "localhost");
+ m = map_findbyname("localhost");
$$ = m->m_id;
}
| /* empty */ {
struct map *m;
- m = map_findbyname(conf, "localhost");
+ m = map_findbyname("localhost");
$$ = m->m_id;
}
;
@@ -1008,7 +1008,7 @@ rule : decision on from {
if ((rule = calloc(1, sizeof(*rule))) == NULL)
fatal("out of memory");
- rule->r_sources = map_find(conf, $3);
+ rule->r_sources = map_find($3);
if ((conditions = calloc(1, sizeof(*conditions))) == NULL)
@@ -1513,7 +1513,7 @@ parse_config(struct smtpd *x_conf, const char *filename, int opts)
conf->sc_opts = opts;
if ((file = pushfile(filename, 0)) == NULL) {
- purge_config(conf, PURGE_EVERYTHING);
+ purge_config(PURGE_EVERYTHING);
free(m);
return (-1);
}
@@ -1568,7 +1568,7 @@ parse_config(struct smtpd *x_conf, const char *filename, int opts)
}
if (errors) {
- purge_config(conf, PURGE_EVERYTHING);
+ purge_config(PURGE_EVERYTHING);
return (-1);
}
@@ -1858,7 +1858,7 @@ set_localaddrs(void)
if (getifaddrs(&ifap) == -1)
fatal("getifaddrs");
- m = map_findbyname(conf, "localhost");
+ m = map_findbyname("localhost");
for (p = ifap; p != NULL; p = p->ifa_next) {
switch (p->ifa_addr->sa_family) {
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c
index b540fa17a57..1326f8606ab 100644
--- a/usr.sbin/smtpd/queue.c
+++ b/usr.sbin/smtpd/queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue.c,v 1.102 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: queue.c,v 1.103 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -36,14 +36,14 @@
#include "smtpd.h"
#include "log.h"
-static void queue_imsg(struct smtpd *, struct imsgev *, struct imsg *);
-static void queue_pass_to_runner(struct smtpd *, struct imsgev *, struct imsg *);
+static void queue_imsg(struct imsgev *, struct imsg *);
+static void queue_pass_to_runner(struct imsgev *, struct imsg *);
static void queue_shutdown(void);
static void queue_sig_handler(int, short, void *);
-static void queue_purge(struct smtpd *, enum queue_kind, char *);
+static void queue_purge(enum queue_kind, char *);
static void
-queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
+queue_imsg(struct imsgev *iev, struct imsg *imsg)
{
struct submit_status ss;
struct envelope *m;
@@ -59,9 +59,9 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
ss.code = 250;
ss.u.msgid = 0;
if (m->flags & F_MESSAGE_ENQUEUED)
- ret = queue_message_create(env, Q_ENQUEUE, &ss.u.msgid);
+ ret = queue_message_create(Q_ENQUEUE, &ss.u.msgid);
else
- ret = queue_message_create(env, Q_INCOMING, &ss.u.msgid);
+ ret = queue_message_create(Q_INCOMING, &ss.u.msgid);
if (ret == 0)
ss.code = 421;
imsg_compose_event(iev, IMSG_QUEUE_CREATE_MESSAGE, 0, 0, -1,
@@ -70,20 +70,20 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_QUEUE_REMOVE_MESSAGE:
if (m->flags & F_MESSAGE_ENQUEUED)
- queue_message_purge(env, Q_ENQUEUE, evpid_to_msgid(m->evpid));
+ queue_message_purge(Q_ENQUEUE, evpid_to_msgid(m->evpid));
else
- queue_message_purge(env, Q_INCOMING, evpid_to_msgid(m->evpid));
+ queue_message_purge(Q_INCOMING, evpid_to_msgid(m->evpid));
return;
case IMSG_QUEUE_COMMIT_MESSAGE:
ss.id = m->session_id;
if (m->flags & F_MESSAGE_ENQUEUED) {
- if (queue_message_commit(env, Q_ENQUEUE, evpid_to_msgid(m->evpid)))
+ if (queue_message_commit(Q_ENQUEUE, evpid_to_msgid(m->evpid)))
env->stats->queue.inserts_local++;
else
ss.code = 421;
} else {
- if (queue_message_commit(env, Q_INCOMING, evpid_to_msgid(m->evpid)))
+ if (queue_message_commit(Q_INCOMING, evpid_to_msgid(m->evpid)))
env->stats->queue.inserts_remote++;
else
ss.code = 421;
@@ -92,16 +92,16 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
&ss, sizeof ss);
if (ss.code != 421)
- queue_pass_to_runner(env, iev, imsg);
+ queue_pass_to_runner(iev, imsg);
return;
case IMSG_QUEUE_MESSAGE_FILE:
ss.id = m->session_id;
if (m->flags & F_MESSAGE_ENQUEUED)
- fd = queue_message_fd_rw(env, Q_ENQUEUE, evpid_to_msgid(m->evpid));
+ fd = queue_message_fd_rw(Q_ENQUEUE, evpid_to_msgid(m->evpid));
else
- fd = queue_message_fd_rw(env, Q_INCOMING, evpid_to_msgid(m->evpid));
+ fd = queue_message_fd_rw(Q_INCOMING, evpid_to_msgid(m->evpid));
if (fd == -1)
ss.code = 421;
imsg_compose_event(iev, IMSG_QUEUE_MESSAGE_FILE, 0, 0, fd,
@@ -109,7 +109,7 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
return;
case IMSG_SMTP_ENQUEUE:
- queue_pass_to_runner(env, iev, imsg);
+ queue_pass_to_runner(iev, imsg);
return;
}
}
@@ -129,9 +129,9 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
/* Write to disk */
if (m->flags & F_MESSAGE_ENQUEUED)
- ret = queue_envelope_create(env, Q_ENQUEUE, m);
+ ret = queue_envelope_create(Q_ENQUEUE, m);
else
- ret = queue_envelope_create(env, Q_INCOMING, m);
+ ret = queue_envelope_create(Q_INCOMING, m);
if (ret == 0) {
ss.code = 421;
@@ -163,14 +163,14 @@ 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_message_fd_r(env, Q_QUEUE, rq_batch->msgid);
+ fd = queue_message_fd_r(Q_QUEUE, rq_batch->msgid);
imsg_compose_event(iev, IMSG_QUEUE_MESSAGE_FD, 0, 0,
fd, rq_batch, sizeof *rq_batch);
return;
case IMSG_QUEUE_MESSAGE_UPDATE:
case IMSG_BATCH_DONE:
- queue_pass_to_runner(env, iev, imsg);
+ queue_pass_to_runner(iev, imsg);
return;
}
}
@@ -179,7 +179,7 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
switch (imsg->hdr.type) {
case IMSG_QUEUE_MESSAGE_UPDATE:
case IMSG_MDA_SESS_NEW:
- queue_pass_to_runner(env, iev, imsg);
+ queue_pass_to_runner(iev, imsg);
return;
}
}
@@ -192,7 +192,7 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_QUEUE_RESUME_OUTGOING:
case IMSG_QUEUE_SCHEDULE:
case IMSG_QUEUE_REMOVE:
- queue_pass_to_runner(env, iev, imsg);
+ queue_pass_to_runner(iev, imsg);
return;
}
}
@@ -200,12 +200,12 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
if (iev->proc == PROC_PARENT) {
switch (imsg->hdr.type) {
case IMSG_PARENT_ENQUEUE_OFFLINE:
- queue_pass_to_runner(env, iev, imsg);
+ queue_pass_to_runner(iev, imsg);
return;
case IMSG_CTL_VERBOSE:
log_verbose(*(int *)imsg->data);
- queue_pass_to_runner(env, iev, imsg);
+ queue_pass_to_runner(iev, imsg);
return;
}
}
@@ -214,7 +214,7 @@ queue_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
}
static void
-queue_pass_to_runner(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
+queue_pass_to_runner(struct imsgev *iev, struct imsg *imsg)
{
imsg_compose_event(env->sc_ievs[PROC_RUNNER], imsg->hdr.type,
iev->proc, imsg->hdr.pid, imsg->fd, imsg->data,
@@ -242,7 +242,7 @@ queue_shutdown(void)
}
pid_t
-queue(struct smtpd *env)
+queue(void)
{
pid_t pid;
struct passwd *pw;
@@ -269,7 +269,7 @@ queue(struct smtpd *env)
return (pid);
}
- purge_config(env, PURGE_EVERYTHING);
+ purge_config(PURGE_EVERYTHING);
pw = env->sc_pw;
@@ -289,8 +289,8 @@ queue(struct smtpd *env)
imsg_callback = queue_imsg;
event_init();
- signal_set(&ev_sigint, SIGINT, queue_sig_handler, env);
- signal_set(&ev_sigterm, SIGTERM, queue_sig_handler, env);
+ signal_set(&ev_sigint, SIGINT, queue_sig_handler, NULL);
+ signal_set(&ev_sigterm, SIGTERM, queue_sig_handler, NULL);
signal_add(&ev_sigint, NULL);
signal_add(&ev_sigterm, NULL);
signal(SIGPIPE, SIG_IGN);
@@ -305,11 +305,11 @@ queue(struct smtpd *env)
if ((env->sc_maxconn = availdesc() / 4) < 1)
fatalx("runner: fd starvation");
- config_pipes(env, peers, nitems(peers));
- config_peers(env, peers, nitems(peers));
+ config_pipes(peers, nitems(peers));
+ config_peers(peers, nitems(peers));
- queue_purge(env, Q_INCOMING, PATH_INCOMING);
- queue_purge(env, Q_ENQUEUE, PATH_ENQUEUE);
+ queue_purge(Q_INCOMING, PATH_INCOMING);
+ queue_purge(Q_ENQUEUE, PATH_ENQUEUE);
if (event_dispatch() < 0)
fatal("event_dispatch");
@@ -319,7 +319,7 @@ queue(struct smtpd *env)
}
static void
-queue_purge(struct smtpd *env, enum queue_kind qkind, char *queuepath)
+queue_purge(enum queue_kind qkind, char *queuepath)
{
char path[MAXPATHLEN];
struct qwalk *q;
@@ -333,14 +333,14 @@ queue_purge(struct smtpd *env, enum queue_kind qkind, char *queuepath)
log_warnx("queue_purge: invalid evpid");
continue;
}
- queue_message_purge(env, qkind, msgid);
+ queue_message_purge(qkind, msgid);
}
qwalk_close(q);
}
void
-queue_submit_envelope(struct smtpd *env, struct envelope *m)
+queue_submit_envelope(struct envelope *m)
{
imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_SUBMIT_ENVELOPE, 0, 0, -1,
@@ -348,7 +348,7 @@ queue_submit_envelope(struct smtpd *env, struct envelope *m)
}
void
-queue_commit_envelopes(struct smtpd *env, struct envelope *m)
+queue_commit_envelopes(struct envelope *m)
{
imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_COMMIT_ENVELOPES, 0, 0, -1,
diff --git a/usr.sbin/smtpd/queue_backend.c b/usr.sbin/smtpd/queue_backend.c
index 4d14f47881b..a5f363838f2 100644
--- a/usr.sbin/smtpd/queue_backend.c
+++ b/usr.sbin/smtpd/queue_backend.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue_backend.c,v 1.9 2011/04/17 11:39:22 gilles Exp $ */
+/* $OpenBSD: queue_backend.c,v 1.10 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -36,11 +36,9 @@
#include "log.h"
/* fsqueue backend */
-int fsqueue_init(struct smtpd *);
-int fsqueue_message(struct smtpd *, enum queue_kind,
- enum queue_op, u_int32_t *);
-int fsqueue_envelope(struct smtpd *, enum queue_kind,
- enum queue_op , struct envelope *);
+int fsqueue_init(void);
+int fsqueue_message(enum queue_kind, enum queue_op, u_int32_t *);
+int fsqueue_envelope(enum queue_kind, enum queue_op , struct envelope *);
struct queue_backend queue_backends[] = {
@@ -66,66 +64,62 @@ queue_backend_lookup(enum queue_type type)
}
int
-queue_message_create(struct smtpd *env, enum queue_kind qkind, u_int32_t *msgid)
+queue_message_create(enum queue_kind qkind, u_int32_t *msgid)
{
- return env->sc_queue->message(env, qkind, QOP_CREATE, msgid);
+ return env->sc_queue->message(qkind, QOP_CREATE, msgid);
}
int
-queue_message_delete(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid)
+queue_message_delete(enum queue_kind qkind, u_int32_t msgid)
{
- return env->sc_queue->message(env, qkind, QOP_DELETE, &msgid);
+ return env->sc_queue->message(qkind, QOP_DELETE, &msgid);
}
int
-queue_message_commit(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid)
+queue_message_commit(enum queue_kind qkind, u_int32_t msgid)
{
- return env->sc_queue->message(env, qkind, QOP_COMMIT, &msgid);
+ return env->sc_queue->message(qkind, QOP_COMMIT, &msgid);
}
int
-queue_message_purge(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid)
+queue_message_purge(enum queue_kind qkind, u_int32_t msgid)
{
- return env->sc_queue->message(env, qkind, QOP_PURGE, &msgid);
+ return env->sc_queue->message(qkind, QOP_PURGE, &msgid);
}
int
-queue_message_fd_r(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid)
+queue_message_fd_r(enum queue_kind qkind, u_int32_t msgid)
{
- return env->sc_queue->message(env, qkind, QOP_FD_R, &msgid);
+ return env->sc_queue->message(qkind, QOP_FD_R, &msgid);
}
int
-queue_message_fd_rw(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid)
+queue_message_fd_rw(enum queue_kind qkind, u_int32_t msgid)
{
- return env->sc_queue->message(env, qkind, QOP_FD_RW, &msgid);
+ return env->sc_queue->message(qkind, QOP_FD_RW, &msgid);
}
int
-queue_envelope_create(struct smtpd *env, enum queue_kind qkind,
- struct envelope *m)
+queue_envelope_create(enum queue_kind qkind, struct envelope *m)
{
- return env->sc_queue->envelope(env, qkind, QOP_CREATE, m);
+ return env->sc_queue->envelope(qkind, QOP_CREATE, m);
}
int
-queue_envelope_delete(struct smtpd *env, enum queue_kind qkind,
- struct envelope *m)
+queue_envelope_delete(enum queue_kind qkind, struct envelope *m)
{
- return env->sc_queue->envelope(env, qkind, QOP_DELETE, m);
+ return env->sc_queue->envelope(qkind, QOP_DELETE, m);
}
int
-queue_envelope_load(struct smtpd *env, enum queue_kind qkind,
- u_int64_t evpid, struct envelope *m)
+queue_envelope_load(enum queue_kind qkind, u_int64_t evpid, struct envelope *m)
{
m->evpid = evpid;
- return env->sc_queue->envelope(env, qkind, QOP_LOAD, m);
+ return env->sc_queue->envelope(qkind, QOP_LOAD, m);
}
int
-queue_envelope_update(struct smtpd *env, enum queue_kind qkind,
- struct envelope *m)
+queue_envelope_update(enum queue_kind qkind, struct envelope *m)
{
- return env->sc_queue->envelope(env, qkind, QOP_UPDATE, m);
+ return env->sc_queue->envelope(qkind, QOP_UPDATE, m);
}
diff --git a/usr.sbin/smtpd/queue_fsqueue.c b/usr.sbin/smtpd/queue_fsqueue.c
index 4b4f80c44a8..4b3f131ab34 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.10 2011/04/17 11:39:22 gilles Exp $ */
+/* $OpenBSD: queue_fsqueue.c,v 1.11 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -41,22 +41,20 @@
static char *fsqueue_getpath(enum queue_kind);
/*static*/ u_int16_t fsqueue_hash(u_int32_t);
-static int fsqueue_envelope_load(struct smtpd *, enum queue_kind, struct envelope *);
-static int fsqueue_envelope_update(struct smtpd *, enum queue_kind, struct envelope *);
-static int fsqueue_envelope_delete(struct smtpd *, enum queue_kind, struct envelope *);
+static int fsqueue_envelope_load(enum queue_kind, struct envelope *);
+static int fsqueue_envelope_update(enum queue_kind, struct envelope *);
+static int fsqueue_envelope_delete(enum queue_kind, struct envelope *);
-static int fsqueue_message_create(struct smtpd *, enum queue_kind, u_int32_t *);
-static int fsqueue_message_commit(struct smtpd *, enum queue_kind, u_int32_t);
-static int fsqueue_message_fd_r(struct smtpd *, enum queue_kind, u_int32_t);
-static int fsqueue_message_fd_rw(struct smtpd *, enum queue_kind, u_int32_t);
-static int fsqueue_message_delete(struct smtpd *, enum queue_kind, u_int32_t);
-static int fsqueue_message_purge(struct smtpd *, enum queue_kind, u_int32_t);
+static int fsqueue_message_create(enum queue_kind, u_int32_t *);
+static int fsqueue_message_commit(enum queue_kind, u_int32_t);
+static int fsqueue_message_fd_r(enum queue_kind, u_int32_t);
+static int fsqueue_message_fd_rw(enum queue_kind, u_int32_t);
+static int fsqueue_message_delete(enum queue_kind, u_int32_t);
+static int fsqueue_message_purge(enum queue_kind, u_int32_t);
-int fsqueue_init(struct smtpd *);
-int fsqueue_message(struct smtpd *, enum queue_kind,
- enum queue_op, u_int32_t *);
-int fsqueue_envelope(struct smtpd *, enum queue_kind,
- enum queue_op , struct envelope *);
+int fsqueue_init(void);
+int fsqueue_message(enum queue_kind, enum queue_op, u_int32_t *);
+int fsqueue_envelope(enum queue_kind, enum queue_op , struct envelope *);
static char *
fsqueue_getpath(enum queue_kind kind)
@@ -93,8 +91,7 @@ fsqueue_hash(u_int32_t h)
}
static int
-fsqueue_envelope_create(struct smtpd *env, enum queue_kind qkind,
- struct envelope *m)
+fsqueue_envelope_create(enum queue_kind qkind, struct envelope *m)
{
char evpname[MAXPATHLEN];
FILE *fp;
@@ -164,8 +161,7 @@ tempfail:
}
static int
-fsqueue_envelope_load(struct smtpd *env, enum queue_kind qkind,
- struct envelope *m)
+fsqueue_envelope_load(enum queue_kind qkind, struct envelope *m)
{
char pathname[MAXPATHLEN];
FILE *fp;
@@ -190,8 +186,7 @@ fsqueue_envelope_load(struct smtpd *env, enum queue_kind qkind,
}
static int
-fsqueue_envelope_update(struct smtpd *env, enum queue_kind qkind,
- struct envelope *m)
+fsqueue_envelope_update(enum queue_kind qkind, struct envelope *m)
{
char temp[MAXPATHLEN];
char dest[MAXPATHLEN];
@@ -245,8 +240,7 @@ tempfail:
}
static int
-fsqueue_envelope_delete(struct smtpd *env, enum queue_kind qkind,
- struct envelope *m)
+fsqueue_envelope_delete(enum queue_kind qkind, struct envelope *m)
{
char pathname[MAXPATHLEN];
u_int16_t hval;
@@ -269,13 +263,13 @@ fsqueue_envelope_delete(struct smtpd *env, enum queue_kind qkind,
fatal("fsqueue_envelope_delete: snprintf");
if (rmdir(pathname) != -1)
- fsqueue_message_delete(env, qkind, evpid_to_msgid(m->evpid));
+ fsqueue_message_delete(qkind, evpid_to_msgid(m->evpid));
return 1;
}
static int
-fsqueue_message_create(struct smtpd *env, enum queue_kind qkind, u_int32_t *msgid)
+fsqueue_message_create(enum queue_kind qkind, u_int32_t *msgid)
{
char rootdir[MAXPATHLEN];
char evpdir[MAXPATHLEN];
@@ -335,7 +329,7 @@ again:
}
static int
-fsqueue_message_commit(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid)
+fsqueue_message_commit(enum queue_kind qkind, u_int32_t msgid)
{
char rootdir[MAXPATHLEN];
char queuedir[MAXPATHLEN];
@@ -370,7 +364,7 @@ fsqueue_message_commit(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid
}
static int
-fsqueue_message_fd_r(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid)
+fsqueue_message_fd_r(enum queue_kind qkind, u_int32_t msgid)
{
int fd;
char pathname[MAXPATHLEN];
@@ -395,7 +389,7 @@ fsqueue_message_fd_r(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid)
}
static int
-fsqueue_message_fd_rw(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid)
+fsqueue_message_fd_rw(enum queue_kind qkind, u_int32_t msgid)
{
char pathname[MAXPATHLEN];
@@ -408,7 +402,7 @@ fsqueue_message_fd_rw(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid)
}
static int
-fsqueue_message_delete(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid)
+fsqueue_message_delete(enum queue_kind qkind, u_int32_t msgid)
{
char rootdir[MAXPATHLEN];
char evpdir[MAXPATHLEN];
@@ -451,7 +445,7 @@ fsqueue_message_delete(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid
}
static int
-fsqueue_message_purge(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid)
+fsqueue_message_purge(enum queue_kind qkind, u_int32_t msgid)
{
char rootdir[MAXPATHLEN];
char purgedir[MAXPATHLEN];
@@ -472,7 +466,7 @@ fsqueue_message_purge(struct smtpd *env, enum queue_kind qkind, u_int32_t msgid)
int
-fsqueue_init(struct smtpd *env)
+fsqueue_init(void)
{
unsigned int n;
char *paths[] = { PATH_INCOMING, PATH_ENQUEUE, PATH_QUEUE,
@@ -601,27 +595,26 @@ fsqueue_init(struct smtpd *env)
}
int
-fsqueue_message(struct smtpd *env, enum queue_kind qkind,
- enum queue_op qop, u_int32_t *msgid)
+fsqueue_message(enum queue_kind qkind, enum queue_op qop, u_int32_t *msgid)
{
switch (qop) {
case QOP_CREATE:
- return fsqueue_message_create(env, qkind, msgid);
+ return fsqueue_message_create(qkind, msgid);
case QOP_DELETE:
- return fsqueue_message_delete(env, qkind, *msgid);
+ return fsqueue_message_delete(qkind, *msgid);
case QOP_COMMIT:
- return fsqueue_message_commit(env, qkind, *msgid);
+ return fsqueue_message_commit(qkind, *msgid);
case QOP_FD_R:
- return fsqueue_message_fd_r(env, qkind, *msgid);
+ return fsqueue_message_fd_r(qkind, *msgid);
case QOP_FD_RW:
- return fsqueue_message_fd_rw(env, qkind, *msgid);
+ return fsqueue_message_fd_rw(qkind, *msgid);
case QOP_PURGE:
- return fsqueue_message_purge(env, qkind, *msgid);
+ return fsqueue_message_purge(qkind, *msgid);
default:
fatalx("queue_fsqueue_message: unsupported operation.");
@@ -631,21 +624,20 @@ fsqueue_message(struct smtpd *env, enum queue_kind qkind,
}
int
-fsqueue_envelope(struct smtpd *env, enum queue_kind qkind,
- enum queue_op qop, struct envelope *m)
+fsqueue_envelope(enum queue_kind qkind, enum queue_op qop, struct envelope *m)
{
switch (qop) {
case QOP_CREATE:
- return fsqueue_envelope_create(env, qkind, m);
+ return fsqueue_envelope_create(qkind, m);
case QOP_DELETE:
- return fsqueue_envelope_delete(env, qkind, m);
+ return fsqueue_envelope_delete(qkind, m);
case QOP_LOAD:
- return fsqueue_envelope_load(env, qkind, m);
+ return fsqueue_envelope_load(qkind, m);
case QOP_UPDATE:
- return fsqueue_envelope_update(env, qkind, m);
+ return fsqueue_envelope_update(qkind, m);
default:
fatalx("queue_fsqueue_envelope: unsupported operation.");
diff --git a/usr.sbin/smtpd/queue_shared.c b/usr.sbin/smtpd/queue_shared.c
index 494c76c5ecf..0019e898aff 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.46 2011/04/17 11:39:22 gilles Exp $ */
+/* $OpenBSD: queue_shared.c,v 1.47 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -59,7 +59,7 @@ void display_envelope(struct envelope *, int);
void getflag(u_int *, int, char *, char *, size_t);
int
-bounce_record_message(struct smtpd *env, struct envelope *m, struct envelope *bounce)
+bounce_record_message(struct envelope *m, struct envelope *bounce)
{
u_int32_t msgid;
@@ -73,18 +73,18 @@ bounce_record_message(struct smtpd *env, struct envelope *m, struct envelope *bo
bounce->status &= ~S_MESSAGE_PERMFAILURE;
msgid = evpid_to_msgid(m->evpid);
- if (! queue_message_create(env, Q_BOUNCE, &msgid))
+ if (! queue_message_create(Q_BOUNCE, &msgid))
return 0;
bounce->evpid = msgid_to_evpid(msgid);
- if (! queue_envelope_create(env, Q_BOUNCE, bounce))
+ if (! queue_envelope_create(Q_BOUNCE, bounce))
return 0;
- return queue_message_commit(env, Q_BOUNCE, msgid);
+ return queue_message_commit(Q_BOUNCE, msgid);
}
void
-queue_message_update(struct smtpd *env, struct envelope *m)
+queue_message_update(struct envelope *m)
{
m->flags &= ~F_MESSAGE_PROCESSING;
m->status &= ~(S_MESSAGE_ACCEPTED|S_MESSAGE_REJECTED);
@@ -96,20 +96,20 @@ queue_message_update(struct smtpd *env, struct envelope *m)
m->sender.user[0] != '\0') {
struct envelope bounce;
- bounce_record_message(env, m, &bounce);
+ bounce_record_message(m, &bounce);
}
- queue_envelope_delete(env, Q_QUEUE, m);
+ queue_envelope_delete(Q_QUEUE, m);
return;
}
if (m->status & S_MESSAGE_TEMPFAILURE) {
m->status &= ~S_MESSAGE_TEMPFAILURE;
- queue_envelope_update(env, Q_QUEUE, m);
+ queue_envelope_update(Q_QUEUE, m);
return;
}
/* no error, remove envelope */
- queue_envelope_delete(env, Q_QUEUE, m);
+ queue_envelope_delete(Q_QUEUE, m);
}
struct qwalk *
diff --git a/usr.sbin/smtpd/ramqueue.c b/usr.sbin/smtpd/ramqueue.c
index ee0f5cfeb8a..301649a1727 100644
--- a/usr.sbin/smtpd/ramqueue.c
+++ b/usr.sbin/smtpd/ramqueue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ramqueue.c,v 1.6 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: ramqueue.c,v 1.7 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org>
@@ -45,7 +45,7 @@ void ramqueue_put_host(struct ramqueue *, struct ramqueue_host *);
void ramqueue_put_batch(struct ramqueue *, struct ramqueue_batch *);
int ramqueue_load_offline(struct ramqueue *);
-static int ramqueue_expire(struct smtpd *, struct envelope *, time_t);
+static int ramqueue_expire(struct envelope *, time_t);
static time_t ramqueue_next_schedule(struct envelope *, time_t);
static struct ramqueue_host *ramqueue_get_host(struct ramqueue *, char *);
static struct ramqueue_batch *ramqueue_get_batch(struct ramqueue *,
@@ -53,11 +53,10 @@ static struct ramqueue_batch *ramqueue_get_batch(struct ramqueue *,
void
-ramqueue_init(struct smtpd *env, struct ramqueue *rqueue)
+ramqueue_init(struct ramqueue *rqueue)
{
bzero(rqueue, sizeof (*rqueue));
TAILQ_INIT(&rqueue->queue);
- rqueue->env = env;
rqueue->current_evp = NULL;
}
@@ -105,7 +104,6 @@ int
ramqueue_load_offline(struct ramqueue *rqueue)
{
char path[MAXPATHLEN];
- struct smtpd *env = rqueue->env;
static struct qwalk *q = NULL;
log_debug("ramqueue: offline queue loading in progress");
@@ -147,10 +145,9 @@ ramqueue_load(struct ramqueue *rqueue, time_t *nsched)
if ((evpid = filename_to_evpid(basename(path))) == 0)
continue;
- if (! queue_envelope_load(rqueue->env, Q_QUEUE,
- evpid, &envelope))
+ if (! queue_envelope_load(Q_QUEUE, evpid, &envelope))
continue;
- if (ramqueue_expire(rqueue->env, &envelope, curtm))
+ if (ramqueue_expire(&envelope, curtm))
continue;
ramqueue_insert(rqueue, &envelope, curtm);
@@ -195,9 +192,9 @@ ramqueue_insert(struct ramqueue *rqueue, struct envelope *envelope, time_t curtm
if (evp == NULL)
TAILQ_INSERT_TAIL(&rqueue->queue, rq_evp, queue_entry);
- rqueue->env->stats->ramqueue.envelopes++;
- SET_IF_GREATER(rqueue->env->stats->ramqueue.envelopes,
- rqueue->env->stats->ramqueue.envelopes_max);
+ env->stats->ramqueue.envelopes++;
+ SET_IF_GREATER(env->stats->ramqueue.envelopes,
+ env->stats->ramqueue.envelopes_max);
}
void
@@ -210,11 +207,11 @@ ramqueue_remove(struct ramqueue *rqueue, struct ramqueue_envelope *rq_evp)
TAILQ_REMOVE(&rq_batch->envelope_queue, rq_evp, batchqueue_entry);
TAILQ_REMOVE(&rqueue->queue, rq_evp, queue_entry);
- rqueue->env->stats->ramqueue.envelopes--;
+ env->stats->ramqueue.envelopes--;
}
static int
-ramqueue_expire(struct smtpd *env, struct envelope *envelope, time_t curtm)
+ramqueue_expire(struct envelope *envelope, time_t curtm)
{
struct envelope bounce;
@@ -222,9 +219,9 @@ ramqueue_expire(struct smtpd *env, struct envelope *envelope, time_t curtm)
message_set_errormsg(envelope,
"message expired after sitting in queue for %d days",
envelope->expire / 60 / 60 / 24);
- bounce_record_message(env, envelope, &bounce);
+ bounce_record_message(envelope, &bounce);
ramqueue_insert(&env->sc_rqueue, &bounce, time(NULL));
- queue_envelope_delete(env, Q_QUEUE, envelope);
+ queue_envelope_delete(Q_QUEUE, envelope);
return 1;
}
return 0;
@@ -280,9 +277,9 @@ ramqueue_get_host(struct ramqueue *rqueue, char *hostname)
strlcpy(rq_host->hostname, hostname, sizeof(rq_host->hostname));
TAILQ_INIT(&rq_host->batch_queue);
RB_INSERT(hosttree, &rqueue->hosttree, rq_host);
- rqueue->env->stats->ramqueue.hosts++;
- SET_IF_GREATER(rqueue->env->stats->ramqueue.hosts,
- rqueue->env->stats->ramqueue.hosts_max);
+ env->stats->ramqueue.hosts++;
+ SET_IF_GREATER(env->stats->ramqueue.hosts,
+ env->stats->ramqueue.hosts_max);
}
return rq_host;
@@ -316,9 +313,9 @@ ramqueue_get_batch(struct ramqueue *rqueue, struct ramqueue_host *host,
TAILQ_INIT(&rq_batch->envelope_queue);
TAILQ_INSERT_TAIL(&host->batch_queue, rq_batch, batch_entry);
- rqueue->env->stats->ramqueue.batches++;
- SET_IF_GREATER(rqueue->env->stats->ramqueue.batches,
- rqueue->env->stats->ramqueue.batches_max);
+ env->stats->ramqueue.batches++;
+ SET_IF_GREATER(env->stats->ramqueue.batches,
+ env->stats->ramqueue.batches_max);
return rq_batch;
}
diff --git a/usr.sbin/smtpd/ruleset.c b/usr.sbin/smtpd/ruleset.c
index 84b7e818f14..4ad1d60694e 100644
--- a/usr.sbin/smtpd/ruleset.c
+++ b/usr.sbin/smtpd/ruleset.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ruleset.c,v 1.16 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: ruleset.c,v 1.17 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2009 Gilles Chehade <gilles@openbsd.org>
@@ -33,7 +33,7 @@
#include "log.h"
-struct rule *ruleset_match(struct smtpd *, char *tag, struct path *, struct sockaddr_storage *);
+struct rule *ruleset_match(char *tag, struct path *, struct sockaddr_storage *);
static int ruleset_check_source(struct map *, struct sockaddr_storage *);
static int ruleset_match_mask(struct sockaddr_storage *, struct netaddr *);
@@ -42,7 +42,7 @@ static int ruleset_inet6_match(struct sockaddr_in6 *, struct netaddr *);
struct rule *
-ruleset_match(struct smtpd *env, char *tag, struct path *path, struct sockaddr_storage *ss)
+ruleset_match(char *tag, struct path *path, struct sockaddr_storage *ss)
{
struct rule *r;
struct map *map;
@@ -62,7 +62,7 @@ ruleset_match(struct smtpd *env, char *tag, struct path *path, struct sockaddr_s
return r;
if (r->r_condition.c_type == C_DOM) {
- map = map_find(env, r->r_condition.c_map);
+ map = map_find(r->r_condition.c_map);
if (map == NULL)
fatal("failed to lookup map.");
@@ -74,7 +74,7 @@ ruleset_match(struct smtpd *env, char *tag, struct path *path, struct sockaddr_s
}
break;
case S_DB:
- if (map_lookup(env, map->m_id, path->domain, K_VIRTUAL) != NULL)
+ if (map_lookup(map->m_id, path->domain, K_VIRTUAL) != NULL)
return r;
break;
default:
@@ -84,7 +84,7 @@ ruleset_match(struct smtpd *env, char *tag, struct path *path, struct sockaddr_s
}
if (r->r_condition.c_type == C_VDOM)
- if (aliases_vdomain_exists(env, r->r_condition.c_map, path->domain))
+ if (aliases_vdomain_exists(r->r_condition.c_map, path->domain))
return r;
}
diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c
index 9877a3b5faf..b382380a94a 100644
--- a/usr.sbin/smtpd/runner.c
+++ b/usr.sbin/smtpd/runner.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: runner.c,v 1.105 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: runner.c,v 1.106 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -44,18 +44,18 @@
void ramqueue_insert(struct ramqueue *, struct envelope *, time_t);
-static void runner_imsg(struct smtpd *, struct imsgev *, struct imsg *);
+static void runner_imsg(struct imsgev *, struct imsg *);
static void runner_shutdown(void);
static void runner_sig_handler(int, short, void *);
-static void runner_setup_events(struct smtpd *);
-static void runner_reset_events(struct smtpd *);
-static void runner_disable_events(struct smtpd *);
+static void runner_setup_events(void);
+static void runner_reset_events(void);
+static void runner_disable_events(void);
static void runner_timeout(int, short, void *);
-static int runner_process_envelope(struct smtpd *, struct ramqueue_envelope *, time_t);
-static void runner_process_batch(struct smtpd *, struct ramqueue_envelope *, time_t);
+static int runner_process_envelope(struct ramqueue_envelope *, time_t);
+static void runner_process_batch(struct ramqueue_envelope *, time_t);
static void runner_purge_run(void);
static void runner_purge_message(u_int32_t);
-static int runner_check_loop(struct smtpd *, struct envelope *);
+static int runner_check_loop(struct envelope *);
static int runner_force_message_to_ramqueue(struct ramqueue *, u_int32_t);
@@ -66,7 +66,7 @@ u_int32_t filename_to_msgid(char *);
void
-runner_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
+runner_imsg(struct imsgev *iev, struct imsg *imsg)
{
struct envelope *m;
@@ -74,7 +74,7 @@ runner_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_QUEUE_COMMIT_MESSAGE:
m = imsg->data;
runner_force_message_to_ramqueue(&env->sc_rqueue, m->evpid>>32);
- runner_reset_events(env);
+ runner_reset_events();
return;
case IMSG_QUEUE_MESSAGE_UPDATE:
@@ -87,9 +87,9 @@ runner_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
*/
if (m->status & S_MESSAGE_TEMPFAILURE) {
m->status &= ~S_MESSAGE_TEMPFAILURE;
- queue_envelope_update(env, Q_QUEUE, m);
+ queue_envelope_update(Q_QUEUE, m);
ramqueue_insert(&env->sc_rqueue, m, time(NULL));
- runner_reset_events(env);
+ runner_reset_events();
return;
}
@@ -101,16 +101,16 @@ runner_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
if (m->type != T_BOUNCE_MESSAGE &&
m->sender.user[0] != '\0') {
- bounce_record_message(env, m, &bounce);
+ bounce_record_message(m, &bounce);
ramqueue_insert(&env->sc_rqueue, &bounce, time(NULL));
- runner_reset_events(env);
+ runner_reset_events();
}
}
/* successful delivery or permanent failure,
* remove envelope from queue.
*/
- queue_envelope_delete(env, Q_QUEUE, m);
+ queue_envelope_delete(Q_QUEUE, m);
return;
case IMSG_MDA_SESS_NEW:
@@ -122,16 +122,16 @@ runner_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
return;
case IMSG_PARENT_ENQUEUE_OFFLINE:
- /* runner_process_offline(env);*/
+ /* runner_process_offline();*/
return;
case IMSG_SMTP_ENQUEUE:
m = imsg->data;
- if (imsg->fd < 0 || !bounce_session(env, imsg->fd, m)) {
+ if (imsg->fd < 0 || !bounce_session(imsg->fd, m)) {
m->status = 0;
- queue_envelope_update(env, Q_QUEUE, m);
+ queue_envelope_update(Q_QUEUE, m);
ramqueue_insert(&env->sc_rqueue, m, time(NULL));
- runner_reset_events(env);
+ runner_reset_events();
return;
}
return;
@@ -181,18 +181,18 @@ runner_shutdown(void)
}
void
-runner_setup_events(struct smtpd *env)
+runner_setup_events(void)
{
struct timeval tv;
- evtimer_set(&env->sc_ev, runner_timeout, env);
+ evtimer_set(&env->sc_ev, runner_timeout, NULL);
tv.tv_sec = 0;
tv.tv_usec = 10;
evtimer_add(&env->sc_ev, &tv);
}
void
-runner_reset_events(struct smtpd *env)
+runner_reset_events(void)
{
struct timeval tv;
@@ -202,13 +202,13 @@ runner_reset_events(struct smtpd *env)
}
void
-runner_disable_events(struct smtpd *env)
+runner_disable_events(void)
{
evtimer_del(&env->sc_ev);
}
pid_t
-runner(struct smtpd *env)
+runner(void)
{
pid_t pid;
struct passwd *pw;
@@ -229,7 +229,7 @@ runner(struct smtpd *env)
return (pid);
}
- purge_config(env, PURGE_EVERYTHING);
+ purge_config(PURGE_EVERYTHING);
pw = env->sc_pw;
@@ -246,13 +246,13 @@ runner(struct smtpd *env)
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
fatal("runner: cannot drop privileges");
- ramqueue_init(env, &env->sc_rqueue);
+ ramqueue_init(&env->sc_rqueue);
imsg_callback = runner_imsg;
event_init();
- signal_set(&ev_sigint, SIGINT, runner_sig_handler, env);
- signal_set(&ev_sigterm, SIGTERM, runner_sig_handler, env);
+ signal_set(&ev_sigint, SIGINT, runner_sig_handler, NULL);
+ signal_set(&ev_sigterm, SIGTERM, runner_sig_handler, NULL);
signal_add(&ev_sigint, NULL);
signal_add(&ev_sigterm, NULL);
signal(SIGPIPE, SIG_IGN);
@@ -263,14 +263,14 @@ runner(struct smtpd *env)
if ((env->sc_maxconn = availdesc() / 4) < 1)
fatalx("runner: fd starvation");
- config_pipes(env, peers, nitems(peers));
- config_peers(env, peers, nitems(peers));
+ config_pipes(peers, nitems(peers));
+ config_peers(peers, nitems(peers));
unlink(PATH_QUEUE "/envelope.tmp");
- runner_setup_events(env);
+ runner_setup_events();
event_dispatch();
- runner_disable_events(env);
+ runner_disable_events();
runner_shutdown();
return (0);
@@ -279,7 +279,6 @@ runner(struct smtpd *env)
void
runner_timeout(int fd, short event, void *p)
{
- struct smtpd *env = p;
struct ramqueue *rqueue = &env->sc_rqueue;
struct ramqueue_envelope *rq_evp;
struct timeval tv;
@@ -317,7 +316,7 @@ runner_timeout(int fd, short event, void *p)
while (rq_evp) {
if (rq_evp->sched > curtm)
break;
- runner_process_envelope(env, rq_evp, curtm);
+ runner_process_envelope(rq_evp, curtm);
rq_evp = ramqueue_next_envelope(rqueue);
}
@@ -344,7 +343,7 @@ runner_timeout(int fd, short event, void *p)
}
int
-runner_process_envelope(struct smtpd *env, struct ramqueue_envelope *rq_evp, time_t curtm)
+runner_process_envelope(struct ramqueue_envelope *rq_evp, time_t curtm)
{
size_t mta_av, mda_av, bnc_av;
struct envelope envelope;
@@ -353,7 +352,7 @@ runner_process_envelope(struct smtpd *env, struct ramqueue_envelope *rq_evp, tim
mda_av = env->sc_maxconn - env->stats->mda.sessions_active;
bnc_av = env->sc_maxconn - env->stats->runner.bounces_active;
- if (! queue_envelope_load(env, Q_QUEUE, rq_evp->evpid, &envelope))
+ if (! queue_envelope_load(Q_QUEUE, rq_evp->evpid, &envelope))
return 0;
if (envelope.type & T_MDA_MESSAGE) {
@@ -377,14 +376,14 @@ runner_process_envelope(struct smtpd *env, struct ramqueue_envelope *rq_evp, tim
return 0;
}
- if (runner_check_loop(env, &envelope)) {
+ if (runner_check_loop(&envelope)) {
struct envelope bounce;
message_set_errormsg(&envelope, "loop has been detected");
- bounce_record_message(env, &envelope, &bounce);
+ bounce_record_message(&envelope, &bounce);
ramqueue_insert(&env->sc_rqueue, &bounce, time(NULL));
- runner_setup_events(env);
- queue_envelope_delete(env, Q_QUEUE, &envelope);
+ runner_setup_events();
+ queue_envelope_delete(Q_QUEUE, &envelope);
return 0;
}
@@ -392,14 +391,14 @@ runner_process_envelope(struct smtpd *env, struct ramqueue_envelope *rq_evp, tim
rq_evp->host,
rq_evp->batch,
rq_evp, rq_evp->evpid);
- runner_process_batch(env, rq_evp, curtm);
+ runner_process_batch(rq_evp, curtm);
return 1;
}
void
-runner_process_batch(struct smtpd *env, struct ramqueue_envelope *rq_evp, time_t curtm)
+runner_process_batch(struct ramqueue_envelope *rq_evp, time_t curtm)
{
struct ramqueue_host *host = rq_evp->host;
struct ramqueue_batch *batch = rq_evp->batch;
@@ -409,7 +408,7 @@ runner_process_batch(struct smtpd *env, struct ramqueue_envelope *rq_evp, time_t
switch (batch->type) {
case T_BOUNCE_MESSAGE:
while ((rq_evp = ramqueue_batch_first_envelope(batch))) {
- if (! queue_envelope_load(env, Q_QUEUE, rq_evp->evpid,
+ if (! queue_envelope_load(Q_QUEUE, rq_evp->evpid,
&envelope))
return;
envelope.lasttry = curtm;
@@ -431,11 +430,10 @@ runner_process_batch(struct smtpd *env, struct ramqueue_envelope *rq_evp, time_t
case T_MDA_MESSAGE:
rq_evp = ramqueue_batch_first_envelope(batch);
- if (! queue_envelope_load(env, Q_QUEUE, rq_evp->evpid,
- &envelope))
+ if (! queue_envelope_load(Q_QUEUE, rq_evp->evpid, &envelope))
return;
envelope.lasttry = curtm;
- fd = queue_message_fd_r(env, Q_QUEUE, rq_evp->evpid>>32);
+ fd = queue_message_fd_r(Q_QUEUE, rq_evp->evpid>>32);
imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_MDA_SESS_NEW, PROC_MDA, 0, fd, &envelope,
sizeof envelope);
@@ -456,7 +454,7 @@ runner_process_batch(struct smtpd *env, struct ramqueue_envelope *rq_evp, time_t
IMSG_BATCH_CREATE, PROC_MTA, 0, -1, batch,
sizeof *batch);
while ((rq_evp = ramqueue_batch_first_envelope(batch))) {
- if (! queue_envelope_load(env, Q_QUEUE, rq_evp->evpid,
+ if (! queue_envelope_load(Q_QUEUE, rq_evp->evpid,
&envelope))
return;
envelope.lasttry = curtm;
@@ -527,7 +525,7 @@ runner_force_message_to_ramqueue(struct ramqueue *rqueue, u_int32_t msgid)
continue;
}
- if (! queue_envelope_load(rqueue->env, Q_QUEUE, evpid,
+ if (! queue_envelope_load(Q_QUEUE, evpid,
&envelope))
continue;
ramqueue_insert(rqueue, &envelope, curtm);
@@ -618,7 +616,7 @@ delroot:
}
int
-runner_check_loop(struct smtpd *env, struct envelope *messagep)
+runner_check_loop(struct envelope *messagep)
{
int fd;
FILE *fp;
@@ -628,7 +626,7 @@ runner_check_loop(struct smtpd *env, struct envelope *messagep)
int ret = 0;
int rcvcount = 0;
- fd = queue_message_fd_r(env, Q_QUEUE, messagep->evpid>>32);
+ fd = queue_message_fd_r(Q_QUEUE, messagep->evpid>>32);
if ((fp = fdopen(fd, "r")) == NULL)
fatal("fdopen");
diff --git a/usr.sbin/smtpd/smtp.c b/usr.sbin/smtpd/smtp.c
index 883a1dd103a..ecae30f9177 100644
--- a/usr.sbin/smtpd/smtp.c
+++ b/usr.sbin/smtpd/smtp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp.c,v 1.84 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: smtp.c,v 1.85 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -37,20 +37,20 @@
#include "smtpd.h"
#include "log.h"
-static void smtp_imsg(struct smtpd *, struct imsgev *, struct imsg *);
+static void smtp_imsg(struct imsgev *, struct imsg *);
static void smtp_shutdown(void);
static void smtp_sig_handler(int, short, void *);
-static void smtp_setup_events(struct smtpd *);
-static void smtp_disable_events(struct smtpd *);
-static void smtp_pause(struct smtpd *);
-static int smtp_enqueue(struct smtpd *, uid_t *);
+static void smtp_setup_events(void);
+static void smtp_disable_events(void);
+static void smtp_pause(void);
+static int smtp_enqueue(uid_t *);
static void smtp_accept(int, short, void *);
static struct session *smtp_new(struct listener *);
-static struct session *session_lookup(struct smtpd *, u_int64_t);
+static struct session *session_lookup(u_int64_t);
static void
-smtp_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
+smtp_imsg(struct imsgev *iev, struct imsg *imsg)
{
struct session skey;
struct submit_status *ss;
@@ -64,7 +64,7 @@ smtp_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
switch (imsg->hdr.type) {
case IMSG_DNS_PTR:
dns = imsg->data;
- s = session_lookup(env, dns->id);
+ s = session_lookup(dns->id);
if (s == NULL)
fatalx("smtp: impossible quit");
strlcpy(s->s_hostname,
@@ -83,7 +83,7 @@ smtp_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_MFA_MAIL:
log_debug("smtp: got imsg_mfa_mail/rcpt");
ss = imsg->data;
- s = session_lookup(env, ss->id);
+ s = session_lookup(ss->id);
if (s == NULL)
return;
session_pickup(s, ss);
@@ -97,7 +97,7 @@ smtp_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
switch (imsg->hdr.type) {
case IMSG_QUEUE_CREATE_MESSAGE:
log_debug("smtp: imsg_queue_create_message returned");
- s = session_lookup(env, ss->id);
+ s = session_lookup(ss->id);
if (s == NULL)
return;
s->s_msg.evpid = (u_int64_t)ss->u.msgid << 32;
@@ -106,7 +106,7 @@ smtp_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_QUEUE_MESSAGE_FILE:
log_debug("smtp: imsg_queue_message_file returned");
- s = session_lookup(env, ss->id);
+ s = session_lookup(ss->id);
if (s == NULL) {
close(imsg->fd);
return;
@@ -136,7 +136,7 @@ smtp_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_QUEUE_COMMIT_ENVELOPES:
log_debug("smtp: got imsg_queue_commit_envelopes");
- s = session_lookup(env, ss->id);
+ s = session_lookup(ss->id);
if (s == NULL)
return;
session_pickup(s, ss);
@@ -144,7 +144,7 @@ smtp_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_QUEUE_COMMIT_MESSAGE:
log_debug("smtp: got imsg_queue_commit_message");
- s = session_lookup(env, ss->id);
+ s = session_lookup(ss->id);
if (s == NULL)
return;
session_pickup(s, ss);
@@ -152,7 +152,7 @@ smtp_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_SMTP_ENQUEUE:
imsg_compose_event(iev, IMSG_SMTP_ENQUEUE, 0, 0,
- smtp_enqueue(env, NULL), imsg->data,
+ smtp_enqueue(NULL), imsg->data,
sizeof(struct envelope));
return;
}
@@ -171,7 +171,7 @@ smtp_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
s->s_msg.status |= S_MESSAGE_TEMPFAILURE;
}
if (env->sc_listeners)
- smtp_disable_events(env);
+ smtp_disable_events();
imsg_compose_event(iev, IMSG_PARENT_SEND_CONFIG, 0, 0, -1,
NULL, 0);
return;
@@ -237,13 +237,13 @@ smtp_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_CONF_END:
if (!(env->sc_flags & SMTPD_CONFIGURING))
return;
- smtp_setup_events(env);
+ smtp_setup_events();
env->sc_flags &= ~SMTPD_CONFIGURING;
return;
case IMSG_PARENT_AUTHENTICATE:
auth = imsg->data;
- s = session_lookup(env, auth->id);
+ s = session_lookup(auth->id);
if (s == NULL)
return;
if (auth->success) {
@@ -266,16 +266,16 @@ smtp_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
switch (imsg->hdr.type) {
case IMSG_SMTP_ENQUEUE:
imsg_compose_event(iev, IMSG_SMTP_ENQUEUE,
- imsg->hdr.peerid, 0, smtp_enqueue(env, imsg->data),
+ imsg->hdr.peerid, 0, smtp_enqueue(imsg->data),
NULL, 0);
return;
case IMSG_SMTP_PAUSE:
- smtp_pause(env);
+ smtp_pause();
return;
case IMSG_SMTP_RESUME:
- smtp_resume(env);
+ smtp_resume();
return;
}
}
@@ -304,7 +304,7 @@ smtp_shutdown(void)
}
pid_t
-smtp(struct smtpd *env)
+smtp(void)
{
pid_t pid;
struct passwd *pw;
@@ -330,7 +330,7 @@ smtp(struct smtpd *env)
}
ssl_init();
- purge_config(env, PURGE_EVERYTHING);
+ purge_config(PURGE_EVERYTHING);
pw = env->sc_pw;
@@ -350,8 +350,8 @@ smtp(struct smtpd *env)
imsg_callback = smtp_imsg;
event_init();
- signal_set(&ev_sigint, SIGINT, smtp_sig_handler, env);
- signal_set(&ev_sigterm, SIGTERM, smtp_sig_handler, env);
+ signal_set(&ev_sigint, SIGINT, smtp_sig_handler, NULL);
+ signal_set(&ev_sigterm, SIGTERM, smtp_sig_handler, NULL);
signal_add(&ev_sigint, NULL);
signal_add(&ev_sigterm, NULL);
signal(SIGPIPE, SIG_IGN);
@@ -361,8 +361,8 @@ smtp(struct smtpd *env)
* the listening sockets arrive. */
env->sc_maxconn = availdesc() / 2;
- config_pipes(env, peers, nitems(peers));
- config_peers(env, peers, nitems(peers));
+ config_pipes(peers, nitems(peers));
+ config_peers(peers, nitems(peers));
if (event_dispatch() < 0)
fatal("event_dispatch");
@@ -372,7 +372,7 @@ smtp(struct smtpd *env)
}
static void
-smtp_setup_events(struct smtpd *env)
+smtp_setup_events(void)
{
struct listener *l;
int avail = availdesc();
@@ -385,10 +385,9 @@ smtp_setup_events(struct smtpd *env)
session_socket_blockmode(l->fd, BM_NONBLOCK);
if (listen(l->fd, SMTPD_BACKLOG) == -1)
fatal("listen");
- l->env = env;
event_set(&l->ev, l->fd, EV_READ|EV_PERSIST, smtp_accept, l);
event_add(&l->ev, NULL);
- ssl_setup(env, l);
+ ssl_setup(l);
avail--;
}
@@ -400,7 +399,7 @@ smtp_setup_events(struct smtpd *env)
}
static void
-smtp_disable_events(struct smtpd *env)
+smtp_disable_events(void)
{
struct listener *l;
@@ -417,7 +416,7 @@ smtp_disable_events(struct smtpd *env)
}
static void
-smtp_pause(struct smtpd *env)
+smtp_pause(void)
{
struct listener *l;
@@ -429,7 +428,7 @@ smtp_pause(struct smtpd *env)
}
void
-smtp_resume(struct smtpd *env)
+smtp_resume(void)
{
struct listener *l;
@@ -441,7 +440,7 @@ smtp_resume(struct smtpd *env)
}
static int
-smtp_enqueue(struct smtpd *env, uid_t *euid)
+smtp_enqueue(uid_t *euid)
{
static struct listener local, *l;
static struct sockaddr_storage sa;
@@ -463,7 +462,6 @@ smtp_enqueue(struct smtpd *env, uid_t *euid)
memcpy(&sa, res->ai_addr, res->ai_addrlen);
freeaddrinfo(res);
}
- l->env = env;
/*
* Some enqueue requests buffered in IMSG may still arrive even after
@@ -518,14 +516,13 @@ smtp_accept(int fd, short event, void *p)
s->s_flags |= F_WRITEONLY;
- dns_query_ptr(l->env, &s->s_ss, s->s_id);
+ dns_query_ptr(&s->s_ss, s->s_id);
}
static struct session *
smtp_new(struct listener *l)
{
- struct smtpd *env = l->env;
struct session *s;
log_debug("smtp_new: incoming client on listener: %p", l);
@@ -535,14 +532,13 @@ smtp_new(struct listener *l)
if (env->stats->smtp.sessions_active >= env->sc_maxconn) {
log_warnx("client limit hit, disabling incoming connections");
- smtp_pause(env);
+ smtp_pause();
return (NULL);
}
if ((s = calloc(1, sizeof(*s))) == NULL)
fatal(NULL);
s->s_id = generate_uid();
- s->s_env = env;
s->s_l = l;
strlcpy(s->s_msg.tag, l->tag, sizeof(s->s_msg.tag));
SPLAY_INSERT(sessiontree, &env->sc_sessions, s);
@@ -566,7 +562,7 @@ smtp_new(struct listener *l)
* Helper function for handling IMSG replies.
*/
static struct session *
-session_lookup(struct smtpd *env, u_int64_t id)
+session_lookup(u_int64_t id)
{
struct session key;
struct session *s;
diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c
index a32d213e6d3..20ba091ebcd 100644
--- a/usr.sbin/smtpd/smtp_session.c
+++ b/usr.sbin/smtpd/smtp_session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp_session.c,v 1.140 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: smtp_session.c,v 1.141 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -333,7 +333,7 @@ session_rfc5321_helo_handler(struct session *s, char *args)
s->s_flags &= F_SECURE|F_AUTHENTICATED;
session_respond(s, "250 %s Hello %s [%s], pleased to meet you",
- s->s_env->sc_hostname, args, ss_to_text(&s->s_ss));
+ env->sc_hostname, args, ss_to_text(&s->s_ss));
return 1;
}
@@ -358,14 +358,14 @@ session_rfc5321_ehlo_handler(struct session *s, char *args)
s->s_flags |= F_8BITMIME;
session_respond(s, "250-%s Hello %s [%s], pleased to meet you",
- s->s_env->sc_hostname, args, ss_to_text(&s->s_ss));
+ env->sc_hostname, args, ss_to_text(&s->s_ss));
/* unconditionnal extensions go first */
session_respond(s, "250-8BITMIME");
session_respond(s, "250-ENHANCEDSTATUSCODES");
/* XXX - we also want to support reading SIZE from MAIL parameters */
- session_respond(s, "250-SIZE %zu", s->s_env->sc_maxsize);
+ session_respond(s, "250-SIZE %zu", env->sc_maxsize);
if (ADVERTISE_TLS(s))
session_respond(s, "250-STARTTLS");
@@ -456,7 +456,7 @@ session_rfc5321_rcpt_handler(struct session *s, char *args)
static int
session_rfc5321_quit_handler(struct session *s, char *args)
{
- session_respond(s, "221 2.0.0 %s Closing connection", s->s_env->sc_hostname);
+ session_respond(s, "221 2.0.0 %s Closing connection", env->sc_hostname);
s->s_flags |= F_QUIT;
@@ -603,7 +603,7 @@ session_pickup(struct session *s, struct submit_status *ss)
if ((ss != NULL && ss->code == 421) ||
(s->s_msg.status & S_MESSAGE_TEMPFAILURE)) {
session_respond(s, "421 Service temporarily unavailable");
- s->s_env->stats->smtp.tempfail++;
+ env->stats->smtp.tempfail++;
s->s_flags |= F_QUIT;
return;
}
@@ -612,7 +612,7 @@ session_pickup(struct session *s, struct submit_status *ss)
case S_INIT:
s->s_state = S_GREETED;
log_debug("session_pickup: greeting client");
- session_respond(s, SMTPD_BANNER, s->s_env->sc_hostname);
+ session_respond(s, SMTPD_BANNER, env->sc_hostname);
break;
case S_TLS:
@@ -683,7 +683,7 @@ session_pickup(struct session *s, struct submit_status *ss)
fprintf(s->datafp, "Received: from %s (%s [%s])\n",
s->s_msg.session_helo, s->s_hostname, ss_to_text(&s->s_ss));
fprintf(s->datafp, "\tby %s (OpenSMTPD) with %sSMTP id %08x",
- s->s_env->sc_hostname, s->s_flags & F_EHLO ? "E" : "",
+ env->sc_hostname, s->s_flags & F_EHLO ? "E" : "",
(u_int32_t)(s->s_msg.evpid >> 32));
if (s->s_flags & F_SECURE) {
@@ -808,7 +808,7 @@ session_read(struct bufferevent *bev, void *p)
tempfail:
session_respond(s, "421 4.0.0 Service temporarily unavailable");
- s->s_env->stats->smtp.tempfail++;
+ env->stats->smtp.tempfail++;
s->s_flags |= F_QUIT;
free(line);
}
@@ -832,7 +832,7 @@ session_read_data(struct session *s, char *line)
} else if (s->s_msg.status & S_MESSAGE_TEMPFAILURE) {
session_respond(s, "421 4.0.0 Temporary failure");
s->s_flags |= F_QUIT;
- s->s_env->stats->smtp.tempfail++;
+ env->stats->smtp.tempfail++;
} else {
session_imsg(s, PROC_QUEUE, IMSG_QUEUE_COMMIT_MESSAGE,
0, 0, -1, &s->s_msg, sizeof(s->s_msg));
@@ -859,7 +859,7 @@ session_read_data(struct session *s, char *line)
*/
datalen = ftell(s->datafp);
if (SIZE_MAX - datalen < len + 1 ||
- datalen + len + 1 > s->s_env->sc_maxsize) {
+ datalen + len + 1 > env->sc_maxsize) {
s->s_msg.status |= S_MESSAGE_PERMFAILURE;
return;
}
@@ -927,12 +927,12 @@ session_error(struct bufferevent *bev, short event, void *p)
if (event & EVBUFFER_READ) {
if (event & EVBUFFER_TIMEOUT) {
log_warnx("client %s read timeout", ip);
- s->s_env->stats->smtp.read_timeout++;
+ env->stats->smtp.read_timeout++;
} else if (event & EVBUFFER_EOF)
- s->s_env->stats->smtp.read_eof++;
+ env->stats->smtp.read_eof++;
else if (event & EVBUFFER_ERROR) {
log_warn("client %s read error", ip);
- s->s_env->stats->smtp.read_error++;
+ env->stats->smtp.read_error++;
}
session_destroy(s);
@@ -942,12 +942,12 @@ session_error(struct bufferevent *bev, short event, void *p)
if (event & EVBUFFER_WRITE) {
if (event & EVBUFFER_TIMEOUT) {
log_warnx("client %s write timeout", ip);
- s->s_env->stats->smtp.write_timeout++;
+ env->stats->smtp.write_timeout++;
} else if (event & EVBUFFER_EOF)
- s->s_env->stats->smtp.write_eof++;
+ env->stats->smtp.write_eof++;
else if (event & EVBUFFER_ERROR) {
log_warn("client %s write error", ip);
- s->s_env->stats->smtp.write_error++;
+ env->stats->smtp.write_error++;
}
if (s->s_flags & F_WRITEONLY)
@@ -974,7 +974,7 @@ session_destroy(struct session *s)
fclose(s->datafp);
if (s->s_msg.evpid != 0 && s->s_state != S_DONE)
- imsg_compose_event(s->s_env->sc_ievs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_REMOVE_MESSAGE, 0, 0, -1, &s->s_msg,
sizeof(s->s_msg));
@@ -986,16 +986,16 @@ session_destroy(struct session *s)
if (s->s_fd != -1 && close(s->s_fd) == -1)
fatal("session_destroy: close");
- s->s_env->stats->smtp.sessions_active--;
+ env->stats->smtp.sessions_active--;
/* resume when session count decreases to 95% */
- resume = s->s_env->sc_maxconn * 95 / 100;
- if (s->s_env->stats->smtp.sessions_active == resume) {
+ resume = env->sc_maxconn * 95 / 100;
+ if (env->stats->smtp.sessions_active == resume) {
log_warnx("re-enabling incoming connections");
- smtp_resume(s->s_env);
+ smtp_resume();
}
- SPLAY_REMOVE(sessiontree, &s->s_env->sc_sessions, s);
+ SPLAY_REMOVE(sessiontree, &env->sc_sessions, s);
bzero(s, sizeof(*s));
free(s);
}
@@ -1011,7 +1011,7 @@ session_readline(struct session *s)
if (line == NULL) {
if (EVBUFFER_LENGTH(s->s_bev->input) > SMTP_LINE_MAX) {
session_respond(s, "500 5.0.0 Line too long");
- s->s_env->stats->smtp.linetoolong++;
+ env->stats->smtp.linetoolong++;
s->s_flags |= F_QUIT;
}
return NULL;
@@ -1023,7 +1023,7 @@ session_readline(struct session *s)
if (nr > SMTP_LINE_MAX) {
session_respond(s, "500 5.0.0 Line too long");
- s->s_env->stats->smtp.linetoolong++;
+ env->stats->smtp.linetoolong++;
s->s_flags |= F_QUIT;
return NULL;
}
@@ -1032,7 +1032,7 @@ session_readline(struct session *s)
(line2 = evbuffer_readln(s->s_bev->input, NULL,
EVBUFFER_EOL_CRLF)) != NULL) {
session_respond(s, "500 5.0.0 Pipelining unsupported");
- s->s_env->stats->smtp.toofast++;
+ env->stats->smtp.toofast++;
s->s_flags |= F_QUIT;
free(line);
free(line2);
@@ -1131,7 +1131,7 @@ session_respond(struct session *s, char *fmt, ...)
if (delay > 0) {
struct timeval tv = { delay, 0 };
- s->s_env->stats->smtp.delays++;
+ env->stats->smtp.delays++;
evtimer_set(&s->s_ev, session_respond_delayed, s);
evtimer_add(&s->s_ev, &tv);
} else
@@ -1170,7 +1170,7 @@ session_imsg(struct session *s, enum smtp_proc_type proc, enum imsg_type type,
*/
s->s_flags |= F_WRITEONLY;
bufferevent_disable(s->s_bev, EV_READ);
- imsg_compose_event(s->s_env->sc_ievs[proc], type, peerid, pid, fd, data,
+ imsg_compose_event(env->sc_ievs[proc], type, peerid, pid, fd, data,
datalen);
}
diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
index d9c7db9d518..e785d6434b0 100644
--- a/usr.sbin/smtpd/smtpctl.c
+++ b/usr.sbin/smtpd/smtpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpctl.c,v 1.59 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: smtpctl.c,v 1.60 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -47,6 +47,8 @@ struct imsgbuf *ibuf;
int sendmail = 0;
extern char *__progname;
+struct smtpd *env = NULL;
+
__dead void
usage(void)
{
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index d5f49cb1ff8..df12e11c697 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.121 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: smtpd.c,v 1.122 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -44,42 +44,43 @@
#include "smtpd.h"
#include "log.h"
-static void parent_imsg(struct smtpd *, struct imsgev *, struct imsg *);
+static void parent_imsg(struct imsgev *, struct imsg *);
static void usage(void);
-static void parent_shutdown(struct smtpd *);
+static void parent_shutdown(void);
static void parent_send_config(int, short, void *);
-static void parent_send_config_listeners(struct smtpd *);
-static void parent_send_config_client_certs(struct smtpd *);
-static void parent_send_config_ruleset(struct smtpd *, int);
+static void parent_send_config_listeners(void);
+static void parent_send_config_client_certs(void);
+static void parent_send_config_ruleset(int);
static void parent_sig_handler(int, short, void *);
-static void forkmda(struct smtpd *, struct imsgev *, u_int32_t,
- struct deliver *);
-static int parent_enqueue_offline(struct smtpd *, char *);
+static void forkmda(struct imsgev *, u_int32_t, struct deliver *);
+static int parent_enqueue_offline(char *);
static int parent_forward_open(char *);
static int path_starts_with(char *, char *);
-static void fork_peers(struct smtpd *);
-static struct child *child_lookup(struct smtpd *, pid_t);
-static struct child *child_add(struct smtpd *, pid_t, int, int);
-static void child_del(struct smtpd *, pid_t);
+static void fork_peers(void);
+static struct child *child_lookup(pid_t);
+static struct child *child_add(pid_t, int, int);
+static void child_del(pid_t);
extern char **environ;
-void (*imsg_callback)(struct smtpd *, struct imsgev *, struct imsg *);
+void (*imsg_callback)(struct imsgev *, struct imsg *);
+
+struct smtpd *env = NULL;
int __b64_pton(char const *, unsigned char *, size_t);
static void
-parent_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
+parent_imsg(struct imsgev *iev, struct imsg *imsg)
{
- struct smtpd newenv;
+ struct smtpd newenv, *saveenv;
struct forward_req *fwreq;
struct reload *reload;
struct auth *auth;
- int fd;
+ int fd, r;
if (iev->proc == PROC_SMTP) {
switch (imsg->hdr.type) {
case IMSG_PARENT_SEND_CONFIG:
- parent_send_config_listeners(env);
+ parent_send_config_listeners();
return;
case IMSG_PARENT_AUTHENTICATE:
@@ -113,7 +114,7 @@ parent_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
if (iev->proc == PROC_QUEUE) {
switch (imsg->hdr.type) {
case IMSG_PARENT_ENQUEUE_OFFLINE:
- if (! parent_enqueue_offline(env, imsg->data))
+ if (! parent_enqueue_offline(imsg->data))
imsg_compose_event(iev,
IMSG_PARENT_ENQUEUE_OFFLINE, 0, 0, -1,
NULL, 0);
@@ -124,7 +125,7 @@ parent_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
if (iev->proc == PROC_MDA) {
switch (imsg->hdr.type) {
case IMSG_PARENT_FORK_MDA:
- forkmda(env, iev, imsg->hdr.peerid, imsg->data);
+ forkmda(iev, imsg->hdr.peerid, imsg->data);
return;
}
}
@@ -134,7 +135,11 @@ parent_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
case IMSG_CONF_RELOAD:
reload = imsg->data;
reload->ret = 0;
- if (parse_config(&newenv, env->sc_conffile, 0) == 0) {
+ saveenv = env;
+ env = &newenv;
+ r = parse_config(&newenv, saveenv->sc_conffile, 0);
+ env = saveenv;
+ if (r == 0) {
strlcpy(env->sc_hostname, newenv.sc_hostname,
sizeof env->sc_hostname);
env->sc_listeners = newenv.sc_listeners;
@@ -143,9 +148,9 @@ parent_imsg(struct smtpd *env, struct imsgev *iev, struct imsg *imsg)
env->sc_rules = newenv.sc_rules;
env->sc_ssl = newenv.sc_ssl;
- parent_send_config_client_certs(env);
- parent_send_config_ruleset(env, PROC_MFA);
- parent_send_config_ruleset(env, PROC_LKA);
+ parent_send_config_client_certs();
+ parent_send_config_ruleset(PROC_MFA);
+ parent_send_config_ruleset(PROC_LKA);
imsg_compose_event(env->sc_ievs[PROC_SMTP],
IMSG_CONF_RELOAD, 0, 0, -1, NULL, 0);
reload->ret = 1;
@@ -188,7 +193,7 @@ usage(void)
}
static void
-parent_shutdown(struct smtpd *env)
+parent_shutdown(void)
{
struct child *child;
pid_t pid;
@@ -208,13 +213,13 @@ parent_shutdown(struct smtpd *env)
static void
parent_send_config(int fd, short event, void *p)
{
- parent_send_config_listeners(p);
- parent_send_config_client_certs(p);
- parent_send_config_ruleset(p, PROC_LKA);
+ parent_send_config_listeners();
+ parent_send_config_client_certs();
+ parent_send_config_ruleset(PROC_LKA);
}
static void
-parent_send_config_listeners(struct smtpd *env)
+parent_send_config_listeners(void)
{
struct listener *l;
struct ssl *s;
@@ -260,7 +265,7 @@ parent_send_config_listeners(struct smtpd *env)
}
static void
-parent_send_config_client_certs(struct smtpd *env)
+parent_send_config_client_certs(void)
{
struct ssl *s;
struct iovec iov[4];
@@ -292,7 +297,7 @@ parent_send_config_client_certs(struct smtpd *env)
}
void
-parent_send_config_ruleset(struct smtpd *env, int proc)
+parent_send_config_ruleset(int proc)
{
struct rule *r;
struct map *m;
@@ -325,7 +330,6 @@ parent_send_config_ruleset(struct smtpd *env, int proc)
static void
parent_sig_handler(int sig, short event, void *p)
{
- struct smtpd *env = p;
struct child *child;
int die = 0, status, fail;
pid_t pid;
@@ -342,7 +346,7 @@ parent_sig_handler(int sig, short event, void *p)
if (pid <= 0)
continue;
- child = child_lookup(env, pid);
+ child = child_lookup(pid);
if (child == NULL)
fatalx("unexpected SIGCHLD");
@@ -394,12 +398,12 @@ parent_sig_handler(int sig, short event, void *p)
fatalx("unexpected child type");
}
- child_del(env, child->pid);
+ child_del(child->pid);
free(cause);
} while (pid > 0 || (pid == -1 && errno == EINTR));
if (die)
- parent_shutdown(env);
+ parent_shutdown();
break;
default:
fatalx("unexpected signal");
@@ -413,7 +417,7 @@ main(int argc, char *argv[])
int debug, verbose;
int opts;
const char *conffile = CONF_FILE;
- struct smtpd env;
+ struct smtpd smtpd;
struct event ev_sigint;
struct event ev_sigterm;
struct event ev_sigchld;
@@ -429,6 +433,8 @@ main(int argc, char *argv[])
{ PROC_QUEUE, imsg_dispatch }
};
+ env = &smtpd;
+
opts = 0;
debug = 0;
verbose = 0;
@@ -465,14 +471,14 @@ main(int argc, char *argv[])
argv += optind;
argc -= optind;
- if (parse_config(&env, conffile, opts))
+ if (parse_config(&smtpd, conffile, opts))
exit(1);
- if (strlcpy(env.sc_conffile, conffile, MAXPATHLEN) >= MAXPATHLEN)
+ if (strlcpy(env->sc_conffile, conffile, MAXPATHLEN) >= MAXPATHLEN)
errx(1, "config file exceeds MAXPATHLEN");
- if (env.sc_opts & SMTPD_OPT_NOACTION) {
+ if (env->sc_opts & SMTPD_OPT_NOACTION) {
fprintf(stderr, "configuration OK\n");
exit(0);
}
@@ -481,14 +487,14 @@ main(int argc, char *argv[])
if (geteuid())
errx(1, "need root privileges");
- if ((env.sc_pw = getpwnam(SMTPD_USER)) == NULL)
+ if ((env->sc_pw = getpwnam(SMTPD_USER)) == NULL)
errx(1, "unknown user %s", SMTPD_USER);
- env.sc_queue = queue_backend_lookup(QT_FS);
- if (env.sc_queue == NULL)
+ env->sc_queue = queue_backend_lookup(QT_FS);
+ if (env->sc_queue == NULL)
errx(1, "could not find queue backend");
- if (!env.sc_queue->init(&env))
+ if (!env->sc_queue->init())
errx(1, "invalid directory permissions");
log_init(debug);
@@ -500,38 +506,38 @@ main(int argc, char *argv[])
log_info("startup%s", (debug > 1)?" [debug mode]":"");
- if (env.sc_hostname[0] == '\0')
+ if (env->sc_hostname[0] == '\0')
errx(1, "machine does not have a hostname set");
- env.stats = mmap(NULL, sizeof(struct stats), PROT_WRITE|PROT_READ,
+ env->stats = mmap(NULL, sizeof(struct stats), PROT_WRITE|PROT_READ,
MAP_ANON|MAP_SHARED, -1, (off_t)0);
- if (env.stats == MAP_FAILED)
+ if (env->stats == MAP_FAILED)
fatal("mmap");
- bzero(env.stats, sizeof(struct stats));
+ bzero(env->stats, sizeof(struct stats));
- env.stats->parent.start = time(NULL);
+ env->stats->parent.start = time(NULL);
- fork_peers(&env);
+ fork_peers();
imsg_callback = parent_imsg;
event_init();
- signal_set(&ev_sigint, SIGINT, parent_sig_handler, &env);
- signal_set(&ev_sigterm, SIGTERM, parent_sig_handler, &env);
- signal_set(&ev_sigchld, SIGCHLD, parent_sig_handler, &env);
- signal_set(&ev_sighup, SIGHUP, parent_sig_handler, &env);
+ signal_set(&ev_sigint, SIGINT, parent_sig_handler, NULL);
+ signal_set(&ev_sigterm, SIGTERM, parent_sig_handler, NULL);
+ signal_set(&ev_sigchld, SIGCHLD, parent_sig_handler, NULL);
+ signal_set(&ev_sighup, SIGHUP, parent_sig_handler, NULL);
signal_add(&ev_sigint, NULL);
signal_add(&ev_sigterm, NULL);
signal_add(&ev_sigchld, NULL);
signal_add(&ev_sighup, NULL);
signal(SIGPIPE, SIG_IGN);
- config_pipes(&env, peers, nitems(peers));
- config_peers(&env, peers, nitems(peers));
+ config_pipes(peers, nitems(peers));
+ config_peers(peers, nitems(peers));
- evtimer_set(&env.sc_ev, parent_send_config, &env);
+ evtimer_set(&env->sc_ev, parent_send_config, NULL);
bzero(&tv, sizeof(tv));
- evtimer_add(&env.sc_ev, &tv);
+ evtimer_add(&env->sc_ev, &tv);
if (event_dispatch() < 0)
fatal("event_dispatch");
@@ -540,7 +546,7 @@ main(int argc, char *argv[])
}
static void
-fork_peers(struct smtpd *env)
+fork_peers(void)
{
SPLAY_INIT(&env->children);
@@ -569,7 +575,7 @@ fork_peers(struct smtpd *env)
env->sc_instances[PROC_RUNNER] = 1;
env->sc_instances[PROC_SMTP] = 1;
- init_pipes(env);
+ init_pipes();
env->sc_title[PROC_CONTROL] = "control";
env->sc_title[PROC_LKA] = "lookup agent";
@@ -580,20 +586,20 @@ fork_peers(struct smtpd *env)
env->sc_title[PROC_RUNNER] = "runner";
env->sc_title[PROC_SMTP] = "smtp server";
- child_add(env, control(env), CHILD_DAEMON, PROC_CONTROL);
- child_add(env, lka(env), CHILD_DAEMON, PROC_LKA);
- child_add(env, mda(env), CHILD_DAEMON, PROC_MDA);
- child_add(env, mfa(env), CHILD_DAEMON, PROC_MFA);
- child_add(env, mta(env), CHILD_DAEMON, PROC_MTA);
- child_add(env, queue(env), CHILD_DAEMON, PROC_QUEUE);
- child_add(env, runner(env), CHILD_DAEMON, PROC_RUNNER);
- child_add(env, smtp(env), CHILD_DAEMON, PROC_SMTP);
+ child_add(control(), CHILD_DAEMON, PROC_CONTROL);
+ child_add(lka(), CHILD_DAEMON, PROC_LKA);
+ child_add(mda(), CHILD_DAEMON, PROC_MDA);
+ child_add(mfa(), CHILD_DAEMON, PROC_MFA);
+ child_add(mta(), CHILD_DAEMON, PROC_MTA);
+ child_add(queue(), CHILD_DAEMON, PROC_QUEUE);
+ child_add(runner(), CHILD_DAEMON, PROC_RUNNER);
+ child_add(smtp(), CHILD_DAEMON, PROC_SMTP);
setproctitle("[priv]");
}
struct child *
-child_add(struct smtpd *env, pid_t pid, int type, int title)
+child_add(pid_t pid, int type, int title)
{
struct child *child;
@@ -611,11 +617,11 @@ child_add(struct smtpd *env, pid_t pid, int type, int title)
}
static void
-child_del(struct smtpd *env, pid_t pid)
+child_del(pid_t pid)
{
struct child *p;
- p = child_lookup(env, pid);
+ p = child_lookup(pid);
if (p == NULL)
fatalx("child_del: unknown child");
@@ -625,7 +631,7 @@ child_del(struct smtpd *env, pid_t pid)
}
static struct child *
-child_lookup(struct smtpd *env, pid_t pid)
+child_lookup(pid_t pid)
{
struct child key;
@@ -660,7 +666,7 @@ imsg_compose_event(struct imsgev *iev, u_int16_t type, u_int32_t peerid,
}
static void
-forkmda(struct smtpd *env, struct imsgev *iev, u_int32_t id,
+forkmda(struct imsgev *iev, u_int32_t id,
struct deliver *deliver)
{
char ebuf[128], sfn[32];
@@ -722,7 +728,7 @@ forkmda(struct smtpd *env, struct imsgev *iev, u_int32_t id,
if (pid > 0) {
if (seteuid(0) < 0)
fatal("forkmda: cannot restore privileges");
- child = child_add(env, pid, CHILD_MDA, -1);
+ child = child_add(pid, CHILD_MDA, -1);
child->mda_out = allout;
child->mda_id = id;
close(pipefd[0]);
@@ -862,7 +868,7 @@ forkmda(struct smtpd *env, struct imsgev *iev, u_int32_t id,
#undef error2
static int
-parent_enqueue_offline(struct smtpd *env, char *runner_path)
+parent_enqueue_offline(char *runner_path)
{
char path[MAXPATHLEN];
struct passwd *pw;
@@ -966,7 +972,7 @@ parent_enqueue_offline(struct smtpd *env, char *runner_path)
_exit(1);
}
- child_add(env, pid, CHILD_ENQUEUE_OFFLINE, -1);
+ child_add(pid, CHILD_ENQUEUE_OFFLINE, -1);
return (1);
}
@@ -1054,7 +1060,7 @@ imsg_dispatch(int fd, short event, void *p)
fatal("imsg_get");
if (n == 0)
break;
- imsg_callback(iev->env, iev, &imsg);
+ imsg_callback(iev, &imsg);
imsg_free(&imsg);
}
imsg_event_add(iev);
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index ca4a489cb89..4f1aef729f0 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.219 2011/04/17 13:36:07 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.220 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -191,7 +191,6 @@ struct imsgev {
void (*handler)(int, short, void *);
struct event ev;
void *data;
- struct smtpd *env;
int proc;
short events;
};
@@ -506,7 +505,6 @@ struct listener {
in_port_t port;
struct timeval timeout;
struct event ev;
- struct smtpd *env;
char ssl_cert_name[PATH_MAX];
struct ssl *ssl;
void *ssl_ctx;
@@ -544,7 +542,6 @@ struct session {
struct event s_ev;
struct bufferevent *s_bev;
struct listener *s_l;
- struct smtpd *s_env;
void *s_ssl;
u_char *s_buf;
int s_buflen;
@@ -588,7 +585,6 @@ struct ramqueue_envelope {
};
struct ramqueue {
- struct smtpd *env;
struct ramqueue_envelope *current_evp;
RB_HEAD(hosttree, ramqueue_host) hosttree;
TAILQ_HEAD(,ramqueue_envelope) queue;
@@ -758,7 +754,6 @@ struct dns {
int type;
struct imsgev *asker;
struct sockaddr_storage ss;
- struct smtpd *env;
struct dns *next;
};
@@ -855,7 +850,6 @@ struct mta_relay {
struct mta_session {
SPLAY_ENTRY(mta_session) entry;
u_int64_t id;
- struct smtpd *env;
enum mta_state state;
char *host;
int port;
@@ -920,22 +914,22 @@ enum queue_op {
struct queue_backend {
enum queue_type type;
- int (*init)(struct smtpd *);
- int (*message)(struct smtpd *, enum queue_kind, enum queue_op, u_int32_t *);
- int (*envelope)(struct smtpd *, enum queue_kind, enum queue_op,
- struct envelope *);
+ int (*init)(void);
+ int (*message)(enum queue_kind, enum queue_op, u_int32_t *);
+ int (*envelope)(enum queue_kind, enum queue_op, struct envelope *);
};
-extern void (*imsg_callback)(struct smtpd *, struct imsgev *, struct imsg *);
+extern struct smtpd *env;
+extern void (*imsg_callback)(struct imsgev *, struct imsg *);
/* aliases.c */
-int aliases_exist(struct smtpd *, objid_t, char *);
-int aliases_get(struct smtpd *, objid_t, struct expandtree *, char *);
-int aliases_vdomain_exists(struct smtpd *, objid_t, char *);
-int aliases_virtual_exist(struct smtpd *, objid_t, struct path *);
-int aliases_virtual_get(struct smtpd *, objid_t, struct expandtree *, struct path *);
+int aliases_exist(objid_t, char *);
+int aliases_get(objid_t, struct expandtree *, char *);
+int aliases_vdomain_exists(objid_t, char *);
+int aliases_virtual_exist(objid_t, struct path *);
+int aliases_virtual_get(objid_t, struct expandtree *, struct path *);
int alias_parse(struct expandnode *, char *);
@@ -944,9 +938,8 @@ int authenticate_user(char *, char *);
/* bounce.c */
-int bounce_session(struct smtpd *, int, struct envelope *);
-int bounce_session_switch(struct smtpd *, FILE *, enum session_state *, char *,
- struct envelope *);
+int bounce_session(int, struct envelope *);
+int bounce_session_switch(FILE *, enum session_state *, char *, struct envelope *);
void bounce_event(int, short, void *);
@@ -956,27 +949,26 @@ void bounce_event(int, short, void *);
#define PURGE_RULES 0x04
#define PURGE_SSL 0x08
#define PURGE_EVERYTHING 0xff
-void purge_config(struct smtpd *, u_int8_t);
-void unconfigure(struct smtpd *);
-void configure(struct smtpd *);
-void init_pipes(struct smtpd *);
-void config_pipes(struct smtpd *, struct peer *, u_int);
-void config_peers(struct smtpd *, struct peer *, u_int);
+void purge_config(u_int8_t);
+void unconfigure(void);
+void configure(void);
+void init_pipes(void);
+void config_pipes(struct peer *, u_int);
+void config_peers(struct peer *, u_int);
/* control.c */
-pid_t control(struct smtpd *);
+pid_t control(void);
void session_socket_blockmode(int, enum blockmodes);
void session_socket_no_linger(int);
int session_socket_error(int);
/* dns.c */
-void dns_query_host(struct smtpd *, char *, int, u_int64_t);
-void dns_query_mx(struct smtpd *, char *, int, u_int64_t);
-void dns_query_ptr(struct smtpd *, struct sockaddr_storage *,
- u_int64_t);
-void dns_async(struct smtpd *, struct imsgev *, int, struct dns *);
+void dns_query_host(char *, int, u_int64_t);
+void dns_query_mx(char *, int, u_int64_t);
+void dns_query_ptr(struct sockaddr_storage *, u_int64_t);
+void dns_async(struct imsgev *, int, struct dns *);
int dnssession_cmp(struct dnssession *, struct dnssession *);
SPLAY_PROTOTYPE(dnstree, dnssession, nodes, dnssession_cmp);
@@ -1001,27 +993,27 @@ int forwards_get(int, struct expandtree *);
/* lka.c */
-pid_t lka(struct smtpd *);
+pid_t lka(void);
int lkasession_cmp(struct lkasession *, struct lkasession *);
SPLAY_PROTOTYPE(lkatree, lkasession, nodes, lkasession_cmp);
/* map.c */
-void *map_lookup(struct smtpd *, objid_t, char *, enum map_kind);
-struct map *map_find(struct smtpd *, objid_t);
-struct map *map_findbyname(struct smtpd *, const char *);
+void *map_lookup(objid_t, char *, enum map_kind);
+struct map *map_find(objid_t);
+struct map *map_findbyname(const char *);
/* mda.c */
-pid_t mda(struct smtpd *);
+pid_t mda(void);
/* mfa.c */
-pid_t mfa(struct smtpd *);
+pid_t mfa(void);
/* mta.c */
-pid_t mta(struct smtpd *);
+pid_t mta(void);
int mta_session_cmp(struct mta_session *, struct mta_session *);
SPLAY_PROTOTYPE(mtatree, mta_session, entry, mta_session_cmp);
@@ -1032,40 +1024,36 @@ int cmdline_symset(char *);
/* queue.c */
-pid_t queue(struct smtpd *);
-void queue_submit_envelope(struct smtpd *, struct envelope *);
-void queue_commit_envelopes(struct smtpd *, struct envelope *);
+pid_t queue(void);
+void queue_submit_envelope(struct envelope *);
+void queue_commit_envelopes(struct envelope *);
/* queue_backend.c */
struct queue_backend *queue_backend_lookup(enum queue_type);
-int queue_message_create(struct smtpd *, enum queue_kind, u_int32_t *);
-int queue_message_delete(struct smtpd *, enum queue_kind, u_int32_t);
-int queue_message_commit(struct smtpd *, enum queue_kind, u_int32_t);
-int queue_message_fd_r(struct smtpd *, enum queue_kind, u_int32_t);
-int queue_message_fd_rw(struct smtpd *, enum queue_kind, u_int32_t);
-int queue_message_purge(struct smtpd *, enum queue_kind, u_int32_t);
-int queue_envelope_create(struct smtpd *, enum queue_kind,
- struct envelope *);
-int queue_envelope_delete(struct smtpd *, enum queue_kind,
- struct envelope *);
-int queue_envelope_load(struct smtpd *, enum queue_kind,
- u_int64_t, struct envelope *);
-int queue_envelope_update(struct smtpd *, enum queue_kind,
- struct envelope *);
+int queue_message_create(enum queue_kind, u_int32_t *);
+int queue_message_delete(enum queue_kind, u_int32_t);
+int queue_message_commit(enum queue_kind, u_int32_t);
+int queue_message_fd_r(enum queue_kind, u_int32_t);
+int queue_message_fd_rw(enum queue_kind, u_int32_t);
+int queue_message_purge(enum queue_kind, u_int32_t);
+int queue_envelope_create(enum queue_kind, struct envelope *);
+int queue_envelope_delete(enum queue_kind, struct envelope *);
+int queue_envelope_load(enum queue_kind, u_int64_t, struct envelope *);
+int queue_envelope_update(enum queue_kind, struct envelope *);
/* queue_shared.c */
-void queue_message_update(struct smtpd *, struct envelope *);
+void queue_message_update(struct envelope *);
struct qwalk *qwalk_new(char *);
int qwalk(struct qwalk *, char *);
void qwalk_close(struct qwalk *);
-int bounce_record_message(struct smtpd *, struct envelope *, struct envelope *);
+int bounce_record_message(struct envelope *, struct envelope *);
void show_queue(char *, int);
/* ramqueue.c */
-void ramqueue_init(struct smtpd *, struct ramqueue *);
+void ramqueue_init(struct ramqueue *);
int ramqueue_load(struct ramqueue *, time_t *);
int ramqueue_load_offline(struct ramqueue *);
int ramqueue_host_cmp(struct ramqueue_host *, struct ramqueue_host *);
@@ -1083,13 +1071,13 @@ RB_PROTOTYPE(hosttree, ramqueue_host, host_entry, ramqueue_host_cmp);
/* runner.c */
-pid_t runner(struct smtpd *);
+pid_t runner(void);
void message_reset_flags(struct envelope *);
/* smtp.c */
-pid_t smtp(struct smtpd *);
-void smtp_resume(struct smtpd *);
+pid_t smtp(void);
+void smtp_resume(void);
/* smtp_session.c */
@@ -1117,8 +1105,8 @@ void ssl_init(void);
void ssl_transaction(struct session *);
void ssl_session_init(struct session *);
void ssl_session_destroy(struct session *);
-int ssl_load_certfile(struct smtpd *, const char *, u_int8_t);
-void ssl_setup(struct smtpd *, struct listener *);
+int ssl_load_certfile(const char *, u_int8_t);
+void ssl_setup(struct listener *);
int ssl_cmp(struct ssl *, struct ssl *);
SPLAY_PROTOTYPE(ssltree, ssl, ssl_nodes, ssl_cmp);
diff --git a/usr.sbin/smtpd/ssl.c b/usr.sbin/smtpd/ssl.c
index 9f42764a6f0..7e4add15aaa 100644
--- a/usr.sbin/smtpd/ssl.c
+++ b/usr.sbin/smtpd/ssl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssl.c,v 1.32 2011/03/15 19:24:55 gilles Exp $ */
+/* $OpenBSD: ssl.c,v 1.33 2011/05/01 12:57:11 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -112,7 +112,7 @@ ssl_connect(int fd, short event, void *p)
s->s_flags |= F_SECURE;
if (s->s_flags & F_PEERHASTLS) {
- session_respond(s, "EHLO %s", s->s_env->sc_hostname);
+ session_respond(s, "EHLO %s", env->sc_hostname);
}
return;
@@ -346,7 +346,7 @@ ssl_ctx_create(void)
}
int
-ssl_load_certfile(struct smtpd *env, const char *name, u_int8_t flags)
+ssl_load_certfile(const char *name, u_int8_t flags)
{
struct ssl *s;
struct ssl key;
@@ -423,7 +423,7 @@ ssl_init(void)
}
void
-ssl_setup(struct smtpd *env, struct listener *l)
+ssl_setup(struct listener *l)
{
struct ssl key;
DH *dh;
@@ -536,16 +536,16 @@ ssl_session_accept(int fd, short event, void *p)
s->s_flags |= F_SECURE;
if (s->s_l->flags & F_SMTPS) {
- s->s_env->stats->smtp.smtps++;
- s->s_env->stats->smtp.smtps_active++;
- SET_IF_GREATER(s->s_env->stats->smtp.smtps_active,
- s->s_env->stats->smtp.smtps_maxactive);
+ env->stats->smtp.smtps++;
+ env->stats->smtp.smtps_active++;
+ SET_IF_GREATER(env->stats->smtp.smtps_active,
+ env->stats->smtp.smtps_maxactive);
}
if (s->s_l->flags & F_STARTTLS) {
- s->s_env->stats->smtp.starttls++;
- s->s_env->stats->smtp.starttls_active++;
- SET_IF_GREATER(s->s_env->stats->smtp.starttls_active,
- s->s_env->stats->smtp.starttls_maxactive);
+ env->stats->smtp.starttls++;
+ env->stats->smtp.starttls_active++;
+ SET_IF_GREATER(env->stats->smtp.starttls_active,
+ env->stats->smtp.starttls_maxactive);
}
session_bufferevent_new(s);
@@ -645,11 +645,11 @@ ssl_session_destroy(struct session *s)
if (s->s_l->flags & F_SMTPS) {
if (s->s_flags & F_SECURE)
- s->s_env->stats->smtp.smtps_active--;
+ env->stats->smtp.smtps_active--;
}
if (s->s_l->flags & F_STARTTLS) {
if (s->s_flags & F_SECURE)
- s->s_env->stats->smtp.starttls_active--;
+ env->stats->smtp.starttls_active--;
}
}