Mercurial > hg > nginx-quic
annotate src/mail/ngx_mail_handler.c @ 1672:bc93d5ab3e27
fix comment
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 30 Nov 2007 22:06:48 +0000 |
parents | 6535fb51976a |
children | e584e946e198 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
423
diff
changeset
|
5 |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_event.h> |
1136 | 10 #include <ngx_mail.h> |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
11 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
12 |
1136 | 13 static void ngx_mail_init_session(ngx_connection_t *c); |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 |
1136 | 15 #if (NGX_MAIL_SSL) |
16 static void ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c); | |
17 static void ngx_mail_ssl_handshake_handler(ngx_connection_t *c); | |
539 | 18 #endif |
19 | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 |
521 | 21 void |
1136 | 22 ngx_mail_init_connection(ngx_connection_t *c) |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
23 { |
641 | 24 in_addr_t in_addr; |
25 socklen_t len; | |
26 ngx_uint_t i; | |
27 struct sockaddr_in sin; | |
1136 | 28 ngx_mail_log_ctx_t *ctx; |
29 ngx_mail_in_port_t *imip; | |
30 ngx_mail_in_addr_t *imia; | |
31 ngx_mail_session_t *s; | |
32 #if (NGX_MAIL_SSL) | |
33 ngx_mail_ssl_conf_t *sslcf; | |
543 | 34 #endif |
541 | 35 |
641 | 36 |
37 /* find the server configuration for the address:port */ | |
38 | |
39 /* AF_INET only */ | |
40 | |
41 imip = c->listening->servers; | |
42 imia = imip->addrs; | |
43 | |
44 i = 0; | |
45 | |
46 if (imip->naddrs > 1) { | |
47 | |
48 /* | |
49 * There are several addresses on this port and one of them | |
50 * is the "*:port" wildcard so getsockname() is needed to determine | |
51 * the server address. | |
52 * | |
53 * AcceptEx() already gave this address. | |
54 */ | |
55 | |
56 #if (NGX_WIN32) | |
57 if (c->local_sockaddr) { | |
58 in_addr = | |
59 ((struct sockaddr_in *) c->local_sockaddr)->sin_addr.s_addr; | |
541 | 60 |
641 | 61 } else |
62 #endif | |
63 { | |
64 len = sizeof(struct sockaddr_in); | |
65 if (getsockname(c->fd, (struct sockaddr *) &sin, &len) == -1) { | |
66 ngx_connection_error(c, ngx_socket_errno, | |
67 "getsockname() failed"); | |
1136 | 68 ngx_mail_close_connection(c); |
641 | 69 return; |
70 } | |
71 | |
72 in_addr = sin.sin_addr.s_addr; | |
73 } | |
74 | |
75 /* the last address is "*" */ | |
76 | |
77 for ( /* void */ ; i < imip->naddrs - 1; i++) { | |
78 if (in_addr == imia[i].addr) { | |
79 break; | |
80 } | |
81 } | |
82 } | |
83 | |
84 | |
1136 | 85 s = ngx_pcalloc(c->pool, sizeof(ngx_mail_session_t)); |
641 | 86 if (s == NULL) { |
1136 | 87 ngx_mail_close_connection(c); |
541 | 88 return; |
577 | 89 } |
541 | 90 |
641 | 91 s->main_conf = imia[i].ctx->main_conf; |
92 s->srv_conf = imia[i].ctx->srv_conf; | |
93 | |
94 s->addr_text = &imia[i].addr_text; | |
95 | |
96 c->data = s; | |
97 s->connection = c; | |
98 | |
99 ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%ui client %V connected to %V", | |
100 c->number, &c->addr_text, s->addr_text); | |
101 | |
1136 | 102 ctx = ngx_palloc(c->pool, sizeof(ngx_mail_log_ctx_t)); |
641 | 103 if (ctx == NULL) { |
1136 | 104 ngx_mail_close_connection(c); |
641 | 105 return; |
106 } | |
107 | |
108 ctx->client = &c->addr_text; | |
109 ctx->session = s; | |
541 | 110 |
111 c->log->connection = c->number; | |
1136 | 112 c->log->handler = ngx_mail_log_error; |
641 | 113 c->log->data = ctx; |
541 | 114 c->log->action = "sending client greeting line"; |
115 | |
116 c->log_error = NGX_ERROR_INFO; | |
117 | |
1136 | 118 #if (NGX_MAIL_SSL) |
543 | 119 |
1136 | 120 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
543 | 121 |
122 if (sslcf->enable) { | |
1136 | 123 ngx_mail_ssl_init_connection(&sslcf->ssl, c); |
547 | 124 return; |
543 | 125 } |
126 | |
127 #endif | |
128 | |
1136 | 129 ngx_mail_init_session(c); |
541 | 130 } |
131 | |
132 | |
1136 | 133 #if (NGX_MAIL_SSL) |
547 | 134 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
135 void |
1136 | 136 ngx_mail_starttls_handler(ngx_event_t *rev) |
583 | 137 { |
138 ngx_connection_t *c; | |
1136 | 139 ngx_mail_session_t *s; |
140 ngx_mail_ssl_conf_t *sslcf; | |
583 | 141 |
142 c = rev->data; | |
143 s = c->data; | |
641 | 144 s->starttls = 1; |
583 | 145 |
146 c->log->action = "in starttls state"; | |
147 | |
1136 | 148 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); |
583 | 149 |
1136 | 150 ngx_mail_ssl_init_connection(&sslcf->ssl, c); |
583 | 151 } |
152 | |
153 | |
154 static void | |
1136 | 155 ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c) |
583 | 156 { |
1136 | 157 ngx_mail_session_t *s; |
158 ngx_mail_core_srv_conf_t *cscf; | |
583 | 159 |
160 if (ngx_ssl_create_connection(ssl, c, 0) == NGX_ERROR) { | |
1136 | 161 ngx_mail_close_connection(c); |
583 | 162 return; |
163 } | |
164 | |
165 if (ngx_ssl_handshake(c) == NGX_AGAIN) { | |
166 | |
641 | 167 s = c->data; |
168 | |
1136 | 169 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
583 | 170 |
171 ngx_add_timer(c->read, cscf->timeout); | |
172 | |
1136 | 173 c->ssl->handler = ngx_mail_ssl_handshake_handler; |
583 | 174 |
175 return; | |
176 } | |
177 | |
1136 | 178 ngx_mail_ssl_handshake_handler(c); |
583 | 179 } |
180 | |
181 | |
182 static void | |
1136 | 183 ngx_mail_ssl_handshake_handler(ngx_connection_t *c) |
577 | 184 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
185 ngx_mail_session_t *s; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
186 ngx_mail_core_srv_conf_t *cscf; |
641 | 187 |
547 | 188 if (c->ssl->handshaked) { |
583 | 189 |
641 | 190 s = c->data; |
191 | |
192 if (s->starttls) { | |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
193 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
194 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
195 c->read->handler = cscf->protocol->init_protocol; |
1136 | 196 c->write->handler = ngx_mail_send; |
583 | 197 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
198 cscf->protocol->init_protocol(c->read); |
583 | 199 |
200 return; | |
201 } | |
202 | |
1136 | 203 ngx_mail_init_session(c); |
547 | 204 return; |
205 } | |
206 | |
1136 | 207 ngx_mail_close_connection(c); |
547 | 208 } |
209 | |
210 #endif | |
211 | |
212 | |
213 static void | |
1136 | 214 ngx_mail_init_session(ngx_connection_t *c) |
541 | 215 { |
1136 | 216 ngx_mail_session_t *s; |
217 ngx_mail_core_srv_conf_t *cscf; | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
218 |
641 | 219 s = c->data; |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
220 |
1136 | 221 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
539 | 222 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
223 s->protocol = cscf->protocol->type; |
539 | 224 |
1136 | 225 s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_mail_max_module); |
539 | 226 if (s->ctx == NULL) { |
1136 | 227 ngx_mail_session_internal_server_error(s); |
539 | 228 return; |
229 } | |
230 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
231 c->write->handler = ngx_mail_send; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
232 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
233 cscf->protocol->init_session(s, c); |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
234 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
235 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
236 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
237 ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
238 ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
239 ngx_mail_core_srv_conf_t *cscf) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
240 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
241 s->salt.data = ngx_palloc(c->pool, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
242 sizeof(" <18446744073709551616.@>" CRLF) - 1 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
243 + NGX_TIME_T_LEN |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
244 + cscf->server_name.len); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
245 if (s->salt.data == NULL) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
246 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
247 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
248 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
249 s->salt.len = ngx_sprintf(s->salt.data, "<%ul.%T@%V>" CRLF, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
250 ngx_random(), ngx_time(), &cscf->server_name) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
251 - s->salt.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
252 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
253 return NGX_OK; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
254 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
255 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
256 |
1479 | 257 #if (NGX_MAIL_SSL) |
258 | |
259 ngx_int_t | |
260 ngx_mail_starttls_only(ngx_mail_session_t *s, ngx_connection_t *c) | |
261 { | |
262 ngx_mail_ssl_conf_t *sslcf; | |
263 | |
264 if (c->ssl) { | |
265 return 0; | |
266 } | |
267 | |
268 sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); | |
269 | |
270 if (sslcf->starttls == NGX_MAIL_STARTTLS_ONLY) { | |
271 return 1; | |
272 } | |
273 | |
274 return 0; | |
275 } | |
276 | |
277 #endif | |
278 | |
279 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
280 ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
281 ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c, ngx_uint_t n) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
282 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
283 u_char *p, *last; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
284 ngx_str_t *arg, plain; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
285 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
286 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
287 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
288 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
289 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
290 "mail auth plain: \"%V\"", &arg[n]); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
291 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
292 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
293 plain.data = ngx_palloc(c->pool, ngx_base64_decoded_length(arg[n].len)); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
294 if (plain.data == NULL){ |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
295 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
296 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
297 |
1494
6535fb51976a
fix "AUTH PLAIN [initial-response]" bug introduced in r1477
Igor Sysoev <igor@sysoev.ru>
parents:
1491
diff
changeset
|
298 if (ngx_decode_base64(&plain, &arg[n]) != NGX_OK) { |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
299 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
300 "client sent invalid base64 encoding in AUTH PLAIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
301 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
302 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
303 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
304 p = plain.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
305 last = p + plain.len; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
306 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
307 while (p < last && *p++) { /* void */ } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
308 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
309 if (p == last) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
310 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
311 "client sent invalid login in AUTH PLAIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
312 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
313 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
314 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
315 s->login.data = p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
316 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
317 while (p < last && *p) { p++; } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
318 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
319 if (p == last) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
320 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
321 "client sent invalid password in AUTH PLAIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
322 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
323 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
324 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
325 s->login.len = p++ - s->login.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
326 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
327 s->passwd.len = last - p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
328 s->passwd.data = p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
329 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
330 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
331 ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
332 "mail auth plain: \"%V\" \"%V\"", &s->login, &s->passwd); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
333 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
334 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
335 return NGX_DONE; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
336 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
337 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
338 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
339 ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
340 ngx_mail_auth_login_username(ngx_mail_session_t *s, ngx_connection_t *c) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
341 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
342 ngx_str_t *arg; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
343 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
344 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
345 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
346 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
347 "mail auth login username: \"%V\"", &arg[0]); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
348 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
349 s->login.data = ngx_palloc(c->pool, ngx_base64_decoded_length(arg[0].len)); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
350 if (s->login.data == NULL){ |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
351 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
352 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
353 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
354 if (ngx_decode_base64(&s->login, &arg[0]) != NGX_OK) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
355 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
356 "client sent invalid base64 encoding in AUTH LOGIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
357 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
358 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
359 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
360 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
361 "mail auth login username: \"%V\"", &s->login); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
362 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
363 return NGX_OK; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
364 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
365 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
366 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
367 ngx_int_t |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
368 ngx_mail_auth_login_password(ngx_mail_session_t *s, ngx_connection_t *c) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
369 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
370 ngx_str_t *arg; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
371 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
372 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
373 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
374 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
375 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
376 "mail auth login password: \"%V\"", &arg[0]); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
377 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
378 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
379 s->passwd.data = ngx_palloc(c->pool, ngx_base64_decoded_length(arg[0].len)); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
380 if (s->passwd.data == NULL){ |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
381 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
382 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
383 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
384 if (ngx_decode_base64(&s->passwd, &arg[0]) != NGX_OK) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
385 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
386 "client sent invalid base64 encoding in AUTH LOGIN command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
387 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
388 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
389 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
390 #if (NGX_DEBUG_MAIL_PASSWD) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
391 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
392 "mail auth login password: \"%V\"", &s->passwd); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
393 #endif |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
394 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
395 return NGX_DONE; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
396 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
397 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
398 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
399 ngx_int_t |
1479 | 400 ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s, ngx_connection_t *c, |
401 char *prefix, size_t len) | |
402 { | |
403 u_char *p; | |
404 ngx_str_t salt; | |
405 ngx_uint_t n; | |
406 | |
407 p = ngx_palloc(c->pool, len + ngx_base64_encoded_length(s->salt.len) + 2); | |
408 if (p == NULL) { | |
409 return NGX_ERROR; | |
410 } | |
411 | |
412 salt.data = ngx_cpymem(p, prefix, len); | |
413 s->salt.len -= 2; | |
414 | |
415 ngx_encode_base64(&salt, &s->salt); | |
416 | |
417 s->salt.len += 2; | |
418 n = len + salt.len; | |
419 p[n++] = CR; p[n++] = LF; | |
420 | |
421 s->out.len = n; | |
422 s->out.data = p; | |
423 | |
424 return NGX_OK; | |
425 } | |
426 | |
427 | |
428 ngx_int_t | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
429 ngx_mail_auth_cram_md5(ngx_mail_session_t *s, ngx_connection_t *c) |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
430 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
431 u_char *p, *last; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
432 ngx_str_t *arg; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
433 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
434 arg = s->args.elts; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
435 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
436 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
437 "mail auth cram-md5: \"%V\"", &arg[0]); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
438 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
439 s->login.data = ngx_palloc(c->pool, ngx_base64_decoded_length(arg[0].len)); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
440 if (s->login.data == NULL){ |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
441 return NGX_ERROR; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
442 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
443 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
444 if (ngx_decode_base64(&s->login, &arg[0]) != NGX_OK) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
445 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
446 "client sent invalid base64 encoding in AUTH CRAM-MD5 command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
447 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
448 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
449 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
450 p = s->login.data; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
451 last = p + s->login.len; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
452 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
453 while (p < last) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
454 if (*p++ == ' ') { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
455 s->login.len = p - s->login.data - 1; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
456 s->passwd.len = last - p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
457 s->passwd.data = p; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
458 break; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
459 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
460 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
461 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
462 if (s->passwd.len != 32) { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
463 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
464 "client sent invalid CRAM-MD5 hash in AUTH CRAM-MD5 command"); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
465 return NGX_MAIL_PARSE_INVALID_COMMAND; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
466 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
467 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
468 ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0, |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
469 "mail auth cram-md5: \"%V\" \"%V\"", &s->login, &s->passwd); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
470 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
471 s->auth_method = NGX_MAIL_AUTH_CRAM_MD5; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
472 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
473 return NGX_DONE; |
539 | 474 } |
475 | |
476 | |
477 void | |
1136 | 478 ngx_mail_send(ngx_event_t *wev) |
539 | 479 { |
541 | 480 ngx_int_t n; |
481 ngx_connection_t *c; | |
1136 | 482 ngx_mail_session_t *s; |
483 ngx_mail_core_srv_conf_t *cscf; | |
539 | 484 |
485 c = wev->data; | |
486 s = c->data; | |
487 | |
488 if (wev->timedout) { | |
489 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); | |
577 | 490 c->timedout = 1; |
1136 | 491 ngx_mail_close_connection(c); |
539 | 492 return; |
493 } | |
494 | |
495 if (s->out.len == 0) { | |
496 if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) { | |
1136 | 497 ngx_mail_close_connection(c); |
539 | 498 } |
499 | |
500 return; | |
501 } | |
502 | |
503 n = c->send(c, s->out.data, s->out.len); | |
504 | |
505 if (n > 0) { | |
506 s->out.len -= n; | |
507 | |
541 | 508 if (wev->timer_set) { |
509 ngx_del_timer(wev); | |
510 } | |
511 | |
539 | 512 if (s->quit) { |
1136 | 513 ngx_mail_close_connection(c); |
539 | 514 return; |
515 } | |
516 | |
517 if (s->blocked) { | |
518 c->read->handler(c->read); | |
519 } | |
520 | |
521 return; | |
522 } | |
523 | |
524 if (n == NGX_ERROR) { | |
1136 | 525 ngx_mail_close_connection(c); |
539 | 526 return; |
527 } | |
528 | |
529 /* n == NGX_AGAIN */ | |
530 | |
1136 | 531 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
541 | 532 |
533 ngx_add_timer(c->write, cscf->timeout); | |
534 | |
539 | 535 if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) { |
1136 | 536 ngx_mail_close_connection(c); |
539 | 537 return; |
538 } | |
413
de9d4726e28a
nginx-0.0.10-2004-08-31-23:05:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
539 } |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
540 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
541 |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
542 ngx_int_t |
1482 | 543 ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c) |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
544 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
545 ssize_t n; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
546 ngx_int_t rc; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
547 ngx_str_t l; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
548 ngx_mail_core_srv_conf_t *cscf; |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
549 |
1482 | 550 n = c->recv(c, s->buffer->last, s->buffer->end - s->buffer->last); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
551 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
552 if (n == NGX_ERROR || n == 0) { |
1482 | 553 ngx_mail_close_connection(c); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
554 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
555 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
556 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
557 if (n > 0) { |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
558 s->buffer->last += n; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
559 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
560 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
561 if (n == NGX_AGAIN) { |
1482 | 562 if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) { |
1136 | 563 ngx_mail_session_internal_server_error(s); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
564 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
565 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
566 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
567 return NGX_AGAIN; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
568 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
569 |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
570 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
571 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
572 rc = cscf->protocol->parse_command(s); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
573 |
1108
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
574 if (rc == NGX_AGAIN) { |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
575 |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
576 if (s->buffer->last < s->buffer->end) { |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
577 return rc; |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
578 } |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
579 |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
580 l.len = s->buffer->last - s->buffer->start; |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
581 l.data = s->buffer->start; |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
582 |
1482 | 583 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
1108
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
584 "client sent too long command \"%V\"", &l); |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
585 |
1111
b0fc4af1f196
close connection for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1108
diff
changeset
|
586 s->quit = 1; |
b0fc4af1f196
close connection for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1108
diff
changeset
|
587 |
1136 | 588 return NGX_MAIL_PARSE_INVALID_COMMAND; |
1108
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
589 } |
109e8c7d7cc1
return error for too long commands
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
590 |
1136 | 591 if (rc == NGX_IMAP_NEXT || rc == NGX_MAIL_PARSE_INVALID_COMMAND) { |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
592 return rc; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
593 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
594 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
595 if (rc == NGX_ERROR) { |
1482 | 596 ngx_mail_close_connection(c); |
420
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
597 return NGX_ERROR; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
598 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
599 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
600 return NGX_OK; |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
601 } |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
602 |
33a8253115b4
nginx-0.0.10-2004-09-09-22:55:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
419
diff
changeset
|
603 |
521 | 604 void |
1482 | 605 ngx_mail_auth(ngx_mail_session_t *s, ngx_connection_t *c) |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
606 { |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
607 s->args.nelts = 0; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
608 s->buffer->pos = s->buffer->start; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
609 s->buffer->last = s->buffer->start; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
610 s->state = 0; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
611 |
1482 | 612 if (c->read->timer_set) { |
613 ngx_del_timer(c->read); | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
614 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
615 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
616 s->login_attempt++; |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
617 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
618 ngx_mail_auth_http_init(s); |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
619 } |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
620 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
621 |
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
622 void |
1136 | 623 ngx_mail_session_internal_server_error(ngx_mail_session_t *s) |
525 | 624 { |
1487
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
625 ngx_mail_core_srv_conf_t *cscf; |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
626 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
627 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
628 |
f69493e8faab
ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
Igor Sysoev <igor@sysoev.ru>
parents:
1482
diff
changeset
|
629 s->out = cscf->protocol->internal_server_error; |
539 | 630 s->quit = 1; |
525 | 631 |
1136 | 632 ngx_mail_send(s->connection->write); |
525 | 633 } |
634 | |
635 | |
636 void | |
1136 | 637 ngx_mail_close_connection(ngx_connection_t *c) |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
638 { |
479 | 639 ngx_pool_t *pool; |
640 | |
1136 | 641 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, |
642 "close mail connection: %d", c->fd); | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
643 |
1136 | 644 #if (NGX_MAIL_SSL) |
539 | 645 |
646 if (c->ssl) { | |
647 if (ngx_ssl_shutdown(c) == NGX_AGAIN) { | |
1136 | 648 c->ssl->handler = ngx_mail_close_connection; |
539 | 649 return; |
650 } | |
651 } | |
652 | |
653 #endif | |
654 | |
1472
32450a2bbdf4
decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
655 #if (NGX_STAT_STUB) |
32450a2bbdf4
decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
656 ngx_atomic_fetch_add(ngx_stat_active, -1); |
32450a2bbdf4
decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
657 #endif |
32450a2bbdf4
decrement active connection counter in mail proxy
Igor Sysoev <igor@sysoev.ru>
parents:
1323
diff
changeset
|
658 |
583 | 659 c->destroyed = 1; |
543 | 660 |
479 | 661 pool = c->pool; |
662 | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
663 ngx_close_connection(c); |
479 | 664 |
501 | 665 ngx_destroy_pool(pool); |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
415
diff
changeset
|
666 } |
539 | 667 |
668 | |
1476
67578e966dcc
split pop3, imap, and smtp handlers
Igor Sysoev <igor@sysoev.ru>
parents:
1472
diff
changeset
|
669 u_char * |
1136 | 670 ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len) |
541 | 671 { |
567 | 672 u_char *p; |
1136 | 673 ngx_mail_session_t *s; |
674 ngx_mail_log_ctx_t *ctx; | |
541 | 675 |
676 if (log->action) { | |
677 p = ngx_snprintf(buf, len, " while %s", log->action); | |
678 len -= p - buf; | |
679 buf = p; | |
680 } | |
577 | 681 |
541 | 682 ctx = log->data; |
683 | |
684 p = ngx_snprintf(buf, len, ", client: %V", ctx->client); | |
685 len -= p - buf; | |
686 buf = p; | |
687 | |
688 s = ctx->session; | |
689 | |
690 if (s == NULL) { | |
691 return p; | |
692 } | |
693 | |
1491 | 694 p = ngx_snprintf(buf, len, "%s, server: %V", |
695 s->starttls ? " using starttls" : "", | |
696 s->addr_text); | |
541 | 697 len -= p - buf; |
698 buf = p; | |
699 | |
700 if (s->login.len == 0) { | |
701 return p; | |
702 } | |
703 | |
704 p = ngx_snprintf(buf, len, ", login: \"%V\"", &s->login); | |
705 len -= p - buf; | |
706 buf = p; | |
707 | |
708 if (s->proxy == NULL) { | |
709 return p; | |
710 } | |
711 | |
884 | 712 p = ngx_snprintf(buf, len, ", upstream: %V", s->proxy->upstream.name); |
541 | 713 |
714 return p; | |
715 } |