summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/smtpd/config.c30
-rw-r--r--usr.sbin/smtpd/control.c145
-rw-r--r--usr.sbin/smtpd/dns.c91
-rw-r--r--usr.sbin/smtpd/imsg.c5
-rw-r--r--usr.sbin/smtpd/imsg.h11
-rw-r--r--usr.sbin/smtpd/lka.c84
-rw-r--r--usr.sbin/smtpd/mda.c34
-rw-r--r--usr.sbin/smtpd/mfa.c46
-rw-r--r--usr.sbin/smtpd/mta.c40
-rw-r--r--usr.sbin/smtpd/queue.c66
-rw-r--r--usr.sbin/smtpd/runner.c60
-rw-r--r--usr.sbin/smtpd/smtp.c49
-rw-r--r--usr.sbin/smtpd/smtp_session.c6
-rw-r--r--usr.sbin/smtpd/smtpctl.c11
-rw-r--r--usr.sbin/smtpd/smtpd.c134
-rw-r--r--usr.sbin/smtpd/smtpd.h20
16 files changed, 465 insertions, 367 deletions
diff --git a/usr.sbin/smtpd/config.c b/usr.sbin/smtpd/config.c
index 6bed7d4ae25..866276ba6e7 100644
--- a/usr.sbin/smtpd/config.c
+++ b/usr.sbin/smtpd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.7 2009/06/02 22:23:35 gilles Exp $ */
+/* $OpenBSD: config.c,v 1.8 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -203,23 +203,23 @@ config_peers(struct smtpd *env, struct peer *p, u_int peercount)
if (dst == smtpd_process)
fatal("config_peers: cannot peer with oneself");
- if ((env->sc_ibufs[dst] = calloc(env->sc_instances[dst],
- sizeof(struct imsgbuf))) == NULL)
+ if ((env->sc_ievs[dst] = calloc(env->sc_instances[dst],
+ sizeof(struct imsgev))) == NULL)
fatal("config_peers");
for (count = 0; count < env->sc_instances[dst]; count++) {
- imsg_init(&(env->sc_ibufs[dst][count]),
- env->sc_pipes[src][dst][count], p[i].cb);
-
- env->sc_ibufs[dst][count].events = EV_READ;
- env->sc_ibufs[dst][count].data = env;
-
- event_set(&(env->sc_ibufs[dst][count].ev),
- env->sc_ibufs[dst][count].fd,
- env->sc_ibufs[dst][count].events,
- env->sc_ibufs[dst][count].handler,
- env->sc_ibufs[dst][count].data);
- event_add(&(env->sc_ibufs[dst][count].ev), NULL);
+ imsg_init(&(env->sc_ievs[dst][count].ibuf),
+ env->sc_pipes[src][dst][count]);
+ env->sc_ievs[dst][count].handler = p[i].cb;
+ env->sc_ievs[dst][count].events = EV_READ;
+ env->sc_ievs[dst][count].data = env;
+
+ event_set(&(env->sc_ievs[dst][count].ev),
+ env->sc_ievs[dst][count].ibuf.fd,
+ env->sc_ievs[dst][count].events,
+ env->sc_ievs[dst][count].handler,
+ env->sc_ievs[dst][count].data);
+ event_add(&(env->sc_ievs[dst][count].ev), NULL);
}
}
}
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c
index fff8a621fce..76199121e64 100644
--- a/usr.sbin/smtpd/control.c
+++ b/usr.sbin/smtpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.33 2009/06/05 20:43:57 pyr Exp $ */
+/* $OpenBSD: control.c,v 1.34 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -228,12 +228,13 @@ control_accept(int listenfd, short event, void *arg)
return;
}
- imsg_init(&c->ibuf, connfd, control_dispatch_ext);
- c->ibuf.events = EV_READ;
- c->ibuf.data = env;
- event_set(&c->ibuf.ev, c->ibuf.fd, c->ibuf.events,
- c->ibuf.handler, env);
- event_add(&c->ibuf.ev, NULL);
+ 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);
+ event_add(&c->iev.ev, NULL);
TAILQ_INSERT_TAIL(&ctl_conns, c, entry);
}
@@ -243,7 +244,7 @@ control_connbyfd(int fd)
{
struct ctl_conn *c;
- for (c = TAILQ_FIRST(&ctl_conns); c != NULL && c->ibuf.fd != fd;
+ for (c = TAILQ_FIRST(&ctl_conns); c != NULL && c->iev.ibuf.fd != fd;
c = TAILQ_NEXT(c, entry))
; /* nothing */
@@ -260,11 +261,11 @@ control_close(int fd)
return;
}
- msgbuf_clear(&c->ibuf.w);
+ msgbuf_clear(&c->iev.ibuf.w);
TAILQ_REMOVE(&ctl_conns, c, entry);
- event_del(&c->ibuf.ev);
- close(c->ibuf.fd);
+ event_del(&c->iev.ev);
+ close(c->iev.ibuf.fd);
free(c);
}
@@ -288,21 +289,21 @@ control_dispatch_ext(int fd, short event, void *arg)
}
if (event & EV_READ) {
- if ((n = imsg_read(&c->ibuf)) == -1 || n == 0) {
+ if ((n = imsg_read(&c->iev.ibuf)) == -1 || n == 0) {
control_close(fd);
return;
}
}
if (event & EV_WRITE) {
- if (msgbuf_write(&c->ibuf.w) < 0) {
+ if (msgbuf_write(&c->iev.ibuf.w) < 0) {
control_close(fd);
return;
}
}
for (;;) {
- if ((n = imsg_get(&c->ibuf, &imsg)) == -1) {
+ if ((n = imsg_get(&c->iev.ibuf, &imsg)) == -1) {
control_close(fd);
return;
}
@@ -314,17 +315,17 @@ control_dispatch_ext(int fd, short event, void *arg)
case IMSG_SMTP_ENQUEUE:
if (env->sc_flags & (SMTPD_SMTP_PAUSED |
SMTPD_CONFIGURING | SMTPD_EXITING)) {
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
- imsg_compose_event(env->sc_ibufs[PROC_SMTP],
+ imsg_compose_event(env->sc_ievs[PROC_SMTP],
IMSG_SMTP_ENQUEUE, 0, 0, -1, &fd, sizeof(fd));
break;
case IMSG_STATS:
if (euid)
goto badcred;
- imsg_compose_event(&c->ibuf, IMSG_STATS, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_STATS, 0, 0, -1,
env->stats, sizeof(struct stats));
break;
case IMSG_RUNNER_SCHEDULE: {
@@ -339,12 +340,12 @@ control_dispatch_ext(int fd, short event, void *arg)
s->fd = fd;
if (! valid_message_id(s->mid) && ! valid_message_uid(s->mid)) {
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
- imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_RUNNER_SCHEDULE, 0, 0, -1, s, sizeof(*s));
+ imsg_compose_event(env->sc_ievs[PROC_RUNNER], IMSG_RUNNER_SCHEDULE, 0, 0, -1, s, sizeof(*s));
break;
}
case IMSG_CONF_RELOAD: {
@@ -356,14 +357,14 @@ control_dispatch_ext(int fd, short event, void *arg)
goto badcred;
if (env->sc_flags & SMTPD_CONFIGURING) {
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags |= SMTPD_CONFIGURING;
r.fd = fd;
- imsg_compose_event(env->sc_ibufs[PROC_PARENT], IMSG_CONF_RELOAD, 0, 0, -1, &r, sizeof(r));
+ imsg_compose_event(env->sc_ievs[PROC_PARENT], IMSG_CONF_RELOAD, 0, 0, -1, &r, sizeof(r));
break;
}
case IMSG_CTL_SHUTDOWN:
@@ -374,96 +375,96 @@ control_dispatch_ext(int fd, short event, void *arg)
goto badcred;
if (env->sc_flags & SMTPD_EXITING) {
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags |= SMTPD_EXITING;
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
case IMSG_MDA_PAUSE:
if (euid)
goto badcred;
if (env->sc_flags & SMTPD_MDA_PAUSED) {
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags |= SMTPD_MDA_PAUSED;
- imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_MDA_PAUSE,
+ imsg_compose_event(env->sc_ievs[PROC_RUNNER], IMSG_MDA_PAUSE,
0, 0, -1, NULL, 0);
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
case IMSG_MTA_PAUSE:
if (euid)
goto badcred;
if (env->sc_flags & SMTPD_MTA_PAUSED) {
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags |= SMTPD_MTA_PAUSED;
- imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_MTA_PAUSE,
+ imsg_compose_event(env->sc_ievs[PROC_RUNNER], IMSG_MTA_PAUSE,
0, 0, -1, NULL, 0);
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
case IMSG_SMTP_PAUSE:
if (euid)
goto badcred;
if (env->sc_flags & SMTPD_SMTP_PAUSED) {
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags |= SMTPD_SMTP_PAUSED;
- imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_SMTP_PAUSE,
+ imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_SMTP_PAUSE,
0, 0, -1, NULL, 0);
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
case IMSG_MDA_RESUME:
if (euid)
goto badcred;
if (! (env->sc_flags & SMTPD_MDA_PAUSED)) {
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags &= ~SMTPD_MDA_PAUSED;
- imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_MTA_RESUME,
+ imsg_compose_event(env->sc_ievs[PROC_RUNNER], IMSG_MTA_RESUME,
0, 0, -1, NULL, 0);
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
case IMSG_MTA_RESUME:
if (euid)
goto badcred;
if (!(env->sc_flags & SMTPD_MTA_PAUSED)) {
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags &= ~SMTPD_MTA_PAUSED;
- imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_MTA_RESUME,
+ imsg_compose_event(env->sc_ievs[PROC_RUNNER], IMSG_MTA_RESUME,
0, 0, -1, NULL, 0);
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
case IMSG_SMTP_RESUME:
if (euid)
goto badcred;
if (!(env->sc_flags & SMTPD_SMTP_PAUSED)) {
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags &= ~SMTPD_SMTP_PAUSED;
- imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_SMTP_RESUME,
+ imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_SMTP_RESUME,
0, 0, -1, NULL, 0);
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
default:
log_debug("control_dispatch_ext: "
@@ -474,29 +475,31 @@ control_dispatch_ext(int fd, short event, void *arg)
continue;
badcred:
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
}
- imsg_event_add(&c->ibuf);
+ imsg_event_add(&c->iev);
}
void
control_dispatch_parent(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_PARENT];
+ iev = env->sc_ievs[PROC_PARENT];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -527,9 +530,9 @@ control_dispatch_parent(int sig, short event, void *p)
}
if (r->ret)
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
else
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0);
break;
}
default:
@@ -539,25 +542,27 @@ control_dispatch_parent(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
control_dispatch_lka(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_LKA];
+ iev = env->sc_ievs[PROC_LKA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -582,25 +587,27 @@ control_dispatch_lka(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
control_dispatch_mfa(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_MFA];
+ iev = env->sc_ievs[PROC_MFA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -625,25 +632,27 @@ control_dispatch_mfa(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
control_dispatch_queue(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_QUEUE];
+ iev = env->sc_ievs[PROC_QUEUE];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -668,25 +677,27 @@ control_dispatch_queue(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
control_dispatch_runner(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_RUNNER];
+ iev = env->sc_ievs[PROC_RUNNER];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -717,9 +728,9 @@ control_dispatch_runner(int sig, short event, void *p)
}
if (s->ret)
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
else
- imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->iev, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0);
break;
}
default:
@@ -729,25 +740,27 @@ control_dispatch_runner(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
control_dispatch_smtp(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_SMTP];
+ iev = env->sc_ievs[PROC_SMTP];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -780,7 +793,7 @@ control_dispatch_smtp(int sig, short event, void *p)
return;
}
- imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0,
+ imsg_compose_event(&c->iev, IMSG_CTL_OK, 0, 0,
imsg_get_fd(ibuf), NULL, 0);
break;
}
@@ -791,7 +804,7 @@ control_dispatch_smtp(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
diff --git a/usr.sbin/smtpd/dns.c b/usr.sbin/smtpd/dns.c
index 2352a03d8c2..3f59e9f395e 100644
--- a/usr.sbin/smtpd/dns.c
+++ b/usr.sbin/smtpd/dns.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dns.c,v 1.13 2009/06/05 20:43:57 pyr Exp $ */
+/* $OpenBSD: dns.c,v 1.14 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -36,8 +36,8 @@
#include "smtpd.h"
struct resdata {
- struct imsgbuf ibuf;
- struct imsgbuf *asker;
+ struct imsgev iev;
+ struct imsgev *asker;
};
struct mx {
@@ -49,12 +49,12 @@ void parent_dispatch_dns(int, short, void *);
int dns(void);
void dns_dispatch_parent(int, short, void *);
-void lookup_a(struct imsgbuf *, struct dns *, int);
-void lookup_mx(struct imsgbuf *, struct dns *);
+void lookup_a(struct imsgev *, struct dns *, int);
+void lookup_mx(struct imsgev *, struct dns *);
int get_mxlist(char *, char *, struct dns **);
void free_mxlist(struct dns *);
int mxcmp(const void *, const void *);
-void lookup_ptr(struct imsgbuf *, struct dns *);
+void lookup_ptr(struct imsgev *, struct dns *);
/*
* User interface.
@@ -70,7 +70,7 @@ dns_query_a(struct smtpd *env, char *host, int port, u_int64_t id)
query.port = port;
query.id = id;
- imsg_compose_event(env->sc_ibufs[PROC_LKA], IMSG_DNS_A, 0, 0, -1, &query,
+ imsg_compose_event(env->sc_ievs[PROC_LKA], IMSG_DNS_A, 0, 0, -1, &query,
sizeof(query));
}
@@ -84,7 +84,7 @@ dns_query_mx(struct smtpd *env, char *host, int port, u_int64_t id)
query.port = port;
query.id = id;
- imsg_compose_event(env->sc_ibufs[PROC_LKA], IMSG_DNS_MX, 0, 0, -1, &query,
+ imsg_compose_event(env->sc_ievs[PROC_LKA], IMSG_DNS_MX, 0, 0, -1, &query,
sizeof(query));
}
@@ -97,7 +97,7 @@ dns_query_ptr(struct smtpd *env, struct sockaddr_storage *ss, u_int64_t id)
query.ss = *ss;
query.id = id;
- imsg_compose_event(env->sc_ibufs[PROC_LKA], IMSG_DNS_PTR, 0, 0, -1, &query,
+ imsg_compose_event(env->sc_ievs[PROC_LKA], IMSG_DNS_PTR, 0, 0, -1, &query,
sizeof(query));
}
@@ -106,7 +106,7 @@ dns_query_ptr(struct smtpd *env, struct sockaddr_storage *ss, u_int64_t id)
*/
void
-dns_async(struct smtpd *env, struct imsgbuf *asker, int type, struct dns *query)
+dns_async(struct smtpd *env, struct imsgev *asker, int type, struct dns *query)
{
struct resdata *rd;
int fd;
@@ -118,25 +118,28 @@ dns_async(struct smtpd *env, struct imsgbuf *asker, int type, struct dns *query)
query->env = env;
fd = dns();
- imsg_init(&rd->ibuf, fd, parent_dispatch_dns);
- rd->ibuf.events = EV_READ;
- rd->ibuf.data = rd;
- event_set(&rd->ibuf.ev, rd->ibuf.fd, rd->ibuf.events, rd->ibuf.handler,
- rd->ibuf.data);
- event_add(&rd->ibuf.ev, NULL);
-
- imsg_compose_event(&rd->ibuf, type, 0, 0, -1, query, sizeof(*query));
+ imsg_init(&rd->iev.ibuf, fd);
+ rd->iev.handler = parent_dispatch_dns;
+ rd->iev.events = EV_READ;
+ rd->iev.data = rd;
+ event_set(&rd->iev.ev, rd->iev.ibuf.fd, rd->iev.events, rd->iev.handler,
+ rd->iev.data);
+ event_add(&rd->iev.ev, NULL);
+
+ imsg_compose_event(&rd->iev, type, 0, 0, -1, query, sizeof(*query));
}
void
parent_dispatch_dns(int sig, short event, void *p)
{
struct resdata *rd = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = &rd->ibuf;
+ iev = &rd->iev;
+ ibuf = &rd->iev.ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
@@ -166,8 +169,8 @@ parent_dispatch_dns(int sig, short event, void *p)
case IMSG_DNS_PTR:
imsg_compose_event(rd->asker, imsg.hdr.type, 0, 0, -1,
imsg.data, sizeof(struct dns));
- close(rd->ibuf.fd);
- event_del(&ibuf->ev);
+ close(ibuf->fd);
+ event_del(&iev->ev);
free(rd);
imsg_free(&imsg);
return;
@@ -179,7 +182,7 @@ parent_dispatch_dns(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
/*
@@ -191,7 +194,7 @@ dns(void)
{
int fd[2];
pid_t pid;
- struct imsgbuf *ibuf;
+ struct imsgev *iev;
if (socketpair(AF_UNIX, SOCK_STREAM, AF_UNSPEC, fd) == -1)
fatal("socketpair");
@@ -213,13 +216,14 @@ dns(void)
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
- if ((ibuf = calloc(1, sizeof(*ibuf))) == NULL)
+ if ((iev = calloc(1, sizeof(*iev))) == NULL)
fatal(NULL);
- imsg_init(ibuf, fd[1], dns_dispatch_parent);
- ibuf->events = EV_READ;
- ibuf->data = ibuf;
- event_set(&ibuf->ev, ibuf->fd, ibuf->events, ibuf->handler, ibuf->data);
- event_add(&ibuf->ev, NULL);
+ imsg_init(&iev->ibuf, fd[1]);
+ iev->handler = dns_dispatch_parent;
+ iev->events = EV_READ;
+ iev->data = iev;
+ event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev->data);
+ event_add(&iev->ev, NULL);
event_dispatch();
_exit(0);
@@ -228,7 +232,8 @@ dns(void)
void
dns_dispatch_parent(int sig, short event, void *p)
{
- struct imsgbuf *ibuf = p;
+ struct imsgev *iev = p;
+ struct imsgbuf *ibuf = &iev->ibuf;
struct imsg imsg;
ssize_t n;
@@ -237,7 +242,7 @@ dns_dispatch_parent(int sig, short event, void *p)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -256,15 +261,15 @@ dns_dispatch_parent(int sig, short event, void *p)
switch (imsg.hdr.type) {
case IMSG_DNS_A:
- lookup_a(ibuf, imsg.data, 1);
+ lookup_a(iev, imsg.data, 1);
break;
case IMSG_DNS_MX:
- lookup_mx(ibuf, imsg.data);
+ lookup_mx(iev, imsg.data);
break;
case IMSG_DNS_PTR:
- lookup_ptr(ibuf, imsg.data);
+ lookup_ptr(iev, imsg.data);
break;
default:
@@ -274,11 +279,11 @@ dns_dispatch_parent(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
-lookup_a(struct imsgbuf *ibuf, struct dns *query, int finalize)
+lookup_a(struct imsgev *iev, struct dns *query, int finalize)
{
struct addrinfo *res0, *res, hints;
char *port = NULL;
@@ -298,20 +303,20 @@ lookup_a(struct imsgbuf *ibuf, struct dns *query, int finalize)
for (res = res0; res; res = res->ai_next) {
memcpy(&query->ss, res->ai_addr, res->ai_addr->sa_len);
- imsg_compose_event(ibuf, IMSG_DNS_A, 0, 0, -1, query, sizeof(*query));
+ imsg_compose_event(iev, IMSG_DNS_A, 0, 0, -1, query, sizeof(*query));
}
freeaddrinfo(res0);
end:
free(port);
if (finalize) {
log_debug("lookup_a %s", query->error ? "failed" : "success");
- imsg_compose_event(ibuf, IMSG_DNS_A_END, 0, 0, -1, query,
+ imsg_compose_event(iev, IMSG_DNS_A_END, 0, 0, -1, query,
sizeof(*query));
}
}
void
-lookup_mx(struct imsgbuf *ibuf, struct dns *query)
+lookup_mx(struct imsgev *iev, struct dns *query)
{
struct dns *mx0, *mx;
int success = 0;
@@ -332,7 +337,7 @@ lookup_mx(struct imsgbuf *ibuf, struct dns *query)
for (mx = mx0; mx; mx = mx->next) {
mx->port = query->port;
mx->id = query->id;
- lookup_a(ibuf, mx, 0);
+ lookup_a(iev, mx, 0);
if (!mx->error)
success++;
}
@@ -343,7 +348,7 @@ lookup_mx(struct imsgbuf *ibuf, struct dns *query)
end:
log_debug("lookup_mx %s", query->error ? "failed" : "success");
- imsg_compose_event(ibuf, IMSG_DNS_A_END, 0, 0, -1, query, sizeof(*query));
+ imsg_compose_event(iev, IMSG_DNS_A_END, 0, 0, -1, query, sizeof(*query));
}
int
@@ -481,7 +486,7 @@ mxcmp(const void *va, const void *vb)
}
void
-lookup_ptr(struct imsgbuf *ibuf, struct dns *query)
+lookup_ptr(struct imsgev *iev, struct dns *query)
{
struct addrinfo *res, hints;
@@ -504,5 +509,5 @@ lookup_ptr(struct imsgbuf *ibuf, struct dns *query)
}
end:
log_debug("lookup_ptr %s", query->error ? "failed" : "success");
- imsg_compose_event(ibuf, IMSG_DNS_PTR, 0, 0, -1, query, sizeof(*query));
+ imsg_compose_event(iev, IMSG_DNS_PTR, 0, 0, -1, query, sizeof(*query));
}
diff --git a/usr.sbin/smtpd/imsg.c b/usr.sbin/smtpd/imsg.c
index 3224027fd67..ffedd039cf2 100644
--- a/usr.sbin/smtpd/imsg.c
+++ b/usr.sbin/smtpd/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.3 2009/06/05 20:43:57 pyr Exp $ */
+/* $OpenBSD: imsg.c,v 1.4 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -29,13 +29,12 @@
#include "imsg.h"
void
-imsg_init(struct imsgbuf *ibuf, int fd, void (*handler)(int, short, void *))
+imsg_init(struct imsgbuf *ibuf, int fd)
{
if (!ibuf->pid) {
msgbuf_init(&ibuf->w);
bzero(&ibuf->r, sizeof(ibuf->r));
ibuf->pid = getpid();
- ibuf->handler = handler;
TAILQ_INIT(&ibuf->fds);
}
ibuf->fd = fd;
diff --git a/usr.sbin/smtpd/imsg.h b/usr.sbin/smtpd/imsg.h
index ba11fbcf0ac..6a4309f9f66 100644
--- a/usr.sbin/smtpd/imsg.h
+++ b/usr.sbin/smtpd/imsg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.h,v 1.2 2009/06/05 21:15:07 pyr Exp $ */
+/* $OpenBSD: imsg.h,v 1.3 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -19,11 +19,10 @@
*/
#include <sys/tree.h>
-#include <event.h>
#define READ_BUF_SIZE 65535
#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
-#define MAX_IMSGSIZE 16834
+#define MAX_IMSGSIZE 16384
struct buf {
TAILQ_ENTRY(buf) entry;
@@ -56,12 +55,8 @@ struct imsgbuf {
TAILQ_HEAD(, imsg_fd) fds;
struct buf_read r;
struct msgbuf w;
- struct event ev;
- void (*handler)(int, short, void *);
int fd;
pid_t pid;
- void *data;
- short events;
};
struct imsg_hdr {
@@ -93,7 +88,7 @@ void msgbuf_clear(struct msgbuf *);
int msgbuf_write(struct msgbuf *);
/* imsg.c */
-void imsg_init(struct imsgbuf *, int, void (*)(int, short, void *));
+void imsg_init(struct imsgbuf *, int);
ssize_t imsg_read(struct imsgbuf *);
ssize_t imsg_get(struct imsgbuf *, struct imsg *);
int imsg_compose(struct imsgbuf *, u_int16_t, u_int32_t, pid_t,
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c
index 17e53aa6bed..5542b9937d0 100644
--- a/usr.sbin/smtpd/lka.c
+++ b/usr.sbin/smtpd/lka.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka.c,v 1.58 2009/06/05 20:43:57 pyr Exp $ */
+/* $OpenBSD: lka.c,v 1.59 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -98,18 +98,20 @@ void
lka_dispatch_parent(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_PARENT];
+ iev = env->sc_ievs[PROC_PARENT];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -260,12 +262,12 @@ lka_dispatch_parent(int sig, short event, void *p)
log_debug("expansion failed...");
}
- imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_SUBMIT_ENVELOPE, 0, 0, -1,
&message, sizeof(struct message));
if (! lkasession->pending)
- imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_COMMIT_ENVELOPES, 0, 0, -1,
&message, sizeof(struct message));
break;
@@ -288,25 +290,27 @@ lka_dispatch_parent(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
lka_dispatch_mfa(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_MFA];
+ iev = env->sc_ievs[PROC_MFA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -337,7 +341,7 @@ lka_dispatch_mfa(int sig, short event, void *p)
if (lka_verify_mail(env, &ss->u.path))
ss->code = 250;
- imsg_compose_event(ibuf, IMSG_LKA_MAIL, 0, 0, -1,
+ imsg_compose_event(iev, IMSG_LKA_MAIL, 0, 0, -1,
ss, sizeof(*ss));
break;
@@ -357,17 +361,17 @@ lka_dispatch_mfa(int sig, short event, void *p)
ss->code = 250;
message = ss->msg;
message.recipient = ss->u.path;
- imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_SUBMIT_ENVELOPE, 0, 0, -1,
&message, sizeof(struct message));
- imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_COMMIT_ENVELOPES, 0, 0, -1,
&message, sizeof(struct message));
break;
}
if (! lka_resolve_path(env, &ss->u.path)) {
- imsg_compose_event(ibuf, IMSG_LKA_RCPT, 0, 0, -1,
+ imsg_compose_event(iev, IMSG_LKA_RCPT, 0, 0, -1,
ss, sizeof(*ss));
break;
}
@@ -390,7 +394,7 @@ lka_dispatch_mfa(int sig, short event, void *p)
if (lkasession->path.flags & F_PATH_ACCOUNT) {
fwreq.id = lkasession->id;
(void)strlcpy(fwreq.pw_name, ss->u.path.pw_name, sizeof(fwreq.pw_name));
- imsg_compose_event(env->sc_ibufs[PROC_PARENT], IMSG_PARENT_FORWARD_OPEN, 0, 0, -1,
+ imsg_compose_event(env->sc_ievs[PROC_PARENT], IMSG_PARENT_FORWARD_OPEN, 0, 0, -1,
&fwreq, sizeof(fwreq));
++lkasession->pending;
break;
@@ -407,7 +411,7 @@ lka_dispatch_mfa(int sig, short event, void *p)
if (ret == 0) {
/* No aliases ... */
ss->code = 530;
- imsg_compose_event(ibuf, IMSG_LKA_RCPT, 0, 0,
+ imsg_compose_event(iev, IMSG_LKA_RCPT, 0, 0,
-1, ss, sizeof(*ss));
break;
}
@@ -423,25 +427,27 @@ lka_dispatch_mfa(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
lka_dispatch_mta(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_MTA];
+ iev = env->sc_ievs[PROC_MTA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -482,7 +488,7 @@ lka_dispatch_mta(int sig, short event, void *p)
query->host, map);
}
- imsg_compose_event(ibuf, IMSG_LKA_SECRET, 0, 0, -1, query,
+ imsg_compose_event(iev, IMSG_LKA_SECRET, 0, 0, -1, query,
sizeof(*query));
free(secret);
break;
@@ -493,7 +499,7 @@ lka_dispatch_mta(int sig, short event, void *p)
struct dns *query = imsg.data;
IMSG_SIZE_CHECK(query);
- dns_async(env, ibuf, imsg.hdr.type, query);
+ dns_async(env, iev, imsg.hdr.type, query);
break;
}
@@ -504,25 +510,27 @@ lka_dispatch_mta(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
lka_dispatch_smtp(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_SMTP];
+ iev = env->sc_ievs[PROC_SMTP];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -544,7 +552,7 @@ lka_dispatch_smtp(int sig, short event, void *p)
struct dns *query = imsg.data;
IMSG_SIZE_CHECK(query);
- dns_async(env, ibuf, IMSG_DNS_PTR, query);
+ dns_async(env, iev, IMSG_DNS_PTR, query);
break;
}
default:
@@ -554,25 +562,27 @@ lka_dispatch_smtp(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
lka_dispatch_queue(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_QUEUE];
+ iev = env->sc_ievs[PROC_QUEUE];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -597,25 +607,27 @@ lka_dispatch_queue(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
lka_dispatch_runner(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_RUNNER];
+ iev = env->sc_ievs[PROC_RUNNER];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -640,7 +652,7 @@ lka_dispatch_runner(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
@@ -968,16 +980,16 @@ lka_expand_rcpt(struct smtpd *env, struct aliaseslist *aliases, struct lkasessio
if (lkasession->flags & F_ERROR) {
lka_clear_aliaseslist(&lkasession->aliaseslist);
- imsg_compose_event(env->sc_ibufs[PROC_MFA], IMSG_LKA_RCPT, 0, 0,
+ imsg_compose_event(env->sc_ievs[PROC_MFA], IMSG_LKA_RCPT, 0, 0,
-1, &lkasession->ss, sizeof(struct submit_status));
}
else if (TAILQ_FIRST(&lkasession->aliaseslist) == NULL) {
message = lkasession->message;
message.recipient = lkasession->path;
- imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_SUBMIT_ENVELOPE, 0, 0, -1,
&message, sizeof(struct message));
- imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_COMMIT_ENVELOPES, 0, 0, -1,
&message, sizeof(struct message));
}
@@ -990,14 +1002,14 @@ lka_expand_rcpt(struct smtpd *env, struct aliaseslist *aliases, struct lkasessio
lka_resolve_alias(env, &message.recipient, alias);
lka_rcpt_action(env, &message.recipient);
- imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_SUBMIT_ENVELOPE, 0, 0, -1,
&message, sizeof(struct message));
TAILQ_REMOVE(&lkasession->aliaseslist, alias, entry);
free(alias);
}
- imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_COMMIT_ENVELOPES, 0, 0, -1, &message,
sizeof(struct message));
}
@@ -1037,7 +1049,7 @@ lka_expand_rcpt_iteration(struct smtpd *env, struct aliaseslist *aliases, struct
done = 0;
fwreq.id = lkasession->id;
(void)strlcpy(fwreq.pw_name, alias->u.username, sizeof(fwreq.pw_name));
- imsg_compose_event(env->sc_ibufs[PROC_PARENT], IMSG_PARENT_FORWARD_OPEN, 0, 0, -1,
+ imsg_compose_event(env->sc_ievs[PROC_PARENT], IMSG_PARENT_FORWARD_OPEN, 0, 0, -1,
&fwreq, sizeof(fwreq));
++lkasession->pending;
rmalias = alias;
diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c
index 380f4539ad7..a9a21135051 100644
--- a/usr.sbin/smtpd/mda.c
+++ b/usr.sbin/smtpd/mda.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mda.c,v 1.21 2009/06/05 20:43:57 pyr Exp $ */
+/* $OpenBSD: mda.c,v 1.22 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -59,18 +59,20 @@ void
mda_dispatch_parent(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_PARENT];
+ iev = env->sc_ievs[PROC_PARENT];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -116,7 +118,7 @@ mda_dispatch_parent(int sig, short event, void *p)
}
batchp->message = *messagep;
- imsg_compose_event(env->sc_ibufs[PROC_PARENT],
+ imsg_compose_event(env->sc_ievs[PROC_PARENT],
IMSG_PARENT_MESSAGE_OPEN, 0, 0, -1, batchp,
sizeof(struct batch));
break;
@@ -159,7 +161,7 @@ mda_dispatch_parent(int sig, short event, void *p)
if (store_message(batchp, messagep, store)) {
if (batchp->message.recipient.rule.r_action == A_MAILDIR)
- imsg_compose_event(env->sc_ibufs[PROC_PARENT],
+ imsg_compose_event(env->sc_ievs[PROC_PARENT],
IMSG_PARENT_MAILBOX_RENAME, 0, 0, -1, batchp,
sizeof(struct batch));
}
@@ -179,25 +181,27 @@ mda_dispatch_parent(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
mda_dispatch_queue(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_QUEUE];
+ iev = env->sc_ievs[PROC_QUEUE];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -222,25 +226,27 @@ mda_dispatch_queue(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
mda_dispatch_runner(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_RUNNER];
+ iev = env->sc_ievs[PROC_RUNNER];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -327,7 +333,7 @@ mda_dispatch_runner(int sig, short event, void *p)
lookup = *batchp;
TAILQ_FOREACH(messagep, &batchp->messages, entry) {
lookup.message = *messagep;
- imsg_compose_event(env->sc_ibufs[PROC_PARENT],
+ imsg_compose_event(env->sc_ievs[PROC_PARENT],
IMSG_PARENT_MAILBOX_OPEN, 0, 0, -1, &lookup,
sizeof(struct batch));
}
@@ -340,7 +346,7 @@ mda_dispatch_runner(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
@@ -432,7 +438,7 @@ mda(struct smtpd *env)
void
mda_remove_message(struct smtpd *env, struct batch *batchp, struct message *messagep)
{
- imsg_compose_event(env->sc_ibufs[PROC_QUEUE], IMSG_QUEUE_MESSAGE_UPDATE, 0, 0,
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE], IMSG_QUEUE_MESSAGE_UPDATE, 0, 0,
-1, messagep, sizeof (struct message));
if ((batchp->message.status & S_MESSAGE_TEMPFAILURE) == 0 &&
diff --git a/usr.sbin/smtpd/mfa.c b/usr.sbin/smtpd/mfa.c
index 0b0aa8cec0f..31c4b63d324 100644
--- a/usr.sbin/smtpd/mfa.c
+++ b/usr.sbin/smtpd/mfa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mfa.c,v 1.35 2009/06/05 20:43:57 pyr Exp $ */
+/* $OpenBSD: mfa.c,v 1.36 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -67,18 +67,20 @@ void
mfa_dispatch_parent(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_PARENT];
+ iev = env->sc_ievs[PROC_PARENT];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -190,25 +192,27 @@ mfa_dispatch_parent(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
mfa_dispatch_smtp(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_SMTP];
+ iev = env->sc_ievs[PROC_SMTP];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -251,25 +255,27 @@ mfa_dispatch_smtp(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
mfa_dispatch_lka(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_LKA];
+ iev = env->sc_ievs[PROC_LKA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -292,7 +298,7 @@ mfa_dispatch_lka(int sig, short event, void *p)
IMSG_SIZE_CHECK(ss);
- imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_MFA_MAIL,
+ imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_MFA_MAIL,
0, 0, -1, ss, sizeof(*ss));
break;
}
@@ -301,7 +307,7 @@ mfa_dispatch_lka(int sig, short event, void *p)
IMSG_SIZE_CHECK(ss);
- imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_MFA_RCPT,
+ imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_MFA_RCPT,
0, 0, -1, ss, sizeof(*ss));
break;
}
@@ -312,25 +318,27 @@ mfa_dispatch_lka(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
mfa_dispatch_control(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_CONTROL];
+ iev = env->sc_ievs[PROC_CONTROL];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -355,7 +363,7 @@ mfa_dispatch_control(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
@@ -487,13 +495,13 @@ mfa_test_mail(struct smtpd *env, struct message *m)
goto accept;
refuse:
- imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_MFA_MAIL, 0, 0, -1, &ss,
+ imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_MFA_MAIL, 0, 0, -1, &ss,
sizeof(ss));
return;
accept:
ss.code = 250;
- imsg_compose_event(env->sc_ibufs[PROC_LKA], IMSG_LKA_MAIL, 0,
+ imsg_compose_event(env->sc_ievs[PROC_LKA], IMSG_LKA_MAIL, 0,
0, -1, &ss, sizeof(ss));
}
@@ -530,13 +538,13 @@ mfa_test_rcpt(struct smtpd *env, struct message *m)
goto accept;
refuse:
- imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_MFA_RCPT, 0, 0, -1, &ss,
+ imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_MFA_RCPT, 0, 0, -1, &ss,
sizeof(ss));
return;
accept:
ss.code = 250;
- imsg_compose_event(env->sc_ibufs[PROC_LKA], IMSG_LKA_RCPT, 0, 0, -1,
+ imsg_compose_event(env->sc_ievs[PROC_LKA], IMSG_LKA_RCPT, 0, 0, -1,
&ss, sizeof(ss));
}
diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c
index 63744dae7d5..ac5e88fc6e6 100644
--- a/usr.sbin/smtpd/mta.c
+++ b/usr.sbin/smtpd/mta.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mta.c,v 1.58 2009/06/05 20:43:57 pyr Exp $ */
+/* $OpenBSD: mta.c,v 1.59 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -74,18 +74,20 @@ void
mta_dispatch_parent(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_PARENT];
+ iev = env->sc_ievs[PROC_PARENT];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -144,25 +146,27 @@ mta_dispatch_parent(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
mta_dispatch_lka(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_LKA];
+ iev = env->sc_ievs[PROC_LKA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -258,25 +262,27 @@ mta_dispatch_lka(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
mta_dispatch_queue(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_QUEUE];
+ iev = env->sc_ievs[PROC_QUEUE];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -323,25 +329,27 @@ mta_dispatch_queue(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
mta_dispatch_runner(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_RUNNER];
+ iev = env->sc_ievs[PROC_RUNNER];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -440,7 +448,7 @@ mta_dispatch_runner(int sig, short event, void *p)
batchp->rule.r_value.relayhost.hostname,
sizeof(query.host));
- imsg_compose_event(env->sc_ibufs[PROC_LKA],
+ imsg_compose_event(env->sc_ievs[PROC_LKA],
IMSG_LKA_SECRET, 0, 0, -1, &query,
sizeof(query));
} else
@@ -455,7 +463,7 @@ mta_dispatch_runner(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
@@ -923,7 +931,7 @@ mta_reply_handler(struct bufferevent *bev, void *arg)
}
}
- imsg_compose_event(env->sc_ibufs[PROC_QUEUE], IMSG_QUEUE_MESSAGE_FD,
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE], IMSG_QUEUE_MESSAGE_FD,
0, 0, -1, batchp, sizeof(*batchp));
bufferevent_disable(sessionp->s_bev, EV_READ);
}
@@ -1112,7 +1120,7 @@ mta_batch_update_queue(struct batch *batchp)
time(NULL) - messagep->creation);
}
- imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_MESSAGE_UPDATE, 0, 0, -1, messagep,
sizeof(struct message));
TAILQ_REMOVE(&batchp->messages, messagep, entry);
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c
index b51d706ccd6..3690e409850 100644
--- a/usr.sbin/smtpd/queue.c
+++ b/usr.sbin/smtpd/queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue.c,v 1.67 2009/06/05 20:43:57 pyr Exp $ */
+/* $OpenBSD: queue.c,v 1.68 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -73,18 +73,20 @@ void
queue_dispatch_control(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_CONTROL];
+ iev = env->sc_ievs[PROC_CONTROL];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -109,25 +111,27 @@ queue_dispatch_control(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
queue_dispatch_smtp(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_SMTP];
+ iev = env->sc_ievs[PROC_SMTP];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -166,7 +170,7 @@ queue_dispatch_smtp(int sig, short event, void *p)
if (! f(ss.u.msgid))
ss.code = 421;
- imsg_compose_event(ibuf, IMSG_QUEUE_CREATE_MESSAGE, 0, 0, -1,
+ imsg_compose_event(iev, IMSG_QUEUE_CREATE_MESSAGE, 0, 0, -1,
&ss, sizeof(ss));
break;
}
@@ -208,7 +212,7 @@ queue_dispatch_smtp(int sig, short event, void *p)
else
ss.code = 421;
- imsg_compose_event(ibuf, IMSG_QUEUE_COMMIT_MESSAGE, 0, 0, -1,
+ imsg_compose_event(iev, IMSG_QUEUE_COMMIT_MESSAGE, 0, 0, -1,
&ss, sizeof(ss));
break;
@@ -232,7 +236,7 @@ queue_dispatch_smtp(int sig, short event, void *p)
if (fd == -1)
ss.code = 421;
- imsg_compose_event(ibuf, IMSG_QUEUE_MESSAGE_FILE, 0, 0, fd,
+ imsg_compose_event(iev, IMSG_QUEUE_MESSAGE_FILE, 0, 0, fd,
&ss, sizeof(ss));
break;
}
@@ -243,25 +247,27 @@ queue_dispatch_smtp(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
queue_dispatch_mda(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_MDA];
+ iev = env->sc_ievs[PROC_MDA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -281,7 +287,7 @@ queue_dispatch_mda(int sig, short event, void *p)
switch (imsg.hdr.type) {
case IMSG_QUEUE_MESSAGE_UPDATE: {
- imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_RUNNER_UPDATE_ENVELOPE,
+ imsg_compose_event(env->sc_ievs[PROC_RUNNER], IMSG_RUNNER_UPDATE_ENVELOPE,
0, 0, -1, imsg.data, sizeof(struct message));
break;
}
@@ -292,25 +298,27 @@ queue_dispatch_mda(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
queue_dispatch_mta(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_MTA];
+ iev = env->sc_ievs[PROC_MTA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -336,13 +344,13 @@ queue_dispatch_mta(int sig, short event, void *p)
IMSG_SIZE_CHECK(batchp);
fd = queue_open_message_file(batchp->message_id);
- imsg_compose_event(ibuf, IMSG_QUEUE_MESSAGE_FD, 0, 0, fd, batchp,
+ imsg_compose_event(iev, IMSG_QUEUE_MESSAGE_FD, 0, 0, fd, batchp,
sizeof(*batchp));
break;
}
case IMSG_QUEUE_MESSAGE_UPDATE: {
- imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_RUNNER_UPDATE_ENVELOPE,
+ imsg_compose_event(env->sc_ievs[PROC_RUNNER], IMSG_RUNNER_UPDATE_ENVELOPE,
0, 0, -1, imsg.data, sizeof(struct message));
break;
}
@@ -353,25 +361,27 @@ queue_dispatch_mta(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
queue_dispatch_lka(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_LKA];
+ iev = env->sc_ievs[PROC_LKA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -414,7 +424,7 @@ queue_dispatch_lka(int sig, short event, void *p)
if (! f(messagep)) {
ss.code = 421;
- imsg_compose_event(env->sc_ibufs[PROC_SMTP],
+ imsg_compose_event(env->sc_ievs[PROC_SMTP],
IMSG_QUEUE_TEMPFAIL, 0, 0, -1, &ss,
sizeof(ss));
}
@@ -431,7 +441,7 @@ queue_dispatch_lka(int sig, short event, void *p)
ss.id = messagep->session_id;
ss.code = 250;
- imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_QUEUE_COMMIT_ENVELOPES,
+ imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_QUEUE_COMMIT_ENVELOPES,
0, 0, -1, &ss, sizeof(ss));
break;
@@ -443,25 +453,27 @@ queue_dispatch_lka(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
queue_dispatch_runner(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_RUNNER];
+ iev = env->sc_ievs[PROC_RUNNER];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -485,7 +497,7 @@ queue_dispatch_runner(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c
index efd9f3a323e..28aeca98907 100644
--- a/usr.sbin/smtpd/runner.c
+++ b/usr.sbin/smtpd/runner.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: runner.c,v 1.51 2009/06/05 20:43:57 pyr Exp $ */
+/* $OpenBSD: runner.c,v 1.52 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -99,18 +99,20 @@ void
runner_dispatch_parent(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_PARENT];
+ iev = env->sc_ievs[PROC_PARENT];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -138,25 +140,27 @@ runner_dispatch_parent(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
runner_dispatch_control(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_CONTROL];
+ iev = env->sc_ievs[PROC_CONTROL];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -197,7 +201,7 @@ runner_dispatch_control(int sig, short event, void *p)
else if (valid_message_id(s->mid))
s->ret = runner_force_message_schedule(s->mid);
- imsg_compose_event(ibuf, IMSG_RUNNER_SCHEDULE, 0, 0, -1, s, sizeof(*s));
+ imsg_compose_event(iev, IMSG_RUNNER_SCHEDULE, 0, 0, -1, s, sizeof(*s));
break;
}
default:
@@ -207,25 +211,27 @@ runner_dispatch_control(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
runner_dispatch_queue(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_QUEUE];
+ iev = env->sc_ievs[PROC_QUEUE];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -259,25 +265,27 @@ runner_dispatch_queue(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
runner_dispatch_mda(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_MDA];
+ iev = env->sc_ievs[PROC_MDA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -302,25 +310,27 @@ runner_dispatch_mda(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
runner_dispatch_mta(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_MTA];
+ iev = env->sc_ievs[PROC_MTA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -346,25 +356,27 @@ runner_dispatch_mta(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
runner_dispatch_lka(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_LKA];
+ iev = env->sc_ievs[PROC_LKA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -389,7 +401,7 @@ runner_dispatch_lka(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
@@ -500,7 +512,7 @@ runner_process_offline(struct smtpd *env)
q = qwalk_new(PATH_OFFLINE);
if (qwalk(q, path))
- imsg_compose_event(env->sc_ibufs[PROC_PARENT],
+ imsg_compose_event(env->sc_ievs[PROC_PARENT],
IMSG_PARENT_ENQUEUE_OFFLINE, 0, 0, -1, path,
strlen(path) + 1);
@@ -681,18 +693,18 @@ runner_batch_dispatch(struct smtpd *env, struct batch *batchp, time_t curtime)
else if (batchp->type & T_MTA_BATCH)
proctype = PROC_MTA;
- imsg_compose_event(env->sc_ibufs[proctype], IMSG_BATCH_CREATE, 0, 0, -1,
+ imsg_compose_event(env->sc_ievs[proctype], IMSG_BATCH_CREATE, 0, 0, -1,
batchp, sizeof (struct batch));
while ((messagep = TAILQ_FIRST(&batchp->messages))) {
- imsg_compose_event(env->sc_ibufs[proctype], IMSG_BATCH_APPEND, 0, 0,
+ imsg_compose_event(env->sc_ievs[proctype], IMSG_BATCH_APPEND, 0, 0,
-1, messagep, sizeof (struct message));
TAILQ_REMOVE(&batchp->messages, messagep, entry);
bzero(messagep, sizeof(struct message));
free(messagep);
}
- imsg_compose_event(env->sc_ibufs[proctype], IMSG_BATCH_CLOSE, 0, 0, -1,
+ imsg_compose_event(env->sc_ievs[proctype], IMSG_BATCH_CLOSE, 0, 0, -1,
batchp, sizeof(struct batch));
}
diff --git a/usr.sbin/smtpd/smtp.c b/usr.sbin/smtpd/smtp.c
index f09927d407e..baca27584ee 100644
--- a/usr.sbin/smtpd/smtp.c
+++ b/usr.sbin/smtpd/smtp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp.c,v 1.56 2009/06/05 20:43:57 pyr Exp $ */
+/* $OpenBSD: smtp.c,v 1.57 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -69,18 +69,21 @@ void
smtp_dispatch_parent(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_PARENT];
+ iev = env->sc_ievs[PROC_PARENT];
+ ibuf = &iev->ibuf;
+
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -111,7 +114,7 @@ smtp_dispatch_parent(int sig, short event, void *p)
}
if (env->sc_listeners)
smtp_disable_events(env);
- imsg_compose_event(ibuf, IMSG_PARENT_SEND_CONFIG, 0, 0, -1,
+ imsg_compose_event(iev, IMSG_PARENT_SEND_CONFIG, 0, 0, -1,
NULL, 0);
break;
}
@@ -210,25 +213,27 @@ smtp_dispatch_parent(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
smtp_dispatch_mfa(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_MFA];
+ iev = env->sc_ievs[PROC_MFA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -268,25 +273,27 @@ smtp_dispatch_mfa(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
smtp_dispatch_lka(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_LKA];
+ iev = env->sc_ievs[PROC_LKA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -335,25 +342,27 @@ smtp_dispatch_lka(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
smtp_dispatch_queue(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_QUEUE];
+ iev = env->sc_ievs[PROC_QUEUE];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -459,25 +468,27 @@ smtp_dispatch_queue(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
smtp_dispatch_control(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_CONTROL];
+ iev = env->sc_ievs[PROC_CONTROL];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -508,7 +519,7 @@ smtp_dispatch_control(int sig, short event, void *p)
env->sc_maxconn) {
log_warnx("denying local connection, too many"
" sessions active");
- imsg_compose_event(ibuf, IMSG_SMTP_ENQUEUE, 0, 0, -1,
+ imsg_compose_event(iev, IMSG_SMTP_ENQUEUE, 0, 0, -1,
imsg.data, sizeof(int));
break;
}
@@ -547,7 +558,7 @@ smtp_dispatch_control(int sig, short event, void *p)
session_init(s->s_l, s);
- imsg_compose_event(ibuf, IMSG_SMTP_ENQUEUE, 0, 0, fd[1],
+ imsg_compose_event(iev, IMSG_SMTP_ENQUEUE, 0, 0, fd[1],
imsg.data, sizeof(int));
break;
}
@@ -564,7 +575,7 @@ smtp_dispatch_control(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c
index a7eca55d5aa..ea47532147d 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.106 2009/06/05 20:43:57 pyr Exp $ */
+/* $OpenBSD: smtp_session.c,v 1.107 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -954,7 +954,7 @@ session_destroy(struct session *s)
fclose(s->datafp);
if (s->s_msg.message_id[0] != '\0' && s->s_state != S_DONE)
- imsg_compose_event(s->s_env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(s->s_env->sc_ievs[PROC_QUEUE],
IMSG_QUEUE_REMOVE_MESSAGE, 0, 0, -1, &s->s_msg,
sizeof(s->s_msg));
@@ -1141,7 +1141,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_ibufs[proc], type, peerid, pid, fd, data,
+ imsg_compose_event(s->s_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 9751791375e..30e7b5c18c4 100644
--- a/usr.sbin/smtpd/smtpctl.c
+++ b/usr.sbin/smtpd/smtpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpctl.c,v 1.30 2009/06/06 03:22:21 jacekm Exp $ */
+/* $OpenBSD: smtpctl.c,v 1.31 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -82,13 +82,6 @@ usage(void)
exit(1);
}
-/* dummy function so that smtpctl does not need libevent */
-void
-imsg_event_add(struct imsgbuf *i)
-{
- /* nothing */
-}
-
int
main(int argc, char *argv[])
{
@@ -141,7 +134,7 @@ connected:
if ((ibuf = calloc(1, sizeof(struct imsgbuf))) == NULL)
err(1, NULL);
- imsg_init(ibuf, ctl_sock, NULL);
+ imsg_init(ibuf, ctl_sock);
if (sendmail)
return enqueue(argc, argv);
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index 8ef4f4a986c..7782e45935a 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.74 2009/06/05 20:43:57 pyr Exp $ */
+/* $OpenBSD: smtpd.c,v 1.75 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -133,7 +133,7 @@ parent_send_config_listeners(struct smtpd *env)
int opt;
log_debug("parent_send_config: configuring smtp");
- imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_CONF_START,
+ imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_CONF_START,
0, 0, -1, NULL, 0);
SPLAY_FOREACH(s, ssltree, env->sc_ssl) {
@@ -147,8 +147,9 @@ parent_send_config_listeners(struct smtpd *env)
iov[2].iov_base = s->ssl_key;
iov[2].iov_len = s->ssl_key_len;
- imsg_composev(env->sc_ibufs[PROC_SMTP], IMSG_CONF_SSL, 0, 0, -1,
- iov, nitems(iov));
+ imsg_composev(&env->sc_ievs[PROC_SMTP]->ibuf,
+ IMSG_CONF_SSL, 0, 0, -1, iov, nitems(iov));
+ imsg_event_add(env->sc_ievs[PROC_SMTP]);
}
TAILQ_FOREACH(l, env->sc_listeners, entry) {
@@ -159,11 +160,11 @@ parent_send_config_listeners(struct smtpd *env)
fatal("setsockopt");
if (bind(l->fd, (struct sockaddr *)&l->ss, l->ss.ss_len) == -1)
fatal("bind");
- imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_CONF_LISTENER,
+ imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_CONF_LISTENER,
0, 0, l->fd, l, sizeof(*l));
}
- imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_CONF_END,
+ imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_CONF_END,
0, 0, -1, NULL, 0);
}
@@ -174,7 +175,7 @@ parent_send_config_client_certs(struct smtpd *env)
struct iovec iov[3];
log_debug("parent_send_config_client_certs: configuring smtp");
- imsg_compose_event(env->sc_ibufs[PROC_MTA], IMSG_CONF_START,
+ imsg_compose_event(env->sc_ievs[PROC_MTA], IMSG_CONF_START,
0, 0, -1, NULL, 0);
SPLAY_FOREACH(s, ssltree, env->sc_ssl) {
@@ -188,11 +189,12 @@ parent_send_config_client_certs(struct smtpd *env)
iov[2].iov_base = s->ssl_key;
iov[2].iov_len = s->ssl_key_len;
- imsg_composev(env->sc_ibufs[PROC_MTA], IMSG_CONF_SSL, 0, 0, -1,
- iov, nitems(iov));
+ imsg_composev(&env->sc_ievs[PROC_MTA]->ibuf, IMSG_CONF_SSL,
+ 0, 0, -1, iov, nitems(iov));
+ imsg_event_add(env->sc_ievs[PROC_MTA]);
}
- imsg_compose_event(env->sc_ibufs[PROC_MTA], IMSG_CONF_END,
+ imsg_compose_event(env->sc_ievs[PROC_MTA], IMSG_CONF_END,
0, 0, -1, NULL, 0);
}
@@ -205,30 +207,30 @@ parent_send_config_ruleset(struct smtpd *env, int proc)
struct mapel *mapel;
log_debug("parent_send_config_ruleset: reloading rules and maps");
- imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_START,
+ imsg_compose_event(env->sc_ievs[proc], IMSG_CONF_START,
0, 0, -1, NULL, 0);
TAILQ_FOREACH(m, env->sc_maps, m_entry) {
- imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_MAP,
+ imsg_compose_event(env->sc_ievs[proc], IMSG_CONF_MAP,
0, 0, -1, m, sizeof(*m));
TAILQ_FOREACH(mapel, &m->m_contents, me_entry) {
- imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_MAP_CONTENT,
+ imsg_compose_event(env->sc_ievs[proc], IMSG_CONF_MAP_CONTENT,
0, 0, -1, mapel, sizeof(*mapel));
}
}
TAILQ_FOREACH(r, env->sc_rules, r_entry) {
- imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_RULE,
+ imsg_compose_event(env->sc_ievs[proc], IMSG_CONF_RULE,
0, 0, -1, r, sizeof(*r));
- imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_RULE_SOURCE,
+ imsg_compose_event(env->sc_ievs[proc], IMSG_CONF_RULE_SOURCE,
0, 0, -1, &r->r_sources->m_name, sizeof(r->r_sources->m_name));
TAILQ_FOREACH(cond, &r->r_conditions, c_entry) {
- imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_CONDITION,
+ imsg_compose_event(env->sc_ievs[proc], IMSG_CONF_CONDITION,
0, 0, -1, cond, sizeof(*cond));
}
}
- imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_END,
+ imsg_compose_event(env->sc_ievs[proc], IMSG_CONF_END,
0, 0, -1, NULL, 0);
}
@@ -236,18 +238,20 @@ void
parent_dispatch_lka(int fd, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_LKA];
+ iev = env->sc_ievs[PROC_LKA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -277,7 +281,7 @@ parent_dispatch_lka(int fd, short event, void *p)
if (errno == ENOENT)
fwreq->status = 1;
}
- imsg_compose_event(ibuf, IMSG_PARENT_FORWARD_OPEN, 0, 0, ret, fwreq, sizeof(*fwreq));
+ imsg_compose_event(iev, IMSG_PARENT_FORWARD_OPEN, 0, 0, ret, fwreq, sizeof(*fwreq));
break;
}
default:
@@ -287,25 +291,27 @@ parent_dispatch_lka(int fd, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
parent_dispatch_mfa(int fd, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_MFA];
+ iev = env->sc_ievs[PROC_MFA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -330,25 +336,27 @@ parent_dispatch_mfa(int fd, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
parent_dispatch_mta(int fd, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_MTA];
+ iev = env->sc_ievs[PROC_MTA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -373,25 +381,27 @@ parent_dispatch_mta(int fd, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
parent_dispatch_mda(int fd, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_MDA];
+ iev = env->sc_ievs[PROC_MDA];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -454,7 +464,7 @@ parent_dispatch_mda(int fd, short event, void *p)
batchp->message.status |= S_MESSAGE_TEMPFAILURE;
else
batchp->message.status |= S_MESSAGE_PERMFAILURE;
- imsg_compose_event(ibuf, IMSG_MDA_MAILBOX_FILE, 0, 0,
+ imsg_compose_event(iev, IMSG_MDA_MAILBOX_FILE, 0, 0,
-1, batchp, sizeof(struct batch));
break;
}
@@ -463,7 +473,7 @@ parent_dispatch_mda(int fd, short event, void *p)
fatal("privdrop failed");
desc = action_hdl_table[i].handler(file, pw, batchp);
- imsg_compose_event(ibuf, IMSG_MDA_MAILBOX_FILE, 0, 0,
+ imsg_compose_event(iev, IMSG_MDA_MAILBOX_FILE, 0, 0,
desc, batchp, sizeof(struct batch));
if (setegid(0) || seteuid(0))
@@ -479,7 +489,7 @@ parent_dispatch_mda(int fd, short event, void *p)
desc = parent_open_message_file(batchp);
- imsg_compose_event(ibuf, IMSG_MDA_MESSAGE_FILE, 0, 0,
+ imsg_compose_event(iev, IMSG_MDA_MESSAGE_FILE, 0, 0,
desc, batchp, sizeof(struct batch));
break;
@@ -517,25 +527,27 @@ parent_dispatch_mda(int fd, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
parent_dispatch_smtp(int fd, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_SMTP];
+ iev = env->sc_ievs[PROC_SMTP];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -565,7 +577,7 @@ parent_dispatch_smtp(int fd, short event, void *p)
req->success = auth_userokay(req->user, NULL,
"auth-smtp", req->pass);
- imsg_compose_event(ibuf, IMSG_PARENT_AUTHENTICATE, 0, 0,
+ imsg_compose_event(iev, IMSG_PARENT_AUTHENTICATE, 0, 0,
-1, req, sizeof(*req));
break;
}
@@ -576,25 +588,27 @@ parent_dispatch_smtp(int fd, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
parent_dispatch_runner(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_RUNNER];
+ iev = env->sc_ievs[PROC_RUNNER];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -614,7 +628,7 @@ parent_dispatch_runner(int sig, short event, void *p)
switch (imsg.hdr.type) {
case IMSG_PARENT_ENQUEUE_OFFLINE:
if (! parent_enqueue_offline(env, imsg.data))
- imsg_compose_event(ibuf, IMSG_PARENT_ENQUEUE_OFFLINE,
+ imsg_compose_event(iev, IMSG_PARENT_ENQUEUE_OFFLINE,
0, 0, -1, NULL, 0);
break;
default:
@@ -624,25 +638,27 @@ parent_dispatch_runner(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
parent_dispatch_control(int sig, short event, void *p)
{
struct smtpd *env = p;
+ struct imsgev *iev;
struct imsgbuf *ibuf;
struct imsg imsg;
ssize_t n;
- ibuf = env->sc_ibufs[PROC_CONTROL];
+ iev = env->sc_ievs[PROC_CONTROL];
+ ibuf = &iev->ibuf;
if (event & EV_READ) {
if ((n = imsg_read(ibuf)) == -1)
fatal("imsg_read_error");
if (n == 0) {
/* this pipe is dead, so remove the event handler */
- event_del(&ibuf->ev);
+ event_del(&iev->ev);
event_loopexit(NULL);
return;
}
@@ -678,11 +694,11 @@ parent_dispatch_control(int sig, short event, void *p)
parent_send_config_client_certs(env);
parent_send_config_ruleset(env, PROC_MFA);
parent_send_config_ruleset(env, PROC_LKA);
- imsg_compose_event(env->sc_ibufs[PROC_SMTP],
+ imsg_compose_event(env->sc_ievs[PROC_SMTP],
IMSG_CONF_RELOAD, 0, 0, -1, NULL, 0);
r->ret = 1;
}
- imsg_compose_event(ibuf, IMSG_CONF_RELOAD, 0, 0, -1, r, sizeof(*r));
+ imsg_compose_event(iev, IMSG_CONF_RELOAD, 0, 0, -1, r, sizeof(*r));
break;
}
default:
@@ -692,7 +708,7 @@ parent_dispatch_control(int sig, short event, void *p)
}
imsg_free(&imsg);
}
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
}
void
@@ -754,7 +770,7 @@ parent_sig_handler(int sig, short event, void *p)
"message; smtpctl %s", cause);
else
log_debug("offline message enqueued");
- imsg_compose_event(env->sc_ibufs[PROC_RUNNER],
+ imsg_compose_event(env->sc_ievs[PROC_RUNNER],
IMSG_PARENT_ENQUEUE_OFFLINE, 0, 0, -1,
NULL, 0);
break;
@@ -1120,31 +1136,31 @@ setup_spool(uid_t uid, gid_t gid)
}
void
-imsg_event_add(struct imsgbuf *ibuf)
+imsg_event_add(struct imsgev *iev)
{
- if (ibuf->handler == NULL) {
- imsg_flush(ibuf);
+ if (iev->handler == NULL) {
+ imsg_flush(&iev->ibuf);
return;
}
- ibuf->events = EV_READ;
- if (ibuf->w.queued)
- ibuf->events |= EV_WRITE;
+ iev->events = EV_READ;
+ if (iev->ibuf.w.queued)
+ iev->events |= EV_WRITE;
- event_del(&ibuf->ev);
- event_set(&ibuf->ev, ibuf->fd, ibuf->events, ibuf->handler, ibuf->data);
- event_add(&ibuf->ev, NULL);
+ event_del(&iev->ev);
+ event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev->data);
+ event_add(&iev->ev, NULL);
}
int
-imsg_compose_event(struct imsgbuf *ibuf, u_int16_t type, u_int32_t peerid,
+imsg_compose_event(struct imsgev *iev, u_int16_t type, u_int32_t peerid,
pid_t pid, int fd, void *data, u_int16_t datalen)
{
int ret;
- if ((ret = imsg_compose(ibuf, type, peerid,
+ if ((ret = imsg_compose(&iev->ibuf, type, peerid,
pid, fd, data, datalen)) != -1)
- imsg_event_add(ibuf);
+ imsg_event_add(iev);
return (ret);
}
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 2f9458ec11c..67778fb609d 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.126 2009/06/05 20:43:57 pyr Exp $ */
+/* $OpenBSD: smtpd.h,v 1.127 2009/06/06 04:14:21 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -200,11 +200,19 @@ enum blockmodes {
BM_NONBLOCK
};
+struct imsgev {
+ struct imsgbuf ibuf;
+ void (*handler)(int, short, void *);
+ struct event ev;
+ void *data;
+ short events;
+};
+
struct ctl_conn {
TAILQ_ENTRY(ctl_conn) entry;
u_int8_t flags;
#define CTL_CONN_NOTIFY 0x01
- struct imsgbuf ibuf;
+ struct imsgev iev;
};
TAILQ_HEAD(ctl_connlist, ctl_conn);
@@ -594,7 +602,7 @@ struct smtpd {
struct event sc_ev;
int *sc_pipes[PROC_COUNT]
[PROC_COUNT];
- struct imsgbuf *sc_ibufs[PROC_COUNT];
+ struct imsgev *sc_ievs[PROC_COUNT];
int sc_instances[PROC_COUNT];
int sc_instance;
char *sc_title[PROC_COUNT];
@@ -747,7 +755,7 @@ void dns_query_a(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 imsgbuf *, int,
+void dns_async(struct smtpd *, struct imsgev *, int,
struct dns *);
@@ -757,8 +765,8 @@ int forwards_get(int, struct aliaseslist *);
/* smtpd.c */
int child_cmp(struct child *, struct child *);
SPLAY_PROTOTYPE(childtree, child, entry, child_cmp);
-void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
-int imsg_compose_event(struct imsgbuf *, u_int16_t, u_int32_t, pid_t,
+void imsg_event_add(struct imsgev *);
+int imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t, pid_t,
int, void *, u_int16_t);
/* lka.c */