aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/ngx_http_auth_basic_module.c
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2021-05-06 02:22:07 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2021-05-06 02:22:07 +0300
commita6bce8c2274c971d4d61b78e002857d1ec69a901 (patch)
tree19cf5e3e00743b712d65d31e29dadfc1930869aa /src/http/modules/ngx_http_auth_basic_module.c
parent4faa84085379346fa1cf322907a1f9b6a7fbd583 (diff)
downloadnginx-a6bce8c2274c971d4d61b78e002857d1ec69a901.tar.gz
nginx-a6bce8c2274c971d4d61b78e002857d1ec69a901.zip
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.
Diffstat (limited to 'src/http/modules/ngx_http_auth_basic_module.c')
-rw-r--r--src/http/modules/ngx_http_auth_basic_module.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/http/modules/ngx_http_auth_basic_module.c b/src/http/modules/ngx_http_auth_basic_module.c
index 4e28b6ce6..069331982 100644
--- a/src/http/modules/ngx_http_auth_basic_module.c
+++ b/src/http/modules/ngx_http_auth_basic_module.c
@@ -16,7 +16,7 @@
typedef struct {
ngx_http_complex_value_t *realm;
- ngx_http_complex_value_t user_file;
+ ngx_http_complex_value_t *user_file;
} ngx_http_auth_basic_loc_conf_t;
@@ -107,7 +107,7 @@ ngx_http_auth_basic_handler(ngx_http_request_t *r)
alcf = ngx_http_get_module_loc_conf(r, ngx_http_auth_basic_module);
- if (alcf->realm == NULL || alcf->user_file.value.data == NULL) {
+ if (alcf->realm == NULL || alcf->user_file == NULL) {
return NGX_DECLINED;
}
@@ -133,7 +133,7 @@ ngx_http_auth_basic_handler(ngx_http_request_t *r)
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
- if (ngx_http_complex_value(r, &alcf->user_file, &user_file) != NGX_OK) {
+ if (ngx_http_complex_value(r, alcf->user_file, &user_file) != NGX_OK) {
return NGX_ERROR;
}
@@ -358,6 +358,7 @@ ngx_http_auth_basic_create_loc_conf(ngx_conf_t *cf)
}
conf->realm = NGX_CONF_UNSET_PTR;
+ conf->user_file = NGX_CONF_UNSET_PTR;
return conf;
}
@@ -370,10 +371,7 @@ ngx_http_auth_basic_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_http_auth_basic_loc_conf_t *conf = child;
ngx_conf_merge_ptr_value(conf->realm, prev->realm, NULL);
-
- if (conf->user_file.value.data == NULL) {
- conf->user_file = prev->user_file;
- }
+ ngx_conf_merge_ptr_value(conf->user_file, prev->user_file, NULL);
return NGX_CONF_OK;
}
@@ -406,17 +404,22 @@ ngx_http_auth_basic_user_file(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_str_t *value;
ngx_http_compile_complex_value_t ccv;
- if (alcf->user_file.value.data) {
+ if (alcf->user_file != NGX_CONF_UNSET_PTR) {
return "is duplicate";
}
+ alcf->user_file = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t));
+ if (alcf->user_file == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
value = cf->args->elts;
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
ccv.cf = cf;
ccv.value = &value[1];
- ccv.complex_value = &alcf->user_file;
+ ccv.complex_value = alcf->user_file;
ccv.zero = 1;
ccv.conf_prefix = 1;