From b8769181a388c20dc196a7927404f2f8b4a76867 Mon Sep 17 00:00:00 2001 From: Nick Kew Date: Tue, 22 Jun 2010 23:03:11 +0000 Subject: [PATCH] Enable authn_cache in the main easy-to-do authn provider modules git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@957072 13f79535-47bb-0310-9956-ffa450edef68 --- modules/aaa/mod_authn_dbd.c | 12 +++++++++++- modules/aaa/mod_authn_dbm.c | 12 ++++++++++++ modules/aaa/mod_authn_file.c | 12 ++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/modules/aaa/mod_authn_dbd.c b/modules/aaa/mod_authn_dbd.c index 429d10782a..e868363dd6 100644 --- a/modules/aaa/mod_authn_dbd.c +++ b/modules/aaa/mod_authn_dbd.c @@ -41,6 +41,10 @@ typedef struct { /* optional function - look it up once in post_config */ static ap_dbd_t *(*authn_dbd_acquire_fn)(request_rec*) = NULL; static void (*authn_dbd_prepare_fn)(server_rec*, const char*, const char*) = NULL; +static APR_OPTIONAL_FN_TYPE(ap_authn_cache_store) *authn_cache_store = NULL; +#define AUTHN_CACHE_STORE(r,user,realm,data) \ + if (authn_cache_store != NULL) \ + authn_cache_store((r), "dbd", (user), (realm), (data)) static void *authn_dbd_cr_conf(apr_pool_t *pool, char *dummy) { @@ -168,6 +172,7 @@ static authn_status authn_dbd_password(request_rec *r, const char *user, if (!dbd_password) { return AUTH_USER_NOT_FOUND; } + AUTHN_CACHE_STORE(r, user, NULL, dbd_password); rv = apr_password_validate(password, dbd_password); @@ -258,10 +263,14 @@ static authn_status authn_dbd_realm(request_rec *r, const char *user, if (!dbd_hash) { return AUTH_USER_NOT_FOUND; } - + AUTHN_CACHE_STORE(r, user, realm, dbd_hash); *rethash = apr_pstrdup(r->pool, dbd_hash); return AUTH_USER_FOUND; } +static void opt_retr(void) +{ + authn_cache_store = APR_RETRIEVE_OPTIONAL_FN(ap_authn_cache_store); +} static void authn_dbd_hooks(apr_pool_t *p) { static const authn_provider authn_dbd_provider = { @@ -272,6 +281,7 @@ static void authn_dbd_hooks(apr_pool_t *p) ap_register_auth_provider(p, AUTHN_PROVIDER_GROUP, "dbd", AUTHN_PROVIDER_VERSION, &authn_dbd_provider, AP_AUTH_INTERNAL_PER_CONF); + ap_hook_optional_fn_retrieve(opt_retr, NULL, NULL, APR_HOOK_MIDDLE); } AP_DECLARE_MODULE(authn_dbd) = { diff --git a/modules/aaa/mod_authn_dbm.c b/modules/aaa/mod_authn_dbm.c index 94c089aab5..f1e1dbecad 100644 --- a/modules/aaa/mod_authn_dbm.c +++ b/modules/aaa/mod_authn_dbm.c @@ -39,6 +39,11 @@ #include "mod_auth.h" +static APR_OPTIONAL_FN_TYPE(ap_authn_cache_store) *authn_cache_store = NULL; +#define AUTHN_CACHE_STORE(r,user,realm,data) \ + if (authn_cache_store != NULL) \ + authn_cache_store((r), "dbm", (user), (realm), (data)) + typedef struct { const char *pwfile; const char *dbmtype; @@ -137,6 +142,7 @@ static authn_status check_dbm_pw(request_rec *r, const char *user, if (colon_pw) { *colon_pw = '\0'; } + AUTHN_CACHE_STORE(r, user, NULL, dbm_password); rv = apr_password_validate(password, dbm_password); @@ -177,6 +183,7 @@ static authn_status get_dbm_realm_hash(request_rec *r, const char *user, } *rethash = dbm_hash; + AUTHN_CACHE_STORE(r, user, realm, dbm_hash); return AUTH_USER_FOUND; } @@ -187,11 +194,16 @@ static const authn_provider authn_dbm_provider = &get_dbm_realm_hash, }; +static void opt_retr(void) +{ + authn_cache_store = APR_RETRIEVE_OPTIONAL_FN(ap_authn_cache_store); +} static void register_hooks(apr_pool_t *p) { ap_register_auth_provider(p, AUTHN_PROVIDER_GROUP, "dbm", AUTHN_PROVIDER_VERSION, &authn_dbm_provider, AP_AUTH_INTERNAL_PER_CONF); + ap_hook_optional_fn_retrieve(opt_retr, NULL, NULL, APR_HOOK_MIDDLE); } AP_DECLARE_MODULE(authn_dbm) = diff --git a/modules/aaa/mod_authn_file.c b/modules/aaa/mod_authn_file.c index 32185f39e4..a50b47d2d8 100644 --- a/modules/aaa/mod_authn_file.c +++ b/modules/aaa/mod_authn_file.c @@ -32,6 +32,11 @@ typedef struct { char *pwfile; } authn_file_config_rec; +static APR_OPTIONAL_FN_TYPE(ap_authn_cache_store) *authn_cache_store = NULL; +#define AUTHN_CACHE_STORE(r,user,realm,data) \ + if (authn_cache_store != NULL) \ + authn_cache_store((r), "file", (user), (realm), (data)) + static void *create_authn_file_dir_config(apr_pool_t *p, char *d) { authn_file_config_rec *conf = apr_palloc(p, sizeof(*conf)); @@ -99,6 +104,7 @@ static authn_status check_password(request_rec *r, const char *user, if (!file_password) { return AUTH_USER_NOT_FOUND; } + AUTHN_CACHE_STORE(r, user, NULL, file_password); status = apr_password_validate(password, file_password); if (status != APR_SUCCESS) { @@ -151,6 +157,7 @@ static authn_status get_realm_hash(request_rec *r, const char *user, } *rethash = file_hash; + AUTHN_CACHE_STORE(r, user, realm, file_hash); return AUTH_USER_FOUND; } @@ -161,11 +168,16 @@ static const authn_provider authn_file_provider = &get_realm_hash, }; +static void opt_retr(void) +{ + authn_cache_store = APR_RETRIEVE_OPTIONAL_FN(ap_authn_cache_store); +} static void register_hooks(apr_pool_t *p) { ap_register_auth_provider(p, AUTHN_PROVIDER_GROUP, "file", AUTHN_PROVIDER_VERSION, &authn_file_provider, AP_AUTH_INTERNAL_PER_CONF); + ap_hook_optional_fn_retrieve(opt_retr, NULL, NULL, APR_HOOK_MIDDLE); } AP_DECLARE_MODULE(authn_file) = -- 2.40.0