Welcome! Log In Create A New Profile

Advanced

Проброс AUTH PLAIN в SMTP-прокси

January 31, 2010 06:17AM
Встала задача сделать SMTP-прокси с поддержкой TLS на незащищенный сервер с пробросом AUTH PLAIN

Готового решения не нашел, налабал маленький патчик для nginx для поддержки этой возможности.
Сильно в идеологию не вникал, так что ногами не бить.

Где прикрепляется файл не нашел, постю прямо сюда.
Патч к версии 0.7.64. Воможно в нем некорректно отдается клиенту ошибка авторизации на сервере, но мне это не требовалось.

[code]
--- ngx_mail.h.orig 2010-01-31 11:49:35.000000000 +0300
+++ ngx_mail.h 2010-01-31 12:47:40.000000000 +0300
@@ -209,6 +209,7 @@ typedef struct {

ngx_str_t login;
ngx_str_t passwd;
+ ngx_str_t auth_plain;

ngx_str_t salt;
ngx_str_t tag;
--- ngx_mail_handler.c~ 2009-06-22 13:31:33.000000000 +0400
+++ ngx_mail_handler.c 2010-01-31 12:55:38.000000000 +0300
@@ -345,6 +345,7 @@ ngx_mail_auth_plain(ngx_mail_session_t *
"mail auth plain: \"%V\"", &arg[n]);
#endif

+
plain.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len));
if (plain.data == NULL){
return NGX_ERROR;
@@ -382,6 +383,15 @@ ngx_mail_auth_plain(ngx_mail_session_t *
s->passwd.len = last - p;
s->passwd.data = p;

+ /* Saving AUTH PLAIN arg for later use in SMTP proxy */
+ s->auth_plain.len = arg[n].len;
+ s->auth_plain.data = ngx_pnalloc(c->pool, s->auth_plain.len);
+ if(s->auth_plain.data == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_cpystrn(s->auth_plain.data, arg[n].data, s->auth_plain.len);
+
#if (NGX_DEBUG_MAIL_PASSWD)
ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0,
"mail auth plain: \"%V\" \"%V\"", &s->login, &s->passwd);
--- ngx_mail_proxy_module.c.orig 2010-01-31 12:16:37.000000000 +0300
+++ ngx_mail_proxy_module.c 2010-01-31 13:03:46.000000000 +0300
@@ -527,6 +527,9 @@ ngx_mail_proxy_smtp_handler(ngx_event_t
} else if (s->auth_method == NGX_MAIL_AUTH_NONE) {
s->mail_state = ngx_smtp_helo_from;

+ } else if (s->auth_method == NGX_MAIL_AUTH_PLAIN) {
+ s->mail_state = ngx_smtp_auth_plain;
+
} else {
s->mail_state = ngx_smtp_helo;
}
@@ -632,6 +635,29 @@ ngx_mail_proxy_smtp_handler(ngx_event_t

break;

+ case ngx_smtp_auth_plain:
+ ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "SMTP plain auth send");
+
+ s->connection->log->action = "sending plain auth to upstream";
+ if(s->auth_plain.data == NULL || s->auth_plain.len == 0) {
+ ngx_mail_proxy_internal_server_error(s);
+ }
+
+ line.len = sizeof("AUTH PLAIN" CRLF) + s->auth_plain.len;
+ line.data = ngx_pnalloc(c->pool, line.len);
+
+ if (line.data == NULL) {
+ ngx_mail_proxy_internal_server_error(s);
+ return;
+ }
+
+ p = ngx_cpymem(line.data, "AUTH PLAIN ", sizeof("AUTH PLAIN ") - 1);
+ p = ngx_cpymem(p, s->auth_plain.data, s->auth_plain.len);
+ *p++ = CR; *p = LF;
+
+ s->mail_state = ngx_smtp_to;
+ break;
+
case ngx_smtp_helo:
case ngx_smtp_xclient:
case ngx_smtp_to:
@@ -793,6 +819,7 @@ ngx_mail_proxy_read_response(ngx_mail_se
case ngx_smtp_helo_xclient:
case ngx_smtp_helo_from:
case ngx_smtp_from:
+ case ngx_smtp_auth_plain:
if (p[0] == '2' && p[1] == '5' && p[2] == '0') {
return NGX_OK;
}
[/code]
Subject Author Posted

Проброс AUTH PLAIN в SMTP-прокси

kelav January 31, 2010 06:17AM

Re: Проброс AUTH PLAIN в SMTP-прокси

Maxim Dounin January 31, 2010 08:28AM

Re: Проброс AUTH PLAIN в SMTP-прокси

kelav January 31, 2010 09:24AM

Re: Проброс AUTH PLAIN в SMTP-прокси

Богун Дмитрий January 31, 2010 01:22PM

Re: Проброс AUTH PLAIN в SMTP-прокси

kelav January 31, 2010 02:49PM

Re: Проброс AUTH PLAIN в SMTP-прокси

Maxim Dounin February 01, 2010 05:46AM

Re: Проброс AUTH PLAIN в SMTP-прокси

kelav February 05, 2010 01:11PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 123
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready