httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John K. Sterling <j...@sterls.com>
Subject [PATCH] modules/aaa use optional function to register
Date Sat, 14 Sep 2002 14:45:36 GMT
Hi -

Here is the patch that changes the auth providers to use an optional  
function.  It delares the optional function in mod_auth.h, register it  
in mod_auth_basic.c, and retrieve it in mod_authn_file.c and  
mod_authn_dbm.c.

Notice how the only current auth_providers are dbm and file -- and  
there are no authz providers.  When those are switched, they simply  
need to lookup the optional function in the pre_config phase.  Even  
though there are no authz providers, I optionalized the register  
method.  I did my best to implement this without modifying any current  
logic, so it should be simple to read.

sterling

Index: modules/aaa/mod_auth.h
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/aaa/mod_auth.h,v
retrieving revision 1.3
diff -u -r1.3 mod_auth.h
--- modules/aaa/mod_auth.h	13 Sep 2002 21:55:31 -0000	1.3
+++ modules/aaa/mod_auth.h	14 Sep 2002 14:33:24 -0000
@@ -58,7 +58,7 @@

  #include "apr_pools.h"
  #include "apr_hash.h"
-
+#include "apr_optional.h"
  #include "httpd.h"

  #ifdef __cplusplus
@@ -106,8 +106,10 @@
                                     const char *realm, char **rethash);
  } authn_provider;

+APR_DECLARE_OPTIONAL_FN(void, authn_register_provider, (apr_pool_t *p,  
const char *name,
+                                                        const  
authn_provider *provider));
  AAA_DECLARE(void) authn_register_provider(apr_pool_t *p, const char  
*name,
-                                         const authn_provider  
*provider);
+                                          const authn_provider  
*provider);
  AAA_DECLARE(const authn_provider *) authn_lookup_provider(const char  
*name);

  typedef struct {
@@ -117,7 +119,12 @@

  AAA_DECLARE(void) authz_register_provider(apr_pool_t *p, const char  
*name,
                                           const authz_provider  
*provider);
+
+APR_DECLARE_OPTIONAL_FN(void, authz_register_provider,
+                        (apr_pool_t *p, const char *name, const  
authz_provider *provider)
+                       );
  AAA_DECLARE(const authz_provider *) authz_lookup_provider(const char  
*name);
+
  #ifdef __cplusplus
  }
  #endif
Index: modules/aaa/mod_auth_basic.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/aaa/mod_auth_basic.c,v
retrieving revision 1.4
diff -u -r1.4 mod_auth_basic.c
--- modules/aaa/mod_auth_basic.c	10 Sep 2002 14:40:46 -0000	1.4
+++ modules/aaa/mod_auth_basic.c	14 Sep 2002 14:33:24 -0000
@@ -285,6 +285,8 @@

  static void register_hooks(apr_pool_t *p)
  {
+    APR_REGISTER_OPTIONAL_FN(authn_register_provider);
+    APR_REGISTER_OPTIONAL_FN(authz_register_provider);
       
ap_hook_check_user_id(authenticate_basic_user,NULL,NULL,APR_HOOK_MIDDLE) 
;
  }

Index: modules/aaa/mod_authn_dbm.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/aaa/mod_authn_dbm.c,v
retrieving revision 1.3
diff -u -r1.3 mod_authn_dbm.c
--- modules/aaa/mod_authn_dbm.c	13 Sep 2002 17:33:27 -0000	1.3
+++ modules/aaa/mod_authn_dbm.c	14 Sep 2002 14:33:27 -0000
@@ -198,9 +198,23 @@
      NULL,               /* No realm support yet. */
  };

+static int authn_dbm_pre_config(apr_pool_t *pconf, apr_pool_t *plog,  
apr_pool_t *ptemp)
+{
+    APR_OPTIONAL_FN_TYPE(authn_register_provider) *register_provider;
+    register_provider =  
APR_RETRIEVE_OPTIONAL_FN(authn_register_provider);
+    if( register_provider == NULL ) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, NULL, NULL,
+                     "Unable to register auth_dbm as a provider.  This  
is probably because auth_basic is not loaded");
+        return HTTP_INTERNAL_SERVER_ERROR;
+    } else {
+        register_provider(pconf, "dbm", &authn_dbm_provider);
+    }
+    return OK;
+}
+
  static void register_hooks(apr_pool_t *p)
  {
-    authn_register_provider(p, "dbm", &authn_dbm_provider);
+    ap_hook_pre_config(authn_dbm_pre_config, NULL, NULL,  
APR_HOOK_FIRST);
  }

  module AP_MODULE_DECLARE_DATA authn_dbm_module =
Index: modules/aaa/mod_authn_file.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/aaa/mod_authn_file.c,v
retrieving revision 1.2
diff -u -r1.2 mod_authn_file.c
--- modules/aaa/mod_authn_file.c	10 Sep 2002 06:57:03 -0000	1.2
+++ modules/aaa/mod_authn_file.c	14 Sep 2002 14:33:27 -0000
@@ -224,9 +224,24 @@
      &get_realm_hash,
  };

+static int authn_file_pre_config(apr_pool_t *pconf, apr_pool_t *plog,  
apr_pool_t *ptemp)
+{
+    APR_OPTIONAL_FN_TYPE(authn_register_provider) *register_provider;
+
+    register_provider =  
APR_RETRIEVE_OPTIONAL_FN(authn_register_provider);
+    if( register_provider == NULL ) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, NULL, NULL,
+                                 "Unable to register auth_file as a  
provider.  This is probably because auth_basic is not loaded");
+        return HTTP_INTERNAL_SERVER_ERROR;
+    } else {
+        register_provider(pconf, "file", &authn_file_provider);
+    }
+    return OK;
+}
+
  static void register_hooks(apr_pool_t *p)
  {
-    authn_register_provider(p, "file", &authn_file_provider);
+    ap_hook_pre_config(authn_file_pre_config, NULL, NULL,  
APR_HOOK_FIRST);
  }

  module AP_MODULE_DECLARE_DATA authn_file_module =


Mime
View raw message