Mercurial > hg > nginx
comparison src/imap/ngx_imap_auth_http_module.c @ 800:887d8dec72dc
APOP
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 23 Oct 2006 13:10:10 +0000 |
parents | 9737d6fb1ac6 |
children | 8ee450f30c25 |
comparison
equal
deleted
inserted
replaced
799:9737d6fb1ac6 | 800:887d8dec72dc |
---|---|
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 { |
556 ngx_memcpy(s->login.data, ctx->header_start, s->login.len); | 559 ngx_memcpy(s->login.data, ctx->header_start, s->login.len); |
557 | 560 |
558 continue; | 561 continue; |
559 } | 562 } |
560 | 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 | |
561 if (len == sizeof("Auth-Wait") - 1 | 583 if (len == sizeof("Auth-Wait") - 1 |
562 && ngx_strncasecmp(ctx->header_name_start, "Auth-Wait", | 584 && ngx_strncasecmp(ctx->header_name_start, "Auth-Wait", |
563 sizeof("Auth-Wait") - 1) == 0) | 585 sizeof("Auth-Wait") - 1) == 0) |
564 { | 586 { |
565 n = ngx_atoi(ctx->header_start, | 587 n = ngx_atoi(ctx->header_start, |
606 } | 628 } |
607 | 629 |
608 if (ctx->addr.len == 0 || ctx->port.len == 0) { | 630 if (ctx->addr.len == 0 || ctx->port.len == 0) { |
609 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, | 631 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, |
610 "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", | |
611 &ctx->peer.peers->peer[0].name); | 642 &ctx->peer.peers->peer[0].name); |
612 ngx_destroy_pool(ctx->pool); | 643 ngx_destroy_pool(ctx->pool); |
613 ngx_imap_session_internal_server_error(s); | 644 ngx_imap_session_internal_server_error(s); |
614 return; | 645 return; |
615 } | 646 } |
728 | 759 |
729 } else { | 760 } else { |
730 s->imap_state = ngx_imap_start; | 761 s->imap_state = ngx_imap_start; |
731 s->connection->read->handler = ngx_imap_auth_state; | 762 s->connection->read->handler = ngx_imap_auth_state; |
732 } | 763 } |
764 | |
765 s->auth_method = NGX_IMAP_AUTH_PLAIN; | |
733 | 766 |
734 c->log->action = "in auth state"; | 767 c->log->action = "in auth state"; |
735 | 768 |
736 ngx_imap_send(s->connection->write); | 769 ngx_imap_send(s->connection->write); |
737 | 770 |
1005 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 |
1006 + sizeof("Host: ") - 1 + ahcf->host_header.len + sizeof(CRLF) - 1 | 1039 + sizeof("Host: ") - 1 + ahcf->host_header.len + sizeof(CRLF) - 1 |
1007 + sizeof("Auth-Method: plain" CRLF) - 1 | 1040 + sizeof("Auth-Method: plain" CRLF) - 1 |
1008 + sizeof("Auth-User: ") - 1 + login.len + sizeof(CRLF) - 1 | 1041 + sizeof("Auth-User: ") - 1 + login.len + sizeof(CRLF) - 1 |
1009 + 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 | |
1010 + sizeof("Auth-Protocol: imap" CRLF) - 1 | 1044 + sizeof("Auth-Protocol: imap" CRLF) - 1 |
1011 + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN | 1045 + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN |
1012 + sizeof(CRLF) - 1 | 1046 + sizeof(CRLF) - 1 |
1013 + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len | 1047 + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len |
1014 + sizeof(CRLF) - 1 | 1048 + sizeof(CRLF) - 1 |
1027 b->last = ngx_cpymem(b->last, "Host: ", sizeof("Host: ") - 1); | 1061 b->last = ngx_cpymem(b->last, "Host: ", sizeof("Host: ") - 1); |
1028 b->last = ngx_copy(b->last, ahcf->host_header.data, | 1062 b->last = ngx_copy(b->last, ahcf->host_header.data, |
1029 ahcf->host_header.len); | 1063 ahcf->host_header.len); |
1030 *b->last++ = CR; *b->last++ = LF; | 1064 *b->last++ = CR; *b->last++ = LF; |
1031 | 1065 |
1032 b->last = ngx_cpymem(b->last, "Auth-Method: plain" CRLF, | 1066 b->last = ngx_cpymem(b->last, "Auth-Method: ", |
1033 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; | |
1034 | 1072 |
1035 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); |
1036 b->last = ngx_copy(b->last, login.data, login.len); | 1074 b->last = ngx_copy(b->last, login.data, login.len); |
1037 *b->last++ = CR; *b->last++ = LF; | 1075 *b->last++ = CR; *b->last++ = LF; |
1038 | 1076 |
1039 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); |
1040 b->last = ngx_copy(b->last, passwd.data, passwd.len); | 1078 b->last = ngx_copy(b->last, passwd.data, passwd.len); |
1041 *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 } | |
1042 | 1087 |
1043 b->last = ngx_cpymem(b->last, "Auth-Protocol: ", | 1088 b->last = ngx_cpymem(b->last, "Auth-Protocol: ", |
1044 sizeof("Auth-Protocol: ") - 1); | 1089 sizeof("Auth-Protocol: ") - 1); |
1045 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], |
1046 sizeof("imap") - 1); | 1091 sizeof("imap") - 1); |