Mercurial > hg > nginx-vendor-current
comparison src/http/modules/ngx_http_userid_filter_module.c @ 122:d25a1d6034f1 NGINX_0_3_8
nginx 0.3.8
*) Security: nginx now checks URI got from a backend in
"X-Accel-Redirect" header line or in SSI file for the "/../" paths
and zeroes.
*) Change: nginx now does not treat the empty user name in the
"Authorization" header line as valid one.
*) Feature: the "ssl_session_timeout" directives of the
ngx_http_ssl_module and ngx_imap_ssl_module.
*) Feature: the "auth_http_header" directive of the
ngx_imap_auth_http_module.
*) Feature: the "add_header" directive.
*) Feature: the ngx_http_realip_module.
*) Feature: the new variables to use in the "log_format" directive:
$bytes_sent, $apache_bytes_sent, $status, $time_gmt, $uri,
$request_time, $request_length, $upstream_status,
$upstream_response_time, $gzip_ratio, $uid_got, $uid_set,
$connection, $pipe, and $msec. The parameters in the "%name" form
will be canceled soon.
*) Change: now the false variable values in the "if" directive are the
empty string "" and string starting with "0".
*) Bugfix: while using proxied or FastCGI-server nginx may leave
connections and temporary files with client requests in open state.
*) Bugfix: the worker processes did not flush the buffered logs on
graceful exit.
*) Bugfix: if the request URI was changes by the "rewrite" directive
and the request was proxied in location given by regular expression,
then the incorrect request was transferred to backend; bug appeared
in 0.2.6.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" header.
*) Bugfix: nginx may stop to accept requests if the "rtsig" method and
several worker processes were used.
*) Bugfix: the "\"" and "\'" escape symbols were incorrectly handled in
SSI commands.
*) Bugfix: if the response was ended just after the SSI command and
gzipping was used, then the response did not transferred complete or
did not transferred at all.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 09 Nov 2005 00:00:00 +0300 |
parents | f63280c59dd5 |
children | df17fbafec8f |
comparison
equal
deleted
inserted
replaced
121:737953b238a4 | 122:d25a1d6034f1 |
---|---|
53 static size_t ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r, | 53 static size_t ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r, |
54 uintptr_t data); | 54 uintptr_t data); |
55 static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, | 55 static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, |
56 ngx_http_log_op_t *op); | 56 ngx_http_log_op_t *op); |
57 | 57 |
58 static ngx_int_t ngx_http_userid_add_log_formats(ngx_conf_t *cf); | 58 static ngx_int_t ngx_http_userid_add_variables(ngx_conf_t *cf); |
59 static ngx_int_t ngx_http_userid_variable(ngx_http_request_t *r, | |
60 ngx_http_variable_value_t *v, uintptr_t data); | |
61 | |
59 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle); | 62 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle); |
60 static void *ngx_http_userid_create_conf(ngx_conf_t *cf); | 63 static void *ngx_http_userid_create_conf(ngx_conf_t *cf); |
61 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, | 64 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, |
62 void *child); | 65 void *child); |
63 static char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data); | 66 static char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data); |
156 ngx_null_command | 159 ngx_null_command |
157 }; | 160 }; |
158 | 161 |
159 | 162 |
160 ngx_http_module_t ngx_http_userid_filter_module_ctx = { | 163 ngx_http_module_t ngx_http_userid_filter_module_ctx = { |
161 ngx_http_userid_add_log_formats, /* preconfiguration */ | 164 ngx_http_userid_add_variables, /* preconfiguration */ |
162 NULL, /* postconfiguration */ | 165 NULL, /* postconfiguration */ |
163 | 166 |
164 NULL, /* create main configuration */ | 167 NULL, /* create main configuration */ |
165 NULL, /* init main configuration */ | 168 NULL, /* init main configuration */ |
166 | 169 |
197 ngx_http_userid_log_uid_set }, | 200 ngx_http_userid_log_uid_set }, |
198 { ngx_null_string, 0, NULL, NULL, NULL } | 201 { ngx_null_string, 0, NULL, NULL, NULL } |
199 }; | 202 }; |
200 | 203 |
201 | 204 |
205 static ngx_str_t ngx_http_userid_got = ngx_string("uid_got"); | |
206 static ngx_str_t ngx_http_userid_set = ngx_string("uid_set"); | |
207 | |
208 | |
202 static ngx_int_t | 209 static ngx_int_t |
203 ngx_http_userid_filter(ngx_http_request_t *r) | 210 ngx_http_userid_filter(ngx_http_request_t *r) |
204 { | 211 { |
205 ngx_int_t rc; | 212 ngx_int_t rc; |
206 ngx_http_userid_ctx_t *ctx; | 213 ngx_http_userid_ctx_t *ctx; |
385 cookie = ngx_palloc(r->pool, len); | 392 cookie = ngx_palloc(r->pool, len); |
386 if (cookie == NULL) { | 393 if (cookie == NULL) { |
387 return NGX_ERROR; | 394 return NGX_ERROR; |
388 } | 395 } |
389 | 396 |
390 p = ngx_cpymem(cookie, conf->name.data, conf->name.len); | 397 p = ngx_copy(cookie, conf->name.data, conf->name.len); |
391 *p++ = '='; | 398 *p++ = '='; |
392 | 399 |
393 if (ctx->uid_got[3] == 0) { | 400 if (ctx->uid_got[3] == 0) { |
394 src.len = 16; | 401 src.len = 16; |
395 src.data = (u_char *) ctx->uid_set; | 402 src.data = (u_char *) ctx->uid_set; |
415 } else if (conf->expires) { | 422 } else if (conf->expires) { |
416 p = ngx_cpymem(p, expires, sizeof("; expires=") - 1); | 423 p = ngx_cpymem(p, expires, sizeof("; expires=") - 1); |
417 p = ngx_http_cookie_time(p, ngx_time() + conf->expires); | 424 p = ngx_http_cookie_time(p, ngx_time() + conf->expires); |
418 } | 425 } |
419 | 426 |
420 if (conf->domain.len) { | 427 p = ngx_copy(p, conf->domain.data, conf->domain.len); |
421 p = ngx_cpymem(p, conf->domain.data, conf->domain.len); | 428 |
422 } | 429 p = ngx_copy(p, conf->path.data, conf->path.len); |
423 | |
424 p = ngx_cpymem(p, conf->path.data, conf->path.len); | |
425 | 430 |
426 set_cookie = ngx_list_push(&r->headers_out.headers); | 431 set_cookie = ngx_list_push(&r->headers_out.headers); |
427 if (set_cookie == NULL) { | 432 if (set_cookie == NULL) { |
428 return NGX_ERROR; | 433 return NGX_ERROR; |
429 } | 434 } |
487 return buf + 1; | 492 return buf + 1; |
488 } | 493 } |
489 | 494 |
490 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); | 495 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); |
491 | 496 |
492 buf = ngx_cpymem(buf, conf->name.data, conf->name.len); | 497 buf = ngx_copy(buf, conf->name.data, conf->name.len); |
493 | 498 |
494 *buf++ = '='; | 499 *buf++ = '='; |
495 | 500 |
496 return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD", | 501 return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD", |
497 ctx->uid_got[0], ctx->uid_got[1], | 502 ctx->uid_got[0], ctx->uid_got[1], |
531 return buf + 1; | 536 return buf + 1; |
532 } | 537 } |
533 | 538 |
534 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); | 539 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); |
535 | 540 |
536 buf = ngx_cpymem(buf, conf->name.data, conf->name.len); | 541 buf = ngx_copy(buf, conf->name.data, conf->name.len); |
537 | 542 |
538 *buf++ = '='; | 543 *buf++ = '='; |
539 | 544 |
540 return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD", | 545 return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD", |
541 ctx->uid_set[0], ctx->uid_set[1], | 546 ctx->uid_set[0], ctx->uid_set[1], |
542 ctx->uid_set[2], ctx->uid_set[3]); | 547 ctx->uid_set[2], ctx->uid_set[3]); |
543 } | 548 } |
544 | 549 |
545 | 550 |
546 static ngx_int_t | 551 static ngx_int_t |
547 ngx_http_userid_add_log_formats(ngx_conf_t *cf) | 552 ngx_http_userid_add_variables(ngx_conf_t *cf) |
548 { | 553 { |
554 ngx_http_variable_t *var; | |
549 ngx_http_log_op_name_t *op; | 555 ngx_http_log_op_name_t *op; |
556 | |
557 var = ngx_http_add_variable(cf, &ngx_http_userid_got, 0); | |
558 if (var == NULL) { | |
559 return NGX_ERROR; | |
560 } | |
561 | |
562 var->handler = ngx_http_userid_variable; | |
563 var->data = offsetof(ngx_http_userid_ctx_t, uid_got); | |
564 | |
565 var = ngx_http_add_variable(cf, &ngx_http_userid_set, 0); | |
566 if (var == NULL) { | |
567 return NGX_ERROR; | |
568 } | |
569 | |
570 var->handler = ngx_http_userid_variable; | |
571 var->data = offsetof(ngx_http_userid_ctx_t, uid_set); | |
572 | |
550 | 573 |
551 for (op = ngx_http_userid_log_fmt_ops; op->name.len; op++) { /* void */ } | 574 for (op = ngx_http_userid_log_fmt_ops; op->name.len; op++) { /* void */ } |
552 op->run = NULL; | 575 op->run = NULL; |
553 | 576 |
554 for (op = ngx_http_log_fmt_ops; op->run; op++) { | 577 for (op = ngx_http_log_fmt_ops; op->run; op++) { |
556 op = (ngx_http_log_op_name_t *) op->run; | 579 op = (ngx_http_log_op_name_t *) op->run; |
557 } | 580 } |
558 } | 581 } |
559 | 582 |
560 op->run = (ngx_http_log_op_run_pt) ngx_http_userid_log_fmt_ops; | 583 op->run = (ngx_http_log_op_run_pt) ngx_http_userid_log_fmt_ops; |
584 | |
585 return NGX_OK; | |
586 } | |
587 | |
588 | |
589 static ngx_int_t | |
590 ngx_http_userid_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
591 uintptr_t data) | |
592 { | |
593 uint32_t *uid; | |
594 ngx_http_userid_ctx_t *ctx; | |
595 ngx_http_userid_conf_t *conf; | |
596 | |
597 v->valid = 1; | |
598 v->no_cachable = 0; | |
599 v->not_found = 0; | |
600 | |
601 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); | |
602 | |
603 uid = (uint32_t *) ((char *) ctx + data); | |
604 | |
605 if (ctx == NULL || uid[3] == 0) { | |
606 v->not_found = 1; | |
607 return NGX_OK; | |
608 } | |
609 | |
610 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); | |
611 | |
612 v->len = conf->name.len + sizeof("=00001111222233334444555566667777") - 1; | |
613 v->data = ngx_palloc(r->pool, v->len); | |
614 if (v->data == NULL) { | |
615 return NGX_ERROR; | |
616 } | |
617 | |
618 ngx_sprintf(v->data, "%V=%08XD%08XD%08XD%08XD", | |
619 &conf->name, uid[0], uid[1], uid[2], uid[3]); | |
561 | 620 |
562 return NGX_OK; | 621 return NGX_OK; |
563 } | 622 } |
564 | 623 |
565 | 624 |