From: Justin Erenkrantz Date: Fri, 20 Sep 2002 00:57:50 +0000 (+0000) Subject: Add ap_register_provider and ap_lookup_provider functions which resolve X-Git-Tag: WROWE_2_0_43_PRE1~76 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7efe3077312760f0d3ecd9e284f0f2769ede0978;p=apache Add ap_register_provider and ap_lookup_provider functions which resolve 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 (in concept) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96919 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 8803fa1696..a082636269 100644 --- 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 , 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 index 0000000000..c5e06d414d --- /dev/null +++ b/include/ap_provider.h @@ -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 + * . + */ + +#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 diff --git a/modules/aaa/config.m4 b/modules/aaa/config.m4 index 500623cfb4..8579d33b4d 100644 --- a/modules/aaa/config.m4 +++ b/modules/aaa/config.m4 @@ -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 ], [ diff --git a/modules/aaa/mod_auth.h b/modules/aaa/mod_auth.h index f0f4fbf4cc..bf334601b0 100644 --- a/modules/aaa/mod_auth.h +++ b/modules/aaa/mod_auth.h @@ -65,23 +65,7 @@ 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 diff --git a/modules/aaa/mod_auth_basic.c b/modules/aaa/mod_auth_basic.c index c4b390ff87..a5f99beff8 100644 --- a/modules/aaa/mod_auth_basic.c +++ b/modules/aaa/mod_auth_basic.c @@ -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; diff --git a/modules/aaa/mod_auth_digest.c b/modules/aaa/mod_auth_digest.c index 4058c93b4c..4abc035f93 100644 --- a/modules/aaa/mod_auth_digest.c +++ b/modules/aaa/mod_auth_digest.c @@ -118,6 +118,7 @@ #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; diff --git a/modules/aaa/mod_authn_dbm.c b/modules/aaa/mod_authn_dbm.c index dcce4768ee..33486c4872 100644 --- a/modules/aaa/mod_authn_dbm.c +++ b/modules/aaa/mod_authn_dbm.c @@ -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 = diff --git a/modules/aaa/mod_authn_file.c b/modules/aaa/mod_authn_file.c index 422a9ac2a9..de79253e67 100644 --- a/modules/aaa/mod_authn_file.c +++ b/modules/aaa/mod_authn_file.c @@ -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 = diff --git a/modules/dav/main/providers.c b/modules/dav/main/providers.c index 5358a04835..c808dcd53f 100644 --- a/modules/dav/main/providers.c +++ b/modules/dav/main/providers.c @@ -54,36 +54,18 @@ #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); } diff --git a/server/Makefile.in b/server/Makefile.in index 47f028f690..1e82213de7 100644 --- a/server/Makefile.in +++ b/server/Makefile.in @@ -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 index 0000000000..d90a5e349e --- /dev/null +++ b/server/provider.c @@ -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 + * . + * + */ + +#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); +}