]> granicus.if.org Git - apache/commitdiff
Add ap_register_provider and ap_lookup_provider functions which resolve
authorJustin Erenkrantz <jerenkrantz@apache.org>
Fri, 20 Sep 2002 00:57:50 +0000 (00:57 +0000)
committerJustin Erenkrantz <jerenkrantz@apache.org>
Fri, 20 Sep 2002 00:57:50 +0000 (00:57 +0000)
the DSO link problems for DAV and the new aaa modules by moving the
provider code into the core of the server and generalizing them to be
used by any code.

Remove the auth{nz}_*_provider functions as they are no longer needed.

Change the dav_*_provider functions to wrap the ap_*_provider functions
as they have a bit more of a historical precedent that we should keep
around.

Reviewed by: John K. Sterling <john@sterls.com> (in concept)

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96919 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
include/ap_provider.h [new file with mode: 0644]
modules/aaa/config.m4
modules/aaa/mod_auth.h
modules/aaa/mod_auth_basic.c
modules/aaa/mod_auth_digest.c
modules/aaa/mod_authn_dbm.c
modules/aaa/mod_authn_file.c
modules/dav/main/providers.c
server/Makefile.in
server/provider.c [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index 8803fa1696065e5f8286f35c1ad52e0bfc4ce8ee..a0826362691bad3f20928653619e6f848276544d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
 Changes with Apache 2.0.43
 
+  *) Add ap_register_provider/ap_lookup_provider API.
+     [John K. Sterling <john@sterls.com>, Justin Erenkrantz]
+
   *) Add -p option to apxs to allow programs to be compiled with apxs.
      [Justin Erenkrantz]
 
diff --git a/include/ap_provider.h b/include/ap_provider.h
new file mode 100644 (file)
index 0000000..c5e06d4
--- /dev/null
@@ -0,0 +1,88 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+#ifndef AP_PROVIDER_H
+#define AP_PROVIDER_H
+
+#include "ap_config.h"
+
+/**
+ * @package Provider API
+ */
+
+/**
+ * This function is used to register a provider with the global
+ * provider pool.
+ * @param pool The pool to create any storage from
+ * @param provider_group The group to store the provider in
+ * @param provider_name The name for this provider
+ * @param provider Opaque structure for this provider
+ * @return APR_SUCCESS if all went well
+ */
+AP_DECLARE(apr_status_t) ap_register_provider(apr_pool_t *pool,
+                                              const char *provider_group,
+                                              const char *provider_name,
+                                              const void *provider);
+
+/**
+ * This function is used to retrieve a provider from the global
+ * provider pool.
+ * @param provider_group The group to look for this provider in
+ * @param provider_name The name for the provider
+ * @return provider point if found, NULL otherwise
+ */
+AP_DECLARE(void *) ap_lookup_provider(const char *provider_group,
+                                      const char *provider_name);
+
+#endif
index 500623cfb4c523f1e60f1824e0eb011246bfe7a2..8579d33b4dd8e427ab9ed2824182abd67473bd6c 100644 (file)
@@ -33,12 +33,8 @@ APACHE_MODULE(authz_default, authorization control backstopper, , , yes)
 
 dnl these are the front-end authentication modules
 
