Mercurial > hg > nginx-vendor-current
comparison src/http/modules/ngx_http_auth_basic_module.c @ 464:c8cfb6c462ef NGINX_0_7_44
nginx 0.7.44
*) Feature: the ngx_http_proxy_module preliminary cache support.
*) Feature: the --with-pcre option in the configure.
*) Feature: the "try_files" directive is now allowed on the server
block level.
*) Bugfix: the "try_files" directive handled incorrectly a query string
in a fallback parameter.
*) Bugfix: the "try_files" directive might test incorrectly directories.
*) Bugfix: if there is the single server for given address:port pair,
then captures in regular expressions in a "server_name" directive
did not work.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 23 Mar 2009 00:00:00 +0300 |
parents | dcb6b5f9d526 |
children | f39b9e29530d |
comparison
equal
deleted
inserted
replaced
463:51cb914e6d3a | 464:c8cfb6c462ef |
---|---|
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 } |