0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_http.h>
|
|
10
|
|
11
|
|
12 #define NGX_HTTP_USERID_OFF 0
|
|
13 #define NGX_HTTP_USERID_LOG 1
|
|
14 #define NGX_HTTP_USERID_V1 2
|
|
15 #define NGX_HTTP_USERID_ON 3
|
|
16
|
|
17 /* 31 Dec 2037 23:55:55 GMT */
|
|
18 #define NGX_HTTP_USERID_MAX_EXPIRES 2145916555
|
|
19
|
|
20
|
|
21 typedef struct {
|
|
22 ngx_flag_t enable;
|
|
23
|
|
24 ngx_int_t service;
|
|
25
|
|
26 ngx_str_t name;
|
|
27 ngx_str_t domain;
|
|
28 ngx_str_t path;
|
|
29 time_t expires;
|
10
|
30 ngx_str_t p3p;
|
0
|
31 } ngx_http_userid_conf_t;
|
|
32
|
|
33
|
|
34 typedef struct {
|
10
|
35 uint32_t uid_got[4];
|
|
36 uint32_t uid_set[4];
|
0
|
37 } ngx_http_userid_ctx_t;
|
|
38
|
|
39
|
|
40 static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r,
|
|
41 ngx_http_userid_ctx_t *ctx,
|
|
42 ngx_http_userid_conf_t *conf);
|
|
43 static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
|
|
44 ngx_http_userid_ctx_t *ctx,
|
|
45 ngx_http_userid_conf_t *conf);
|
|
46
|
|
47 static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf,
|
|
48 uintptr_t data);
|
|
49 static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf,
|
|
50 uintptr_t data);
|
|
51
|
|
52 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle);
|
|
53 static ngx_int_t ngx_http_userid_pre_conf(ngx_conf_t *cf);
|
|
54 static void *ngx_http_userid_create_conf(ngx_conf_t *cf);
|
|
55 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
|
|
56 void *child);
|
10
|
57 char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data);
|
|
58 char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data);
|
0
|
59 char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
10
|
60 char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data);
|
0
|
61
|
|
62
|
|
63 static uint32_t sequencer_v1 = 1;
|
|
64 static uint32_t sequencer_v2 = 0x03030302;
|
|
65
|
|
66
|
|
67 static u_char expires[] = "; expires=Thu, 31-Dec-37 23:55:55 GMT";
|
|
68
|
|
69
|
|
70 static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
|
|
71
|
|
72
|
|
73 static ngx_conf_enum_t ngx_http_userid_state[] = {
|
|
74 { ngx_string("off"), NGX_HTTP_USERID_OFF },
|
|
75 { ngx_string("log"), NGX_HTTP_USERID_LOG },
|
|
76 { ngx_string("v1"), NGX_HTTP_USERID_V1 },
|
|
77 { ngx_string("on"), NGX_HTTP_USERID_ON },
|
|
78 { ngx_null_string, 0 }
|
|
79 };
|
|
80
|
|
81
|
10
|
82 static ngx_conf_post_handler_pt ngx_http_userid_domain_p =
|
|
83 ngx_http_userid_domain;
|
|
84
|
|
85 static ngx_conf_post_handler_pt ngx_http_userid_path_p = ngx_http_userid_path;
|
|
86 static ngx_conf_post_handler_pt ngx_http_userid_p3p_p = ngx_http_userid_p3p;
|
0
|
87
|
|
88
|
|
89 static ngx_command_t ngx_http_userid_commands[] = {
|
|
90
|
|
91 { ngx_string("userid"),
|
|
92 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
93 ngx_conf_set_enum_slot,
|
|
94 NGX_HTTP_LOC_CONF_OFFSET,
|
|
95 offsetof(ngx_http_userid_conf_t, enable),
|
|
96 ngx_http_userid_state },
|
|
97
|
|
98 { ngx_string("userid_service"),
|
|
99 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
100 ngx_conf_set_num_slot,
|
|
101 NGX_HTTP_LOC_CONF_OFFSET,
|
|
102 offsetof(ngx_http_userid_conf_t, service),
|
|
103 NULL },
|
|
104
|
|
105 { ngx_string("userid_name"),
|
|
106 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
107 ngx_conf_set_str_slot,
|
|
108 NGX_HTTP_LOC_CONF_OFFSET,
|
|
109 offsetof(ngx_http_userid_conf_t, name),
|
|
110 NULL },
|
|
111
|
|
112 { ngx_string("userid_domain"),
|
|
113 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
114 ngx_conf_set_str_slot,
|
|
115 NGX_HTTP_LOC_CONF_OFFSET,
|
|
116 offsetof(ngx_http_userid_conf_t, domain),
|
10
|
117 &ngx_http_userid_domain_p },
|
0
|
118
|
|
119 { ngx_string("userid_path"),
|
|
120 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
121 ngx_conf_set_str_slot,
|
|
122 NGX_HTTP_LOC_CONF_OFFSET,
|
|
123 offsetof(ngx_http_userid_conf_t, path),
|
10
|
124 &ngx_http_userid_path_p },
|
0
|
125
|
|
126 { ngx_string("userid_expires"),
|
|
127 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
128 ngx_http_userid_expires,
|
|
129 NGX_HTTP_LOC_CONF_OFFSET,
|
|
130 0,
|
|
131 NULL },
|
|
132
|
10
|
133 { ngx_string("userid_p3p"),
|
|
134 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
135 ngx_conf_set_str_slot,
|
|
136 NGX_HTTP_LOC_CONF_OFFSET,
|
|
137 offsetof(ngx_http_userid_conf_t, p3p),
|
|
138 &ngx_http_userid_p3p_p },
|
|
139
|
0
|
140 ngx_null_command
|
|
141 };
|
|
142
|
|
143
|
|
144 ngx_http_module_t ngx_http_userid_filter_module_ctx = {
|
|
145 ngx_http_userid_pre_conf, /* pre conf */
|
|
146
|
|
147 NULL, /* create main configuration */
|
|
148 NULL, /* init main configuration */
|
|
149
|
|
150 NULL, /* create server configuration */
|
|
151 NULL, /* merge server configuration */
|
|
152
|
|
153 ngx_http_userid_create_conf, /* create location configration */
|
|
154 ngx_http_userid_merge_conf /* merge location configration */
|
|
155 };
|
|
156
|
|
157
|
|
158 ngx_module_t ngx_http_userid_filter_module = {
|
|
159 NGX_MODULE,
|
|
160 &ngx_http_userid_filter_module_ctx, /* module context */
|
|
161 ngx_http_userid_commands, /* module directives */
|
|
162 NGX_HTTP_MODULE, /* module type */
|
|
163 ngx_http_userid_init, /* init module */
|
|
164 NULL /* init process */
|
|
165 };
|
|
166
|
|
167
|
|
168 static ngx_http_log_op_name_t ngx_http_userid_log_fmt_ops[] = {
|
|
169 { ngx_string("uid_got"), 0, ngx_http_userid_log_uid_got },
|
|
170 { ngx_string("uid_set"), 0, ngx_http_userid_log_uid_set },
|
|
171 { ngx_null_string, 0, NULL }
|
|
172 };
|
|
173
|
|
174
|
|
175 static ngx_int_t ngx_http_userid_filter(ngx_http_request_t *r)
|
|
176 {
|
|
177 ngx_int_t rc;
|
|
178 ngx_http_userid_ctx_t *ctx;
|
|
179 ngx_http_userid_conf_t *conf;
|
|
180
|
|
181 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module);
|
|
182
|
|
183 if (conf->enable == NGX_HTTP_USERID_OFF) {
|
|
184 return ngx_http_next_header_filter(r);
|
|
185 }
|
|
186
|
|
187 ngx_http_create_ctx(r, ctx, ngx_http_userid_filter_module,
|
|
188 sizeof(ngx_http_userid_ctx_t), NGX_ERROR);
|
|
189
|
|
190 rc = ngx_http_userid_get_uid(r, ctx, conf);
|
|
191
|
|
192 if (rc != NGX_OK) {
|
|
193 return rc;
|
|
194 }
|
|
195
|
|
196 if (conf->enable == NGX_HTTP_USERID_LOG || ctx->uid_got[3] != 0) {
|
|
197 return ngx_http_next_header_filter(r);
|
|
198 }
|
|
199
|
|
200 rc = ngx_http_userid_set_uid(r, ctx, conf);
|
|
201
|
|
202 if (rc != NGX_OK) {
|
|
203 return rc;
|
|
204 }
|
|
205
|
|
206 return ngx_http_next_header_filter(r);
|
|
207 }
|
|
208
|
|
209
|
|
210 static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r,
|
|
211 ngx_http_userid_ctx_t *ctx,
|
|
212 ngx_http_userid_conf_t *conf)
|
|
213 {
|
|
214 u_char *start, *last, *end;
|
|
215 ngx_uint_t i;
|
|
216 ngx_str_t src, dst;
|
|
217 ngx_table_elt_t **cookies;
|
|
218
|
|
219 cookies = r->headers_in.cookies.elts;
|
|
220
|
|
221 for (i = 0; i < r->headers_in.cookies.nelts; i++) {
|
|
222 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
10
|
223 "cookie: \"%V\"", &cookies[i]->value);
|
0
|
224
|
10
|
225 if (conf->name.len >= cookies[i]->value.len) {
|
|
226 continue;
|
|
227 }
|
|
228
|
|
229 start = cookies[i]->value.data;
|
0
|
230 end = cookies[i]->value.data + cookies[i]->value.len;
|
|
231
|
10
|
232 while (start < end) {
|
0
|
233
|
10
|
234 if (ngx_strncmp(start, conf->name.data, conf->name.len) != 0) {
|
|
235
|
0
|
236 while (start < end && *start++ != ';') { /* void */ }
|
10
|
237 while (start < end && *start == ' ') { start++; }
|
0
|
238
|
|
239 continue;
|
|
240 }
|
|
241
|
10
|
242 start += conf->name.len;
|
0
|
243
|
10
|
244 while (start < end && *start == ' ') { start++; }
|
|
245
|
|
246 if (start == end || *start++ != '=') {
|
|
247 /* the invalid "Cookie" header */
|
0
|
248 break;
|
|
249 }
|
|
250
|
10
|
251 while (start < end && *start == ' ') { start++; }
|
0
|
252
|
10
|
253 last = start;
|
|
254
|
|
255 while (last < end && *last++ != ';') { /* void */ }
|
0
|
256
|
|
257 if (last - start < 22) {
|
|
258 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
10
|
259 "client sent too short userid cookie \"%V\"",
|
|
260 &cookies[i]->value);
|
0
|
261 break;
|
|
262 }
|
|
263
|
|
264 /*
|
|
265 * we have to limit encoded string to 22 characters
|
|
266 * because there are already the millions cookies with a garbage
|
|
267 * instead of the correct base64 trail "=="
|
|
268 */
|
|
269
|
|
270 src.len = 22;
|
|
271 src.data = start;
|
|
272 dst.data = (u_char *) ctx->uid_got;
|
|
273
|
2
|
274 if (ngx_decode_base64(&dst, &src) == NGX_ERROR) {
|
0
|
275 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
10
|
276 "client sent invalid userid cookie \"%V\"",
|
|
277 &cookies[i]->value);
|
0
|
278 break;
|
|
279 }
|
|
280
|
|
281 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
10
|
282 "uid: %08XD%08XD%08XD%08XD",
|
0
|
283 ctx->uid_got[0], ctx->uid_got[1],
|
|
284 ctx->uid_got[2], ctx->uid_got[3]);
|
|
285
|
|
286 return NGX_OK;
|
|
287 }
|
|
288 }
|
|
289
|
|
290 return NGX_OK;
|
|
291 }
|
|
292
|
|
293
|
|
294 static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
|
|
295 ngx_http_userid_ctx_t *ctx,
|
|
296 ngx_http_userid_conf_t *conf)
|
|
297 {
|
|
298 u_char *cookie, *p;
|
|
299 size_t len;
|
|
300 socklen_t slen;
|
|
301 struct sockaddr_in addr_in;
|
|
302 ngx_str_t src, dst;
|
10
|
303 ngx_table_elt_t *set_cookie, *p3p;
|
0
|
304
|
|
305 /* TODO: mutex for sequencers */
|
|
306
|
|
307 if (conf->enable == NGX_HTTP_USERID_V1) {
|
|
308 if (conf->service == NGX_CONF_UNSET) {
|
|
309 ctx->uid_set[0] = 0;
|
|
310 } else {
|
|
311 ctx->uid_set[0] = htonl(conf->service);
|
|
312 }
|
|
313
|
|
314 ctx->uid_set[1] = ngx_time();
|
|
315 ctx->uid_set[2] = ngx_pid;
|
|
316 ctx->uid_set[3] = sequencer_v1;
|
|
317 sequencer_v1 += 0x100;
|
|
318
|
|
319 } else {
|
|
320 if (conf->service == NGX_CONF_UNSET) {
|
|
321 if (r->in_addr == 0) {
|
|
322 slen = sizeof(struct sockaddr_in);
|
|
323 if (getsockname(r->connection->fd,
|
|
324 (struct sockaddr *) &addr_in, &slen) == -1)
|
|
325 {
|
|
326 ngx_log_error(NGX_LOG_CRIT, r->connection->log,
|
|
327 ngx_socket_errno,
|
|
328 "getsockname() failed");
|
|
329 }
|
|
330
|
|
331 r->in_addr = addr_in.sin_addr.s_addr;
|
|
332 }
|
|
333
|
|
334 ctx->uid_set[0] = htonl(r->in_addr);
|
|
335
|
|
336 } else {
|
|
337 ctx->uid_set[0] = htonl(conf->service);
|
|
338 }
|
|
339
|
|
340 ctx->uid_set[1] = htonl(ngx_time());
|
|
341 ctx->uid_set[2] = htonl(ngx_pid);
|
|
342 ctx->uid_set[3] = htonl(sequencer_v2);
|
|
343 sequencer_v2 += 0x100;
|
|
344 if (sequencer_v2 < 0x03030302) {
|
|
345 sequencer_v2 = 0x03030302;
|
|
346 }
|
|
347 }
|
|
348
|
10
|
349 len = conf->name.len + 1 + ngx_base64_encoded_length(16) + conf->path.len;
|
0
|
350
|
|
351 if (conf->expires) {
|
|
352 len += sizeof(expires) - 1 + 2;
|
|
353 }
|
|
354
|
|
355 if (conf->domain.len > 1) {
|
10
|
356 len += conf->domain.len;
|
0
|
357 }
|
|
358
|
|
359 if (!(cookie = ngx_palloc(r->pool, len))) {
|
|
360 return NGX_ERROR;
|
|
361 }
|
|
362
|
|
363 p = ngx_cpymem(cookie, conf->name.data, conf->name.len);
|
|
364 *p++ = '=';
|
|
365
|
|
366 src.len = 16;
|
|
367 src.data = (u_char *) ctx->uid_set;
|
|
368 dst.data = p;
|
|
369
|
2
|
370 ngx_encode_base64(&dst, &src);
|
0
|
371
|
|
372 p += dst.len;
|
|
373
|
|
374 if (conf->expires == NGX_HTTP_USERID_MAX_EXPIRES) {
|
|
375 p = ngx_cpymem(p, expires, sizeof(expires) - 1);
|
|
376
|
|
377 } else if (conf->expires) {
|
|
378 p = ngx_cpymem(p, expires, sizeof("; expires=") - 1);
|
4
|
379 p = ngx_http_cookie_time(p, ngx_time() + conf->expires);
|
0
|
380 }
|
|
381
|
|
382 if (conf->domain.len > 1) {
|
|
383 p = ngx_cpymem(p, conf->domain.data, conf->domain.len);
|
|
384 }
|
|
385
|
10
|
386 p = ngx_cpymem(p, conf->path.data, conf->path.len);
|
0
|
387
|
|
388 if (!(set_cookie = ngx_list_push(&r->headers_out.headers))) {
|
|
389 return NGX_ERROR;
|
|
390 }
|
|
391
|
|
392 set_cookie->key.len = sizeof("Set-Cookie") - 1;
|
|
393 set_cookie->key.data = (u_char *) "Set-Cookie";
|
|
394 set_cookie->value.len = p - cookie;
|
|
395 set_cookie->value.data = cookie;
|
|
396
|
10
|
397 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
398 "uid cookie: \"%V\"", &set_cookie->value);
|
|
399
|
|
400 if (conf->p3p.len == 1) {
|
|
401 return NGX_OK;
|
|
402 }
|
|
403
|
|
404 if (!(p3p = ngx_list_push(&r->headers_out.headers))) {
|
|
405 return NGX_ERROR;
|
|
406 }
|
|
407
|
|
408 p3p->key.len = sizeof("P3P") - 1;
|
|
409 p3p->key.data = (u_char *) "P3P";
|
|
410 p3p->value = conf->p3p;
|
|
411
|
0
|
412 return NGX_OK;
|
|
413 }
|
|
414
|
|
415
|
|
416 static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf,
|
|
417 uintptr_t data)
|
|
418 {
|
|
419 ngx_http_userid_ctx_t *ctx;
|
|
420 ngx_http_userid_conf_t *conf;
|
|
421
|
|
422 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module);
|
|
423
|
|
424 if (ctx == NULL || ctx->uid_got[3] == 0) {
|
|
425 if (buf == NULL) {
|
|
426 return (u_char *) 1;
|
|
427 }
|
|
428
|
|
429 *buf = '-';
|
|
430 return buf + 1;
|
|
431 }
|
|
432
|
|
433 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module);
|
|
434
|
|
435 if (buf == NULL) {
|
|
436 return (u_char *) (conf->name.len + 1 + 32);
|
|
437 }
|
|
438
|
|
439 buf = ngx_cpymem(buf, conf->name.data, conf->name.len);
|
|
440
|
|
441 *buf++ = '=';
|
|
442
|
10
|
443 return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD",
|
|
444 ctx->uid_got[0], ctx->uid_got[1],
|
|
445 ctx->uid_got[2], ctx->uid_got[3]);
|
0
|
446 }
|
|
447
|
|
448
|
|
449 static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf,
|
|
450 uintptr_t data)
|
|
451 {
|
|
452 ngx_http_userid_ctx_t *ctx;
|
|
453 ngx_http_userid_conf_t *conf;
|
|
454
|
|
455 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module);
|
|
456
|
|
457 if (ctx == NULL || ctx->uid_set[3] == 0) {
|
|
458 if (buf == NULL) {
|
|
459 return (u_char *) 1;
|
|
460 }
|
|
461
|
|
462 *buf = '-';
|
|
463 return buf + 1;
|
|
464 }
|
|
465
|
|
466 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module);
|
|
467
|
|
468 if (buf == NULL) {
|
|
469 return (u_char *) (conf->name.len + 1 + 32);
|
|
470 }
|
|
471
|
|
472 buf = ngx_cpymem(buf, conf->name.data, conf->name.len);
|
|
473
|
|
474 *buf++ = '=';
|
|
475
|
10
|
476 return ngx_sprintf(buf, "%08XD%08XD%08XD%08XD",
|
|
477 ctx->uid_set[0], ctx->uid_set[1],
|
|
478 ctx->uid_set[2], ctx->uid_set[3]);
|
0
|
479 }
|
|
480
|
|
481
|
|
482 static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle)
|
|
483 {
|
|
484 ngx_http_next_header_filter = ngx_http_top_header_filter;
|
|
485 ngx_http_top_header_filter = ngx_http_userid_filter;
|
|
486
|
|
487 return NGX_OK;
|
|
488 }
|
|
489
|
|
490
|
|
491 static ngx_int_t ngx_http_userid_pre_conf(ngx_conf_t *cf)
|
|
492 {
|
|
493 ngx_http_log_op_name_t *op;
|
|
494
|
|
495 for (op = ngx_http_userid_log_fmt_ops; op->name.len; op++) { /* void */ }
|
|
496 op->op = NULL;
|
|
497
|
|
498 op = ngx_http_log_fmt_ops;
|
|
499
|
|
500 for (op = ngx_http_log_fmt_ops; op->op; op++) {
|
|
501 if (op->name.len == 0) {
|
|
502 op = (ngx_http_log_op_name_t *) op->op;
|
|
503 }
|
|
504 }
|
|
505
|
|
506 op->op = (ngx_http_log_op_pt) ngx_http_userid_log_fmt_ops;
|
|
507
|
|
508 return NGX_OK;
|
|
509 }
|
|
510
|
|
511
|
|
512 static void *ngx_http_userid_create_conf(ngx_conf_t *cf)
|
|
513 {
|
|
514 ngx_http_userid_conf_t *conf;
|
|
515
|
|
516 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_userid_conf_t)))) {
|
|
517 return NGX_CONF_ERROR;
|
|
518 }
|
|
519
|
|
520 /* set by ngx_pcalloc():
|
|
521
|
|
522 conf->name.len = 0;
|
|
523 conf->name.date = NULL;
|
|
524 conf->domain.len = 0;
|
|
525 conf->domain.date = NULL;
|
|
526 conf->path.len = 0;
|
|
527 conf->path.date = NULL;
|
10
|
528 conf->p3p.len = 0;
|
|
529 conf->p3p.date = NULL;
|
0
|
530
|
|
531 */
|
|
532
|
|
533 conf->enable = NGX_CONF_UNSET;
|
|
534 conf->service = NGX_CONF_UNSET;
|
|
535 conf->expires = NGX_CONF_UNSET;
|
|
536
|
|
537 return conf;
|
|
538 }
|
|
539
|
|
540
|
|
541 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
|
|
542 void *child)
|
|
543 {
|
|
544 ngx_http_userid_conf_t *prev = parent;
|
|
545 ngx_http_userid_conf_t *conf = child;
|
|
546
|
|
547 ngx_conf_merge_value(conf->enable, prev->enable, NGX_HTTP_USERID_OFF);
|
|
548
|
|
549 ngx_conf_merge_str_value(conf->name, prev->name, "uid");
|
|
550 ngx_conf_merge_str_value(conf->domain, prev->domain, ".");
|
10
|
551 ngx_conf_merge_str_value(conf->path, prev->path, "; path=/");
|
|
552 ngx_conf_merge_str_value(conf->p3p, prev->p3p, ".");
|
0
|
553
|
|
554 ngx_conf_merge_value(conf->service, prev->service, NGX_CONF_UNSET);
|
|
555 ngx_conf_merge_sec_value(conf->expires, prev->expires, 0);
|
|
556
|
|
557 return NGX_CONF_OK;
|
|
558 }
|
|
559
|
|
560
|
10
|
561 char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
|
0
|
562 {
|
|
563 ngx_str_t *domain = data;
|
|
564
|
10
|
565 u_char *p, *new;
|
|
566
|
0
|
567 if (domain->len == 4 && ngx_strcmp(domain->data, "none") == 0) {
|
|
568 domain->len = 1;
|
|
569 domain->data = (u_char *) ".";
|
10
|
570
|
|
571 return NGX_CONF_OK;
|
0
|
572 }
|
|
573
|
10
|
574 if (!(new = ngx_palloc(cf->pool, sizeof("; domain=") - 1 + domain->len))) {
|
|
575 return NGX_CONF_ERROR;
|
|
576 }
|
|
577
|
|
578 p = ngx_cpymem(new, "; domain=", sizeof("; domain=") - 1);
|
|
579 p = ngx_cpymem(p, domain->data, domain->len);
|
|
580
|
|
581 domain->len += sizeof("; domain=") - 1;
|
|
582 domain->data = new;
|
|
583
|
|
584 return NGX_CONF_OK;
|
|
585 }
|
|
586
|
|
587
|
|
588 char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data)
|
|
589 {
|
|
590 ngx_str_t *path = data;
|
|
591
|
|
592 u_char *p, *new;
|
|
593
|
|
594 if (!(new = ngx_palloc(cf->pool, sizeof("; path=") - 1 + path->len))) {
|
|
595 return NGX_CONF_ERROR;
|
|
596 }
|
|
597
|
|
598 p = ngx_cpymem(new, "; path=", sizeof("; path=") - 1);
|
|
599 p = ngx_cpymem(p, path->data, path->len);
|
|
600
|
|
601 path->len += sizeof("; path=") - 1;
|
|
602 path->data = new;
|
|
603
|
0
|
604 return NGX_CONF_OK;
|
|
605 }
|
|
606
|
|
607
|
|
608 char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
609 {
|
|
610 ngx_http_userid_conf_t *ucf = conf;
|
|
611
|
|
612 ngx_str_t *value;
|
|
613
|
|
614 if (ucf->expires != NGX_CONF_UNSET) {
|
|
615 return "is duplicate";
|
|
616 }
|
|
617
|
|
618 value = cf->args->elts;
|
|
619
|
|
620 if (ngx_strcmp(value[1].data, "max") == 0) {
|
|
621 ucf->expires = NGX_HTTP_USERID_MAX_EXPIRES;
|
|
622 return NGX_CONF_OK;
|
|
623 }
|
|
624
|
|
625 if (ngx_strcmp(value[1].data, "off") == 0) {
|
|
626 ucf->expires = 0;
|
|
627 return NGX_CONF_OK;
|
|
628 }
|
|
629
|
|
630 ucf->expires = ngx_parse_time(&value[1], 1);
|
|
631 if (ucf->expires == NGX_ERROR) {
|
|
632 return "invalid value";
|
|
633 }
|
|
634
|
|
635 if (ucf->expires == NGX_PARSE_LARGE_TIME) {
|
|
636 return "value must be less than 68 years";
|
|
637 }
|
|
638
|
|
639 return NGX_CONF_OK;
|
|
640 }
|
10
|
641
|
|
642
|
|
643 char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data)
|
|
644 {
|
|
645 ngx_str_t *p3p = data;
|
|
646
|
|
647 if (p3p->len == 4 && ngx_strcmp(p3p->data, "none") == 0) {
|
|
648 p3p->len = 1;
|
|
649 p3p->data = (u_char *) ".";
|
|
650 }
|
|
651
|
|
652 return NGX_CONF_OK;
|
|
653 }
|