Mercurial > hg > nginx
comparison src/http/modules/ngx_http_auth_basic_module.c @ 2588:a6954ce88b80
use complex values in add_header, auth_basic_user_file,
sub_filter, and xslt_stylesheet parameters
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 22 Mar 2009 09:39:19 +0000 |
parents | 5c8d9e3cbd8a |
children | c7d57b539248 |
comparison
equal
deleted
inserted
replaced
2587:8afc4df77ee8 | 2588:a6954ce88b80 |
---|---|
11 | 11 |
12 #define NGX_HTTP_AUTH_BUF_SIZE 2048 | 12 #define NGX_HTTP_AUTH_BUF_SIZE 2048 |
13 | 13 |
14 | 14 |
15 typedef struct { | 15 typedef struct { |
16 ngx_str_t passwd; | 16 ngx_str_t passwd; |
17 } ngx_http_auth_basic_ctx_t; | 17 } ngx_http_auth_basic_ctx_t; |
18 | 18 |
19 | 19 |
20 typedef struct { | 20 typedef struct { |
21 ngx_str_t realm; | 21 ngx_str_t realm; |
22 ngx_str_t user_file; | 22 ngx_http_complex_value_t user_file; |
23 ngx_array_t *user_file_lengths; | |
24 ngx_array_t *user_file_values; | |
25 } ngx_http_auth_basic_loc_conf_t; | 23 } ngx_http_auth_basic_loc_conf_t; |
26 | 24 |
27 | 25 |
28 static ngx_int_t ngx_http_auth_basic_handler(ngx_http_request_t *r); | 26 static ngx_int_t ngx_http_auth_basic_handler(ngx_http_request_t *r); |
29 static ngx_int_t ngx_http_auth_basic_crypt_handler(ngx_http_request_t *r, | 27 static ngx_int_t ngx_http_auth_basic_crypt_handler(ngx_http_request_t *r, |
115 sw_skip | 113 sw_skip |
116 } state; | 114 } state; |
117 | 115 |
118 alcf = ngx_http_get_module_loc_conf(r, ngx_http_auth_basic_module); | 116 alcf = ngx_http_get_module_loc_conf(r, ngx_http_auth_basic_module); |
119 | 117 |
120 if (alcf->realm.len == 0 || alcf->user_file.len == 0) { | 118 if (alcf->realm.len == 0 || alcf->user_file.value.len == 0) { |
121 return NGX_DECLINED; | 119 return NGX_DECLINED; |
122 } | 120 } |
123 | 121 |
124 ctx = ngx_http_get_module_ctx(r, ngx_http_auth_basic_module); | 122 ctx = ngx_http_get_module_ctx(r, ngx_http_auth_basic_module); |
125 | 123 |
140 | 138 |
141 if (rc == NGX_ERROR) { | 139 if (rc == NGX_ERROR) { |
142 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 140 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
143 } | 141 } |
144 | 142 |
145 if (alcf->user_file_lengths) { | 143 if (ngx_http_complex_value(r, &alcf->user_file, &user_file) != NGX_OK) { |
146 if (ngx_http_script_run(r, &user_file, alcf->user_file_lengths->elts, 1, | 144 return NGX_ERROR; |
147 alcf->user_file_values->elts) | |
148 == NULL) | |
149 { | |
150 return NGX_ERROR; | |
151 } | |
152 | |
153 user_file.data[--user_file.len] = '\0'; | |
154 | |
155 } else { | |
156 user_file = alcf->user_file; | |
157 } | 145 } |
158 | 146 |
159 fd = ngx_open_file(user_file.data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); | 147 fd = ngx_open_file(user_file.data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); |
160 | 148 |
161 if (fd == NGX_INVALID_FILE) { | 149 if (fd == NGX_INVALID_FILE) { |
399 | 387 |
400 if (conf->realm.data == NULL) { | 388 if (conf->realm.data == NULL) { |
401 conf->realm = prev->realm; | 389 conf->realm = prev->realm; |
402 } | 390 } |
403 | 391 |
404 if (conf->user_file.data == NULL) { | 392 if (conf->user_file.value.len == 0) { |
405 conf->user_file = prev->user_file; | 393 conf->user_file = prev->user_file; |
406 conf->user_file_lengths = prev->user_file_lengths; | |
407 conf->user_file_values = prev->user_file_values; | |
408 } | 394 } |
409 | 395 |
410 return NGX_CONF_OK; | 396 return NGX_CONF_OK; |
411 } | 397 } |
412 | 398 |
466 static char * | 452 static char * |
467 ngx_http_auth_basic_user_file(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 453 ngx_http_auth_basic_user_file(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
468 { | 454 { |
469 ngx_http_auth_basic_loc_conf_t *alcf = conf; | 455 ngx_http_auth_basic_loc_conf_t *alcf = conf; |
470 | 456 |
471 ngx_str_t *value; | 457 ngx_str_t *value; |
472 ngx_uint_t n; | 458 ngx_http_compile_complex_value_t ccv; |
473 ngx_http_script_compile_t sc; | 459 |
474 | 460 if (alcf->user_file.value.len) { |
475 if (alcf->user_file.data) { | |
476 return "is duplicate"; | 461 return "is duplicate"; |
477 } | 462 } |
478 | 463 |
479 value = cf->args->elts; | 464 value = cf->args->elts; |
480 | 465 |
481 alcf->user_file = value[1]; | 466 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
482 | 467 |
483 if (alcf->user_file.len == 0) { | 468 ccv.cf = cf; |
484 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 469 ccv.value = &value[1]; |
485 "invalid parameter \"%V\"", &alcf->user_file); | 470 ccv.complex_value = &alcf->user_file; |
471 ccv.zero = 1; | |
472 ccv.conf_prefix = 1; | |
473 | |
474 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
486 return NGX_CONF_ERROR; | 475 return NGX_CONF_ERROR; |
487 } | 476 } |
488 | 477 |
489 if (alcf->user_file.data[0] != '$') { | |
490 if (ngx_conf_full_name(cf->cycle, &alcf->user_file, 1) != NGX_OK) { | |
491 return NGX_CONF_ERROR; | |
492 } | |
493 } | |
494 | |
495 n = ngx_http_script_variables_count(&alcf->user_file); | |
496 | |
497 if (n == 0) { | |
498 return NGX_CONF_OK; | |
499 } | |
500 | |
501 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
502 | |
503 sc.cf = cf; | |
504 sc.source = &alcf->user_file; | |
505 sc.lengths = &alcf->user_file_lengths; | |
506 sc.values = &alcf->user_file_values; | |
507 sc.variables = n; | |
508 sc.complete_lengths = 1; | |
509 sc.complete_values = 1; | |
510 | |
511 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
512 return NGX_CONF_ERROR; | |
513 } | |
514 | |
515 return NGX_CONF_OK; | 478 return NGX_CONF_OK; |
516 } | 479 } |