14 #define NGX_HTTP_AUTH_BUF_SIZE 2048
33 static void ngx_http_auth_basic_close(
ngx_file_t *file);
34 static void *ngx_http_auth_basic_create_loc_conf(
ngx_conf_t *cf);
35 static char *ngx_http_auth_basic_merge_loc_conf(
ngx_conf_t *cf,
36 void *parent,
void *child);
55 ngx_http_auth_basic_user_file,
66 ngx_http_auth_basic_init,
74 ngx_http_auth_basic_create_loc_conf,
75 ngx_http_auth_basic_merge_loc_conf
81 &ngx_http_auth_basic_module_ctx,
82 ngx_http_auth_basic_commands,
132 return ngx_http_auth_basic_crypt_handler(r, ctx, &ctx->
passwd,
141 "no user/password was provided for basic authentication");
143 return ngx_http_auth_basic_set_realm(r, &realm);
177 file.
name = user_file;
193 ngx_http_auth_basic_close(&file);
201 for (i = left; i < left + n; i++) {
207 if (buf[i] ==
'#' || buf[i] ==
CR) {
232 if (buf[i] ==
LF || buf[i] ==
CR || buf[i] ==
':') {
235 ngx_http_auth_basic_close(&file);
237 pwd.
len = i - passwd;
238 pwd.
data = &buf[passwd];
240 return ngx_http_auth_basic_crypt_handler(r, NULL, &pwd,
256 if (state == sw_passwd) {
257 left = left + n - passwd;
268 ngx_http_auth_basic_close(&file);
270 if (state == sw_passwd) {
271 pwd.
len = i - passwd;
273 if (pwd.
data == NULL) {
279 return ngx_http_auth_basic_crypt_handler(r, NULL, &pwd, &realm);
283 "user \"%V\" was not found in \"%V\"",
286 return ngx_http_auth_basic_set_realm(r, &realm);
301 "rc: %d user: \"%V\" salt: \"%s\"",
310 "encrypted: \"%s\"", encrypted);
313 "user \"%V\": password mismatch",
316 return ngx_http_auth_basic_set_realm(r, realm);
360 len =
sizeof(
"Basic realm=\"\"") - 1 + realm->
len;
367 p =
ngx_cpymem(basic,
"Basic realm=\"",
sizeof(
"Basic realm=\"") - 1);
390 ngx_http_auth_basic_create_loc_conf(
ngx_conf_t *cf)
404 ngx_http_auth_basic_merge_loc_conf(
ngx_conf_t *cf,
void *parent,
void *child)
409 if (conf->
realm == NULL) {
434 *h = ngx_http_auth_basic_handler;
449 return "is duplicate";
457 ccv.
value = &value[1];