Mercurial > hg > nginx-ranges
comparison src/mail/ngx_mail_auth_http_module.c @ 336:1c519aff5c0c NGINX_0_6_12
nginx 0.6.12
*) Change: mail proxy was split on three modules: pop3, imap and smtp.
*) Feature: the --without-mail_pop3_module, --without-mail_imap_module,
and --without-mail_smtp_module configuration parameters.
*) Feature: the "smtp_greeting_delay" and "smtp_client_buffer"
directives of the ngx_mail_smtp_module.
*) Bugfix: the trailing wildcards did not work; bug appeared in 0.6.9.
*) Bugfix: nginx could not start on Solaris if the shared PCRE library
located in non-standard place was used.
*) Bugfix: the "proxy_hide_header" and "fastcgi_hide_header" directives
did not hide response header lines whose name was longer than 32
characters.
Thanks to Manlio Perillo.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Fri, 21 Sep 2007 00:00:00 +0400 |
parents | 390b8f8309d6 |
children | 10cc350ed8a1 |
comparison
equal
deleted
inserted
replaced
335:9a32ae248b7a | 336:1c519aff5c0c |
---|---|
109 ngx_null_command | 109 ngx_null_command |
110 }; | 110 }; |
111 | 111 |
112 | 112 |
113 static ngx_mail_module_t ngx_mail_auth_http_module_ctx = { | 113 static ngx_mail_module_t ngx_mail_auth_http_module_ctx = { |
114 NULL, /* protocol */ | |
115 | |
114 NULL, /* create main configuration */ | 116 NULL, /* create main configuration */ |
115 NULL, /* init main configuration */ | 117 NULL, /* init main configuration */ |
116 | 118 |
117 ngx_mail_auth_http_create_conf, /* create server configuration */ | 119 ngx_mail_auth_http_create_conf, /* create server configuration */ |
118 ngx_mail_auth_http_merge_conf /* merge server configuration */ | 120 ngx_mail_auth_http_merge_conf /* merge server configuration */ |
133 NULL, /* exit master */ | 135 NULL, /* exit master */ |
134 NGX_MODULE_V1_PADDING | 136 NGX_MODULE_V1_PADDING |
135 }; | 137 }; |
136 | 138 |
137 | 139 |
138 static char *ngx_mail_auth_http_protocol[] = { "pop3", "imap", "smtp" }; | |
139 static ngx_str_t ngx_mail_auth_http_method[] = { | 140 static ngx_str_t ngx_mail_auth_http_method[] = { |
140 ngx_string("plain"), | 141 ngx_string("plain"), |
141 ngx_string("plain"), | 142 ngx_string("plain"), |
142 ngx_string("apop"), | 143 ngx_string("apop"), |
143 ngx_string("cram-md5") | 144 ngx_string("cram-md5") |
144 }; | 145 }; |
145 | 146 |
146 static ngx_str_t ngx_mail_smtp_errcode = ngx_string("535 5.7.0"); | 147 static ngx_str_t ngx_mail_smtp_errcode = ngx_string("535 5.7.0"); |
148 | |
147 | 149 |
148 void | 150 void |
149 ngx_mail_auth_http_init(ngx_mail_session_t *s) | 151 ngx_mail_auth_http_init(ngx_mail_session_t *s) |
150 { | 152 { |
151 ngx_int_t rc; | 153 ngx_int_t rc; |
237 "mail auth http write handler"); | 239 "mail auth http write handler"); |
238 | 240 |
239 if (wev->timedout) { | 241 if (wev->timedout) { |
240 ngx_log_error(NGX_LOG_ERR, wev->log, NGX_ETIMEDOUT, | 242 ngx_log_error(NGX_LOG_ERR, wev->log, NGX_ETIMEDOUT, |
241 "auth http server %V timed out", ctx->peer.name); | 243 "auth http server %V timed out", ctx->peer.name); |
242 ngx_close_connection(ctx->peer.connection); | 244 ngx_close_connection(c); |
243 ngx_destroy_pool(ctx->pool); | 245 ngx_destroy_pool(ctx->pool); |
244 ngx_mail_session_internal_server_error(s); | 246 ngx_mail_session_internal_server_error(s); |
245 return; | 247 return; |
246 } | 248 } |
247 | 249 |
248 size = ctx->request->last - ctx->request->pos; | 250 size = ctx->request->last - ctx->request->pos; |
249 | 251 |
250 n = ngx_send(c, ctx->request->pos, size); | 252 n = ngx_send(c, ctx->request->pos, size); |
251 | 253 |
252 if (n == NGX_ERROR) { | 254 if (n == NGX_ERROR) { |
253 ngx_close_connection(ctx->peer.connection); | 255 ngx_close_connection(c); |
254 ngx_destroy_pool(ctx->pool); | 256 ngx_destroy_pool(ctx->pool); |
255 ngx_mail_session_internal_server_error(s); | 257 ngx_mail_session_internal_server_error(s); |
256 return; | 258 return; |
257 } | 259 } |
258 | 260 |
265 if (wev->timer_set) { | 267 if (wev->timer_set) { |
266 ngx_del_timer(wev); | 268 ngx_del_timer(wev); |
267 } | 269 } |
268 | 270 |
269 if (ngx_handle_write_event(wev, 0) == NGX_ERROR) { | 271 if (ngx_handle_write_event(wev, 0) == NGX_ERROR) { |
270 ngx_close_connection(ctx->peer.connection); | 272 ngx_close_connection(c); |
271 ngx_destroy_pool(ctx->pool); | 273 ngx_destroy_pool(ctx->pool); |
272 ngx_mail_session_internal_server_error(s); | 274 ngx_mail_session_internal_server_error(s); |
273 } | 275 } |
274 | 276 |
275 return; | 277 return; |
300 ctx = ngx_mail_get_module_ctx(s, ngx_mail_auth_http_module); | 302 ctx = ngx_mail_get_module_ctx(s, ngx_mail_auth_http_module); |
301 | 303 |
302 if (rev->timedout) { | 304 if (rev->timedout) { |
303 ngx_log_error(NGX_LOG_ERR, rev->log, NGX_ETIMEDOUT, | 305 ngx_log_error(NGX_LOG_ERR, rev->log, NGX_ETIMEDOUT, |
304 "auth http server %V timed out", ctx->peer.name); | 306 "auth http server %V timed out", ctx->peer.name); |
305 ngx_close_connection(ctx->peer.connection); | 307 ngx_close_connection(c); |
306 ngx_destroy_pool(ctx->pool); | 308 ngx_destroy_pool(ctx->pool); |
307 ngx_mail_session_internal_server_error(s); | 309 ngx_mail_session_internal_server_error(s); |
308 return; | 310 return; |
309 } | 311 } |
310 | 312 |
311 if (ctx->response == NULL) { | 313 if (ctx->response == NULL) { |
312 ctx->response = ngx_create_temp_buf(ctx->pool, 1024); | 314 ctx->response = ngx_create_temp_buf(ctx->pool, 1024); |
313 if (ctx->response == NULL) { | 315 if (ctx->response == NULL) { |
314 ngx_close_connection(ctx->peer.connection); | 316 ngx_close_connection(c); |
315 ngx_destroy_pool(ctx->pool); | 317 ngx_destroy_pool(ctx->pool); |
316 ngx_mail_session_internal_server_error(s); | 318 ngx_mail_session_internal_server_error(s); |
317 return; | 319 return; |
318 } | 320 } |
319 } | 321 } |
331 | 333 |
332 if (n == NGX_AGAIN) { | 334 if (n == NGX_AGAIN) { |
333 return; | 335 return; |
334 } | 336 } |
335 | 337 |
336 ngx_close_connection(ctx->peer.connection); | 338 ngx_close_connection(c); |
337 ngx_destroy_pool(ctx->pool); | 339 ngx_destroy_pool(ctx->pool); |
338 ngx_mail_session_internal_server_error(s); | 340 ngx_mail_session_internal_server_error(s); |
339 } | 341 } |
340 | 342 |
341 | 343 |
747 ngx_destroy_pool(ctx->pool); | 749 ngx_destroy_pool(ctx->pool); |
748 ngx_mail_session_internal_server_error(s); | 750 ngx_mail_session_internal_server_error(s); |
749 return; | 751 return; |
750 } | 752 } |
751 | 753 |
752 if (s->passwd.data == NULL && s->protocol != NGX_MAIL_SMTP_PROTOCOL) | 754 if (s->passwd.data == NULL |
755 && s->protocol != NGX_MAIL_SMTP_PROTOCOL) | |
753 { | 756 { |
754 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, | 757 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, |
755 "auth http server %V did not send password", | 758 "auth http server %V did not send password", |
756 ctx->peer.name); | 759 ctx->peer.name); |
757 ngx_destroy_pool(ctx->pool); | 760 ngx_destroy_pool(ctx->pool); |
866 s->auth_wait = 0; | 869 s->auth_wait = 0; |
867 ngx_mail_auth_http_init(s); | 870 ngx_mail_auth_http_init(s); |
868 return; | 871 return; |
869 } | 872 } |
870 | 873 |
871 switch (s->protocol) { | 874 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); |
872 | 875 |
873 case NGX_MAIL_POP3_PROTOCOL: | 876 rev->handler = cscf->protocol->auth_state; |
874 s->mail_state = ngx_pop3_start; | 877 |
875 s->connection->read->handler = ngx_pop3_auth_state; | 878 s->mail_state = 0; |
876 break; | |
877 | |
878 case NGX_MAIL_IMAP_PROTOCOL: | |
879 s->mail_state = ngx_imap_start; | |
880 s->connection->read->handler = ngx_imap_auth_state; | |
881 break; | |
882 | |
883 default: /* NGX_MAIL_SMTP_PROTOCOL */ | |
884 s->mail_state = ngx_smtp_start; | |
885 s->connection->read->handler = ngx_smtp_auth_state; | |
886 break; | |
887 } | |
888 | |
889 s->auth_method = NGX_MAIL_AUTH_PLAIN; | 879 s->auth_method = NGX_MAIL_AUTH_PLAIN; |
890 | 880 |
891 c->log->action = "in auth state"; | 881 c->log->action = "in auth state"; |
892 | 882 |
893 ngx_mail_send(s->connection->write); | 883 ngx_mail_send(c->write); |
894 | 884 |
895 if (c->destroyed) { | 885 if (c->destroyed) { |
896 return; | 886 return; |
897 } | 887 } |
898 | 888 |
899 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); | |
900 | |
901 ngx_add_timer(rev, cscf->timeout); | 889 ngx_add_timer(rev, cscf->timeout); |
902 | 890 |
903 if (rev->ready) { | 891 if (rev->ready) { |
904 s->connection->read->handler(rev); | 892 rev->handler(rev); |
905 return; | 893 return; |
906 } | 894 } |
907 | 895 |
908 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { | 896 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { |
909 ngx_mail_close_connection(s->connection); | 897 ngx_mail_close_connection(c); |
910 } | 898 } |
911 | 899 |
912 return; | 900 return; |
913 } | 901 } |
914 | 902 |
915 if (rev->active) { | 903 if (rev->active) { |
916 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { | 904 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { |
917 ngx_mail_close_connection(s->connection); | 905 ngx_mail_close_connection(c); |
918 } | 906 } |
919 } | 907 } |
920 } | 908 } |
921 | 909 |
922 | 910 |
1145 | 1133 |
1146 static ngx_buf_t * | 1134 static ngx_buf_t * |
1147 ngx_mail_auth_http_create_request(ngx_mail_session_t *s, ngx_pool_t *pool, | 1135 ngx_mail_auth_http_create_request(ngx_mail_session_t *s, ngx_pool_t *pool, |
1148 ngx_mail_auth_http_conf_t *ahcf) | 1136 ngx_mail_auth_http_conf_t *ahcf) |
1149 { | 1137 { |
1150 size_t len; | 1138 size_t len; |
1151 ngx_buf_t *b; | 1139 ngx_buf_t *b; |
1152 ngx_str_t login, passwd; | 1140 ngx_str_t login, passwd; |
1141 ngx_mail_core_srv_conf_t *cscf; | |
1153 | 1142 |
1154 if (ngx_mail_auth_http_escape(pool, &s->login, &login) != NGX_OK) { | 1143 if (ngx_mail_auth_http_escape(pool, &s->login, &login) != NGX_OK) { |
1155 return NULL; | 1144 return NULL; |
1156 } | 1145 } |
1157 | 1146 |
1158 if (ngx_mail_auth_http_escape(pool, &s->passwd, &passwd) != NGX_OK) { | 1147 if (ngx_mail_auth_http_escape(pool, &s->passwd, &passwd) != NGX_OK) { |
1159 return NULL; | 1148 return NULL; |
1160 } | 1149 } |
1150 | |
1151 cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module); | |
1161 | 1152 |
1162 len = sizeof("GET ") - 1 + ahcf->uri.len + sizeof(" HTTP/1.0" CRLF) - 1 | 1153 len = sizeof("GET ") - 1 + ahcf->uri.len + sizeof(" HTTP/1.0" CRLF) - 1 |
1163 + sizeof("Host: ") - 1 + ahcf->host_header.len + sizeof(CRLF) - 1 | 1154 + sizeof("Host: ") - 1 + ahcf->host_header.len + sizeof(CRLF) - 1 |
1164 + sizeof("Auth-Method: ") - 1 | 1155 + sizeof("Auth-Method: ") - 1 |
1165 + ngx_mail_auth_http_method[s->auth_method].len | 1156 + ngx_mail_auth_http_method[s->auth_method].len |
1166 + sizeof(CRLF) - 1 | 1157 + sizeof(CRLF) - 1 |
1167 + sizeof("Auth-User: ") - 1 + login.len + sizeof(CRLF) - 1 | 1158 + sizeof("Auth-User: ") - 1 + login.len + sizeof(CRLF) - 1 |
1168 + sizeof("Auth-Pass: ") - 1 + passwd.len + sizeof(CRLF) - 1 | 1159 + sizeof("Auth-Pass: ") - 1 + passwd.len + sizeof(CRLF) - 1 |
1169 + sizeof("Auth-Salt: ") - 1 + s->salt.len | 1160 + sizeof("Auth-Salt: ") - 1 + s->salt.len |
1170 + sizeof("Auth-Protocol: imap" CRLF) - 1 | 1161 + sizeof("Auth-Protocol: ") - 1 + cscf->protocol->name.len |
1162 + sizeof(CRLF) - 1 | |
1171 + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN | 1163 + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN |
1172 + sizeof(CRLF) - 1 | 1164 + sizeof(CRLF) - 1 |
1173 + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len | 1165 + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len |
1174 + sizeof(CRLF) - 1 | 1166 + sizeof(CRLF) - 1 |
1175 + ahcf->header.len | 1167 + ahcf->header.len |
1212 s->passwd.data = NULL; | 1204 s->passwd.data = NULL; |
1213 } | 1205 } |
1214 | 1206 |
1215 b->last = ngx_cpymem(b->last, "Auth-Protocol: ", | 1207 b->last = ngx_cpymem(b->last, "Auth-Protocol: ", |
1216 sizeof("Auth-Protocol: ") - 1); | 1208 sizeof("Auth-Protocol: ") - 1); |
1217 b->last = ngx_cpymem(b->last, ngx_mail_auth_http_protocol[s->protocol], | 1209 b->last = ngx_cpymem(b->last, cscf->protocol->name.data, |
1218 sizeof("imap") - 1); | 1210 cscf->protocol->name.len); |
1219 *b->last++ = CR; *b->last++ = LF; | 1211 *b->last++ = CR; *b->last++ = LF; |
1220 | 1212 |
1221 b->last = ngx_sprintf(b->last, "Auth-Login-Attempt: %ui" CRLF, | 1213 b->last = ngx_sprintf(b->last, "Auth-Login-Attempt: %ui" CRLF, |
1222 s->login_attempt); | 1214 s->login_attempt); |
1223 | 1215 |