-std_auth_provider_objects="auth_provider.lo"
-
-APACHE_MODULE(auth_basic, basic authentication,
-              mod_auth_basic.lo $std_auth_provider_objects, , yes)
-APACHE_MODULE(auth_digest, RFC2617 Digest authentication,
-              mod_auth_digest.lo $std_auth_provider_objects , , most, [
+APACHE_MODULE(auth_basic, basic authentication, , , yes)
+APACHE_MODULE(auth_digest, RFC2617 Digest authentication, , , most, [
   ap_old_cppflags=$CPPFLAGS
   CPPFLAGS="$CPPFLAGS -I$APR_SOURCE_DIR/include -I$abs_builddir/srclib/apr/include"
   AC_TRY_COMPILE([#include <apr.h>], [
index f0f4fbf4ccfc2bbd5c14643d568410718bd9a2af..bf334601b09699eae7139690841d02d3cfd51dd7 100644 (file)
 extern "C" {
 #endif
 
-/* Create a set of AAA_DECLARE(type) and AAA_DECLARE_DATA with 
- * appropriate export and import tags for the platform
- */
-#if !defined(WIN32)
-#define AAA_DECLARE(type)            type
-#define AAA_DECLARE_DATA
-#elif defined(AAA_DECLARE_STATIC)
-#define AAA_DECLARE(type)            type __stdcall
-#define AAA_DECLARE_DATA
-#elif defined(AAA_DECLARE_EXPORT)
-#define AAA_DECLARE(type)            __declspec(dllexport) type __stdcall
-#define AAA_DECLARE_DATA             __declspec(dllexport)
-#else
-#define AAA_DECLARE(type)            __declspec(dllimport) type __stdcall
-#define AAA_DECLARE_DATA             __declspec(dllimport)
-#endif
-
+#define AUTHN_PROVIDER_GROUP "authn"
 #define AUTHN_DEFAULT_PROVIDER "file"
 
 typedef enum {
@@ -115,18 +99,11 @@ struct authn_provider_list {
     authn_provider_list *next;
 };
 
-AAA_DECLARE(void) authn_register_provider(apr_pool_t *p, const char *name,
-                                         const authn_provider *provider);
-AAA_DECLARE(const authn_provider *) authn_lookup_provider(const char *name);
-
 typedef struct {
     /* For a given user, return a hash of all groups the user belongs to.  */
     apr_hash_t * (*get_user_groups)(request_rec *r, const char *user);
 } authz_provider;
 
-AAA_DECLARE(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 c4b390ff87ee56f2c047396e14b3f285c5eb543e..a5f99beff803d1c1c180e892b79fa5f9efd45fa9 100644 (file)
@@ -70,6 +70,7 @@
 #include "http_log.h"
 #include "http_protocol.h"
 #include "http_request.h"
+#include "ap_provider.h"
 
 #include "mod_auth.h"
 
@@ -113,7 +114,8 @@ static const char *add_authn_provider(cmd_parms *cmd, void *config,
     newp->provider_name = provider_name;
 
     /* lookup and cache the actual provider now */
-    newp->provider = authn_lookup_provider(newp->provider_name);
+    newp->provider = ap_lookup_provider(AUTHN_PROVIDER_GROUP,
+                                        newp->provider_name);
 
     if (newp->provider == NULL) {
         /* by the time they use it, the provider should be loaded and
@@ -253,7 +255,8 @@ static int authenticate_basic_user(request_rec *r)
          * provider.
          */
         if (!current_provider) {
-            provider = authn_lookup_provider(AUTHN_DEFAULT_PROVIDER);
+            provider = ap_lookup_provider(AUTHN_PROVIDER_GROUP,
+                                          AUTHN_DEFAULT_PROVIDER);
         }
         else {
             provider = current_provider->provider;
index 4058c93b4c13c19592bfd8b7327aa68bffef8b12..4abc035f93b4243dc35018210d4a1db6d20f9345 100644 (file)
 #include "util_md5.h"
 #include "apr_shm.h"
 #include "apr_rmm.h"
+#include "ap_provider.h"
 
 #include "mod_auth.h"
 
@@ -504,7 +505,8 @@ static const char *add_authn_provider(cmd_parms *cmd, void *config,
     newp->provider_name = provider_name;
 
     /* lookup and cache the actual provider now */
-    newp->provider = authn_lookup_provider(newp->provider_name);
+    newp->provider = ap_lookup_provider(AUTHN_PROVIDER_GROUP,
+                                        newp->provider_name);
 
     if (newp->provider == NULL) {
        /* by the time they use it, the provider should be loaded and
@@ -1473,7 +1475,8 @@ static const char *get_hash(request_rec *r, const char *user,
          * provider.
          */
         if (!current_provider) {
-            provider = authn_lookup_provider(AUTHN_DEFAULT_PROVIDER);
+            provider = ap_lookup_provider(AUTHN_PROVIDER_GROUP,
+                                          AUTHN_DEFAULT_PROVIDER);
         }
         else {
             provider = current_provider->provider;
index dcce4768ee240f7f842e5ec4084ce17be4d3a687..33486c48721b9b467b27130d0956587d0510773f 100644 (file)
@@ -190,7 +190,7 @@ static const authn_provider authn_dbm_provider =
 
 static void register_hooks(apr_pool_t *p)
 {
-    authn_register_provider(p, "dbm", &authn_dbm_provider);
+    ap_register_provider(p, AUTHN_PROVIDER_GROUP, "dbm", &authn_dbm_provider);
 }
 
 module AP_MODULE_DECLARE_DATA authn_dbm_module =
index 422a9ac2a97590acb0dea77799486dc6b545aa00..de79253e67265e33f144637ce1bf701ae67f715e 100644 (file)
@@ -218,7 +218,7 @@ static const authn_provider authn_file_provider =
 
 static void register_hooks(apr_pool_t *p)
 {
-    authn_register_provider(p, "file", &authn_file_provider);
+    ap_register_provider(p, AUTHN_PROVIDER_GROUP, "file", &authn_file_provider);
 }
 
 module AP_MODULE_DECLARE_DATA authn_file_module =
index 5358a04835ac0360c6a45d1a4dd133fd70a43eaf..c808dcd53f46e66e0440f6143c73d270bf7b836d 100644 (file)
 
 #include "apr_pools.h"
 #include "apr_hash.h"
+#include "ap_provider.h"
 #include "mod_dav.h"
 
-
-static apr_hash_t *dav_repos_providers = NULL;
-
-
-static apr_status_t dav_cleanup_providers(void *ctx)
-{
-    dav_repos_providers = NULL;
-    return APR_SUCCESS;
-}
+#define DAV_PROVIDER_GROUP "dav"
 
 DAV_DECLARE(void) dav_register_provider(apr_pool_t *p, const char *name,
                                         const dav_provider *provider)
 {
-    if (dav_repos_providers == NULL) {
-        dav_repos_providers = apr_hash_make(p);
-        apr_pool_cleanup_register(p, NULL, dav_cleanup_providers, apr_pool_cleanup_null);
-    }
-
-    /* just set it. no biggy if it was there before. */
-    apr_hash_set(dav_repos_providers, name, APR_HASH_KEY_STRING, provider);
+    ap_register_provider(p, DAV_PROVIDER_GROUP, name, provider);
 }
 
 const dav_provider * dav_lookup_provider(const char *name)
 {
-    /* Better watch out against no registered providers */
-    if (dav_repos_providers == NULL) {
-        return NULL;
-    }
-
-    return apr_hash_get(dav_repos_providers, name, APR_HASH_KEY_STRING);
+    return ap_lookup_provider(DAV_PROVIDER_GROUP, name);
 }
index 47f028f6901e3f26d0e1f877055745d0b503205b..1e82213de7fadebe63b074e34201ef3e7660f122 100644 (file)
@@ -14,7 +14,7 @@ LTLIBRARY_SOURCES = \
        rfc1413.c connection.c listen.c \
        mpm_common.c util_charset.c util_debug.c util_xml.c \
        util_filter.c exports.c buildmark.c scoreboard.c \
-       error_bucket.c protocol.c core.c request.c
+       error_bucket.c protocol.c core.c request.c provider.c
 
 TARGETS = delete-exports $(LTLIBRARY_NAME) $(CORE_IMPLIB_FILE) export_vars.h httpd.exp
 
diff --git a/server/provider.c b/server/provider.c
new file mode 100644 (file)
index 0000000..d90a5e3
--- /dev/null
@@ -0,0 +1,117 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+#include "apr_pools.h"
+#include "apr_hash.h"
+
+#include "ap_provider.h"
+
+static apr_hash_t *global_providers = NULL;
+
+static apr_status_t cleanup_global_providers(void *ctx)
+{
+    global_providers = NULL;
+    return APR_SUCCESS;
+}
+
+AP_DECLARE(apr_status_t) ap_register_provider(apr_pool_t *pool,
+                                              const char *provider_group,
+                                              const char *provider_name,
+                                              const void *provider)
+{
+    apr_hash_t *provider_group_hash;
+
+    if (global_providers == NULL) {
+        global_providers = apr_hash_make(pool);
+        apr_pool_cleanup_register(pool, NULL, cleanup_global_providers,
+                                  apr_pool_cleanup_null);
+    }
+
+    provider_group_hash = apr_hash_get(global_providers, provider_group,
+                                       APR_HASH_KEY_STRING);
+
+    if (!provider_group_hash) {
+        provider_group_hash = apr_hash_make(pool);
+        apr_hash_set(global_providers, provider_group, APR_HASH_KEY_STRING,
+                     provider_group_hash);
+        
+    }
+
+    /* just set it. no biggy if it was there before. */
+    apr_hash_set(provider_group_hash, provider_name, APR_HASH_KEY_STRING,
+                 provider);
+
+    return APR_SUCCESS;
+}
+
+AP_DECLARE(void *) ap_lookup_provider(const char *provider_group,
+                                      const char *provider_name)
+{
+    apr_hash_t *provider_group_hash;
+
+    if (global_providers == NULL) {
+        return NULL;
+    }
+
+    provider_group_hash = apr_hash_get(global_providers, provider_group,
+                                       APR_HASH_KEY_STRING);
+
+    if (provider_group_hash == NULL) {
+        return NULL;
+    }
+
+    return apr_hash_get(provider_group_hash, provider_name,
+                        APR_HASH_KEY_STRING);
+}