diff options
author | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2009-06-06 04:14:22 +0000 |
---|---|---|
committer | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2009-06-06 04:14:22 +0000 |
commit | a0213c2ae7b042ded867a7062b034704e5665fcc (patch) | |
tree | d38e429e0c9afb6c788333d497726ec07a939057 /usr.sbin/smtpd/smtpd.c | |
parent | 6ab1d49e9d67904695f4398a2d1b6aa1d86de58d (diff) |
Sync with relayd:
Stop pushing event handling in the imsg framework.
Instead, provide a small glue layer on top of both imsg and libevent.
This finally clearly separates event handling and imsg construction.
Sidetrack bonus: remove the mega-ugly hack of having a dummy imsg_event_add
stub in smtpctl.
ok jaceckm@
Diffstat (limited to 'usr.sbin/smtpd/smtpd.c')
-rw-r--r-- | usr.sbin/smtpd/smtpd.c | 134 |
1 files changed, 75 insertions, 59 deletions
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); } |