~britco/nginx/master

« back to all changes in this revision

Viewing changes to src/http/modules/ngx_http_userid_filter_module.c

  • Committer: Bazaar Package Importer
  • Author(s): Kartik Mistry, Kartik Mistry, Michael Lustfield
  • Date: 2010-11-27 21:04:02 UTC
  • mfrom: (1.3.8 upstream)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: james.westby@ubuntu.com-20101127210402-14sgjpe6r3jup8a9
Tags: 0.8.53-1
[Kartik Mistry]
* debian/control:
  + Added Michael Lustfield as co-maintainer
* nginx.conf:
  + No need to use regex in gzip_disable for msie6, Thanks to António P. P.
    Almeida <appa@perusio.net> (Closes: #592147)
* conf/sites-available/default:
  + Fixed typo for "include fastcgi", Thanks to Mostafa Ghadamyari
    <nginx@gigfa.com> (Closes: #593142, #593143)
* debian/patches/fix_reloading_ipv6.diff:
  + Removed, merged upstream
* debian/init.d:
  + Added fix to control nginx by user in a simple way by setting DAEMON
    variable to an invalid name in /etc/default/nginx. Patch by Toni Mueller
    <support@oeko.net> (Closes: #594598)
* debian/NEWS.Debian:
  + Updated news for 0.8.x as stable branch

[Michael Lustfield]
* New upstream release (Closes: #602970)
  + 0.8.x branch is declared stable by upstream now
* Add a UFW profile set:
  + debian/nginx.ufw.profile: Added.
  + debian/control: nginx: Suggests ufw.
  + debian/dirs: Add 'etc/ufw/applications.d'
  + debian/rules: Add install rule for the nginx UFW profile.
* Moved debian/dirs to debian/nginx.dirs
* Added types_hash_max_size to nginx.conf
* Install simple default index.html file (Closes: #581416)
  + debian/dirs: Add 'usr/share/nginx/www'.
  + debian/nginx.install: Add 'html/* usr/share/nginx/www'.
* debian/patches/nginx-echo.diff:
  + Added Echo module
* Added files for nginx.docs
  - /usr/share/doc/nginx/
    + debian/help/docs/fcgiwrap
    + debian/help/docs/php
    + debian/help/docs/support-irc
    + debian/help/docs/upstream
* Added files for nginx.examples
  - /usr/share/doc/nginx/examples/
    + debian/help/docs/drupal
    + debian/help/docs/http
    + debian/help/docs/mail
    + debian/help/docs/mailman
    + debian/help/docs/nginx.conf
    + debian/help/docs/virtual_hosts
    + debian/help/docs/wordpress
* debian/conf/:
  + Removed excess spaces
  + Added tabs where appropriate
  + Added SCRIPT_FILENAME to fastcgi_params

Show diffs side-by-side

added added

removed removed

Lines of Context:
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);
50
52
 
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);
199
201
 
200
202
    conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module);
201
203
 
202
 
    if (conf->enable <= NGX_HTTP_USERID_LOG) {
 
204
    if (conf->enable < NGX_HTTP_USERID_V1) {
203
205
        return ngx_http_next_header_filter(r);
204
206
    }
205
207
 
209
211
        return NGX_ERROR;
210
212
    }
211
213
 
212
 
    if (ctx->uid_got[3] != 0) {
213
 
 
214
 
        if (conf->mark == '\0') {
215
 
            return ngx_http_next_header_filter(r);
216
 
 
217
 
        } else {
218
 
            if (ctx->cookie.len > 23
219
 
                && ctx->cookie.data[22] == conf->mark
220
 
                && ctx->cookie.data[23] == '=')
221
 
            {
222
 
                return ngx_http_next_header_filter(r);
223
 
            }
224
 
        }
225
 
    }
226
 
 
227
 
    /* ctx->status == NGX_DECLINED */
228
 
 
229
214
    if (ngx_http_userid_set_uid(r, ctx, conf) == NGX_OK) {
230
215
        return ngx_http_next_header_filter(r);
231
216
    }
248
233
        return NGX_OK;
249
234
    }
250
235
 
251
 
    ctx = ngx_http_userid_get_uid(r, conf);
 
236
    ctx = ngx_http_userid_get_uid(r->main, conf);
252
237
 
253
238
    if (ctx == NULL) {
254
239
        return NGX_ERROR;
255
240
    }
256
241
 
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);
259
244
    }
260
245
 
