Re: smtpd: remove filter leftovers
On Tue, Aug 29, 2017 at 12:13:28PM +0200, Eric Faurot wrote: > On Tue, Aug 29, 2017 at 10:26:19AM +0200, Eric Faurot wrote: > > > Now that the filter code path has been short-circuited, start removing stub > > smtp_filter_*() indirections. I'm doing this one function at a time to keep > > the diffs simple, starting with smtp_filter_connect(). > > Actually the complete diff is simple enough. > yes ok gilles@ > Index: smtp_session.c > === > RCS file: /cvs/src/usr.sbin/smtpd/smtp_session.c,v > retrieving revision 1.305 > diff -u -p -r1.305 smtp_session.c > --- smtp_session.c13 Aug 2017 11:10:30 - 1.305 > +++ smtp_session.c29 Aug 2017 10:08:06 - > @@ -189,12 +189,6 @@ static void smtp_queue_open_message(stru > static void smtp_queue_commit(struct smtp_session *); > static void smtp_queue_rollback(struct smtp_session *); > > -static void smtp_filter_connect(struct smtp_session *, struct sockaddr *); > -static void smtp_filter_eom(struct smtp_session *); > -static void smtp_filter_helo(struct smtp_session *); > -static void smtp_filter_mail(struct smtp_session *); > -static void smtp_filter_rcpt(struct smtp_session *); > -static void smtp_filter_data(struct smtp_session *); > static void smtp_filter_dataline(struct smtp_session *, const char *); > > static struct { int code; const char *cmd; } commands[] = { > @@ -1001,150 +995,6 @@ smtp_tls_verified(struct smtp_session *s > } > > void > -smtp_filter_response(uint64_t id, int query, int status, uint32_t code, > -const char *line) > -{ > - struct smtp_session *s; > - struct ca_cert_req_msg req_ca_cert; > - > - s = tree_xpop(_filter, id); > - > - if (status == FILTER_CLOSE) { > - code = code ? code : 421; > - line = line ? line : "Temporary failure"; > - smtp_reply(s, "%d %s", code, line); > - smtp_enter_state(s, STATE_QUIT); > - return; > - } > - > - switch (query) { > - > - case QUERY_CONNECT: > - if (status != FILTER_OK) { > - log_info("%016"PRIx64" smtp " > - "event=closed address=%s host=%s > reason=filter-reject", > - s->id, ss_to_text(>ss), s->hostname); > - smtp_free(s, "rejected by filter"); > - return; > - } > - > - if (s->listener->flags & F_SMTPS) { > - req_ca_cert.reqid = s->id; > - if (s->listener->pki_name[0]) { > - (void)strlcpy(req_ca_cert.name, > s->listener->pki_name, > - sizeof req_ca_cert.name); > - req_ca_cert.fallback = 0; > - } > - else { > - (void)strlcpy(req_ca_cert.name, s->smtpname, > - sizeof req_ca_cert.name); > - req_ca_cert.fallback = 1; > - } > - m_compose(p_lka, IMSG_SMTP_TLS_INIT, 0, 0, -1, > - _ca_cert, sizeof(req_ca_cert)); > - tree_xset(_ssl_init, s->id, s); > - return; > - } > - smtp_send_banner(s); > - return; > - > - case QUERY_HELO: > - if (status != FILTER_OK) { > - code = code ? code : 530; > - line = line ? line : "Hello rejected"; > - smtp_reply(s, "%d %s", code, line); > - return; > - } > - > - smtp_enter_state(s, STATE_HELO); > - smtp_reply(s, "250%c%s Hello %s [%s], pleased to meet you", > - (s->flags & SF_EHLO) ? '-' : ' ', > - s->smtpname, > - s->helo, > - ss_to_text(>ss)); > - > - if (s->flags & SF_EHLO) { > - smtp_reply(s, "250-8BITMIME"); > - smtp_reply(s, "250-ENHANCEDSTATUSCODES"); > - smtp_reply(s, "250-SIZE %zu", env->sc_maxsize); > - if (ADVERTISE_EXT_DSN(s)) > - smtp_reply(s, "250-DSN"); > - if (ADVERTISE_TLS(s)) > - smtp_reply(s, "250-STARTTLS"); > - if (ADVERTISE_AUTH(s)) > - smtp_reply(s, "250-AUTH PLAIN LOGIN"); > - smtp_reply(s, "250 HELP"); > - } > - return; > - > - case QUERY_MAIL: > - if (status != FILTER_OK) { > - smtp_tx_free(s->tx); > - code = code ? code : 530; > - line = line ? line : "Sender rejected"; > - smtp_reply(s, "%d %s", code, line); > - return; > - } > - > - /* only
Re: smtpd: remove filter leftovers
On Tue, Aug 29, 2017 at 10:26:19AM +0200, Eric Faurot wrote: > Now that the filter code path has been short-circuited, start removing stub > smtp_filter_*() indirections. I'm doing this one function at a time to keep > the diffs simple, starting with smtp_filter_connect(). Actually the complete diff is simple enough. Eric. Index: smtp_session.c === RCS file: /cvs/src/usr.sbin/smtpd/smtp_session.c,v retrieving revision 1.305 diff -u -p -r1.305 smtp_session.c --- smtp_session.c 13 Aug 2017 11:10:30 - 1.305 +++ smtp_session.c 29 Aug 2017 10:08:06 - @@ -189,12 +189,6 @@ static void smtp_queue_open_message(stru static void smtp_queue_commit(struct smtp_session *); static void smtp_queue_rollback(struct smtp_session *); -static void smtp_filter_connect(struct smtp_session *, struct sockaddr *); -static void smtp_filter_eom(struct smtp_session *); -static void smtp_filter_helo(struct smtp_session *); -static void smtp_filter_mail(struct smtp_session *); -static void smtp_filter_rcpt(struct smtp_session *); -static void smtp_filter_data(struct smtp_session *); static void smtp_filter_dataline(struct smtp_session *, const char *); static struct { int code; const char *cmd; } commands[] = { @@ -1001,150 +995,6 @@ smtp_tls_verified(struct smtp_session *s } void -smtp_filter_response(uint64_t id, int query, int status, uint32_t code, -const char *line) -{ - struct smtp_session *s; - struct ca_cert_req_msg req_ca_cert; - - s = tree_xpop(_filter, id); - - if (status == FILTER_CLOSE) { - code = code ? code : 421; - line = line ? line : "Temporary failure"; - smtp_reply(s, "%d %s", code, line); - smtp_enter_state(s, STATE_QUIT); - return; - } - - switch (query) { - - case QUERY_CONNECT: - if (status != FILTER_OK) { - log_info("%016"PRIx64" smtp " - "event=closed address=%s host=%s reason=filter-reject", - s->id, ss_to_text(>ss), s->hostname); - smtp_free(s, "rejected by filter"); - return; - } - - if (s->listener->flags & F_SMTPS) { - req_ca_cert.reqid = s->id; - if (s->listener->pki_name[0]) { - (void)strlcpy(req_ca_cert.name, s->listener->pki_name, - sizeof req_ca_cert.name); - req_ca_cert.fallback = 0; - } - else { - (void)strlcpy(req_ca_cert.name, s->smtpname, - sizeof req_ca_cert.name); - req_ca_cert.fallback = 1; - } - m_compose(p_lka, IMSG_SMTP_TLS_INIT, 0, 0, -1, - _ca_cert, sizeof(req_ca_cert)); - tree_xset(_ssl_init, s->id, s); - return; - } - smtp_send_banner(s); - return; - - case QUERY_HELO: - if (status != FILTER_OK) { - code = code ? code : 530; - line = line ? line : "Hello rejected"; - smtp_reply(s, "%d %s", code, line); - return; - } - - smtp_enter_state(s, STATE_HELO); - smtp_reply(s, "250%c%s Hello %s [%s], pleased to meet you", - (s->flags & SF_EHLO) ? '-' : ' ', - s->smtpname, - s->helo, - ss_to_text(>ss)); - - if (s->flags & SF_EHLO) { - smtp_reply(s, "250-8BITMIME"); - smtp_reply(s, "250-ENHANCEDSTATUSCODES"); - smtp_reply(s, "250-SIZE %zu", env->sc_maxsize); - if (ADVERTISE_EXT_DSN(s)) - smtp_reply(s, "250-DSN"); - if (ADVERTISE_TLS(s)) - smtp_reply(s, "250-STARTTLS"); - if (ADVERTISE_AUTH(s)) - smtp_reply(s, "250-AUTH PLAIN LOGIN"); - smtp_reply(s, "250 HELP"); - } - return; - - case QUERY_MAIL: - if (status != FILTER_OK) { - smtp_tx_free(s->tx); - code = code ? code : 530; - line = line ? line : "Sender rejected"; - smtp_reply(s, "%d %s", code, line); - return; - } - - /* only check sendertable if defined and user has authenticated */ - if (s->flags & SF_AUTHENTICATED && s->listener->sendertable[0]) { -
smtpd: remove filter leftovers
Now that the filter code path has been short-circuited, start removing stub smtp_filter_*() indirections. I'm doing this one function at a time to keep the diffs simple, starting with smtp_filter_connect(). Eric. Index: smtp_session.c === RCS file: /cvs/src/usr.sbin/smtpd/smtp_session.c,v retrieving revision 1.305 diff -u -p -r1.305 smtp_session.c --- smtp_session.c 13 Aug 2017 11:10:30 - 1.305 +++ smtp_session.c 29 Aug 2017 08:03:49 - @@ -189,7 +189,6 @@ static void smtp_queue_open_message(stru static void smtp_queue_commit(struct smtp_session *); static void smtp_queue_rollback(struct smtp_session *); -static void smtp_filter_connect(struct smtp_session *, struct sockaddr *); static void smtp_filter_eom(struct smtp_session *); static void smtp_filter_helo(struct smtp_session *); static void smtp_filter_mail(struct smtp_session *); @@ -1005,7 +1004,6 @@ smtp_filter_response(uint64_t id, int qu const char *line) { struct smtp_session *s; - struct ca_cert_req_msg req_ca_cert; s = tree_xpop(_filter, id); @@ -1019,35 +1017,6 @@ smtp_filter_response(uint64_t id, int qu switch (query) { - case QUERY_CONNECT: - if (status != FILTER_OK) { - log_info("%016"PRIx64" smtp " - "event=closed address=%s host=%s reason=filter-reject", - s->id, ss_to_text(>ss), s->hostname); - smtp_free(s, "rejected by filter"); - return; - } - - if (s->listener->flags & F_SMTPS) { - req_ca_cert.reqid = s->id; - if (s->listener->pki_name[0]) { - (void)strlcpy(req_ca_cert.name, s->listener->pki_name, - sizeof req_ca_cert.name); - req_ca_cert.fallback = 0; - } - else { - (void)strlcpy(req_ca_cert.name, s->smtpname, - sizeof req_ca_cert.name); - req_ca_cert.fallback = 1; - } - m_compose(p_lka, IMSG_SMTP_TLS_INIT, 0, 0, -1, - _ca_cert, sizeof(req_ca_cert)); - tree_xset(_ssl_init, s->id, s); - return; - } - smtp_send_banner(s); - return; - case QUERY_HELO: if (status != FILTER_OK) { code = code ? code : 530; @@ -2023,6 +1992,7 @@ smtp_lookup_servername(struct smtp_sessi static void smtp_connected(struct smtp_session *s) { + struct ca_cert_req_msg req_ca_cert; struct sockaddr_storage ss; socklen_t sl; @@ -2037,7 +2007,25 @@ smtp_connected(struct smtp_session *s) return; } - smtp_filter_connect(s, (struct sockaddr *)); + if (s->listener->flags & F_SMTPS) { + req_ca_cert.reqid = s->id; + if (s->listener->pki_name[0]) { + (void)strlcpy(req_ca_cert.name, s->listener->pki_name, + sizeof req_ca_cert.name); + req_ca_cert.fallback = 0; + } + else { + (void)strlcpy(req_ca_cert.name, s->smtpname, + sizeof req_ca_cert.name); + req_ca_cert.fallback = 1; + } + m_compose(p_lka, IMSG_SMTP_TLS_INIT, 0, 0, -1, + _ca_cert, sizeof(req_ca_cert)); + tree_xset(_ssl_init, s->id, s); + return; + } + + smtp_send_banner(s); } static void @@ -2416,13 +2404,6 @@ smtp_queue_rollback(struct smtp_session m_create(p_queue, IMSG_SMTP_MESSAGE_ROLLBACK, 0, 0, -1); m_add_msgid(p_queue, s->tx->msgid); m_close(p_queue); -} - -static void -smtp_filter_connect(struct smtp_session *s, struct sockaddr *sa) -{ - tree_xset(_filter, s->id, s); - smtp_filter_response(s->id, QUERY_CONNECT, FILTER_OK, 0, NULL); } static void