This repository has been archived by the owner on Feb 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
ngx_http_auth_crowd_module.c
673 lines (545 loc) · 17.6 KB
/
ngx_http_auth_crowd_module.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
/*
* Copyright (C) 2013 Reaktor
* Kare Nuorteva <[email protected]>
* Pasi Savanainen <[email protected]>
*
* Based on nginx's 'ngx_http_auth_basic_module.c' by Igor Sysoev and apache's
* 'mod_auth_pam.c' by Ingo Luetkebolhe and ngx_http_auth_pam_module.c by Sergio Talens-Oliag
*
*/
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include <string.h>
#include <curl/curl.h>
// CROWD AUTHENTICATION
/* Module context data */
typedef struct {
char domain[128];
char name[128];
char secure[128];
} ngx_http_auth_crowd_ctx_t;
/* Crowd userinfo */
typedef struct {
ngx_str_t username;
ngx_str_t password;
} ngx_crowd_userinfo;
/* Module configuration struct */
typedef struct {
ngx_str_t realm; /* http basic auth realm */
ngx_str_t crowd_url; /* Crowd server URL */
ngx_str_t crowd_service; /* Crowd service name */
ngx_str_t crowd_password; /* Crowd service password */
} ngx_http_auth_crowd_loc_conf_t;
#define LOG(r) ((r)->connection->log)
static const char *CROWD_SESSION_JSON_TEMPLATE= "{\
\"username\": \"%V\",\
\"password\": \"%V\",\
\"validation-factors\": {\
\"validationFactors\": [{\
\"name\": \"remote_address\",\
\"value\": \"%V\"\
}]}}";
static const char *CROWD_SESSION_VALIDATE_JSON_TEMPLATE= "{\
\"validationFactors\": [{\
\"name\": \"remote_address\", \
\"value\": \"%V\" \
}]}";
struct CrowdRequest {
/* from confifuration */
ngx_str_t server_username;
ngx_str_t server_password;
/* dynamically generated */
ngx_str_t request_url;
ngx_str_t body; /* request body */
unsigned int method; /* 1 == GET */
};
struct CrowdResponse {
int response;
char error_message[255];
};
struct HttpResponse {
char *body;
size_t length;
};
struct HttpRequest {
const char *body;
size_t length;
};
/* Module handler */
static ngx_int_t ngx_http_auth_crowd_handler(ngx_http_request_t *r);
static ngx_int_t ngx_http_auth_crowd_authenticate(ngx_http_request_t *r,
ngx_http_auth_crowd_ctx_t *ctx, void *conf);
static ngx_int_t ngx_http_auth_crowd_set_realm(ngx_http_request_t *r,
ngx_str_t *realm);
static void *ngx_http_auth_crowd_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_auth_crowd_merge_loc_conf(ngx_conf_t *cf,
void *parent, void *child);
static ngx_int_t ngx_http_auth_crowd_init(ngx_conf_t *cf);
static char *ngx_http_auth_crowd(ngx_conf_t *cf, void *post, void *data);
static ngx_conf_post_handler_pt ngx_http_auth_crowd_p = ngx_http_auth_crowd;
static ngx_int_t
ngx_http_auth_crowd_get_token(ngx_http_request_t *r, ngx_str_t *name, ngx_str_t *token)
{
return ngx_http_parse_multi_header_lines(&r->headers_in.cookies, name, token);
}
static int
parse_name_value(const char *json, const char *name, char *value, size_t len, char endm)
{
/* "name1":"value2","name2":"value2" */
char *str = strdup(json);
char *s, *end;
int ec = NGX_DECLINED;
s = strstr(str, name);
if (!s)
return ec;
end = strchr(s + strlen(name), endm);
if (end)
*(end) = '\0';
if (len >= (size_t)(end - (s + strlen(name)))) {
strcpy(value, s + strlen(name));
ec = NGX_OK;
}
free(str);
return ec;
}
static int
parse_config_from_json(ngx_http_request_t *r, const char *json, ngx_http_auth_crowd_ctx_t *cc)
{
// {"domain":".my.domain.fi","secure":false,"name":"my-crowd.token_key"},
const char *domain = "\"domain\":\"";
const char *name = "\"name\":\"";
const char *secure = "\"secure\":";
char buff[6];
int ec1, ec2, ec3;
ec1 = parse_name_value(json, domain, cc->domain, 128, '"');
ec2 = parse_name_value(json, name, cc->name, 128, '"');
ec3 = parse_name_value(json, secure, buff, 6, ',');
if (!strcmp(buff, "true"))
strcpy(cc->secure, "secure");
if (ec1 != NGX_OK || ec2 != NGX_OK || ec3 != NGX_OK)
return NGX_DECLINED;
return NGX_OK;
}
int parse_token_from_json(ngx_http_request_t *r, char const *json, char *token, size_t len)
{
const char *tname = "\"token\":\"";
return parse_name_value(json, tname, token, len, '"');
}
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
{
struct HttpRequest *data = (struct HttpRequest *) userp;
if (size * nmemb < 1)
return 0;
if (data->length) {
*(char *) ptr = data->body[0];
data->body++;
data->length--;
return 1;
}
return 0;
}
static size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
struct HttpResponse *response = (struct HttpResponse *) userp;
response->body = realloc(response->body, response->length + realsize + 1);
if (response->body == NULL) {
perror("Out of memory.");
return 0;
}
memcpy(&(response->body[response->length]), contents, realsize);
response->length += realsize;
response->body[response->length] = 0;
return realsize;
}
void
print_cookies(CURL *curl, ngx_log_t *log)
{
struct curl_slist *cookies;
CURLcode res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
if (res != CURLE_OK) {
ngx_log_debug(NGX_LOG_DEBUG_HTTP, log, 0, "Get cookies failed: '%s'", curl_easy_strerror(res));
}
struct curl_slist *nc = cookies;
int i = 1;
ngx_log_debug(NGX_LOG_DEBUG_HTTP, log, 0, "COOKIE DEBUG");
while (nc) {
ngx_log_debug(NGX_LOG_DEBUG_HTTP, log, 0, "[%d]: '%s'", i, nc->data);
nc = nc->next;
i++;
}
ngx_log_debug(NGX_LOG_DEBUG_HTTP, log, 0, "END COOKIE DEBUG");
curl_slist_free_all(cookies);
}
int
curl_transaction(ngx_http_request_t *r, struct CrowdRequest *crowd_request, int expected_http_code, void *data)
{
struct HttpRequest request;
struct HttpResponse response;
char error_message[CURL_ERROR_SIZE];
u_char server_user_pass[128] = { '\0' };
int get_config = 0; /* this is terrible */
request.body = (char *) crowd_request->body.data;
request.length = crowd_request->body.len;
/* we reallocate a bigger buffer when there is data to be received */
response.body = calloc(1, sizeof(char *));
response.length = 0;
CURL *curl = curl_easy_init();
if (curl == NULL)
return NGX_ERROR;
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "Accept: application/json");
if (crowd_request->method != 1)
headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
headers = curl_slist_append(headers, "Expect:");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
/* Log all curl requests, only use this for debugging */
#if DEBUG
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
#else
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
#endif
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); /* don't verify peer against cert */
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); /* don't verify host against cert */
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); /* bounce through login to next page */
if (crowd_request->method == 1) {
get_config = 1;
} else {
curl_easy_setopt(curl, CURLOPT_POST, 1L);
}
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_message);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(curl, CURLOPT_READDATA, &request);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "nginx-auth-agent/1.0");
ngx_snprintf(server_user_pass, sizeof(server_user_pass), "%V:%V",
&crowd_request->server_username, &crowd_request->server_password);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_easy_setopt(curl, CURLOPT_USERPWD, (char *) server_user_pass);
curl_easy_setopt(curl, CURLOPT_URL, crowd_request->request_url.data);
/* do it now */
CURLcode curl_code = curl_easy_perform(curl);
long http_code = 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
int error_code = NGX_OK;
if (curl_code != 0) {
error_code = NGX_ERROR;
}
if (http_code == expected_http_code) {
if (data != NULL) {
if (!get_config)
error_code = parse_token_from_json(r, response.body, data, 128);
else
error_code = parse_config_from_json(r, response.body, data);
}
goto cleanup;
} else {
error_code = NGX_ERROR;
}
cleanup:
free(response.body);
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return error_code;
}
static int
get_cookie_config(ngx_http_request_t *r, ngx_http_auth_crowd_loc_conf_t *alcf, ngx_http_auth_crowd_ctx_t *cc)
{
const char *url_template = "%V/rest/usermanagement/latest/config/cookie";
u_char url_buf[256] = { '\0' };
struct CrowdRequest request;
ngx_snprintf(url_buf, sizeof(url_buf), url_template, &alcf->crowd_url);
ngx_str_set(&request.request_url, url_buf);
request.server_username = alcf->crowd_service;
request.server_password = alcf->crowd_password;
ngx_str_null(&request.body);
request.method = 1;
return curl_transaction(r, &request, 200, cc);
}
int
create_sso_session(ngx_http_request_t *r, ngx_http_auth_crowd_loc_conf_t *alcf, ngx_str_t *username,
ngx_str_t *password, char *token)
{
const char *url_template = "%V/rest/usermanagement/latest/session";
u_char session_json[256] = { '\0' };
u_char url_buf[256]= { '\0' };
struct CrowdRequest request;
request.server_username = alcf->crowd_service;
request.server_password = alcf->crowd_password;
ngx_snprintf(session_json, sizeof(session_json), CROWD_SESSION_JSON_TEMPLATE,
username, password, &r->connection->addr_text);
ngx_snprintf(url_buf, sizeof(url_buf), url_template, &alcf->crowd_url);
ngx_str_set(&request.body, session_json);
ngx_str_set(&request.request_url, url_buf);
request.method = 0;
return curl_transaction(r, &request, 201, token);
}
int
validate_sso_session_token(ngx_http_request_t *r, ngx_http_auth_crowd_loc_conf_t *alcf, ngx_str_t *token)
{
const char *url_template = "%V/rest/usermanagement/latest/session/%V";
u_char session_json[256] = { '\0' };
u_char url_buf[256] = { '\0' };
struct CrowdRequest request;
ngx_snprintf(session_json, sizeof(session_json),
CROWD_SESSION_VALIDATE_JSON_TEMPLATE, &r->connection->addr_text);
ngx_snprintf(url_buf, sizeof(url_buf), url_template, &alcf->crowd_url, token);
ngx_str_set(&request.body, session_json);
ngx_str_set(&request.request_url, url_buf);
request.server_username = alcf->crowd_service;
request.server_password = alcf->crowd_password;
request.method = 0;
return curl_transaction(r, &request, 200, NULL);
}
// END CROWD AUTHENTICATION
static char *
ngx_http_auth_crowd(ngx_conf_t *cf, void *post, void *data)
{
ngx_str_t *realm = data;
size_t len;
u_char *basic, *p;
if (ngx_strcmp(realm->data, "off") == 0) {
realm->len = 0;
realm->data = (u_char *) "";
return NGX_CONF_OK;
}
len = sizeof("Basic realm=\"") - 1 + realm->len + 1;
basic = ngx_palloc(cf->pool, len);
if (basic == NULL) {
return NGX_CONF_ERROR;
}
p = ngx_cpymem(basic, "Basic realm=\"", sizeof("Basic realm=\"") - 1);
p = ngx_cpymem(p, realm->data, realm->len);
*p = '"';
realm->len = len;
realm->data = basic;
return NGX_CONF_OK;
}
static ngx_command_t ngx_http_auth_crowd_commands[] = {
{
ngx_string("auth_crowd"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_auth_crowd_loc_conf_t, realm),
&ngx_http_auth_crowd_p
},
{
ngx_string("auth_crowd_url"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_auth_crowd_loc_conf_t, crowd_url),
NULL
},
{
ngx_string("auth_crowd_service"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_auth_crowd_loc_conf_t, crowd_service),
NULL
},
{
ngx_string("auth_crowd_password"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_auth_crowd_loc_conf_t, crowd_password),
NULL
},
ngx_null_command
};
static ngx_http_module_t ngx_http_auth_crowd_module_ctx = {
NULL, /* preconfiguration */
ngx_http_auth_crowd_init, /* postconfiguration */
NULL, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
NULL, /* merge server configuration */
ngx_http_auth_crowd_create_loc_conf, /* create location configuration */
ngx_http_auth_crowd_merge_loc_conf /* merge location configuration */
};
ngx_module_t ngx_http_auth_crowd_module = {
NGX_MODULE_V1,
&ngx_http_auth_crowd_module_ctx, /* module context */
ngx_http_auth_crowd_commands, /* 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_int_t
ngx_http_auth_crowd_handler(ngx_http_request_t *r)
{
ngx_int_t rc;
ngx_http_auth_crowd_ctx_t *ctx;
ngx_http_auth_crowd_loc_conf_t *alcf;
ngx_str_t token, name;
alcf = ngx_http_get_module_loc_conf(r, ngx_http_auth_crowd_module);
if (alcf->realm.len == 0) {
return NGX_DECLINED;
}
/* Find out cookie configuration */
ctx = ngx_http_get_module_ctx(r, ngx_http_auth_crowd_module);
if (!ctx) {
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_auth_crowd_ctx_t));
if (ctx == NULL) {
return NGX_ERROR;
}
rc = get_cookie_config(r, alcf, ctx);
if (rc != NGX_OK) {
return NGX_HTTP_SERVICE_UNAVAILABLE;
}
ngx_http_set_ctx(r, ctx, ngx_http_auth_crowd_module);
}
/* Validate old SSO session */
ngx_str_set(&name, ctx->name);
rc = ngx_http_auth_crowd_get_token(r, &name, &token);
if (rc != NGX_DECLINED) {
rc = validate_sso_session_token(r, alcf, &token);
if (rc != NGX_OK)
return ngx_http_auth_crowd_set_realm(r, &alcf->realm);
}
/* Create new SSO session */
/* Decode http auth user and passwd, leaving values on the request */
rc = ngx_http_auth_basic_user(r);
if (rc == NGX_DECLINED) {
return ngx_http_auth_crowd_set_realm(r, &alcf->realm);
}
if (rc == NGX_ERROR) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
/* Check user & password using Crowd */
return ngx_http_auth_crowd_authenticate(r, ctx, alcf);
}
void
print_headers(ngx_http_request_t *r, ngx_log_t *log)
{
ngx_uint_t i;
ngx_array_t *cookie = &r->headers_in.cookies;
ngx_table_elt_t **elem;
elem = cookie->elts;
for (i = 0; i < cookie->nelts; i++) {
ngx_log_debug(NGX_LOG_DEBUG_HTTP, log, 0, "'%V' -> '%V'", &elem[i]->key, &elem[i]->value);
}
}
static ngx_int_t
ngx_http_auth_crowd_set_cookie(ngx_http_request_t *r, const char *name, const char *token,
const char *domain, const char *secure)
{
const char cookie_template[] = "%s=%s;domain=%s;%s";
ngx_table_elt_t *h;
char *cookie;
size_t len = sizeof(cookie_template) - 8 +
strlen(name) + strlen(token) + strlen(domain) + strlen(secure);
cookie = ngx_pnalloc(r->pool, len);
if (cookie == NULL) {
return NGX_ERROR;
}
snprintf(cookie, len, cookie_template, name, token, domain, secure);
h = ngx_list_push(&r->headers_out.headers);
if (h == NULL) {
return NGX_ERROR;
}
ngx_str_set(&h->key, "Set-Cookie");
ngx_str_set(&h->value, cookie);
h->hash = 1;
return NGX_OK;
}
static ngx_int_t
ngx_http_auth_crowd_authenticate(ngx_http_request_t *r, ngx_http_auth_crowd_ctx_t *ctx, void *conf)
{
ngx_http_auth_crowd_loc_conf_t *alcf;
ngx_crowd_userinfo uinfo;
alcf = conf;
size_t len;
u_char *uname_buf, *p;
/**
* Get username and password, note that r->headers_in.user contains the
* string 'user:pass', so we need to copy the username
**/
for (len = 0; len < r->headers_in.user.len; len++) {
if (r->headers_in.user.data[len] == ':') {
break;
}
}
uname_buf = ngx_palloc(r->pool, len + 1);
if (uname_buf == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
p = ngx_cpymem(uname_buf, r->headers_in.user.data , len);
*p ='\0';
uinfo.username.data = uname_buf;
uinfo.username.len = len;
uinfo.password.data = r->headers_in.passwd.data;
uinfo.password.len = r->headers_in.passwd.len;
char token[128];
int status = create_sso_session(r, alcf, &uinfo.username, &uinfo.password, token);
if (status == NGX_OK) {
return ngx_http_auth_crowd_set_cookie(r, ctx->name, token, ctx->domain, ctx->secure);
}
return ngx_http_auth_crowd_set_realm(r, &alcf->realm);
}
static ngx_int_t
ngx_http_auth_crowd_set_realm(ngx_http_request_t *r, ngx_str_t *realm)
{
r->headers_out.www_authenticate = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.www_authenticate == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
r->headers_out.www_authenticate->hash = 1;
ngx_str_set(&r->headers_out.www_authenticate->key, "WWW-Authenticate");
r->headers_out.www_authenticate->value = *realm;
return NGX_HTTP_UNAUTHORIZED;
}
static void *
ngx_http_auth_crowd_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_auth_crowd_loc_conf_t *conf;
conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_auth_crowd_loc_conf_t));
if (conf == NULL) {
return NGX_CONF_ERROR;
}
return conf;
}
static char *
ngx_http_auth_crowd_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_auth_crowd_loc_conf_t *prev = parent;
ngx_http_auth_crowd_loc_conf_t *conf = child;
if (conf->realm.data == NULL) {
conf->realm = prev->realm;
}
if (conf->crowd_url.data == NULL) {
conf->crowd_url = prev->crowd_url;
}
if (conf->crowd_service.data == NULL) {
conf->crowd_service = prev->crowd_service;
}
if (conf->crowd_password.data == NULL) {
conf->crowd_password = prev->crowd_password;
}
return NGX_CONF_OK;
}
static ngx_int_t
ngx_http_auth_crowd_init(ngx_conf_t *cf)
{
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
}
*h = ngx_http_auth_crowd_handler;
return NGX_OK;
}