From 8c5c423c65b3111f16ba22280f5a04a01282dbd3 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sat, 31 Oct 2009 01:37:36 +0000 Subject: In apache module, expose groups match in env variable. In apache module, expose groups matched from "require groups" via HTTPAUTH_GROUPS environment variable. --- apache2x/mod_httpauth.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'apache2x/mod_httpauth.c') diff --git a/apache2x/mod_httpauth.c b/apache2x/mod_httpauth.c index f2c76ad..b52dbdf 100644 --- a/apache2x/mod_httpauth.c +++ b/apache2x/mod_httpauth.c @@ -1076,6 +1076,25 @@ write_needed_groups(httpauth_context_t *ctx, request_rec *r) return 0; } +static httpauth_request_t* +setup_request_hreq (request_rec *r, char *user, char *groups) +{ + httpauth_request_t* hreq; + + hreq = (httpauth_request_t*)apr_pcalloc (r->pool, sizeof (*hreq)); + hreq->user = r->user; + hreq->groups = groups; + + if (groups) + apr_table_setn (r->subprocess_env, "HTTPAUTH_GROUPS", groups); + else + apr_table_unset (r->subprocess_env, "HTTPAUTH_GROUPS"); + + ap_set_module_config (r->request_config, &httpauth_module, hreq); + + return hreq; +} + static int httpauth_authenticate(request_rec* r) { httpauth_context_t* ctx; @@ -1113,17 +1132,13 @@ static int httpauth_authenticate(request_rec* r) r->user = apr_pstrdup (r->pool, hreq->user); r->ap_auth_type = HTTPAUTH_AUTHTYPE; - /* Make another request config for this sub request */ - if (mainreq != r) { - groups = hreq->groups ? apr_pstrdup (r->pool, hreq->groups) : 0; - - hreq = (httpauth_request_t*)apr_pcalloc (r->pool, sizeof (*hreq)); - hreq->user = r->user; - hreq->groups = groups; - ap_set_module_config (r->request_config, &httpauth_module, hreq); - } + /* Make another request config for this sub request */ + if (mainreq != r) { + groups = hreq->groups ? apr_pstrdup (r->pool, hreq->groups) : NULL; + hreq = setup_request_hreq (r, r->user, groups); + } - return OK; + return OK; } /* @@ -1199,12 +1214,8 @@ retry: r->user = apr_pstrdup (r->pool, details); r->ap_auth_type = HTTPAUTH_AUTHTYPE; - hreq = (httpauth_request_t*)apr_pcalloc (r->pool, sizeof (*hreq)); - hreq->user = details; - hreq->groups = groups; - /* Mark request as successfully authenticated */ - ap_set_module_config (r->request_config, &httpauth_module, hreq); + hreq = setup_request_hreq (r, details, groups); return OK; } -- cgit v1.2.3