-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathngx_http_remote_passwd.c
85 lines (61 loc) · 2.46 KB
/
ngx_http_remote_passwd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* ngx_http_remote_passwd - Make the Basic Auth password available as $remote_passwd variable
*
* Copyright (c) 2011, Andreas Jaggi <[email protected]>
*/
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
static ngx_int_t ngx_http_remote_passwd_add_variable(ngx_conf_t *cf);
static ngx_int_t ngx_http_variable_remote_passwd(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data);
static ngx_http_module_t ngx_http_remote_passwd_module_ctx = {
ngx_http_remote_passwd_add_variable, /* preconfiguration */
NULL, /* postconfiguration */
NULL, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
NULL, /* merge server configuration */
NULL, /* create location configuration */
NULL, /* merge location configuration */
};
ngx_module_t ngx_http_remote_passwd_module = {
NGX_MODULE_V1,
&ngx_http_remote_passwd_module_ctx, /* module context */
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
NULL, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING
};
static ngx_str_t ngx_http_remote_passwd_variable_name = ngx_string("remote_passwd");
static ngx_int_t ngx_http_remote_passwd_add_variable(ngx_conf_t *cf) {
ngx_http_variable_t *v;
v = ngx_http_add_variable(cf, &ngx_http_remote_passwd_variable_name, 0);
if (v == NULL) {
return NGX_ERROR;
}
v->get_handler = ngx_http_variable_remote_passwd;
return NGX_OK;
}
static ngx_int_t ngx_http_variable_remote_passwd(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data) {
ngx_int_t rc;
rc = ngx_http_auth_basic_user(r);
if (rc == NGX_DECLINED) {
v->not_found = 1;
return NGX_OK;
}
if (rc == NGX_ERROR) {
return NGX_ERROR;
}
v->len = r->headers_in.passwd.len;
v->valid = 1;
v->no_cacheable = 0;
v->not_found = 0;
v->data = r->headers_in.passwd.data;
return NGX_OK;
}