261
 
    /* ctx->status == NGX_DECLINED */
262
 
 
263
246
    v->not_found = 1;
264
247
 
265
248
    return NGX_OK;
273
256
    ngx_http_userid_ctx_t   *ctx;
274
257
    ngx_http_userid_conf_t  *conf;
275
258
 
276
 
    ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module);
277
 
 
278
 
    if (ctx == NULL || ctx->uid_set[3] == 0) {
279
 
        v->not_found = 1;
280
 
        return NGX_OK;
281
 
    }
282
 
 
283
 
    conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module);
284
 
 
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);
 
260
 
 
261
    if (conf->enable < NGX_HTTP_USERID_V1) {
 
262
        v->not_found = 1;
 
263
        return NGX_OK;
 
264
    }
 
265
 
 
266
    ctx = ngx_http_userid_get_uid(r->main, conf);
 
267
 
 
268
    if (ctx == NULL) {
 
269
        return NGX_ERROR;
 
270
    }
 
271
 
 
272
    if (ngx_http_userid_create_uid(r->main, ctx, conf) != NGX_OK) {
 
273
        return NGX_ERROR;
 
274
    }
 
275
 
 
276
    if (ctx->uid_set[3] == 0) {
 
277
        v->not_found = 1;
 
278
        return NGX_OK;
 
279
    }
 
280
 
 
281
    return ngx_http_userid_variable(r->main, v, &conf->name, ctx->uid_set);
286
282
}
287
283
 
288
284
 
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)
362
358
{
363
 
    u_char               *cookie, *p;
364
 
    size_t                len;
365
 
    ngx_str_t             src, dst;
366
 
    ngx_table_elt_t      *set_cookie, *p3p;
367
 
    ngx_connection_t     *c;
368
 
    struct sockaddr_in   *sin;
369
 
#if (NGX_HAVE_INET6)
370
 
    struct sockaddr_in6  *sin6;
371
 
#endif
372
 
 
373
 
    /*
374
 
     * TODO: in the threaded mode the sequencers should be in TLS and their
375
 
     * ranges should be divided between threads
376
 
     */
377
 
 
378
 
    if (ctx->uid_got[3] == 0) {
379
 
 
380
 
        if (conf->enable == NGX_HTTP_USERID_V1) {
381
 
            if (conf->service == NGX_CONF_UNSET) {
382
 
                ctx->uid_set[0] = 0;
383
 
            } else {
384
 
                ctx->uid_set[0] = conf->service;
385
 
            }
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;
390
 
 
391
 
        } else {
392
 
            if (conf->service == NGX_CONF_UNSET) {
393
 
 
394
 
                c = r->connection;
395
 
 
396
 
                if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) {
397
 
                    return NGX_ERROR;
398
 
                }
399
 
 
400
 
                switch (c->local_sockaddr->sa_family) {
401
 
 
402
 
#if (NGX_HAVE_INET6)
403
 
                case AF_INET6:
404
 
                    sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
405
 
 
406
 
                    p = (u_char *) &ctx->uid_set[0];
407
 
 
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];
412
 
 
413
 
                    break;
414
 
#endif
415
 
                default: /* AF_INET */
416
 
                    sin = (struct sockaddr_in *) c->local_sockaddr;
417
 
                    ctx->uid_set[0] = sin->sin_addr.s_addr;
418
 
                    break;
419
 
                }
420
 
 
421
 
            } else {
422
 
                ctx->uid_set[0] = htonl(conf->service);
423
 
            }
424
 
 
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;
431
 
            }
432
 
        }
433
 
 
434
 
    } else {
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];
 
359
    u_char           *cookie, *p;
 
360
    size_t            len;
 
361
    ngx_str_t         src, dst;
 
362
    ngx_table_elt_t  *set_cookie, *p3p;
 
363
 
 
364
    if (ngx_http_userid_create_uid(r, ctx, conf) != NGX_OK) {
 
365
        return NGX_ERROR;
 
366
    }
 
367
 
 
368
    if (ctx->uid_set[3] == 0) {
 
369
        return NGX_OK;
439
370
    }
440
371
 
441
372
    len = conf->name.len + 1 + ngx_base64_encoded_length(16) + conf->path.len;
493
424
    }
494
425
 
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;
500
430
 
511
441
    }
512
442
 
513
443
    p3p->hash = 1;
514
 
    p3p->key.len = sizeof("P3P") - 1;
