16 static void ngx_mail_smtp_resolve_name(
ngx_event_t *rev);
19 static void ngx_mail_smtp_invalid_pipelining(
ngx_event_t *rev);
37 static u_char smtp_ok[] =
"250 2.0.0 OK" CRLF;
38 static u_char smtp_bye[] =
"221 2.0.0 Bye" CRLF;
39 static u_char smtp_starttls[] =
"220 2.0.0 Start TLS" CRLF;
40 static u_char smtp_next[] =
"334 " CRLF;
41 static u_char smtp_username[] =
"334 VXNlcm5hbWU6" CRLF;
42 static u_char smtp_password[] =
"334 UGFzc3dvcmQ6" CRLF;
43 static u_char smtp_invalid_command[] =
"500 5.5.1 Invalid command" CRLF;
44 static u_char smtp_invalid_pipelining[] =
45 "503 5.5.0 Improper use of SMTP command pipelining" CRLF;
46 static u_char smtp_invalid_argument[] =
"501 5.5.4 Invalid argument" CRLF;
47 static u_char smtp_auth_required[] =
"530 5.7.1 Authentication required" CRLF;
48 static u_char smtp_bad_sequence[] =
"503 5.5.1 Bad sequence of commands" CRLF;
58 struct sockaddr_in *sin;
65 s->
host = smtp_unavailable;
66 ngx_mail_smtp_greeting(s, c);
70 if (c->
sockaddr->sa_family != AF_INET) {
71 s->
host = smtp_tempunavail;
72 ngx_mail_smtp_greeting(s, c);
76 c->
log->
action =
"in resolving client address";
86 sin = (
struct sockaddr_in *) c->
sockaddr;
88 ctx->
addr = sin->sin_addr.s_addr;
89 ctx->
handler = ngx_mail_smtp_resolve_addr_handler;
110 "%V could not be resolved (%i: %s)",
115 s->
host = smtp_unavailable;
118 s->
host = smtp_tempunavail;
128 c->
log->
action =
"in resolving client hostname";
142 "address resolved: %V", &s->
host);
171 ctx->
handler = ngx_mail_smtp_resolve_name_handler;
187 struct sockaddr_in *sin;
195 "\"%V\" could not be resolved (%i: %s)",
200 s->
host = smtp_unavailable;
203 s->
host = smtp_tempunavail;
210 sin = (
struct sockaddr_in *) c->
sockaddr;
212 for (i = 0; i < ctx->
naddrs; i++) {
217 "name was resolved to %ud.%ud.%ud.%ud",
218 (ntohl(addr) >> 24) & 0xff,
219 (ntohl(addr) >> 16) & 0xff,
220 (ntohl(addr) >> 8) & 0xff,
223 if (addr == sin->sin_addr.s_addr) {
228 s->
host = smtp_unavailable;
235 ngx_mail_smtp_greeting(s, c);
247 "smtp greeting for \"%V\"", &s->
host);
260 c->
read->
handler = ngx_mail_smtp_invalid_pipelining;
283 c->
log->
action =
"in delay pipelining state";
311 if (ngx_mail_smtp_create_buffer(s, c) !=
NGX_OK) {
316 if (ngx_mail_smtp_discard_command(s, c,
317 "client was rejected before greeting: \"%V\"")
350 if (ngx_mail_smtp_create_buffer(s, c) !=
NGX_OK) {
428 rc = ngx_mail_smtp_helo(s, c);
432 rc = ngx_mail_smtp_auth(s, c);
441 rc = ngx_mail_smtp_mail(s, c);
445 rc = ngx_mail_smtp_rcpt(s, c);
449 rc = ngx_mail_smtp_rset(s, c);
456 rc = ngx_mail_smtp_starttls(s, c);
555 if (c->ssl == NULL) {
587 if (ngx_mail_starttls_only(s, c)) {
662 ngx_mail_smtp_log_rejected_command(s, c,
"client was rejected: \"%V\"");
677 for (i = 0; i < l.
len; i++) {
680 if (ch !=
CR && ch !=
LF) {
688 if (l.
data[i - 1] !=
' ') {
730 for (i = 0; i < l.
len; i++) {
733 if (ch !=
CR && ch !=
LF) {
741 if (l.
data[i - 1] !=
' ') {
760 "smtp rcpt to:\"%V\"", &s->
smtp_to);
785 if (c->ssl == NULL) {
835 ngx_mail_smtp_log_rejected_command(s, c, err);
859 for (i = 0; i < cmd.
len; i++) {
862 if (ch !=
CR && ch !=
LF) {