Mercurial > hg > nginx-vendor-0-5
comparison src/imap/ngx_imap_core_module.c @ 252:644510700914 NGINX_0_4_11
nginx 0.4.11
*) Feature: the POP3 proxy supports the AUTH LOGIN PLAIN and CRAM-MD5.
*) Feature: the ngx_http_perl_module supports the $r->allow_ranges
method.
*) Bugfix: if the APOP was enabled in the POP3 proxy, then the
USER/PASS commands might not work; bug appeared in 0.4.10.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 25 Oct 2006 00:00:00 +0400 |
parents | fbf2b2f66c9f |
children | 251bcd11a5b8 |
comparison
equal
deleted
inserted
replaced
251:16ffa8ae5759 | 252:644510700914 |
---|---|
46 | 46 |
47 | 47 |
48 static ngx_conf_bitmask_t ngx_imap_auth_methods[] = { | 48 static ngx_conf_bitmask_t ngx_imap_auth_methods[] = { |
49 { ngx_string("plain"), NGX_IMAP_AUTH_PLAIN_ENABLED }, | 49 { ngx_string("plain"), NGX_IMAP_AUTH_PLAIN_ENABLED }, |
50 { ngx_string("apop"), NGX_IMAP_AUTH_APOP_ENABLED }, | 50 { ngx_string("apop"), NGX_IMAP_AUTH_APOP_ENABLED }, |
51 { ngx_string("cram-md5"), NGX_IMAP_AUTH_CRAM_MD5_ENABLED }, | |
51 { ngx_null_string, 0 } | 52 { ngx_null_string, 0 } |
52 }; | 53 }; |
54 | |
55 | |
56 static ngx_str_t ngx_pop3_auth_plain_capability = | |
57 ngx_string("+OK methods supported:" CRLF | |
58 "LOGIN" CRLF | |
59 "PLAIN" CRLF | |
60 "." CRLF); | |
61 | |
62 | |
63 static ngx_str_t ngx_pop3_auth_cram_md5_capability = | |
64 ngx_string("+OK methods supported:" CRLF | |
65 "LOGIN" CRLF | |
66 "PLAIN" CRLF | |
67 "CRAM-MD5" CRLF | |
68 "." CRLF); | |
69 | |
53 | 70 |
54 | 71 |
55 static ngx_command_t ngx_imap_core_commands[] = { | 72 static ngx_command_t ngx_imap_core_commands[] = { |
56 | 73 |
57 { ngx_string("server"), | 74 { ngx_string("server"), |
277 c = conf->pop3_capabilities.elts; | 294 c = conf->pop3_capabilities.elts; |
278 for (i = 0; i < conf->pop3_capabilities.nelts; i++) { | 295 for (i = 0; i < conf->pop3_capabilities.nelts; i++) { |
279 size += c[i].len + sizeof(CRLF) - 1; | 296 size += c[i].len + sizeof(CRLF) - 1; |
280 } | 297 } |
281 | 298 |
299 if (conf->auth_methods & NGX_IMAP_AUTH_CRAM_MD5_ENABLED) { | |
300 size += sizeof("SASL LOGIN PLAIN CRAM-MD5" CRLF) - 1; | |
301 | |
302 } else { | |
303 size += sizeof("SASL LOGIN PLAIN" CRLF) - 1; | |
304 } | |
305 | |
282 p = ngx_palloc(cf->pool, size); | 306 p = ngx_palloc(cf->pool, size); |
283 if (p == NULL) { | 307 if (p == NULL) { |
284 return NGX_CONF_ERROR; | 308 return NGX_CONF_ERROR; |
285 } | 309 } |
286 | 310 |
293 for (i = 0; i < conf->pop3_capabilities.nelts; i++) { | 317 for (i = 0; i < conf->pop3_capabilities.nelts; i++) { |
294 p = ngx_cpymem(p, c[i].data, c[i].len); | 318 p = ngx_cpymem(p, c[i].data, c[i].len); |
295 *p++ = CR; *p++ = LF; | 319 *p++ = CR; *p++ = LF; |
296 } | 320 } |
297 | 321 |
322 if (conf->auth_methods & NGX_IMAP_AUTH_CRAM_MD5_ENABLED) { | |
323 p = ngx_cpymem(p, "SASL LOGIN PLAIN CRAM-MD5" CRLF, | |
324 sizeof("SASL LOGIN PLAIN CRAM-MD5" CRLF) - 1); | |
325 | |
326 } else { | |
327 p = ngx_cpymem(p, "SASL LOGIN PLAIN" CRLF, | |
328 sizeof("SASL LOGIN PLAIN" CRLF) - 1); | |
329 } | |
330 | |
298 *p++ = '.'; *p++ = CR; *p = LF; | 331 *p++ = '.'; *p++ = CR; *p = LF; |
299 | 332 |
300 | 333 |
301 size += sizeof("STLS" CRLF) - 1; | 334 size += sizeof("STLS" CRLF) - 1; |
302 | 335 |
311 p = ngx_cpymem(p, conf->pop3_capability.data, | 344 p = ngx_cpymem(p, conf->pop3_capability.data, |
312 conf->pop3_capability.len - (sizeof("." CRLF) - 1)); | 345 conf->pop3_capability.len - (sizeof("." CRLF) - 1)); |
313 | 346 |
314 p = ngx_cpymem(p, "STLS" CRLF, sizeof("STLS" CRLF) - 1); | 347 p = ngx_cpymem(p, "STLS" CRLF, sizeof("STLS" CRLF) - 1); |
315 *p++ = '.'; *p++ = CR; *p = LF; | 348 *p++ = '.'; *p++ = CR; *p = LF; |
349 | |
350 | |
351 if (conf->auth_methods & NGX_IMAP_AUTH_CRAM_MD5_ENABLED) { | |
352 conf->pop3_auth_capability = ngx_pop3_auth_cram_md5_capability; | |
353 | |
354 } else { | |
355 conf->pop3_auth_capability = ngx_pop3_auth_plain_capability; | |
356 } | |
316 | 357 |
317 | 358 |
318 if (conf->imap_capabilities.nelts == 0) { | 359 if (conf->imap_capabilities.nelts == 0) { |
319 conf->imap_capabilities = prev->imap_capabilities; | 360 conf->imap_capabilities = prev->imap_capabilities; |
320 } | 361 } |
469 /* AF_INET only */ | 510 /* AF_INET only */ |
470 | 511 |
471 static char * | 512 static char * |
472 ngx_imap_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 513 ngx_imap_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
473 { | 514 { |
474 char *err; | |
475 ngx_str_t *value; | 515 ngx_str_t *value; |
476 in_addr_t in_addr; | 516 ngx_url_t u; |
477 ngx_uint_t i; | 517 ngx_uint_t i; |
478 struct hostent *h; | |
479 ngx_imap_listen_t *imls; | 518 ngx_imap_listen_t *imls; |
480 ngx_inet_upstream_t inet_upstream; | |
481 ngx_imap_core_main_conf_t *cmcf; | 519 ngx_imap_core_main_conf_t *cmcf; |
482 | 520 |
483 value = cf->args->elts; | 521 value = cf->args->elts; |
484 | 522 |
485 ngx_memzero(&inet_upstream, sizeof(ngx_inet_upstream_t)); | 523 ngx_memzero(&u, sizeof(ngx_url_t)); |
486 | 524 |
487 inet_upstream.url = value[1]; | 525 u.url = value[1]; |
488 inet_upstream.port_only = 1; | 526 u.listen = 1; |
489 | 527 |
490 err = ngx_inet_parse_host_port(&inet_upstream); | 528 if (ngx_parse_url(cf, &u) != NGX_OK) { |
491 | 529 if (u.err) { |
492 if (err) { | 530 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
531 "%s in \"%V\" of the \"listen\" directive", | |
532 u.err, &u.url); | |
533 } | |
534 | |
535 return NGX_CONF_ERROR; | |
536 } | |
537 | |
538 cmcf = ngx_imap_conf_get_module_main_conf(cf, ngx_imap_core_module); | |
539 | |
540 imls = cmcf->listen.elts; | |
541 | |
542 for (i = 0; i < cmcf->listen.nelts; i++) { | |
543 | |
544 if (imls[i].addr != u.addr.in_addr || imls[i].port != u.portn) { | |
545 continue; | |
546 } | |
547 | |
493 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 548 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
494 "%s in \"%V\" of the \"listen\" directive", | 549 "duplicate \"%V\" address and port pair", &u.url); |
495 err, &inet_upstream.url); | |
496 return NGX_CONF_ERROR; | |
497 } | |
498 | |
499 if (inet_upstream.host.len == 1 && inet_upstream.host.data[0] == '*') { | |
500 inet_upstream.host.len = 0; | |
501 } | |
502 | |
503 if (inet_upstream.host.len) { | |
504 inet_upstream.host.data[inet_upstream.host.len] = '\0'; | |
505 | |
506 in_addr = inet_addr((const char *) inet_upstream.host.data); | |
507 | |
508 if (in_addr == INADDR_NONE) { | |
509 h = gethostbyname((const char *) inet_upstream.host.data); | |
510 | |
511 if (h == NULL || h->h_addr_list[0] == NULL) { | |
512 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
513 "can not resolve host \"%s\" " | |
514 "in the \"listen\" directive", | |
515 inet_upstream.host.data); | |
516 return NGX_CONF_ERROR; | |
517 } | |
518 | |
519 in_addr = *(in_addr_t *)(h->h_addr_list[0]); | |
520 } | |
521 | |
522 } else { | |
523 in_addr = INADDR_ANY; | |
524 } | |
525 | |
526 cmcf = ngx_imap_conf_get_module_main_conf(cf, ngx_imap_core_module); | |
527 | |
528 imls = cmcf->listen.elts; | |
529 | |
530 for (i = 0; i < cmcf->listen.nelts; i++) { | |
531 | |
532 if (imls[i].addr != in_addr || imls[i].port != inet_upstream.port) { | |
533 continue; | |
534 } | |
535 | |
536 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
537 "duplicate \"%V\" address and port pair", | |
538 &inet_upstream.url); | |
539 return NGX_CONF_ERROR; | 550 return NGX_CONF_ERROR; |
540 } | 551 } |
541 | 552 |
542 imls = ngx_array_push(&cmcf->listen); | 553 imls = ngx_array_push(&cmcf->listen); |
543 if (imls == NULL) { | 554 if (imls == NULL) { |
544 return NGX_CONF_ERROR; | 555 return NGX_CONF_ERROR; |
545 } | 556 } |
546 | 557 |
547 ngx_memzero(imls, sizeof(ngx_imap_listen_t)); | 558 ngx_memzero(imls, sizeof(ngx_imap_listen_t)); |
548 | 559 |
549 imls->addr = in_addr; | 560 imls->addr = u.addr.in_addr; |
550 imls->port = inet_upstream.port; | 561 imls->port = u.portn; |
551 imls->family = AF_INET; | 562 imls->family = AF_INET; |
552 imls->ctx = cf->ctx; | 563 imls->ctx = cf->ctx; |
553 | 564 |
554 if (cf->args->nelts == 2) { | 565 if (cf->args->nelts == 2) { |
555 return NGX_CONF_OK; | 566 return NGX_CONF_OK; |