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