comparison src/http/modules/ngx_http_userid_filter_module.c @ 58:b55cbf18157e NGINX_0_1_29

nginx 0.1.29 *) Feature: the ngx_http_ssi_module supports "include virtual" command. *) Feature: the ngx_http_ssi_module supports the condition command like 'if expr="$NAME"' and "else" and "endif" commands. Only one nested level is supported. *) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and DATE_GMT variables and "config timefmt" command. *) Feature: the "ssi_ignore_recycled_buffers" directive. *) Bugfix: the "echo" command did not show the default value for the empty QUERY_STRING variable. *) Change: the ngx_http_proxy_module was rewritten. *) Feature: the "proxy_redirect", "proxy_pass_request_headers", "proxy_pass_request_body", and "proxy_method" directives. *) Feature: the "proxy_set_header" directive. The "proxy_x_var" was canceled and must be replaced with the proxy_set_header directive. *) Change: the "proxy_preserve_host" is canceled and must be replaced with the "proxy_set_header Host $host" and the "proxy_redirect off" directives, the "proxy_set_header Host $host:$proxy_port" directive and the appropriate proxy_redirect directives. *) Change: the "proxy_set_x_real_ip" is canceled and must be replaced with the "proxy_set_header X-Real-IP $remote_addr" directive. *) Change: the "proxy_add_x_forwarded_for" is canceled and must be replaced with the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for" directive. *) Change: the "proxy_set_x_url" is canceled and must be replaced with the "proxy_set_header X-URL http://$host:$server_port$request_uri" directive. *) Feature: the "fastcgi_param" directive. *) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params" directive are canceled and must be replaced with the fastcgi_param directives. *) Feature: the "index" directive can use the variables. *) Feature: the "index" directive can be used at http and server levels. *) Change: the last index only in the "index" directive can be absolute. *) Feature: the "rewrite" directive can use the variables. *) Feature: the "internal" directive. *) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR, SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME, REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables. *) Change: nginx now passes the invalid lines in a client request headers or a backend response header. *) Bugfix: if the backend did not transfer response for a long time and the "send_timeout" was less than "proxy_read_timeout", then nginx returned the 408 response. *) Bugfix: the segmentation fault was occurred if the backend sent an invalid line in response header; bug appeared in 0.1.26. *) Bugfix: the segmentation fault may occurred in FastCGI fault tolerance configuration. *) Bugfix: the "expires" directive did not remove the previous "Expires" and "Cache-Control" headers. *) Bugfix: nginx did not take into account trailing dot in "Host" header line. *) Bugfix: the ngx_http_auth_module did not work under Linux. *) Bugfix: the rewrite directive worked incorrectly, if the arguments were in a request. *) Bugfix: nginx could not be built on MacOS X.
author Igor Sysoev <http://sysoev.ru>
date Thu, 12 May 2005 00:00:00 +0400
parents 0d75d65c642f
children e916a291e9aa
comparison
equal deleted inserted replaced
57:5df375c55338 58:b55cbf18157e
17 /* 31 Dec 2037 23:55:55 GMT */ 17 /* 31 Dec 2037 23:55:55 GMT */
18 #define NGX_HTTP_USERID_MAX_EXPIRES 2145916555 18 #define NGX_HTTP_USERID_MAX_EXPIRES 2145916555
19 19
20 20
21 typedef struct { 21 typedef struct {
22 ngx_flag_t enable; 22 ngx_uint_t enable;
23 23
24 ngx_int_t service; 24 ngx_int_t service;
25 25
26 ngx_str_t name; 26 ngx_str_t name;
27 ngx_str_t domain; 27 ngx_str_t domain;
81 { ngx_null_string, 0 } 81 { ngx_null_string, 0 }
82 }; 82 };
83 83
84 84
85 static ngx_conf_post_handler_pt ngx_http_userid_domain_p = 85 static ngx_conf_post_handler_pt ngx_http_userid_domain_p =
86 ngx_http_userid_domain; 86 ngx_http_userid_domain;
87 87
88 static ngx_conf_post_handler_pt ngx_http_userid_path_p = ngx_http_userid_path; 88 static ngx_conf_post_handler_pt ngx_http_userid_path_p = ngx_http_userid_path;
89 static ngx_conf_post_handler_pt ngx_http_userid_p3p_p = ngx_http_userid_p3p; 89 static ngx_conf_post_handler_pt ngx_http_userid_p3p_p = ngx_http_userid_p3p;
90 90
91 91
143 ngx_null_command 143 ngx_null_command
144 }; 144 };
145 145
146 146
147 ngx_http_module_t ngx_http_userid_filter_module_ctx = { 147 ngx_http_module_t ngx_http_userid_filter_module_ctx = {
148 ngx_http_userid_add_log_formats, /* pre conf */ 148 ngx_http_userid_add_log_formats, /* preconfiguration */
149 NULL, /* postconfiguration */
149 150
150 NULL, /* create main configuration */ 151 NULL, /* create main configuration */
151 NULL, /* init main configuration */ 152 NULL, /* init main configuration */
152 153
153 NULL, /* create server configuration */ 154 NULL, /* create server configuration */
157 ngx_http_userid_merge_conf /* merge location configration */ 158 ngx_http_userid_merge_conf /* merge location configration */
158 }; 159 };
159 160
160 161
161 ngx_module_t ngx_http_userid_filter_module = { 162 ngx_module_t ngx_http_userid_filter_module = {
162 NGX_MODULE, 163 NGX_MODULE_V1,
163 &ngx_http_userid_filter_module_ctx, /* module context */ 164 &ngx_http_userid_filter_module_ctx, /* module context */
164 ngx_http_userid_commands, /* module directives */ 165 ngx_http_userid_commands, /* module directives */
165 NGX_HTTP_MODULE, /* module type */ 166 NGX_HTTP_MODULE, /* module type */
166 ngx_http_userid_init, /* init module */ 167 ngx_http_userid_init, /* init module */
167 NULL /* init process */ 168 NULL /* init process */
184 { 185 {
185 ngx_int_t rc; 186 ngx_int_t rc;
186 ngx_http_userid_ctx_t *ctx; 187 ngx_http_userid_ctx_t *ctx;
187 ngx_http_userid_conf_t *conf; 188 ngx_http_userid_conf_t *conf;
188 189
190 if (r->main) {
191 return ngx_http_next_header_filter(r);
192 }
193
189 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); 194 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module);
190 195
191 if (conf->enable == NGX_HTTP_USERID_OFF) { 196 if (conf->enable == NGX_HTTP_USERID_OFF) {
192 return ngx_http_next_header_filter(r); 197 return ngx_http_next_header_filter(r);
193 } 198 }
223 228
224 static ngx_int_t 229 static ngx_int_t
225 ngx_http_userid_get_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx, 230 ngx_http_userid_get_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
226 ngx_http_userid_conf_t *conf) 231 ngx_http_userid_conf_t *conf)
227 { 232 {
228 u_char *start, *last, *end; 233 ngx_int_t n;
229 ngx_uint_t i;
230 ngx_str_t src, dst; 234 ngx_str_t src, dst;
231 ngx_table_elt_t **cookies; 235 ngx_table_elt_t **cookies;
232 236
233 cookies = r->headers_in.cookies.elts; 237 n = ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &conf->name,
234 238 &src);
235 for (i = 0; i < r->headers_in.cookies.nelts; i++) { 239 if (n == NGX_DECLINED) {
236 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 240 return NGX_OK;
237 "cookie: \"%V\"", &cookies[i]->value); 241 }
238 242
239 if (conf->name.len >= cookies[i]->value.len) { 243 if (src.len < 22) {
240 continue; 244 cookies = r->headers_in.cookies.elts;
241 } 245 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
242 246 "client sent too short userid cookie \"%V\"",
243 start = cookies[i]->value.data; 247 &cookies[n]->value);
244 end = cookies[i]->value.data + cookies[i]->value.len; 248 return NGX_OK;
245 249 }
246 while (start < end) { 250
247 251 /*
248 if (ngx_strncmp(start, conf->name.data, conf->name.len) != 0) { 252 * we have to limit encoded string to 22 characters
249 253 * because there are already the millions cookies with a garbage
250 while (start < end && *start++ != ';') { /* void */ } 254 * instead of the correct base64 trail "=="
251 while (start < end && *start == ' ') { start++; } 255 */
252 256
253 continue; 257 src.len = 22;
254 } 258
255 259 dst.data = (u_char *) ctx->uid_got;
256 start += conf->name.len; 260
257 261 if (ngx_decode_base64(&dst, &src) == NGX_ERROR) {
258 while (start < end && *start == ' ') { start++; } 262 cookies = r->headers_in.cookies.elts;
259 263 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
260 if (start == end || *start++ != '=') { 264 "client sent invalid userid cookie \"%V\"",
261 /* the invalid "Cookie" header */ 265 &cookies[n]->value);
262 break; 266 return NGX_OK;
263 } 267 }
264 268
265 while (start < end && *start == ' ') { start++; } 269 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
266 270 "uid: %08XD%08XD%08XD%08XD",
267 last = start; 271 ctx->uid_got[0], ctx->uid_got[1],
268 272 ctx->uid_got[2], ctx->uid_got[3]);
269 while (last < end && *last++ != ';') { /* void */ }
270
271 if (last - start < 22) {
272 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
273 "client sent too short userid cookie \"%V\"",
274 &cookies[i]->value);
275 break;
276 }
277
278 /*
279 * we have to limit encoded string to 22 characters
280 * because there are already the millions cookies with a garbage
281 * instead of the correct base64 trail "=="
282 */
283
284 src.len = 22;
285 src.data = start;
286 dst.data = (u_char *) ctx->uid_got;
287
288 if (ngx_decode_base64(&dst, &src) == NGX_ERROR) {
289 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
290 "client sent invalid userid cookie \"%V\"",
291 &cookies[i]->value);
292 break;
293 }
294
295 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
296 "uid: %08XD%08XD%08XD%08XD",
297 ctx->uid_got[0], ctx->uid_got[1],
298 ctx->uid_got[2], ctx->uid_got[3]);
299
300 return NGX_OK;
301 }
302 }
303 273
304 return NGX_OK; 274 return NGX_OK;
305 } 275 }
306 276
307 277
402 set_cookie = ngx_list_push(&r->headers_out.headers); 372 set_cookie = ngx_list_push(&r->headers_out.headers);
403 if (set_cookie == NULL) { 373 if (set_cookie == NULL) {
404 return NGX_ERROR; 374 return NGX_ERROR;
405 } 375 }
406 376
377 set_cookie->hash = 1;
407 set_cookie->key.len = sizeof("Set-Cookie") - 1; 378 set_cookie->key.len = sizeof("Set-Cookie") - 1;
408 set_cookie->key.data = (u_char *) "Set-Cookie"; 379 set_cookie->key.data = (u_char *) "Set-Cookie";
409 set_cookie->value.len = p - cookie; 380 set_cookie->value.len = p - cookie;
410 set_cookie->value.data = cookie; 381 set_cookie->value.data = cookie;
411 382
419 p3p = ngx_list_push(&r->headers_out.headers); 390 p3p = ngx_list_push(&r->headers_out.headers);
420 if (p3p == NULL) { 391 if (p3p == NULL) {
421 return NGX_ERROR; 392 return NGX_ERROR;
422 } 393 }
423 394
395 p3p->hash = 1;
424 p3p->key.len = sizeof("P3P") - 1; 396 p3p->key.len = sizeof("P3P") - 1;
425 p3p->key.data = (u_char *) "P3P"; 397 p3p->key.data = (u_char *) "P3P";
426 p3p->value = conf->p3p; 398 p3p->value = conf->p3p;
427 399
428 return NGX_OK; 400 return NGX_OK;
568 * conf->path.date = NULL; 540 * conf->path.date = NULL;
569 * conf->p3p.len = 0; 541 * conf->p3p.len = 0;
570 * conf->p3p.date = NULL; 542 * conf->p3p.date = NULL;
571 */ 543 */
572 544
573 conf->enable = NGX_CONF_UNSET; 545 conf->enable = NGX_CONF_UNSET_UINT;
574 conf->service = NGX_CONF_UNSET; 546 conf->service = NGX_CONF_UNSET;
575 conf->expires = NGX_CONF_UNSET; 547 conf->expires = NGX_CONF_UNSET;
576 548
577 return conf; 549 return conf;
578 } 550 }
582 ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, void *child) 554 ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, void *child)
583 { 555 {
584 ngx_http_userid_conf_t *prev = parent; 556 ngx_http_userid_conf_t *prev = parent;
585 ngx_http_userid_conf_t *conf = child; 557 ngx_http_userid_conf_t *conf = child;
586 558
587 ngx_conf_merge_value(conf->enable, prev->enable, NGX_HTTP_USERID_OFF); 559 ngx_conf_merge_unsigned_value(conf->enable, prev->enable,
560 NGX_HTTP_USERID_OFF);
588 561
589 ngx_conf_merge_str_value(conf->name, prev->name, "uid"); 562 ngx_conf_merge_str_value(conf->name, prev->name, "uid");
590 ngx_conf_merge_str_value(conf->domain, prev->domain, ""); 563 ngx_conf_merge_str_value(conf->domain, prev->domain, "");
591 ngx_conf_merge_str_value(conf->path, prev->path, "; path=/"); 564 ngx_conf_merge_str_value(conf->path, prev->path, "; path=/");
592 ngx_conf_merge_str_value(conf->p3p, prev->p3p, ""); 565 ngx_conf_merge_str_value(conf->p3p, prev->p3p, "");