515
 
    p3p->key.data = (u_char *) "P3P";
 
444
    ngx_str_set(&p3p->key, "P3P");
516
445
    p3p->value = conf->p3p;
517
446
 
518
447
    return NGX_OK;
520
449
 
521
450
 
522
451
static ngx_int_t
 
452
ngx_http_userid_create_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
 
453
    ngx_http_userid_conf_t *conf)
 
454
{
 
455
    ngx_connection_t     *c;
 
456
    struct sockaddr_in   *sin;
 
457
#if (NGX_HAVE_INET6)
 
458
    u_char               *p;
 
459
    struct sockaddr_in6  *sin6;
 
460
#endif
 
461
 
 
462
    if (ctx->uid_set[3] != 0) {
 
463
        return NGX_OK;
 
464
    }
 
465
 
 
466
    if (ctx->uid_got[3] != 0) {
 
467
 
 
468
        if (conf->mark == '\0'
 
469
            || (ctx->cookie.len > 23
 
470
                && ctx->cookie.data[22] == conf->mark
 
471
                && ctx->cookie.data[23] == '='))
 
472
        {
 
473
            return NGX_OK;
 
474
        }
 
475
 
 
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];
 
480
 
 
481
        return NGX_OK;
 
482
    }
 
483
 
 
484
    /*
 
485
     * TODO: in the threaded mode the sequencers should be in TLS and their
 
486
     * ranges should be divided between threads
 
487
     */
 
488
 
 
489
    if (conf->enable == NGX_HTTP_USERID_V1) {
 
490
        if (conf->service == NGX_CONF_UNSET) {
 
491
            ctx->uid_set[0] = 0;
 
492
        } else {
 
493
            ctx->uid_set[0] = conf->service;
 
494
        }
 
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;
 
499
 
 
500
    } else {
 
501
        if (conf->service == NGX_CONF_UNSET) {
 
502
 
 
503
            c = r->connection;
 
504
 
 
505
            if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) {
 
506
                return NGX_ERROR;
 
507
            }
 
508
 
 
509
            switch (c->local_sockaddr->sa_family) {
 
510
 
 
511
#if (NGX_HAVE_INET6)
 
512
            case AF_INET6:
 
513
                sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
 
514
 
 
515
                p = (u_char *) &ctx->uid_set[0];
 
516
 
 
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];
 
521
 
 
522
                break;
 
523
#endif
 
524
            default: /* AF_INET */
 
525
                sin = (struct sockaddr_in *) c->local_sockaddr;
 
526
                ctx->uid_set[0] = sin->sin_addr.s_addr;
 
527
                break;
 
528
            }
 
529
 
 
530
        } else {
 
531
            ctx->uid_set[0] = htonl(conf->service);
 
532
        }
 
533
 
 
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;
 
540
        }
 
541
    }
 
542
 
 
543
    return NGX_OK;
 
544
}
 
545
 
 
546
 
 
547
static ngx_int_t
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)
525
550
{
552
577
 
553
578
    var->get_handler = ngx_http_userid_got_variable;
554
579
 
555
 
    var = ngx_http_add_variable(cf, &ngx_http_userid_set, NGX_HTTP_VAR_NOHASH);
 
580
    var = ngx_http_add_variable(cf, &ngx_http_userid_set, 0);
556
581
    if (var == NULL) {
557
582
        return NGX_ERROR;
558
583
    }
576
601
    /*
577
602
     * set by ngx_pcalloc():
578
603
     *
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;
585
 
     *     conf->p3p.len = 0;
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 };
587
608
     */
588
609
 
589
610
    conf->enable = NGX_CONF_UNSET_UINT;
642
663
    u_char  *p, *new;
643
664
 
644
665
    if (ngx_strcmp(domain->data, "none") == 0) {
645
 
        domain->len = 0;
646
 
        domain->data = (u_char *) "";
647
 
 
 
666
        ngx_str_set(domain, "");
648
667
        return NGX_CONF_OK;
649
668
    }
650
669
 
727
746
    ngx_str_t  *p3p = data;
728
747
 
729
748
    if (ngx_strcmp(p3p->data, "none") == 0) {
730
 
        p3p->len = 0;
731
 
        p3p->data = (u_char *) "";
 
749
        ngx_str_set(p3p, "");
732
750
    }
733
751
 
734
752
    return NGX_CONF_OK;
780
798
 
781
799
    return NGX_OK;
782
800
}
783