diff options
author | 2018-04-29 08:59:30 +0000 | |
---|---|---|
committer | 2018-04-29 08:59:30 +0000 | |
commit | 72cde3cb61e22d2d66f71fd18679061577ad84a6 (patch) | |
tree | b0704364e1b582d92e0bb1dcc649f00348a87124 | |
parent | Fail early when transfers aren't completed in order. (diff) | |
download | wireguard-openbsd-72cde3cb61e22d2d66f71fd18679061577ad84a6.tar.xz wireguard-openbsd-72cde3cb61e22d2d66f71fd18679061577ad84a6.zip |
move "mail from" and "rcpt to" code into their own function.
ok gilles@
-rw-r--r-- | usr.sbin/smtpd/smtp_session.c | 112 |
1 files changed, 65 insertions, 47 deletions
diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c index bc90d900dae..a2617e64f12 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.326 2018/04/28 16:13:37 eric Exp $ */ +/* $OpenBSD: smtp_session.c,v 1.327 2018/04/29 08:59:30 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -179,6 +179,8 @@ static void smtp_auth_failure_resume(int, short, void *); static int smtp_tx(struct smtp_session *); static void smtp_tx_free(struct smtp_tx *); static void smtp_tx_create_message(struct smtp_tx *); +static void smtp_tx_mail_from(struct smtp_tx *, char *); +static void smtp_tx_rcpt_to(struct smtp_tx *, char *); static void smtp_tx_open_message(struct smtp_tx *); static void smtp_tx_commit(struct smtp_tx *); static void smtp_tx_rollback(struct smtp_tx *); @@ -1265,30 +1267,7 @@ smtp_command(struct smtp_session *s, char *line) break; } - if (smtp_mailaddr(&s->tx->evp.sender, args, 1, &args, - s->smtpname) == 0) { - smtp_tx_free(s->tx); - smtp_reply(s, "553 %s: Sender address syntax error", - esc_code(ESC_STATUS_PERMFAIL, ESC_OTHER_ADDRESS_STATUS)); - break; - } - if (args && smtp_parse_mail_args(s, args) == -1) { - smtp_tx_free(s->tx); - break; - } - - /* only check sendertable if defined and user has authenticated */ - if (s->flags & SF_AUTHENTICATED && s->listener->sendertable[0]) { - m_create(p_lka, IMSG_SMTP_CHECK_SENDER, 0, 0, -1); - m_add_id(p_lka, s->id); - m_add_string(p_lka, s->listener->sendertable); - m_add_string(p_lka, s->username); - m_add_mailaddr(p_lka, &s->tx->evp.sender); - m_close(p_lka); - tree_xset(&wait_lka_mail, s->id, s); - } - else - smtp_tx_create_message(s->tx); + smtp_tx_mail_from(s->tx, args); break; /* * TRANSACTION @@ -1301,28 +1280,7 @@ smtp_command(struct smtp_session *s, char *line) break; } - if (s->tx->rcptcount >= env->sc_session_max_rcpt) { - smtp_reply(s, "451 %s %s: Too many recipients", - esc_code(ESC_STATUS_TEMPFAIL, ESC_TOO_MANY_RECIPIENTS), - esc_description(ESC_TOO_MANY_RECIPIENTS)); - break; - } - - if (smtp_mailaddr(&s->tx->evp.rcpt, args, 0, &args, - s->smtpname) == 0) { - smtp_reply(s, - "501 %s: Recipient address syntax error", - esc_code(ESC_STATUS_PERMFAIL, ESC_BAD_DESTINATION_MAILBOX_ADDRESS_SYNTAX)); - break; - } - if (args && smtp_parse_rcpt_args(s, args) == -1) - break; - - m_create(p_lka, IMSG_SMTP_EXPAND_RCPT, 0, 0, -1); - m_add_id(p_lka, s->id); - m_add_envelope(p_lka, &s->tx->evp); - m_close(p_lka); - tree_xset(&wait_lka_rcpt, s->id, s); + smtp_tx_rcpt_to(s->tx, args); break; case CMD_RSET: @@ -2030,6 +1988,37 @@ smtp_tx_free(struct smtp_tx *tx) } static void +smtp_tx_mail_from(struct smtp_tx *tx, char *line) +{ + if (smtp_mailaddr(&tx->evp.sender, line, 1, &line, + tx->session->smtpname) == 0) { + smtp_tx_free(tx); + smtp_reply(tx->session, "553 %s: Sender address syntax error", + esc_code(ESC_STATUS_PERMFAIL, ESC_OTHER_ADDRESS_STATUS)); + return; + } + + if (line && smtp_parse_mail_args(tx->session, line) == -1) { + smtp_tx_free(tx); + return; + } + + /* only check sendertable if defined and user has authenticated */ + if (tx->session->flags & SF_AUTHENTICATED && + tx->session->listener->sendertable[0]) { + m_create(p_lka, IMSG_SMTP_CHECK_SENDER, 0, 0, -1); + m_add_id(p_lka, tx->session->id); + m_add_string(p_lka, tx->session->listener->sendertable); + m_add_string(p_lka, tx->session->username); + m_add_mailaddr(p_lka, &tx->evp.sender); + m_close(p_lka); + tree_xset(&wait_lka_mail, tx->session->id, tx->session); + } + else + smtp_tx_create_message(tx); +} + +static void smtp_tx_create_message(struct smtp_tx *tx) { m_create(p_queue, IMSG_SMTP_MESSAGE_CREATE, 0, 0, -1); @@ -2039,6 +2028,35 @@ smtp_tx_create_message(struct smtp_tx *tx) } static void +smtp_tx_rcpt_to(struct smtp_tx *tx, char *line) +{ + if (tx->rcptcount >= env->sc_session_max_rcpt) { + smtp_reply(tx->session, "451 %s %s: Too many recipients", + esc_code(ESC_STATUS_TEMPFAIL, ESC_TOO_MANY_RECIPIENTS), + esc_description(ESC_TOO_MANY_RECIPIENTS)); + return; + } + + if (smtp_mailaddr(&tx->evp.rcpt, line, 0, &line, + tx->session->smtpname) == 0) { + smtp_reply(tx->session, + "501 %s: Recipient address syntax error", + esc_code(ESC_STATUS_PERMFAIL, + ESC_BAD_DESTINATION_MAILBOX_ADDRESS_SYNTAX)); + return; + } + + if (line && smtp_parse_rcpt_args(tx->session, line) == -1) + return; + + m_create(p_lka, IMSG_SMTP_EXPAND_RCPT, 0, 0, -1); + m_add_id(p_lka, tx->session->id); + m_add_envelope(p_lka, &tx->evp); + m_close(p_lka); + tree_xset(&wait_lka_rcpt, tx->session->id, tx->session); +} + +static void smtp_tx_open_message(struct smtp_tx *tx) { m_create(p_queue, IMSG_SMTP_MESSAGE_OPEN, 0, 0, -1); |