comparison src/imap/ngx_imap_auth_http_module.c @ 250:fbf2b2f66c9f NGINX_0_4_10

nginx 0.4.10 *) Feature: the POP3 proxy supports the APOP command. *) Bugfix: if the select, poll or /dev/poll methods were used, then while waiting authentication server response the IMAP/POP3 proxy hogged CPU. *) Bugfix: a segmentation fault might occur if the $server_addr variable was used in the "map" directive. *) Bugfix: the ngx_http_flv_module did not support the byte ranges for full responses; bug appeared in 0.4.7. *) Bugfix: nginx could not be built on Debian amd64; bug appeared in 0.4.9.
author Igor Sysoev <http://sysoev.ru>
date Mon, 23 Oct 2006 00:00:00 +0400
parents 13710a1813ad
children 644510700914
comparison
equal deleted inserted replaced
249:7a34085272cb 250:fbf2b2f66c9f
129 NULL, /* exit master */ 129 NULL, /* exit master */
130 NGX_MODULE_V1_PADDING 130 NGX_MODULE_V1_PADDING
131 }; 131 };
132 132
133 133
134 static char *ngx_imap_auth_http_protocol[] = { "pop3", "imap" }; 134 static char *ngx_imap_auth_http_protocol[] = { "pop3", "imap" };
135 static ngx_str_t ngx_imap_auth_http_method[] = {
136 ngx_string("plain"), ngx_string("apop")
137 };
135 138
136 139
137 void 140 void
138 ngx_imap_auth_http_init(ngx_imap_session_t *s) 141 ngx_imap_auth_http_init(ngx_imap_session_t *s)
139 { 142 {
246 if (n == size) { 249 if (n == size) {
247 wev->handler = ngx_imap_auth_http_dummy_handler; 250 wev->handler = ngx_imap_auth_http_dummy_handler;
248 251
249 if (wev->timer_set) { 252 if (wev->timer_set) {
250 ngx_del_timer(wev); 253 ngx_del_timer(wev);
254 }
255
256 if (ngx_handle_write_event(wev, 0) == NGX_ERROR) {
257 ngx_close_connection(ctx->peer.connection);
258 ngx_destroy_pool(ctx->pool);
259 ngx_imap_session_internal_server_error(s);
251 } 260 }
252 261
253 return; 262 return;
254 } 263 }
255 } 264 }
550 ngx_memcpy(s->login.data, ctx->header_start, s->login.len); 559 ngx_memcpy(s->login.data, ctx->header_start, s->login.len);
551 560
552 continue; 561 continue;
553 } 562 }
554 563
564 if (len == sizeof("Auth-Pass") - 1
565 && ngx_strncasecmp(ctx->header_name_start, "Auth-Pass",
566 sizeof("Auth-Pass") - 1) == 0)
567 {
568 s->passwd.len = ctx->header_end - ctx->header_start;
569
570 s->passwd.data = ngx_palloc(s->connection->pool, s->passwd.len);
571 if (s->passwd.data == NULL) {
572 ngx_close_connection(ctx->peer.connection);
573 ngx_destroy_pool(ctx->pool);
574 ngx_imap_session_internal_server_error(s);
575 return;
576 }
577
578 ngx_memcpy(s->passwd.data, ctx->header_start, s->passwd.len);
579
580 continue;
581 }
582
555 if (len == sizeof("Auth-Wait") - 1 583 if (len == sizeof("Auth-Wait") - 1
556 && ngx_strncasecmp(ctx->header_name_start, "Auth-Wait", 584 && ngx_strncasecmp(ctx->header_name_start, "Auth-Wait",
557 sizeof("Auth-Wait") - 1) == 0) 585 sizeof("Auth-Wait") - 1) == 0)
558 { 586 {
559 n = ngx_atoi(ctx->header_start, 587 n = ngx_atoi(ctx->header_start,
600 } 628 }
601 629
602 if (ctx->addr.len == 0 || ctx->port.len == 0) { 630 if (ctx->addr.len == 0 || ctx->port.len == 0) {
603 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, 631 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
604 "auth http server %V did not send server or port", 632 "auth http server %V did not send server or port",
633 &ctx->peer.peers->peer[0].name);
634 ngx_destroy_pool(ctx->pool);
635 ngx_imap_session_internal_server_error(s);
636 return;
637 }
638
639 if (s->passwd.data == NULL) {
640 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
641 "auth http server %V did not send password",
605 &ctx->peer.peers->peer[0].name); 642 &ctx->peer.peers->peer[0].name);
606 ngx_destroy_pool(ctx->pool); 643 ngx_destroy_pool(ctx->pool);
607 ngx_imap_session_internal_server_error(s); 644 ngx_imap_session_internal_server_error(s);
608 return; 645 return;
609 } 646 }
722 759
723 } else { 760 } else {
724 s->imap_state = ngx_imap_start; 761 s->imap_state = ngx_imap_start;
725 s->connection->read->handler = ngx_imap_auth_state; 762 s->connection->read->handler = ngx_imap_auth_state;
726 } 763 }
764
765 s->auth_method = NGX_IMAP_AUTH_PLAIN;
727 766
728 c->log->action = "in auth state"; 767 c->log->action = "in auth state";
729 768
730 ngx_imap_send(s->connection->write); 769 ngx_imap_send(s->connection->write);
731 770
999 len = sizeof("GET ") - 1 + ahcf->uri.len + sizeof(" HTTP/1.0" CRLF) - 1 1038 len = sizeof("GET ") - 1 + ahcf->uri.len + sizeof(" HTTP/1.0" CRLF) - 1
1000 + sizeof("Host: ") - 1 + ahcf->host_header.len + sizeof(CRLF) - 1 1039 + sizeof("Host: ") - 1 + ahcf->host_header.len + sizeof(CRLF) - 1
1001 + sizeof("Auth-Method: plain" CRLF) - 1 1040 + sizeof("Auth-Method: plain" CRLF) - 1
1002 + sizeof("Auth-User: ") - 1 + login.len + sizeof(CRLF) - 1 1041 + sizeof("Auth-User: ") - 1 + login.len + sizeof(CRLF) - 1
1003 + sizeof("Auth-Pass: ") - 1 + passwd.len + sizeof(CRLF) - 1 1042 + sizeof("Auth-Pass: ") - 1 + passwd.len + sizeof(CRLF) - 1
1043 + sizeof("Auth-Salt: ") - 1 + s->salt.len
1004 + sizeof("Auth-Protocol: imap" CRLF) - 1 1044 + sizeof("Auth-Protocol: imap" CRLF) - 1
1005 + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN 1045 + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN
1006 + sizeof(CRLF) - 1 1046 + sizeof(CRLF) - 1
1007 + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len 1047 + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len
1008 + sizeof(CRLF) - 1 1048 + sizeof(CRLF) - 1
1021 b->last = ngx_cpymem(b->last, "Host: ", sizeof("Host: ") - 1); 1061 b->last = ngx_cpymem(b->last, "Host: ", sizeof("Host: ") - 1);
1022 b->last = ngx_copy(b->last, ahcf->host_header.data, 1062 b->last = ngx_copy(b->last, ahcf->host_header.data,
1023 ahcf->host_header.len); 1063 ahcf->host_header.len);
1024 *b->last++ = CR; *b->last++ = LF; 1064 *b->last++ = CR; *b->last++ = LF;
1025 1065
1026 b->last = ngx_cpymem(b->last, "Auth-Method: plain" CRLF, 1066 b->last = ngx_cpymem(b->last, "Auth-Method: ",
1027 sizeof("Auth-Method: plain" CRLF) - 1); 1067 sizeof("Auth-Method: ") - 1);
1068 b->last = ngx_cpymem(b->last,
1069 ngx_imap_auth_http_method[s->auth_method].data,
1070 ngx_imap_auth_http_method[s->auth_method].len);
1071 *b->last++ = CR; *b->last++ = LF;
1028 1072
1029 b->last = ngx_cpymem(b->last, "Auth-User: ", sizeof("Auth-User: ") - 1); 1073 b->last = ngx_cpymem(b->last, "Auth-User: ", sizeof("Auth-User: ") - 1);
1030 b->last = ngx_copy(b->last, login.data, login.len); 1074 b->last = ngx_copy(b->last, login.data, login.len);
1031 *b->last++ = CR; *b->last++ = LF; 1075 *b->last++ = CR; *b->last++ = LF;
1032 1076
1033 b->last = ngx_cpymem(b->last, "Auth-Pass: ", sizeof("Auth-Pass: ") - 1); 1077 b->last = ngx_cpymem(b->last, "Auth-Pass: ", sizeof("Auth-Pass: ") - 1);
1034 b->last = ngx_copy(b->last, passwd.data, passwd.len); 1078 b->last = ngx_copy(b->last, passwd.data, passwd.len);
1035 *b->last++ = CR; *b->last++ = LF; 1079 *b->last++ = CR; *b->last++ = LF;
1080
1081 if (s->salt.len) {
1082 b->last = ngx_cpymem(b->last, "Auth-Salt: ", sizeof("Auth-Salt: ") - 1);
1083 b->last = ngx_copy(b->last, s->salt.data, s->salt.len);
1084
1085 s->passwd.data = NULL;
1086 }
1036 1087
1037 b->last = ngx_cpymem(b->last, "Auth-Protocol: ", 1088 b->last = ngx_cpymem(b->last, "Auth-Protocol: ",
1038 sizeof("Auth-Protocol: ") - 1); 1089 sizeof("Auth-Protocol: ") - 1);
1039 b->last = ngx_cpymem(b->last, ngx_imap_auth_http_protocol[s->protocol], 1090 b->last = ngx_cpymem(b->last, ngx_imap_auth_http_protocol[s->protocol],
1040 sizeof("imap") - 1); 1091 sizeof("imap") - 1);