annotate src/mail/ngx_mail_smtp_handler.c @ 326:f70f2f565fe0 NGINX_0_5_33

nginx 0.5.33 *) Change: now by default the "echo" SSI command uses entity encoding. *) Feature: the "encoding" parameter in the "echo" SSI command. *) Change: mail proxy was split on three modules: pop3, imap and smtp. *) Feature: the --without-mail_pop3_module, --without-mail_imap_module, and --without-mail_smtp_module configuration parameters. *) Feature: the "smtp_greeting_delay" and "smtp_client_buffer" directives of the ngx_mail_smtp_module. *) Feature: the "server_name" and "valid_referers" directives support regular expressions. *) Feature: the "server_name", "map", and "valid_referers" directives support the "www.example.*" wildcards. *) Bugfix: sub_filter did not work with empty substitution. *) Bugfix: in sub_filter parsing. *) Bugfix: a worker process may got caught in an endless loop, if the memcached was used. *) Bugfix: nginx supported low case only "close" and "keep-alive" values in the "Connection" request header line; bug appeared in 0.5.32. *) Bugfix: nginx could not start on Solaris if the shared PCRE library located in non-standard place was used.
author Igor Sysoev <http://sysoev.ru>
date Wed, 07 Nov 2007 00:00:00 +0300
parents
children c60beecc6ab5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
326
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_event.h>
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10 #include <ngx_mail.h>
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11 #include <ngx_mail_smtp_module.h>
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14 static void ngx_mail_smtp_invalid_pipelining(ngx_event_t *rev);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15 static ngx_int_t ngx_mail_smtp_create_buffer(ngx_mail_session_t *s,
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
16 ngx_connection_t *c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
17
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
18 static ngx_int_t ngx_mail_smtp_helo(ngx_mail_session_t *s, ngx_connection_t *c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19 static ngx_int_t ngx_mail_smtp_auth(ngx_mail_session_t *s, ngx_connection_t *c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20 static ngx_int_t ngx_mail_smtp_mail(ngx_mail_session_t *s, ngx_connection_t *c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21 static ngx_int_t ngx_mail_smtp_starttls(ngx_mail_session_t *s,
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22 ngx_connection_t *c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
23
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24 static ngx_int_t ngx_mail_smtp_discard_command(ngx_mail_session_t *s,
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25 ngx_connection_t *c, char *err);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26 static void ngx_mail_smtp_log_rejected_command(ngx_mail_session_t *s,
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 ngx_connection_t *c, char *err);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30 static u_char smtp_ok[] = "250 2.0.0 OK" CRLF;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31 static u_char smtp_bye[] = "221 2.0.0 Bye" CRLF;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32 static u_char smtp_next[] = "334 " CRLF;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33 static u_char smtp_username[] = "334 VXNlcm5hbWU6" CRLF;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 static u_char smtp_password[] = "334 UGFzc3dvcmQ6" CRLF;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35 static u_char smtp_invalid_command[] = "500 5.5.1 Invalid command" CRLF;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36 static u_char smtp_invalid_pipelining[] =
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37 "503 5.5.0 Improper use of SMTP command pipelining" CRLF;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38 static u_char smtp_invalid_argument[] = "501 5.5.4 Invalid argument" CRLF;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39 static u_char smtp_auth_required[] = "530 5.7.1 Authentication required" CRLF;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
41
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 void
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43 ngx_mail_smtp_init_session(ngx_mail_session_t *s, ngx_connection_t *c)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 ngx_msec_t timeout;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46 ngx_mail_core_srv_conf_t *cscf;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47 ngx_mail_smtp_srv_conf_t *sscf;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
50 sscf = ngx_mail_get_module_srv_conf(s, ngx_mail_smtp_module);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
51
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
52 timeout = sscf->greeting_delay ? sscf->greeting_delay : cscf->timeout;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
53 ngx_add_timer(c->read, timeout);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
54
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56 ngx_mail_close_connection(c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59 if (sscf->greeting_delay) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60 c->read->handler = ngx_mail_smtp_invalid_pipelining;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61 return;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 c->read->handler = ngx_mail_smtp_init_protocol;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66 s->out = sscf->greeting;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
67
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68 ngx_mail_send(c->write);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72 static void
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73 ngx_mail_smtp_invalid_pipelining(ngx_event_t *rev)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74 {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75 ngx_connection_t *c;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76 ngx_mail_session_t *s;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
77 ngx_mail_core_srv_conf_t *cscf;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78 ngx_mail_smtp_srv_conf_t *sscf;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80 c = rev->data;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81 s = c->data;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
82
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83 c->log->action = "in delay pipelining state";
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85 if (rev->timedout) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
86
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "delay greeting");
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
88
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89 rev->timedout = 0;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
91 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
92
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
93 c->read->handler = ngx_mail_smtp_init_protocol;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
94
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
95 ngx_add_timer(c->read, cscf->timeout);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
96
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
97 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
98 ngx_mail_close_connection(c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
99 return;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
100 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
101
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
102 sscf = ngx_mail_get_module_srv_conf(s, ngx_mail_smtp_module);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
103
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104 s->out = sscf->greeting;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
105
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
106 } else {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
107
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
108 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "invalid pipelining");
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
110 if (s->buffer == NULL) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
111 if (ngx_mail_smtp_create_buffer(s, c) != NGX_OK) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
112 return;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
113 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
114 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116 if (ngx_mail_smtp_discard_command(s, c,
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117 "client was rejected before greeting: \"%V\"")
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118 != NGX_OK)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119 {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120 return;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123 s->out.len = sizeof(smtp_invalid_pipelining) - 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
124 s->out.data = smtp_invalid_pipelining;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
125 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
126
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
127 ngx_mail_send(c->write);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
128 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131 void
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
132 ngx_mail_smtp_init_protocol(ngx_event_t *rev)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
133 {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
134 ngx_connection_t *c;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
135 ngx_mail_session_t *s;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
136
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
137 c = rev->data;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
138
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
139 c->log->action = "in auth state";
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
140
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
141 if (rev->timedout) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
142 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143 c->timedout = 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
144 ngx_mail_close_connection(c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
145 return;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
146 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
148 s = c->data;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
149
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
150 if (s->buffer == NULL) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
151 if (ngx_mail_smtp_create_buffer(s, c) != NGX_OK) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
152 return;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
153 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
154 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
155
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
156 s->mail_state = ngx_smtp_start;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
157 c->read->handler = ngx_mail_smtp_auth_state;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
158
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
159 ngx_mail_smtp_auth_state(rev);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
160 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
161
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
162
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
163 static ngx_int_t
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
164 ngx_mail_smtp_create_buffer(ngx_mail_session_t *s, ngx_connection_t *c)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
165 {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
166 ngx_mail_smtp_srv_conf_t *sscf;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
167
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
168 if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t)) == NGX_ERROR) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
169 ngx_mail_session_internal_server_error(s);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
170 return NGX_ERROR;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
171 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
172
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
173 sscf = ngx_mail_get_module_srv_conf(s, ngx_mail_smtp_module);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
174
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
175 s->buffer = ngx_create_temp_buf(c->pool, sscf->client_buffer_size);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
176 if (s->buffer == NULL) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
177 ngx_mail_session_internal_server_error(s);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
178 return NGX_ERROR;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
179 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
180
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
181 return NGX_OK;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
182 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
183
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
184
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
185 void
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
186 ngx_mail_smtp_auth_state(ngx_event_t *rev)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
187 {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
188 ngx_int_t rc;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
189 ngx_connection_t *c;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
190 ngx_mail_session_t *s;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
191
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
192 c = rev->data;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
193 s = c->data;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
194
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
195 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "smtp auth state");
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
196
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
197 if (rev->timedout) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
198 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
199 c->timedout = 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
200 ngx_mail_close_connection(c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
201 return;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
202 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
203
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
204 if (s->out.len) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
205 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "smtp send handler busy");
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
206 s->blocked = 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
207 return;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
208 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
209
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
210 s->blocked = 0;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
211
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
212 rc = ngx_mail_read_command(s, c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
213
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
214 if (rc == NGX_AGAIN || rc == NGX_ERROR) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
215 return;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
216 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
217
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
218 s->out.len = sizeof(smtp_ok) - 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
219 s->out.data = smtp_ok;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
220
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
221 if (rc == NGX_OK) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
222 switch (s->mail_state) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
223
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
224 case ngx_smtp_start:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
225
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
226 switch (s->command) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
227
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
228 case NGX_SMTP_HELO:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
229 case NGX_SMTP_EHLO:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
230 rc = ngx_mail_smtp_helo(s, c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
231 break;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
232
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
233 case NGX_SMTP_AUTH:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234 rc = ngx_mail_smtp_auth(s, c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
235 break;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
236
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
237 case NGX_SMTP_QUIT:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238 s->quit = 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
239 s->out.len = sizeof(smtp_bye) - 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
240 s->out.data = smtp_bye;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
241 break;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
242
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
243 case NGX_SMTP_MAIL:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
244 rc = ngx_mail_smtp_mail(s, c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
245 break;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
246
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
247 case NGX_SMTP_NOOP:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
248 case NGX_SMTP_RSET:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
249 break;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
250
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
251 case NGX_SMTP_STARTTLS:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
252 rc = ngx_mail_smtp_starttls(s, c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
253 break;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
254
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
255 default:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
256 rc = NGX_MAIL_PARSE_INVALID_COMMAND;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
257 break;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
258 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
259
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
260 break;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
261
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
262 case ngx_smtp_auth_login_username:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
263 rc = ngx_mail_auth_login_username(s, c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
264
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
265 s->out.len = sizeof(smtp_password) - 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
266 s->out.data = smtp_password;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
267 s->mail_state = ngx_smtp_auth_login_password;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
268 break;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
269
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
270 case ngx_smtp_auth_login_password:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
271 rc = ngx_mail_auth_login_password(s, c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
272 break;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
273
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
274 case ngx_smtp_auth_plain:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
275 rc = ngx_mail_auth_plain(s, c, 0);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
276 break;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
277
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
278 case ngx_smtp_auth_cram_md5:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
279 rc = ngx_mail_auth_cram_md5(s, c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
280 break;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
281 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
282 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
283
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
284 switch (rc) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
285
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
286 case NGX_DONE:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
287 ngx_mail_auth(s, c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
288 return;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
289
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
290 case NGX_ERROR:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
291 ngx_mail_session_internal_server_error(s);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
292 return;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
293
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
294 case NGX_MAIL_PARSE_INVALID_COMMAND:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
295 s->mail_state = ngx_smtp_start;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
296 s->state = 0;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
297
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
298 s->out.len = sizeof(smtp_invalid_command) - 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
299 s->out.data = smtp_invalid_command;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
300
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
301 /* fall through */
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
302
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
303 case NGX_OK:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
304 s->args.nelts = 0;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
305 s->buffer->pos = s->buffer->start;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
306 s->buffer->last = s->buffer->start;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
307
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
308 if (s->state) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
309 s->arg_start = s->buffer->start;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
310 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
311
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
312 ngx_mail_send(c->write);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
313 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
314 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
315
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
316
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
317 static ngx_int_t
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
318 ngx_mail_smtp_helo(ngx_mail_session_t *s, ngx_connection_t *c)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
319 {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
320 ngx_str_t *arg;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
321 ngx_mail_smtp_srv_conf_t *sscf;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
322 #if (NGX_MAIL_SSL)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
323 ngx_mail_ssl_conf_t *sslcf;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
324 #endif
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
325
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
326 if (s->args.nelts != 1) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
327 s->out.len = sizeof(smtp_invalid_argument) - 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
328 s->out.data = smtp_invalid_argument;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
329 s->state = 0;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
330 return NGX_OK;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
331 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
332
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
333 arg = s->args.elts;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
334
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
335 s->smtp_helo.len = arg[0].len;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
336
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
337 s->smtp_helo.data = ngx_palloc(c->pool, arg[0].len);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
338 if (s->smtp_helo.data == NULL) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
339 return NGX_ERROR;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
340 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
341
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
342 ngx_memcpy(s->smtp_helo.data, arg[0].data, arg[0].len);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
343
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
344 sscf = ngx_mail_get_module_srv_conf(s, ngx_mail_smtp_module);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
345
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
346 if (s->command == NGX_SMTP_HELO) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
347 s->out = sscf->server_name;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
348
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
349 } else {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
350 s->esmtp = 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
351
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
352 #if (NGX_MAIL_SSL)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
353
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
354 if (c->ssl == NULL) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
355 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
356
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
357 if (sslcf->starttls == NGX_MAIL_STARTTLS_ON) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
358 s->out = sscf->starttls_capability;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
359 return NGX_OK;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
360 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
361
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
362 if (sslcf->starttls == NGX_MAIL_STARTTLS_ONLY) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
363 s->out = sscf->starttls_only_capability;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
364 return NGX_OK;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
365 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
366 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
367 #endif
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
368
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
369 s->out = sscf->capability;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
370 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
371
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
372 return NGX_OK;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
373 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
374
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
375
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
376 static ngx_int_t
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
377 ngx_mail_smtp_auth(ngx_mail_session_t *s, ngx_connection_t *c)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
378 {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
379 ngx_int_t rc;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
380 ngx_mail_core_srv_conf_t *cscf;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
381 ngx_mail_smtp_srv_conf_t *sscf;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
382
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
383 #if (NGX_MAIL_SSL)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
384 if (ngx_mail_starttls_only(s, c)) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
385 return NGX_MAIL_PARSE_INVALID_COMMAND;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
386 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
387 #endif
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
388
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
389 if (s->args.nelts == 0) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
390 s->out.len = sizeof(smtp_invalid_argument) - 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
391 s->out.data = smtp_invalid_argument;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
392 s->state = 0;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
393 return NGX_OK;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
394 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
395
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
396 rc = ngx_mail_auth_parse(s, c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
397
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
398 switch (rc) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
399
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
400 case NGX_MAIL_AUTH_LOGIN:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
401
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
402 s->out.len = sizeof(smtp_username) - 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
403 s->out.data = smtp_username;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
404 s->mail_state = ngx_smtp_auth_login_username;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
405
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
406 return NGX_OK;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
407
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
408 case NGX_MAIL_AUTH_PLAIN:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
409
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
410 s->out.len = sizeof(smtp_next) - 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
411 s->out.data = smtp_next;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
412 s->mail_state = ngx_smtp_auth_plain;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
413
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
414 return NGX_OK;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
415
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
416 case NGX_MAIL_AUTH_CRAM_MD5:
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
417
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
418 sscf = ngx_mail_get_module_srv_conf(s, ngx_mail_smtp_module);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
419
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
420 if (!(sscf->auth_methods & NGX_MAIL_AUTH_CRAM_MD5_ENABLED)) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
421 return NGX_MAIL_PARSE_INVALID_COMMAND;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
422 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
423
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
424 if (s->salt.data == NULL) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
425 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
426
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
427 if (ngx_mail_salt(s, c, cscf) != NGX_OK) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
428 return NGX_ERROR;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
429 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
430 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
431
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
432 if (ngx_mail_auth_cram_md5_salt(s, c, "334 ", 4) == NGX_OK) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
433 s->mail_state = ngx_smtp_auth_cram_md5;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
434 return NGX_OK;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
435 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
436
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
437 return NGX_ERROR;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
438 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
439
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
440 return rc;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
441 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
442
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
443
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
444 static ngx_int_t
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
445 ngx_mail_smtp_mail(ngx_mail_session_t *s, ngx_connection_t *c)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
446 {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
447 ngx_mail_smtp_log_rejected_command(s, c, "client was rejected: \"%V\"");
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
448
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
449 s->out.len = sizeof(smtp_auth_required) - 1;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
450 s->out.data = smtp_auth_required;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
451
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
452 return NGX_OK;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
453 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
454
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
455
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
456 static ngx_int_t
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
457 ngx_mail_smtp_starttls(ngx_mail_session_t *s, ngx_connection_t *c)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
458 {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
459 #if (NGX_MAIL_SSL)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
460 ngx_mail_ssl_conf_t *sslcf;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
461
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
462 if (c->ssl == NULL) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
463 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
464 if (sslcf->starttls) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
465
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
466 /*
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
467 * RFC3207 requires us to discard any knowledge
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
468 * obtained from client before STARTTLS.
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
469 */
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
470
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
471 s->smtp_helo.len = 0;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
472 s->smtp_helo.data = NULL;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
473
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
474 c->read->handler = ngx_mail_starttls_handler;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
475 return NGX_OK;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
476 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
477 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
478
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
479 #endif
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
480
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
481 return NGX_MAIL_PARSE_INVALID_COMMAND;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
482 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
483
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
484
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
485 static ngx_int_t
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
486 ngx_mail_smtp_discard_command(ngx_mail_session_t *s, ngx_connection_t *c,
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
487 char *err)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
488 {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
489 ssize_t n;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
490
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
491 n = c->recv(c, s->buffer->last, s->buffer->end - s->buffer->last);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
492
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
493 if (n == NGX_ERROR || n == 0) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
494 ngx_mail_close_connection(c);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
495 return NGX_ERROR;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
496 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
497
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
498 if (n > 0) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
499 s->buffer->last += n;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
500 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
501
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
502 if (n == NGX_AGAIN) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
503 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
504 ngx_mail_session_internal_server_error(s);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
505 return NGX_ERROR;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
506 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
507
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
508 return NGX_AGAIN;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
509 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
510
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
511 ngx_mail_smtp_log_rejected_command(s, c, err);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
512
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
513 s->buffer->pos = s->buffer->start;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
514 s->buffer->last = s->buffer->start;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
515
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
516 return NGX_OK;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
517 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
518
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
519
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
520 static void
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
521 ngx_mail_smtp_log_rejected_command(ngx_mail_session_t *s, ngx_connection_t *c,
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
522 char *err)
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
523 {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
524 u_char ch;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
525 ngx_str_t cmd;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
526 ngx_uint_t i;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
527
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
528 if (c->log->log_level < NGX_LOG_INFO) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
529 return;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
530 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
531
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
532 cmd.len = s->buffer->last - s->buffer->start;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
533 cmd.data = s->buffer->start;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
534
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
535 for (i = 0; i < cmd.len; i++) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
536 ch = cmd.data[i];
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
537
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
538 if (ch != CR && ch != LF) {
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
539 continue;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
540 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
541
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
542 cmd.data[i] = '_';
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
543 }
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
544
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
545 cmd.len = i;
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
546
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
547 ngx_log_error(NGX_LOG_INFO, c->log, 0, err, &cmd);
f70f2f565fe0 nginx 0.5.33
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
548 }