diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2012-11-23 13:54:13 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2012-11-23 13:54:13 +0000 |
commit | b9eef80dbbeca8137ad43f32f103b9b897304b76 (patch) | |
tree | aad3988e24be823938713c37411652406578fe4f /usr.sbin/smtpd | |
parent | f155d5673f68dcd1346d6d3de8cbdbd457015bd8 (diff) |
knf
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r-- | usr.sbin/smtpd/config.c | 38 | ||||
-rw-r--r-- | usr.sbin/smtpd/filter_api.c | 58 | ||||
-rw-r--r-- | usr.sbin/smtpd/filter_api.h | 33 | ||||
-rw-r--r-- | usr.sbin/smtpd/iobuf.h | 4 | ||||
-rw-r--r-- | usr.sbin/smtpd/log.h | 12 | ||||
-rw-r--r-- | usr.sbin/smtpd/mfa.c | 27 | ||||
-rw-r--r-- | usr.sbin/smtpd/mfa_session.c | 33 |
7 files changed, 121 insertions, 84 deletions
diff --git a/usr.sbin/smtpd/config.c b/usr.sbin/smtpd/config.c index c4d77c8a77d..3fe07c0631c 100644 --- a/usr.sbin/smtpd/config.c +++ b/usr.sbin/smtpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.17 2012/09/27 17:47:49 chl Exp $ */ +/* $OpenBSD: config.c,v 1.18 2012/11/23 13:54:12 eric Exp $ */ /* * Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -116,8 +116,8 @@ init_pipes(void) /* * find out how many instances of this peer there are. */ - if (i >= j || env->sc_instances[i] == 0|| - env->sc_instances[j] == 0) + if (i >= j || env->sc_instances[i] == 0 || + env->sc_instances[j] == 0) continue; if (env->sc_instances[i] > 1 && @@ -185,7 +185,7 @@ config_pipes(struct peer *p, uint peercount) void config_peers(struct peer *p, uint peercount) { - int count; + int n; uint src; uint dst; uint i; @@ -199,24 +199,24 @@ config_peers(struct peer *p, uint peercount) if (dst == smtpd_process) fatal("config_peers: cannot peer with oneself"); - + env->sc_ievs[dst] = xcalloc(env->sc_instances[dst], sizeof(struct imsgev), "config_peers"); - for (count = 0; count < env->sc_instances[dst]; count++) { - 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].proc = dst; - env->sc_ievs[dst][count].data = &env->sc_ievs[dst][count]; - - 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); + for (n = 0; n < env->sc_instances[dst]; n++) { + imsg_init(&(env->sc_ievs[dst][n].ibuf), + env->sc_pipes[src][dst][n]); + env->sc_ievs[dst][n].handler = p[i].cb; + env->sc_ievs[dst][n].events = EV_READ; + env->sc_ievs[dst][n].proc = dst; + env->sc_ievs[dst][n].data = &env->sc_ievs[dst][n]; + + event_set(&(env->sc_ievs[dst][n].ev), + env->sc_ievs[dst][n].ibuf.fd, + env->sc_ievs[dst][n].events, + env->sc_ievs[dst][n].handler, + env->sc_ievs[dst][n].data); + event_add(&(env->sc_ievs[dst][n].ev), NULL); } } } diff --git a/usr.sbin/smtpd/filter_api.c b/usr.sbin/smtpd/filter_api.c index 789cb58e4b8..2b56dc25dba 100644 --- a/usr.sbin/smtpd/filter_api.c +++ b/usr.sbin/smtpd/filter_api.c @@ -1,4 +1,4 @@ -/* $OpenBSD: filter_api.c,v 1.4 2012/08/19 14:16:58 chl Exp $ */ +/* $OpenBSD: filter_api.c,v 1.5 2012/11/23 13:54:12 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -35,31 +35,40 @@ static struct filter_internals { struct event ev; struct imsgbuf ibuf; - enum filter_status (*connect_cb)(uint64_t, struct filter_connect *, void *); + enum filter_status + (*connect_cb)(uint64_t, struct filter_connect *, void *); void *connect_cb_arg; - enum filter_status (*helo_cb)(uint64_t, struct filter_helo *, void *); + enum filter_status + (*helo_cb)(uint64_t, struct filter_helo *, void *); void *helo_cb_arg; - enum filter_status (*ehlo_cb)(uint64_t, struct filter_helo *, void *); + enum filter_status + (*ehlo_cb)(uint64_t, struct filter_helo *, void *); void *ehlo_cb_arg; - enum filter_status (*mail_cb)(uint64_t, struct filter_mail *, void *); + enum filter_status + (*mail_cb)(uint64_t, struct filter_mail *, void *); void *mail_cb_arg; - enum filter_status (*rcpt_cb)(uint64_t, struct filter_rcpt *, void *); + enum filter_status + (*rcpt_cb)(uint64_t, struct filter_rcpt *, void *); void *rcpt_cb_arg; - enum filter_status (*dataline_cb)(uint64_t, struct filter_dataline *, void *); + enum filter_status + (*dataline_cb)(uint64_t, struct filter_dataline *, void *); void *dataline_cb_arg; - enum filter_status (*quit_cb)(uint64_t, void *); + enum filter_status + (*quit_cb)(uint64_t, void *); void *quit_cb_arg; - enum filter_status (*close_cb)(uint64_t, void *); + enum filter_status + (*close_cb)(uint64_t, void *); void *close_cb_arg; - enum filter_status (*rset_cb)(uint64_t, void *); + enum filter_status + (*rset_cb)(uint64_t, void *); void *rset_cb_arg; } fi; @@ -87,55 +96,64 @@ filter_loop(void) } void -filter_register_connect_callback(enum filter_status (*cb)(uint64_t, struct filter_connect *, void *), void *cb_arg) +filter_register_connect_callback(enum filter_status + (*cb)(uint64_t, struct filter_connect *, void *), void *cb_arg) { filter_register_callback(FILTER_CONNECT, cb, cb_arg); } void -filter_register_helo_callback(enum filter_status (*cb)(uint64_t, struct filter_helo *, void *), void *cb_arg) +filter_register_helo_callback(enum filter_status + (*cb)(uint64_t, struct filter_helo *, void *), void *cb_arg) { filter_register_callback(FILTER_HELO, cb, cb_arg); } void -filter_register_ehlo_callback(enum filter_status (*cb)(uint64_t, struct filter_helo *, void *), void *cb_arg) +filter_register_ehlo_callback(enum filter_status + (*cb)(uint64_t, struct filter_helo *, void *), void *cb_arg) { filter_register_callback(FILTER_EHLO, cb, cb_arg); } void -filter_register_mail_callback(enum filter_status (*cb)(uint64_t, struct filter_mail *, void *), void *cb_arg) +filter_register_mail_callback(enum filter_status + (*cb)(uint64_t, struct filter_mail *, void *), void *cb_arg) { filter_register_callback(FILTER_MAIL, cb, cb_arg); } void -filter_register_rcpt_callback(enum filter_status (*cb)(uint64_t, struct filter_rcpt *, void *), void *cb_arg) +filter_register_rcpt_callback(enum filter_status + (*cb)(uint64_t, struct filter_rcpt *, void *), void *cb_arg) { filter_register_callback(FILTER_RCPT, cb, cb_arg); } void -filter_register_dataline_callback(enum filter_status (*cb)(uint64_t, struct filter_dataline *, void *), void *cb_arg) +filter_register_dataline_callback(enum filter_status + (*cb)(uint64_t, struct filter_dataline *, void *), void *cb_arg) { filter_register_callback(FILTER_DATALINE, cb, cb_arg); } void -filter_register_quit_callback(enum filter_status (*cb)(uint64_t, void *), void *cb_arg) +filter_register_quit_callback(enum filter_status + (*cb)(uint64_t, void *), void *cb_arg) { filter_register_callback(FILTER_QUIT, cb, cb_arg); } void -filter_register_close_callback(enum filter_status (*cb)(uint64_t, void *), void *cb_arg) +filter_register_close_callback(enum filter_status + (*cb)(uint64_t, void *), void *cb_arg) { filter_register_callback(FILTER_CLOSE, cb, cb_arg); } void -filter_register_rset_callback(enum filter_status (*cb)(uint64_t, void *), void *cb_arg) +filter_register_rset_callback(enum filter_status + (*cb)(uint64_t, void *), void *cb_arg) { filter_register_callback(FILTER_RSET, cb, cb_arg); } @@ -287,7 +305,7 @@ filter_handler(int fd, short event, void *p) if (fi.rset_cb == NULL) goto ignore; ret = fi.rset_cb(fm.cl_id, fi.rset_cb_arg); - break; + break; default: errx(1, "unsupported imsg"); diff --git a/usr.sbin/smtpd/filter_api.h b/usr.sbin/smtpd/filter_api.h index 6740db2c309..453a620d90a 100644 --- a/usr.sbin/smtpd/filter_api.h +++ b/usr.sbin/smtpd/filter_api.h @@ -1,4 +1,4 @@ -/* $OpenBSD: filter_api.h,v 1.4 2012/08/20 21:14:17 gilles Exp $ */ +/* $OpenBSD: filter_api.h,v 1.5 2012/11/23 13:54:12 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -53,7 +53,7 @@ struct filter_connect { struct filter_helo { char helohost[MAXHOSTNAMELEN]; }; - + struct filter_mail { char user[MAX_LOCALPART_SIZE]; char domain[MAX_DOMAINPART_SIZE]; @@ -79,7 +79,7 @@ union filter_union { struct filter_msg { uint64_t id; /* set by smtpd(8) */ uint64_t cl_id; /* set by smtpd(8) */ - int8_t code; + int8_t code; uint8_t version; enum filter_type type; union filter_union u; @@ -89,13 +89,22 @@ struct filter_msg { void filter_init(void); void filter_loop(void); -void filter_register_connect_callback(enum filter_status (*)(uint64_t, struct filter_connect *, void *), void *); -void filter_register_helo_callback(enum filter_status (*)(uint64_t, struct filter_helo *, void *), void *); -void filter_register_ehlo_callback(enum filter_status (*)(uint64_t, struct filter_helo *, void *), void *); -void filter_register_mail_callback(enum filter_status (*)(uint64_t, struct filter_mail *, void *), void *); -void filter_register_rcpt_callback(enum filter_status (*)(uint64_t, struct filter_rcpt *, void *), void *); -void filter_register_dataline_callback(enum filter_status (*)(uint64_t, struct filter_dataline *, void *), void *); -void filter_register_quit_callback(enum filter_status (*)(uint64_t, void *), void *); -void filter_register_close_callback(enum filter_status (*)(uint64_t, void *), void *); -void filter_register_rset_callback(enum filter_status (*)(uint64_t, void *), void *); +void filter_register_connect_callback(enum filter_status + (*)(uint64_t, struct filter_connect *, void *), void *); +void filter_register_helo_callback(enum filter_status + (*)(uint64_t, struct filter_helo *, void *), void *); +void filter_register_ehlo_callback(enum filter_status + (*)(uint64_t, struct filter_helo *, void *), void *); +void filter_register_mail_callback(enum filter_status + (*)(uint64_t, struct filter_mail *, void *), void *); +void filter_register_rcpt_callback(enum filter_status + (*)(uint64_t, struct filter_rcpt *, void *), void *); +void filter_register_dataline_callback(enum filter_status + (*)(uint64_t, struct filter_dataline *, void *), void *); +void filter_register_quit_callback(enum filter_status + (*)(uint64_t, void *), void *); +void filter_register_close_callback(enum filter_status + (*)(uint64_t, void *), void *); +void filter_register_rset_callback(enum filter_status + (*)(uint64_t, void *), void *); diff --git a/usr.sbin/smtpd/iobuf.h b/usr.sbin/smtpd/iobuf.h index 1129c3160f0..9004afcac0c 100644 --- a/usr.sbin/smtpd/iobuf.h +++ b/usr.sbin/smtpd/iobuf.h @@ -1,5 +1,5 @@ -/* $OpenBSD: iobuf.h,v 1.1 2012/01/29 00:32:51 eric Exp $ */ -/* +/* $OpenBSD: iobuf.h,v 1.2 2012/11/23 13:54:12 eric Exp $ */ +/* * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any diff --git a/usr.sbin/smtpd/log.h b/usr.sbin/smtpd/log.h index ce2e454eec8..3c6dcc6a48a 100644 --- a/usr.sbin/smtpd/log.h +++ b/usr.sbin/smtpd/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.2 2011/10/22 00:16:33 eric Exp $ */ +/* $OpenBSD: log.h,v 1.3 2012/11/23 13:54:12 eric Exp $ */ /* * Copyright (c) 2010 Gilles Chehade <gilles@openbsd.org> @@ -19,14 +19,14 @@ void log_init(int); void log_verbose(int); void log_warn(const char *, ...) - __attribute__ ((format (printf, 1, 2))); + __attribute__((format (printf, 1, 2))); void log_warnx(const char *, ...) - __attribute__ ((format (printf, 1, 2))); + __attribute__((format (printf, 1, 2))); void log_info(const char *, ...) - __attribute__ ((format (printf, 1, 2))); + __attribute__((format (printf, 1, 2))); void log_debug(const char *, ...) - __attribute__ ((format (printf, 1, 2))); + __attribute__((format (printf, 1, 2))); void log_trace(int, const char *, ...) - __attribute__ ((format (printf, 2, 3))); + __attribute__((format (printf, 2, 3))); __dead void fatal(const char *); __dead void fatalx(const char *); diff --git a/usr.sbin/smtpd/mfa.c b/usr.sbin/smtpd/mfa.c index 921d75052c3..9f5e3030a30 100644 --- a/usr.sbin/smtpd/mfa.c +++ b/usr.sbin/smtpd/mfa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mfa.c,v 1.73 2012/11/12 14:58:53 eric Exp $ */ +/* $OpenBSD: mfa.c,v 1.74 2012/11/23 13:54:12 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -115,13 +115,15 @@ mfa_imsg(struct imsgev *iev, struct imsg *imsg) return; case IMSG_CONF_FILTER: - filter = xmemdup(imsg->data, sizeof *filter, "mfa_imsg"); + filter = xmemdup(imsg->data, sizeof *filter, + "mfa_imsg"); TAILQ_INSERT_TAIL(env->sc_filters, filter, f_entry); return; case IMSG_CONF_END: TAILQ_FOREACH(filter, env->sc_filters, f_entry) { - log_info("info: Forking filter: %s", filter->name); + log_info("info: Forking filter: %s", + filter->name); if (! mfa_fork_filter(filter)) fatalx("could not fork filter"); } @@ -280,7 +282,8 @@ mfa_test_mail(struct envelope *e) /* * "MAIL FROM:<>" is the exception we allow. */ - if (!(ss.u.maddr.user[0] == '\0' && ss.u.maddr.domain[0] == '\0')) + if (!(ss.u.maddr.user[0] == '\0' && + ss.u.maddr.domain[0] == '\0')) goto refuse; } @@ -288,8 +291,8 @@ mfa_test_mail(struct envelope *e) return; refuse: - imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_MFA_MAIL, 0, 0, -1, &ss, - sizeof(ss)); + imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_MFA_MAIL, 0, 0, -1, + &ss, sizeof(ss)); return; } @@ -307,7 +310,7 @@ mfa_test_rcpt(struct envelope *e) ss.flags = e->flags; mfa_strip_source_route(ss.u.maddr.user, sizeof(ss.u.maddr.user)); - + if (! valid_localpart(ss.u.maddr.user) || ! valid_domainpart(ss.u.maddr.domain)) goto refuse; @@ -316,16 +319,16 @@ mfa_test_rcpt(struct envelope *e) return; refuse: - imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_MFA_RCPT, 0, 0, -1, &ss, - sizeof(ss)); + imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_MFA_RCPT, 0, 0, -1, + &ss, sizeof(ss)); } static void 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)); + imsg_compose_event(env->sc_ievs[PROC_SMTP], IMSG_MFA_RCPT, 0, 0, + -1, ss, sizeof(*ss)); return; } @@ -416,7 +419,7 @@ mfa_fork_filter(struct filter *filter) if (pid == 0) { /* filter */ dup2(sockpair[0], STDIN_FILENO); - + if (closefrom(STDERR_FILENO + 1) < 0) exit(1); diff --git a/usr.sbin/smtpd/mfa_session.c b/usr.sbin/smtpd/mfa_session.c index e63864d6f5f..7e058da783b 100644 --- a/usr.sbin/smtpd/mfa_session.c +++ b/usr.sbin/smtpd/mfa_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mfa_session.c,v 1.11 2012/10/11 21:51:37 gilles Exp $ */ +/* $OpenBSD: mfa_session.c,v 1.12 2012/11/23 13:54:12 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -71,7 +71,7 @@ mfa_session(struct submit_status *ss, enum session_state state) static int mfa_session_proceed(struct mfa_session *ms) { - struct filter_msg fm; + struct filter_msg fm; fm.id = ms->id; fm.cl_id = ms->ss.id; @@ -82,15 +82,17 @@ mfa_session_proceed(struct mfa_session *ms) case S_CONNECTED: fm.type = FILTER_CONNECT; if (strlcpy(fm.u.connect.hostname, ms->ss.envelope.hostname, - sizeof(fm.u.connect.hostname)) >= sizeof(fm.u.connect.hostname)) + sizeof(fm.u.connect.hostname)) + >= sizeof(fm.u.connect.hostname)) fatalx("mfa_session_proceed: CONNECT: truncation"); fm.u.connect.hostaddr = ms->ss.envelope.ss; break; - case S_HELO: + case S_HELO: fm.type = FILTER_HELO; if (strlcpy(fm.u.helo.helohost, ms->ss.envelope.helo, - sizeof(fm.u.helo.helohost)) >= sizeof(fm.u.helo.helohost)) + sizeof(fm.u.helo.helohost)) + >= sizeof(fm.u.helo.helohost)) fatalx("mfa_session_proceed: HELO: truncation"); break; @@ -117,7 +119,8 @@ mfa_session_proceed(struct mfa_session *ms) case S_DATACONTENT: fm.type = FILTER_DATALINE; if (strlcpy(fm.u.dataline.line, ms->ss.u.dataline, - sizeof(fm.u.dataline.line)) >= sizeof(fm.u.dataline.line)) + sizeof(fm.u.dataline.line)) + >= sizeof(fm.u.dataline.line)) fatalx("mfa_session_proceed: DATA: line truncation"); break; @@ -139,7 +142,8 @@ mfa_session_proceed(struct mfa_session *ms) imsg_compose(ms->filter->ibuf, fm.type, 0, 0, -1, &fm, sizeof(fm)); - event_set(&ms->filter->ev, ms->filter->ibuf->fd, EV_READ|EV_WRITE, mfa_session_imsg, ms->filter); + event_set(&ms->filter->ev, ms->filter->ibuf->fd, EV_READ|EV_WRITE, + mfa_session_imsg, ms->filter); event_add(&ms->filter->ev, NULL); return 1; } @@ -173,8 +177,9 @@ mfa_session_done(struct mfa_session *ms) break; case S_MAIL_MFA: if (ms->ss.code != 530) { - imsg_compose_event(env->sc_ievs[PROC_LKA], IMSG_LKA_MAIL, 0, - 0, -1, &ms->ss, sizeof(ms->ss)); + imsg_compose_event(env->sc_ievs[PROC_LKA], + IMSG_LKA_MAIL, 0, 0, -1, + &ms->ss, sizeof(ms->ss)); mfa_session_destroy(ms); return; } @@ -182,8 +187,9 @@ mfa_session_done(struct mfa_session *ms) break; case S_RCPT_MFA: if (ms->ss.code != 530) { - imsg_compose_event(env->sc_ievs[PROC_LKA], IMSG_LKA_RULEMATCH, - 0, 0, -1, &ms->ss, sizeof(ms->ss)); + imsg_compose_event(env->sc_ievs[PROC_LKA], + IMSG_LKA_RULEMATCH, 0, 0, -1, + &ms->ss, sizeof(ms->ss)); mfa_session_destroy(ms); return; } @@ -191,8 +197,9 @@ mfa_session_done(struct mfa_session *ms) break; case S_DATACONTENT: if (ms->ss.code != 530 && ms->fm.code != 0) - (void)strlcpy(ms->ss.u.dataline, ms->fm.u.dataline.line, - sizeof(ms->ss.u.dataline)); + (void)strlcpy(ms->ss.u.dataline, + ms->fm.u.dataline.line, + sizeof(ms->ss.u.dataline)); imsg_type = IMSG_MFA_DATALINE; break; case S_QUIT: |