47
47
ngx_http_variable_value_t *v, ngx_str_t *name, uint32_t *uid);
48
48
static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
49
49
ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf);
50
static ngx_int_t ngx_http_userid_create_uid(ngx_http_request_t *r,
51
ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf);
51
53
static ngx_int_t ngx_http_userid_add_variables(ngx_conf_t *cf);
52
54
static ngx_int_t ngx_http_userid_init(ngx_conf_t *cf);
209
211
return NGX_ERROR;
212
if (ctx->uid_got[3] != 0) {
214
if (conf->mark == '\0') {
215
return ngx_http_next_header_filter(r);
218
if (ctx->cookie.len > 23
219
&& ctx->cookie.data[22] == conf->mark
220
&& ctx->cookie.data[23] == '=')
222
return ngx_http_next_header_filter(r);
227
/* ctx->status == NGX_DECLINED */
229
214
if (ngx_http_userid_set_uid(r, ctx, conf) == NGX_OK) {
230
215
return ngx_http_next_header_filter(r);
251
ctx = ngx_http_userid_get_uid(r, conf);
236
ctx = ngx_http_userid_get_uid(r->main, conf);
253
238
if (ctx == NULL) {
254
239
return NGX_ERROR;
257
242
if (ctx->uid_got[3] != 0) {
258
return ngx_http_userid_variable(r, v, &conf->name, ctx->uid_got);
243
return ngx_http_userid_variable(r->main, v, &conf->name, ctx->uid_got);
261
/* ctx->status == NGX_DECLINED */
263
246
v->not_found = 1;
273
256
ngx_http_userid_ctx_t *ctx;
274
257
ngx_http_userid_conf_t *conf;
276
ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module);
278
if (ctx == NULL || ctx->uid_set[3] == 0) {
283
conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module);
285
return ngx_http_userid_variable(r, v, &conf->name, ctx->uid_set);
259
conf = ngx_http_get_module_loc_conf(r->main, ngx_http_userid_filter_module);
261
if (conf->enable < NGX_HTTP_USERID_V1) {
266
ctx = ngx_http_userid_get_uid(r->main, conf);
272
if (ngx_http_userid_create_uid(r->main, ctx, conf) != NGX_OK) {
276
if (ctx->uid_set[3] == 0) {
281
return ngx_http_userid_variable(r->main, v, &conf->name, ctx->uid_set);
360
356
ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
361
357
ngx_http_userid_conf_t *conf)
366
ngx_table_elt_t *set_cookie, *p3p;
368
struct sockaddr_in *sin;
370
struct sockaddr_in6 *sin6;
374
* TODO: in the threaded mode the sequencers should be in TLS and their
375
* ranges should be divided between threads
378
if (ctx->uid_got[3] == 0) {
380
if (conf->enable == NGX_HTTP_USERID_V1) {
381
if (conf->service == NGX_CONF_UNSET) {
384
ctx->uid_set[0] = conf->service;
386
ctx->uid_set[1] = (uint32_t) ngx_time();
387
ctx->uid_set[2] = start_value;
388
ctx->uid_set[3] = sequencer_v1;
389
sequencer_v1 += 0x100;
392
if (conf->service == NGX_CONF_UNSET) {
396
if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) {
400
switch (c->local_sockaddr->sa_family) {
404
sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
406
p = (u_char *) &ctx->uid_set[0];
408
*p++ = sin6->sin6_addr.s6_addr[12];
409
*p++ = sin6->sin6_addr.s6_addr[13];
410
*p++ = sin6->sin6_addr.s6_addr[14];
411
*p = sin6->sin6_addr.s6_addr[15];
415
default: /* AF_INET */
416
sin = (struct sockaddr_in *) c->local_sockaddr;
417
ctx->uid_set[0] = sin->sin_addr.s_addr;
422
ctx->uid_set[0] = htonl(conf->service);
425
ctx->uid_set[1] = htonl((uint32_t) ngx_time());
426
ctx->uid_set[2] = htonl(start_value);
427
ctx->uid_set[3] = htonl(sequencer_v2);
428
sequencer_v2 += 0x100;
429
if (sequencer_v2 < 0x03030302) {
430
sequencer_v2 = 0x03030302;
435
ctx->uid_set[0] = ctx->uid_got[0];
436
ctx->uid_set[1] = ctx->uid_got[1];
437
ctx->uid_set[2] = ctx->uid_got[2];
438
ctx->uid_set[3] = ctx->uid_got[3];
362
ngx_table_elt_t *set_cookie, *p3p;
364
if (ngx_http_userid_create_uid(r, ctx, conf) != NGX_OK) {
368
if (ctx->uid_set[3] == 0) {
441
372
len = conf->name.len + 1 + ngx_base64_encoded_length(16) + conf->path.len;
495
426
set_cookie->hash = 1;
496
set_cookie->key.len = sizeof("Set-Cookie") - 1;
497
set_cookie->key.data = (u_char *) "Set-Cookie";
427
ngx_str_set(&set_cookie->key, "Set-Cookie");
498
428
set_cookie->value.len = p - cookie;
499
429
set_cookie->value.data = cookie;
452
ngx_http_userid_create_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
453
ngx_http_userid_conf_t *conf)
456
struct sockaddr_in *sin;
459
struct sockaddr_in6 *sin6;
462
if (ctx->uid_set[3] != 0) {
466
if (ctx->uid_got[3] != 0) {
468
if (conf->mark == '\0'
469
|| (ctx->cookie.len > 23
470
&& ctx->cookie.data[22] == conf->mark
471
&& ctx->cookie.data[23] == '='))
476
ctx->uid_set[0] = ctx->uid_got[0];
477
ctx->uid_set[1] = ctx->uid_got[1];
478
ctx->uid_set[2] = ctx->uid_got[2];
479
ctx->uid_set[3] = ctx->uid_got[3];
485
* TODO: in the threaded mode the sequencers should be in TLS and their
486
* ranges should be divided between threads
489
if (conf->enable == NGX_HTTP_USERID_V1) {
490
if (conf->service == NGX_CONF_UNSET) {
493
ctx->uid_set[0] = conf->service;
495
ctx->uid_set[1] = (uint32_t) ngx_time();
496
ctx->uid_set[2] = start_value;
497
ctx->uid_set[3] = sequencer_v1;
498
sequencer_v1 += 0x100;
501
if (conf->service == NGX_CONF_UNSET) {
505
if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) {
509
switch (c->local_sockaddr->sa_family) {
513
sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
515
p = (u_char *) &ctx->uid_set[0];
517
*p++ = sin6->sin6_addr.s6_addr[12];
518
*p++ = sin6->sin6_addr.s6_addr[13];
519
*p++ = sin6->sin6_addr.s6_addr[14];
520
*p = sin6->sin6_addr.s6_addr[15];
524
default: /* AF_INET */
525
sin = (struct sockaddr_in *) c->local_sockaddr;
526
ctx->uid_set[0] = sin->sin_addr.s_addr;
531
ctx->uid_set[0] = htonl(conf->service);
534
ctx->uid_set[1] = htonl((uint32_t) ngx_time());
535
ctx->uid_set[2] = htonl(start_value);
536
ctx->uid_set[3] = htonl(sequencer_v2);
537
sequencer_v2 += 0x100;
538
if (sequencer_v2 < 0x03030302) {
539
sequencer_v2 = 0x03030302;
523
548
ngx_http_userid_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
524
549
ngx_str_t *name, uint32_t *uid)
577
602
* set by ngx_pcalloc():
579
* conf->name.len = 0;
580
* conf->name.date = NULL;
581
* conf->domain.len = 0;
582
* conf->domain.date = NULL;
583
* conf->path.len = 0;
584
* conf->path.date = NULL;
586
* conf->p3p.date = NULL;
604
* conf->name = { 0, NULL };
605
* conf->domain = { 0, NULL };
606
* conf->path = { 0, NULL };
607
* conf->p3p = { 0, NULL };
589
610
conf->enable = NGX_CONF_UNSET_UINT;