Mercurial > hg > nginx-vendor-current
comparison src/mail/ngx_mail_proxy_module.c @ 420:ad0a34a8efa6 NGINX_0_7_22
nginx 0.7.22
*) Feature: the "none" parameter in the "smtp_auth" directive.
Thanks to Maxim Dounin.
*) Feature: the "$cookie_..." variables.
*) Bugfix: the "directio" directive did not work in XFS filesystem.
*) Bugfix: the resolver did not understand big DNS responses.
Thanks to Zyb.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 20 Nov 2008 00:00:00 +0300 |
parents | 984bb0b1399b |
children | dac47e9ef0d5 |
comparison
equal
deleted
inserted
replaced
419:b986babf3f57 | 420:ad0a34a8efa6 |
---|---|
102 NULL, /* exit master */ | 102 NULL, /* exit master */ |
103 NGX_MODULE_V1_PADDING | 103 NGX_MODULE_V1_PADDING |
104 }; | 104 }; |
105 | 105 |
106 | 106 |
107 static u_char smtp_ok[] = "235 2.0.0 OK" CRLF; | 107 static u_char smtp_ok[] = "250 2.0.0 OK" CRLF; |
108 | 108 |
109 | 109 |
110 void | 110 void |
111 ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_peer_addr_t *peer) | 111 ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_peer_addr_t *peer) |
112 { | 112 { |
463 ngx_mail_proxy_smtp_handler(ngx_event_t *rev) | 463 ngx_mail_proxy_smtp_handler(ngx_event_t *rev) |
464 { | 464 { |
465 u_char *p; | 465 u_char *p; |
466 ngx_int_t rc; | 466 ngx_int_t rc; |
467 ngx_str_t line; | 467 ngx_str_t line; |
468 ngx_buf_t *b; | |
468 ngx_connection_t *c; | 469 ngx_connection_t *c; |
469 ngx_mail_session_t *s; | 470 ngx_mail_session_t *s; |
470 ngx_mail_proxy_conf_t *pcf; | 471 ngx_mail_proxy_conf_t *pcf; |
471 ngx_mail_core_srv_conf_t *cscf; | 472 ngx_mail_core_srv_conf_t *cscf; |
472 | 473 |
518 sizeof("HELO ") - 1); | 519 sizeof("HELO ") - 1); |
519 | 520 |
520 p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); | 521 p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); |
521 *p++ = CR; *p = LF; | 522 *p++ = CR; *p = LF; |
522 | 523 |
523 s->mail_state = pcf->xclient ? ngx_smtp_helo: ngx_smtp_noxclient; | 524 if (pcf->xclient) { |
524 | 525 s->mail_state = ngx_smtp_helo_xclient; |
525 break; | 526 |
526 | 527 } else if (s->auth_method == NGX_MAIL_AUTH_NONE) { |
527 case ngx_smtp_helo: | 528 s->mail_state = ngx_smtp_helo_from; |
529 | |
530 } else { | |
531 s->mail_state = ngx_smtp_helo; | |
532 } | |
533 | |
534 break; | |
535 | |
536 case ngx_smtp_helo_xclient: | |
528 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | 537 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, |
529 "mail proxy send xclient"); | 538 "mail proxy send xclient"); |
530 | 539 |
531 s->connection->log->action = "sending XCLIENT to upstream"; | 540 s->connection->log->action = "sending XCLIENT to upstream"; |
532 | 541 |
539 if (line.data == NULL) { | 548 if (line.data == NULL) { |
540 ngx_mail_proxy_internal_server_error(s); | 549 ngx_mail_proxy_internal_server_error(s); |
541 return; | 550 return; |
542 } | 551 } |
543 | 552 |
544 if (s->smtp_helo.len) { | 553 line.len = ngx_sprintf(line.data, |
545 line.len = ngx_sprintf(line.data, | 554 "XCLIENT PROTO=%sSMTP%s%V ADDR=%V%s%V NAME=%V" CRLF, |
546 "XCLIENT PROTO=%sSMTP HELO=%V ADDR=%V LOGIN=%V " | 555 (s->esmtp ? "E" : ""), |
547 "NAME=%V" CRLF, | 556 (s->smtp_helo.len ? " HELO=" : ""), &s->smtp_helo, |
548 (s->esmtp ? "E" : ""), &s->smtp_helo, | 557 &s->connection->addr_text, |
549 &s->connection->addr_text, &s->login, &s->host) | 558 (s->login.len ? " LOGIN=" : ""), &s->login, &s->host) |
550 - line.data; | 559 - line.data; |
560 | |
561 s->mail_state = (s->auth_method == NGX_MAIL_AUTH_NONE) ? | |
562 ngx_smtp_xclient_from : ngx_smtp_xclient; | |
563 | |
564 break; | |
565 | |
566 case ngx_smtp_helo_from: | |
567 case ngx_smtp_xclient_from: | |
568 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
569 "mail proxy send mail from"); | |
570 | |
571 s->connection->log->action = "sending MAIL FROM to upstream"; | |
572 | |
573 line.len = s->smtp_from.len + sizeof(CRLF) - 1; | |
574 line.data = ngx_pnalloc(c->pool, line.len); | |
575 if (line.data == NULL) { | |
576 ngx_mail_proxy_internal_server_error(s); | |
577 return; | |
578 } | |
579 | |
580 p = ngx_cpymem(line.data, s->smtp_from.data, s->smtp_from.len); | |
581 *p++ = CR; *p = LF; | |
582 | |
583 s->mail_state = ngx_smtp_from; | |
584 | |
585 break; | |
586 | |
587 case ngx_smtp_from: | |
588 ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, | |
589 "mail proxy send rcpt to"); | |
590 | |
591 s->connection->log->action = "sending RCPT TO to upstream"; | |
592 | |
593 line.len = s->smtp_to.len + sizeof(CRLF) - 1; | |
594 line.data = ngx_pnalloc(c->pool, line.len); | |
595 if (line.data == NULL) { | |
596 ngx_mail_proxy_internal_server_error(s); | |
597 return; | |
598 } | |
599 | |
600 p = ngx_cpymem(line.data, s->smtp_to.data, s->smtp_to.len); | |
601 *p++ = CR; *p = LF; | |
602 | |
603 s->mail_state = ngx_smtp_to; | |
604 | |
605 break; | |
606 | |
607 case ngx_smtp_helo: | |
608 case ngx_smtp_xclient: | |
609 case ngx_smtp_to: | |
610 | |
611 b = s->proxy->buffer; | |
612 | |
613 if (s->auth_method == NGX_MAIL_AUTH_NONE) { | |
614 b->pos = b->start; | |
615 | |
551 } else { | 616 } else { |
552 line.len = ngx_sprintf(line.data, | 617 ngx_memcpy(b->start, smtp_ok, sizeof(smtp_ok) - 1); |
553 "XCLIENT PROTO=SMTP ADDR=%V LOGIN=%V NAME=%V" CRLF, | 618 b->last = b->start + sizeof(smtp_ok) - 1; |
554 &s->connection->addr_text, &s->login, &s->host) | 619 } |
555 - line.data; | |
556 } | |
557 | |
558 s->mail_state = ngx_smtp_xclient; | |
559 break; | |
560 | |
561 case ngx_smtp_noxclient: | |
562 case ngx_smtp_xclient: | |
563 | |
564 ngx_memcpy(s->proxy->buffer->start, smtp_ok, sizeof(smtp_ok) - 1); | |
565 | |
566 s->proxy->buffer->pos = s->proxy->buffer->start; | |
567 s->proxy->buffer->last = s->proxy->buffer->start + sizeof(smtp_ok) - 1; | |
568 | 620 |
569 s->connection->read->handler = ngx_mail_proxy_handler; | 621 s->connection->read->handler = ngx_mail_proxy_handler; |
570 s->connection->write->handler = ngx_mail_proxy_handler; | 622 s->connection->write->handler = ngx_mail_proxy_handler; |
571 rev->handler = ngx_mail_proxy_handler; | 623 rev->handler = ngx_mail_proxy_handler; |
572 c->write->handler = ngx_mail_proxy_handler; | 624 c->write->handler = ngx_mail_proxy_handler; |
701 break; | 753 break; |
702 | 754 |
703 default: /* NGX_MAIL_SMTP_PROTOCOL */ | 755 default: /* NGX_MAIL_SMTP_PROTOCOL */ |
704 switch (state) { | 756 switch (state) { |
705 | 757 |
758 case ngx_smtp_start: | |
759 if (p[0] == '2' && p[1] == '2' && p[2] == '0') { | |
760 return NGX_OK; | |
761 } | |
762 break; | |
763 | |
706 case ngx_smtp_helo: | 764 case ngx_smtp_helo: |
707 case ngx_smtp_noxclient: | 765 case ngx_smtp_helo_xclient: |
766 case ngx_smtp_helo_from: | |
767 case ngx_smtp_from: | |
708 if (p[0] == '2' && p[1] == '5' && p[2] == '0') { | 768 if (p[0] == '2' && p[1] == '5' && p[2] == '0') { |
709 return NGX_OK; | 769 return NGX_OK; |
710 } | 770 } |
711 break; | 771 break; |
712 | 772 |
713 case ngx_smtp_start: | |
714 case ngx_smtp_xclient: | 773 case ngx_smtp_xclient: |
715 if (p[0] == '2' && p[1] == '2' && p[2] == '0') { | 774 case ngx_smtp_xclient_from: |
775 if (p[0] == '2' && (p[1] == '2' || p[1] == '5') && p[2] == '0') { | |
716 return NGX_OK; | 776 return NGX_OK; |
717 } | 777 } |
718 break; | 778 break; |
779 | |
780 case ngx_smtp_to: | |
781 return NGX_OK; | |
719 } | 782 } |
720 | 783 |
721 break; | 784 break; |
722 } | 785 } |
723 | 786 |