Mercurial > hg > nginx-vendor-0-7
comparison src/imap/ngx_imap_auth_http_module.c @ 182:13710a1813ad NGINX_0_3_38
nginx 0.3.38
*) Feature: the ngx_http_dav_module.
*) Change: the ngx_http_perl_module optimizations.
Thanks to Sergey Skvortsov.
*) Feature: the ngx_http_perl_module supports the $r->request_body_file
method.
*) Feature: the "client_body_in_file_only" directive.
*) Workaround: now on disk overflow nginx tries to write access logs
once a second only.
Thanks to Anton Yuzhaninov and Maxim Dounin.
*) Bugfix: now the "limit_rate" directive more precisely limits rate if
rate is more than 100 Kbyte/s.
Thanks to ForJest.
*) Bugfix: now the IMAP/POP3 proxy escapes the "\r" and "\n" symbols in
login and password to pass authorization server.
Thanks to Maxim Dounin.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Fri, 14 Apr 2006 00:00:00 +0400 |
parents | 91372f004adf |
children | fbf2b2f66c9f |
comparison
equal
deleted
inserted
replaced
181:de8983d10e75 | 182:13710a1813ad |
---|---|
66 ngx_imap_auth_http_ctx_t *ctx); | 66 ngx_imap_auth_http_ctx_t *ctx); |
67 static void ngx_imap_auth_http_block_read(ngx_event_t *rev); | 67 static void ngx_imap_auth_http_block_read(ngx_event_t *rev); |
68 static void ngx_imap_auth_http_dummy_handler(ngx_event_t *ev); | 68 static void ngx_imap_auth_http_dummy_handler(ngx_event_t *ev); |
69 static ngx_buf_t *ngx_imap_auth_http_create_request(ngx_imap_session_t *s, | 69 static ngx_buf_t *ngx_imap_auth_http_create_request(ngx_imap_session_t *s, |
70 ngx_pool_t *pool, ngx_imap_auth_http_conf_t *ahcf); | 70 ngx_pool_t *pool, ngx_imap_auth_http_conf_t *ahcf); |
71 static ngx_int_t ngx_imap_auth_http_escape(ngx_pool_t *pool, ngx_str_t *text, | |
72 ngx_str_t *escaped); | |
71 | 73 |
72 static void *ngx_imap_auth_http_create_conf(ngx_conf_t *cf); | 74 static void *ngx_imap_auth_http_create_conf(ngx_conf_t *cf); |
73 static char *ngx_imap_auth_http_merge_conf(ngx_conf_t *cf, void *parent, | 75 static char *ngx_imap_auth_http_merge_conf(ngx_conf_t *cf, void *parent, |
74 void *child); | 76 void *child); |
75 static char *ngx_imap_auth_http(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 77 static char *ngx_imap_auth_http(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
982 ngx_imap_auth_http_create_request(ngx_imap_session_t *s, ngx_pool_t *pool, | 984 ngx_imap_auth_http_create_request(ngx_imap_session_t *s, ngx_pool_t *pool, |
983 ngx_imap_auth_http_conf_t *ahcf) | 985 ngx_imap_auth_http_conf_t *ahcf) |
984 { | 986 { |
985 size_t len; | 987 size_t len; |
986 ngx_buf_t *b; | 988 ngx_buf_t *b; |
989 ngx_str_t login, passwd; | |
990 | |
991 if (ngx_imap_auth_http_escape(pool, &s->login, &login) != NGX_OK) { | |
992 return NULL; | |
993 } | |
994 | |
995 if (ngx_imap_auth_http_escape(pool, &s->passwd, &passwd) != NGX_OK) { | |
996 return NULL; | |
997 } | |
987 | 998 |
988 len = sizeof("GET ") - 1 + ahcf->uri.len + sizeof(" HTTP/1.0" CRLF) - 1 | 999 len = sizeof("GET ") - 1 + ahcf->uri.len + sizeof(" HTTP/1.0" CRLF) - 1 |
989 + sizeof("Host: ") - 1 + ahcf->host_header.len + sizeof(CRLF) - 1 | 1000 + sizeof("Host: ") - 1 + ahcf->host_header.len + sizeof(CRLF) - 1 |
990 + sizeof("Auth-Method: plain" CRLF) - 1 | 1001 + sizeof("Auth-Method: plain" CRLF) - 1 |
991 + sizeof("Auth-User: ") - 1 + s->login.len + sizeof(CRLF) - 1 | 1002 + sizeof("Auth-User: ") - 1 + login.len + sizeof(CRLF) - 1 |
992 + sizeof("Auth-Pass: ") - 1 + s->passwd.len + sizeof(CRLF) - 1 | 1003 + sizeof("Auth-Pass: ") - 1 + passwd.len + sizeof(CRLF) - 1 |
993 + sizeof("Auth-Protocol: imap" CRLF) - 1 | 1004 + sizeof("Auth-Protocol: imap" CRLF) - 1 |
994 + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN | 1005 + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN |
995 + sizeof(CRLF) - 1 | 1006 + sizeof(CRLF) - 1 |
996 + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len | 1007 + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len |
997 + sizeof(CRLF) - 1 | 1008 + sizeof(CRLF) - 1 |
1014 | 1025 |
1015 b->last = ngx_cpymem(b->last, "Auth-Method: plain" CRLF, | 1026 b->last = ngx_cpymem(b->last, "Auth-Method: plain" CRLF, |
1016 sizeof("Auth-Method: plain" CRLF) - 1); | 1027 sizeof("Auth-Method: plain" CRLF) - 1); |
1017 | 1028 |
1018 b->last = ngx_cpymem(b->last, "Auth-User: ", sizeof("Auth-User: ") - 1); | 1029 b->last = ngx_cpymem(b->last, "Auth-User: ", sizeof("Auth-User: ") - 1); |
1019 b->last = ngx_copy(b->last, s->login.data, s->login.len); | 1030 b->last = ngx_copy(b->last, login.data, login.len); |
1020 *b->last++ = CR; *b->last++ = LF; | 1031 *b->last++ = CR; *b->last++ = LF; |
1021 | 1032 |
1022 b->last = ngx_cpymem(b->last, "Auth-Pass: ", sizeof("Auth-Pass: ") - 1); | 1033 b->last = ngx_cpymem(b->last, "Auth-Pass: ", sizeof("Auth-Pass: ") - 1); |
1023 b->last = ngx_copy(b->last, s->passwd.data, s->passwd.len); | 1034 b->last = ngx_copy(b->last, passwd.data, passwd.len); |
1024 *b->last++ = CR; *b->last++ = LF; | 1035 *b->last++ = CR; *b->last++ = LF; |
1025 | 1036 |
1026 b->last = ngx_cpymem(b->last, "Auth-Protocol: ", | 1037 b->last = ngx_cpymem(b->last, "Auth-Protocol: ", |
1027 sizeof("Auth-Protocol: ") - 1); | 1038 sizeof("Auth-Protocol: ") - 1); |
1028 b->last = ngx_cpymem(b->last, ngx_imap_auth_http_protocol[s->protocol], | 1039 b->last = ngx_cpymem(b->last, ngx_imap_auth_http_protocol[s->protocol], |
1057 | 1068 |
1058 return b; | 1069 return b; |
1059 } | 1070 } |
1060 | 1071 |
1061 | 1072 |
1073 static ngx_int_t | |
1074 ngx_imap_auth_http_escape(ngx_pool_t *pool, ngx_str_t *text, ngx_str_t *escaped) | |
1075 { | |
1076 u_char ch, *p; | |
1077 ngx_uint_t i, n; | |
1078 | |
1079 n = 0; | |
1080 | |
1081 for (i = 0; i < text->len; i++) { | |
1082 ch = text->data[i]; | |
1083 | |
1084 if (ch == CR || ch == LF) { | |
1085 n++; | |
1086 } | |
1087 } | |
1088 | |
1089 if (n == 0) { | |
1090 *escaped = *text; | |
1091 return NGX_OK; | |
1092 } | |
1093 | |
1094 escaped->len = text->len + n * 2; | |
1095 | |
1096 p = ngx_palloc(pool, escaped->len); | |
1097 if (p == NULL) { | |
1098 return NGX_ERROR; | |
1099 } | |
1100 | |
1101 escaped->data = p; | |
1102 | |
1103 for (i = 0; i < text->len; i++) { | |
1104 ch = text->data[i]; | |
1105 | |
1106 if (ch == CR) { | |
1107 *p++ = '%'; | |
1108 *p++ = '0'; | |
1109 *p++ = 'D'; | |
1110 continue; | |
1111 } | |
1112 | |
1113 if (ch == LF) { | |
1114 *p++ = '%'; | |
1115 *p++ = '0'; | |
1116 *p++ = 'A'; | |
1117 continue; | |
1118 } | |
1119 | |
1120 *p++ = ch; | |
1121 } | |
1122 | |
1123 return NGX_OK; | |
1124 } | |
1125 | |
1126 | |
1062 static void * | 1127 static void * |
1063 ngx_imap_auth_http_create_conf(ngx_conf_t *cf) | 1128 ngx_imap_auth_http_create_conf(ngx_conf_t *cf) |
1064 { | 1129 { |
1065 ngx_imap_auth_http_conf_t *ahcf; | 1130 ngx_imap_auth_http_conf_t *ahcf; |
1066 | 1131 |