Mercurial > hg > nginx
comparison src/http/modules/ngx_http_auth_basic_module.c @ 7832:be82e72c9af8
Auth basic: changed alcf->user_file to be a pointer.
This saves some memory in typical case when auth_basic_user_file is not
explicitly set, and unifies the code with alcf->realm.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 06 May 2021 02:22:07 +0300 |
parents | bdd4d89370a7 |
children | d26db4f82d7d |
comparison
equal
deleted
inserted
replaced
7831:bdd4d89370a7 | 7832:be82e72c9af8 |
---|---|
14 #define NGX_HTTP_AUTH_BUF_SIZE 2048 | 14 #define NGX_HTTP_AUTH_BUF_SIZE 2048 |
15 | 15 |
16 | 16 |
17 typedef struct { | 17 typedef struct { |
18 ngx_http_complex_value_t *realm; | 18 ngx_http_complex_value_t *realm; |
19 ngx_http_complex_value_t user_file; | 19 ngx_http_complex_value_t *user_file; |
20 } ngx_http_auth_basic_loc_conf_t; | 20 } ngx_http_auth_basic_loc_conf_t; |
21 | 21 |
22 | 22 |
23 static ngx_int_t ngx_http_auth_basic_handler(ngx_http_request_t *r); | 23 static ngx_int_t ngx_http_auth_basic_handler(ngx_http_request_t *r); |
24 static ngx_int_t ngx_http_auth_basic_crypt_handler(ngx_http_request_t *r, | 24 static ngx_int_t ngx_http_auth_basic_crypt_handler(ngx_http_request_t *r, |
105 sw_skip | 105 sw_skip |
106 } state; | 106 } state; |
107 | 107 |
108 alcf = ngx_http_get_module_loc_conf(r, ngx_http_auth_basic_module); | 108 alcf = ngx_http_get_module_loc_conf(r, ngx_http_auth_basic_module); |
109 | 109 |
110 if (alcf->realm == NULL || alcf->user_file.value.data == NULL) { | 110 if (alcf->realm == NULL || alcf->user_file == NULL) { |
111 return NGX_DECLINED; | 111 return NGX_DECLINED; |
112 } | 112 } |
113 | 113 |
114 if (ngx_http_complex_value(r, alcf->realm, &realm) != NGX_OK) { | 114 if (ngx_http_complex_value(r, alcf->realm, &realm) != NGX_OK) { |
115 return NGX_ERROR; | 115 return NGX_ERROR; |
131 | 131 |
132 if (rc == NGX_ERROR) { | 132 if (rc == NGX_ERROR) { |
133 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 133 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
134 } | 134 } |
135 | 135 |
136 if (ngx_http_complex_value(r, &alcf->user_file, &user_file) != NGX_OK) { | 136 if (ngx_http_complex_value(r, alcf->user_file, &user_file) != NGX_OK) { |
137 return NGX_ERROR; | 137 return NGX_ERROR; |
138 } | 138 } |
139 | 139 |
140 fd = ngx_open_file(user_file.data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); | 140 fd = ngx_open_file(user_file.data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); |
141 | 141 |
356 if (conf == NULL) { | 356 if (conf == NULL) { |
357 return NULL; | 357 return NULL; |
358 } | 358 } |
359 | 359 |
360 conf->realm = NGX_CONF_UNSET_PTR; | 360 conf->realm = NGX_CONF_UNSET_PTR; |
361 conf->user_file = NGX_CONF_UNSET_PTR; | |
361 | 362 |
362 return conf; | 363 return conf; |
363 } | 364 } |
364 | 365 |
365 | 366 |
368 { | 369 { |
369 ngx_http_auth_basic_loc_conf_t *prev = parent; | 370 ngx_http_auth_basic_loc_conf_t *prev = parent; |
370 ngx_http_auth_basic_loc_conf_t *conf = child; | 371 ngx_http_auth_basic_loc_conf_t *conf = child; |
371 | 372 |
372 ngx_conf_merge_ptr_value(conf->realm, prev->realm, NULL); | 373 ngx_conf_merge_ptr_value(conf->realm, prev->realm, NULL); |
373 | 374 ngx_conf_merge_ptr_value(conf->user_file, prev->user_file, NULL); |
374 if (conf->user_file.value.data == NULL) { | |
375 conf->user_file = prev->user_file; | |
376 } | |
377 | 375 |
378 return NGX_CONF_OK; | 376 return NGX_CONF_OK; |
379 } | 377 } |
380 | 378 |
381 | 379 |
404 ngx_http_auth_basic_loc_conf_t *alcf = conf; | 402 ngx_http_auth_basic_loc_conf_t *alcf = conf; |
405 | 403 |
406 ngx_str_t *value; | 404 ngx_str_t *value; |
407 ngx_http_compile_complex_value_t ccv; | 405 ngx_http_compile_complex_value_t ccv; |
408 | 406 |
409 if (alcf->user_file.value.data) { | 407 if (alcf->user_file != NGX_CONF_UNSET_PTR) { |
410 return "is duplicate"; | 408 return "is duplicate"; |
409 } | |
410 | |
411 alcf->user_file = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); | |
412 if (alcf->user_file == NULL) { | |
413 return NGX_CONF_ERROR; | |
411 } | 414 } |
412 | 415 |
413 value = cf->args->elts; | 416 value = cf->args->elts; |
414 | 417 |
415 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | 418 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
416 | 419 |
417 ccv.cf = cf; | 420 ccv.cf = cf; |
418 ccv.value = &value[1]; | 421 ccv.value = &value[1]; |
419 ccv.complex_value = &alcf->user_file; | 422 ccv.complex_value = alcf->user_file; |
420 ccv.zero = 1; | 423 ccv.zero = 1; |
421 ccv.conf_prefix = 1; | 424 ccv.conf_prefix = 1; |
422 | 425 |
423 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | 426 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
424 return NGX_CONF_ERROR; | 427 return NGX_CONF_ERROR; |