]> granicus.if.org Git - apache/commitdiff
Enable authn_cache in the main easy-to-do authn provider modules
authorNick Kew <niq@apache.org>
Tue, 22 Jun 2010 23:03:11 +0000 (23:03 +0000)
committerNick Kew <niq@apache.org>
Tue, 22 Jun 2010 23:03:11 +0000 (23:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@957072 13f79535-47bb-0310-9956-ffa450edef68

modules/aaa/mod_authn_dbd.c
modules/aaa/mod_authn_dbm.c
modules/aaa/mod_authn_file.c

index 429d10782ab7099501f369b362f9c44c55793a66..e868363dd68fe5925cc521ab7d4bf49d7bdb056c 100644 (file)
@@ -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) =
 {
index 94c089aab518b24d79dd54a0fafa1cb4d7a26da4..f1e1dbecad89bea1387dafdd33963800ddd3cadd 100644 (file)
 
 #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) =
index 32185f39e40a806426bc82bba5364612feab019a..a50b47d2d8e3228386aaaa7299455f67dee7a252 100644 (file)
@@ -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) =