Klaus Demo nginx / 6e574b0
r2496, r2749 merge: compatibility with Microsoft's AUTH LOGIN [base64 encoded user name ] patch by Maxim Dounin Igor Sysoev 13 years ago
7 changed file(s) with 45 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
163163 unsigned no_sync_literal:1;
164164 unsigned starttls:1;
165165 unsigned esmtp:1;
166 unsigned auth_method:2;
166 unsigned auth_method:3;
167167 unsigned auth_wait:1;
168168
169169 ngx_str_t login;
242242 #define NGX_SMTP_STARTTLS 13
243243
244244
245 #define NGX_MAIL_AUTH_PLAIN 0
246 #define NGX_MAIL_AUTH_LOGIN 1
247 #define NGX_MAIL_AUTH_APOP 2
248 #define NGX_MAIL_AUTH_CRAM_MD5 3
245 #define NGX_MAIL_AUTH_PLAIN 0
246 #define NGX_MAIL_AUTH_LOGIN 1
247 #define NGX_MAIL_AUTH_LOGIN_USERNAME 2
248 #define NGX_MAIL_AUTH_APOP 3
249 #define NGX_MAIL_AUTH_CRAM_MD5 4
249250
250251
251252 #define NGX_MAIL_AUTH_PLAIN_ENABLED 0x0002
328329 ngx_int_t ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c,
329330 ngx_uint_t n);
330331 ngx_int_t ngx_mail_auth_login_username(ngx_mail_session_t *s,
331 ngx_connection_t *c);
332 ngx_connection_t *c, ngx_uint_t n);
332333 ngx_int_t ngx_mail_auth_login_password(ngx_mail_session_t *s,
333334 ngx_connection_t *c);
334335 ngx_int_t ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s,
137137
138138
139139 static ngx_str_t ngx_mail_auth_http_method[] = {
140 ngx_string("plain"),
140141 ngx_string("plain"),
141142 ngx_string("plain"),
142143 ngx_string("apop"),
334334
335335
336336 ngx_int_t
337 ngx_mail_auth_login_username(ngx_mail_session_t *s, ngx_connection_t *c)
337 ngx_mail_auth_login_username(ngx_mail_session_t *s, ngx_connection_t *c,
338 ngx_uint_t n)
338339 {
339340 ngx_str_t *arg;
340341
341342 arg = s->args.elts;
342343
343344 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
344 "mail auth login username: \"%V\"", &arg[0]);
345
346 s->login.data = ngx_palloc(c->pool, ngx_base64_decoded_length(arg[0].len));
345 "mail auth login username: \"%V\"", &arg[n]);
346
347 s->login.data = ngx_palloc(c->pool, ngx_base64_decoded_length(arg[n].len));
347348 if (s->login.data == NULL){
348349 return NGX_ERROR;
349350 }
350351
351 if (ngx_decode_base64(&s->login, &arg[0]) != NGX_OK) {
352 if (ngx_decode_base64(&s->login, &arg[n]) != NGX_OK) {
352353 ngx_log_error(NGX_LOG_INFO, c->log, 0,
353354 "client sent invalid base64 encoding in AUTH LOGIN command");
354355 return NGX_MAIL_PARSE_INVALID_COMMAND;
204204 break;
205205
206206 case ngx_imap_auth_login_username:
207 rc = ngx_mail_auth_login_username(s, c);
207 rc = ngx_mail_auth_login_username(s, c, 0);
208208
209209 tag = 0;
210210 s->out.len = sizeof(imap_password) - 1;
369369
370370 return NGX_OK;
371371
372 case NGX_MAIL_AUTH_LOGIN_USERNAME:
373
374 s->out.len = sizeof(imap_password) - 1;
375 s->out.data = imap_password;
376 s->mail_state = ngx_imap_auth_login_password;
377
378 return ngx_mail_auth_login_username(s, c, 1);
379
372380 case NGX_MAIL_AUTH_PLAIN:
373381
374382 s->out.len = sizeof(imap_plain_next) - 1;
847847 return NGX_MAIL_AUTH_LOGIN;
848848 }
849849
850 if (s->args.nelts == 2) {
851 return NGX_MAIL_AUTH_LOGIN_USERNAME;
852 }
853
850854 return NGX_MAIL_PARSE_INVALID_COMMAND;
851855 }
852856
225225 break;
226226
227227 case ngx_pop3_auth_login_username:
228 rc = ngx_mail_auth_login_username(s, c);
228 rc = ngx_mail_auth_login_username(s, c, 0);
229229
230230 s->out.len = sizeof(pop3_password) - 1;
231231 s->out.data = pop3_password;
473473
474474 return NGX_OK;
475475
476 case NGX_MAIL_AUTH_LOGIN_USERNAME:
477
478 s->out.len = sizeof(pop3_password) - 1;
479 s->out.data = pop3_password;
480 s->mail_state = ngx_pop3_auth_login_password;
481
482 return ngx_mail_auth_login_username(s, c, 1);
483
476484 case NGX_MAIL_AUTH_PLAIN:
477485
478486 s->out.len = sizeof(pop3_next) - 1;
451451 break;
452452
453453 case ngx_smtp_auth_login_username:
454 rc = ngx_mail_auth_login_username(s, c);
454 rc = ngx_mail_auth_login_username(s, c, 0);
455455
456456 s->out.len = sizeof(smtp_password) - 1;
457457 s->out.data = smtp_password;
595595
596596 return NGX_OK;
597597
598 case NGX_MAIL_AUTH_LOGIN_USERNAME:
599
600 s->out.len = sizeof(smtp_password) - 1;
601 s->out.data = smtp_password;
602 s->mail_state = ngx_smtp_auth_login_password;
603
604 return ngx_mail_auth_login_username(s, c, 1);
605
598606 case NGX_MAIL_AUTH_PLAIN:
599607
600608 s->out.len = sizeof(smtp_next) - 1;