Mercurial > hg > nginx-vendor-current
diff 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 |
line wrap: on
line diff
--- a/src/http/modules/ngx_http_userid_filter_module.c +++ b/src/http/modules/ngx_http_userid_filter_module.c @@ -55,7 +55,10 @@ static size_t ngx_http_userid_log_uid_se static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op); -static ngx_int_t ngx_http_userid_add_log_formats(ngx_conf_t *cf); +static ngx_int_t ngx_http_userid_add_variables(ngx_conf_t *cf); +static ngx_int_t ngx_http_userid_variable(ngx_http_request_t *r, + ngx_http_variable_value_t *v, uintptr_t data); + static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle); static void *ngx_http_userid_create_conf(ngx_conf_t *cf); static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, @@ -158,7 +161,7 @@ static ngx_command_t ngx_http_userid_co ngx_http_module_t ngx_http_userid_filter_module_ctx = { - ngx_http_userid_add_log_formats, /* preconfiguration */ + ngx_http_userid_add_variables, /* preconfiguration */ NULL, /* postconfiguration */ NULL, /* create main configuration */ @@ -199,6 +202,10 @@ static ngx_http_log_op_name_t ngx_http_u }; +static ngx_str_t ngx_http_userid_got = ngx_string("uid_got"); +static ngx_str_t ngx_http_userid_set = ngx_string("uid_set"); + + static ngx_int_t ngx_http_userid_filter(ngx_http_request_t *r) { @@ -387,7 +394,7 @@ ngx_http_userid_set_uid(ngx_http_request return NGX_ERROR; } - p = ngx_cpymem(cookie, conf->name.data, conf->name.len); + p = ngx_copy(cookie, conf->name.data, conf->name.len); *p++ = '='; if (ctx->uid_got[3] == 0) { @@ -417,11 +424,9 @@ ngx_http_userid_set_uid(ngx_http_request p = ngx_http_cookie_time(p, ngx_time() + conf->expires); } - if (conf->domain.len) { - p = ngx_cpymem(p, conf->domain.data, conf->domain.len); - } + p = ngx_copy(p, conf->domain.data, conf->domain.len); - p = ngx_cpymem(p, conf->path.data, conf->path.len); + p = ngx_copy(p, conf->path.data, conf->path.len); set_cookie = ngx_list_push(&r->headers_out.headers); if (set_cookie == NULL) { @@ -489,7 +494,7 @@ ngx_http_userid_log_uid_got(ngx_http_req conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); - buf = ngx_cpymem(buf, conf->name.data, conf->name.len); + buf = ngx_copy(buf, conf->name.data, conf->name.len); *buf++ = '='; @@ -533,7 +538,7 @@ ngx_http_userid_log_uid_set(ngx_http_req conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); - buf = ngx_cpymem(buf, conf->name.data, conf->name.len); + buf = ngx_copy(buf, conf->name.data, conf->name.len); *buf++ = '='; @@ -544,10 +549,28 @@ ngx_http_userid_log_uid_set(ngx_http_req static ngx_int_t -ngx_http_userid_add_log_formats(ngx_conf_t *cf) +ngx_http_userid_add_variables(ngx_conf_t *cf) { + ngx_http_variable_t *var; ngx_http_log_op_name_t *op; + var = ngx_http_add_variable(cf, &ngx_http_userid_got, 0); + if (var == NULL) { + return NGX_ERROR; + } + + var->handler = ngx_http_userid_variable; + var->data = offsetof(ngx_http_userid_ctx_t, uid_got); + + var = ngx_http_add_variable(cf, &ngx_http_userid_set, 0); + if (var == NULL) { + return NGX_ERROR; + } + + var->handler = ngx_http_userid_variable; + var->data = offsetof(ngx_http_userid_ctx_t, uid_set); + + for (op = ngx_http_userid_log_fmt_ops; op->name.len; op++) { /* void */ } op->run = NULL; @@ -564,6 +587,42 @@ ngx_http_userid_add_log_formats(ngx_conf static ngx_int_t +ngx_http_userid_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, + uintptr_t data) +{ + uint32_t *uid; + ngx_http_userid_ctx_t *ctx; + ngx_http_userid_conf_t *conf; + + v->valid = 1; + v->no_cachable = 0; + v->not_found = 0; + + ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); + + uid = (uint32_t *) ((char *) ctx + data); + + if (ctx == NULL || uid[3] == 0) { + v->not_found = 1; + return NGX_OK; + } + + conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); + + v->len = conf->name.len + sizeof("=00001111222233334444555566667777") - 1; + v->data = ngx_palloc(r->pool, v->len); + if (v->data == NULL) { + return NGX_ERROR; + } + + ngx_sprintf(v->data, "%V=%08XD%08XD%08XD%08XD", + &conf->name, uid[0], uid[1], uid[2], uid[3]); + + return NGX_OK; +} + + +static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle) { ngx_http_next_header_filter = ngx_http_top_header_filter;