Main Page | Modules | Namespace List | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

mod_authn_alias.c File Reference

#include "apr_strings.h"
#include "apr_want.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_request.h"
#include "ap_provider.h"
#include "mod_auth.h"

Go to the source code of this file.

Classes

struct  provider_alias_rec
struct  authn_alias_srv_conf

Defines

#define APR_WANT_STRFUNC
#define CORE_PRIVATE

Typedefs

typedef provider_alias_rec provider_alias_rec
typedef authn_alias_srv_conf authn_alias_srv_conf

Functions

static authn_status authn_alias_check_password (request_rec *r, const char *user, const char *password)
static authn_status authn_alias_get_realm_hash (request_rec *r, const char *user, const char *realm, char **rethash)
static void * create_authn_alias_svr_config (apr_pool_t *p, server_rec *s)
static const char * authaliassection (cmd_parms *cmd, void *mconfig, const char *arg)

Variables

module AP_MODULE_DECLARE_DATA authn_alias_module
static const authn_provider authn_alias_provider
static const command_rec authn_alias_cmds []


Define Documentation

#define APR_WANT_STRFUNC
 

Definition at line 18 of file mod_authn_alias.c.

#define CORE_PRIVATE
 

Definition at line 21 of file mod_authn_alias.c.


Typedef Documentation

typedef struct authn_alias_srv_conf authn_alias_srv_conf
 

typedef struct provider_alias_rec provider_alias_rec
 


Function Documentation

static const char* authaliassection cmd_parms cmd,
void *  mconfig,
const char *  arg
[static]
 

Definition at line 125 of file mod_authn_alias.c.

References ACCESS_CONF, authn_alias_srv_conf::alias_rec, ap_get_module_config, ap_strrchr_c, APR_HASH_KEY_STRING, apr_pcalloc, args, authn_alias_module, AUTHN_PROVIDER_GROUP, cmd_parms_struct::cmd, cmd_parms_struct::directive, err, ap_directive_t::first_child, GLOBAL_ONLY, server_rec::module_config, command_struct::name, NULL, OR_ALL, cmd_parms_struct::override, cmd_parms_struct::pool, provider_alias_rec::provider, provider, provider_alias_rec::provider_alias, provider_alias_rec::provider_name, provider_name, provider_alias_rec::sec_auth, cmd_parms_struct::server, and strcasecmp().

00126 {
00127     int old_overrides = cmd->override;
00128     const char *endp = ap_strrchr_c(arg, '>');
00129     const char *args;
00130     char *provider_alias;
00131     char *provider_name;
00132     const char *errmsg;
00133     const authn_provider *provider = NULL;
00134     ap_conf_vector_t *new_auth_config = ap_create_per_dir_config(cmd->pool);
00135     authn_alias_srv_conf *authcfg =
00136         (authn_alias_srv_conf *)ap_get_module_config(cmd->server->module_config,
00137                                                      &authn_alias_module);
00138 
00139     const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
00140     if (err != NULL) {
00141         return err;
00142     }
00143 
00144     if (endp == NULL) {
00145         return apr_pstrcat(cmd->pool, cmd->cmd->name,
00146                            "> directive missing closing '>'", NULL);
00147     }
00148 
00149     args = apr_pstrndup(cmd->pool, arg, endp - arg);
00150 
00151     if (!args[0]) {
00152         return apr_pstrcat(cmd->pool, cmd->cmd->name,
00153                            "> directive requires additional arguments", NULL);
00154     }
00155 
00156     /* Pull the real provider name and the alias name from the block header */
00157     provider_name = ap_getword_conf(cmd->pool, &args);
00158     provider_alias = ap_getword_conf(cmd->pool, &args);
00159 
00160     if (!provider_name[0] || !provider_alias[0]) {
00161         return apr_pstrcat(cmd->pool, cmd->cmd->name,
00162                            "> directive requires additional arguments", NULL);
00163     }
00164 
00165     if (strcasecmp(provider_name, provider_alias) == 0) {
00166         return apr_pstrcat(cmd->pool,
00167                            "The alias provider name must be different from the base provider name.", NULL);
00168     }
00169 
00170     /* Look up the alias provider to make sure that it hasn't already been registered. */
00171     provider = ap_lookup_provider(AUTHN_PROVIDER_GROUP, provider_alias, "0");
00172     if (provider) {
00173         return apr_pstrcat(cmd->pool, "The alias provider ", provider_alias,
00174                            " has already be registered previously as either a base provider or an alias provider.",
00175                            NULL);
00176     }
00177 
00178     /* walk the subsection configuration to get the per_dir config that we will
00179        merge just before the real provider is called. */
00180     cmd->override = OR_ALL|ACCESS_CONF;
00181     errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_auth_config);
00182 
00183     if (!errmsg) {
00184         provider_alias_rec *prvdraliasrec = apr_pcalloc(cmd->pool, sizeof(provider_alias_rec));
00185         provider = ap_lookup_provider(AUTHN_PROVIDER_GROUP, provider_name, "0");
00186 
00187         /* Save off the new directory config along with the original provider name
00188            and function pointer data */
00189         prvdraliasrec->sec_auth = new_auth_config;
00190         prvdraliasrec->provider_name = provider_name;
00191         prvdraliasrec->provider_alias = provider_alias;
00192         prvdraliasrec->provider = provider;
00193         apr_hash_set(authcfg->alias_rec, provider_alias, APR_HASH_KEY_STRING, prvdraliasrec);
00194 
00195         /* Register the fake provider so that we get called first */
00196         ap_register_provider(cmd->pool, AUTHN_PROVIDER_GROUP, provider_alias, "0",
00197                              &authn_alias_provider);
00198     }
00199 
00200     cmd->override = old_overrides;
00201 
00202     return errmsg;
00203 }

static authn_status authn_alias_check_password request_rec r,
const char *  user,
const char *  password
[static]
 

Definition at line 44 of file mod_authn_alias.c.

References authn_alias_srv_conf::alias_rec, ap_get_module_config, APR_HASH_KEY_STRING, AUTH_USER_NOT_FOUND, authn_alias_module, AUTHN_PROVIDER_NAME_NOTE, authn_provider::check_password, server_rec::module_config, request_rec::notes, request_rec::per_dir_config, request_rec::pool, provider_alias_rec::provider, provider_name, provider_alias_rec::sec_auth, and request_rec::server.

00046 {
00047     /* Look up the provider alias in the alias list */
00048     /* Get the the dir_config and call ap_Merge_per_dir_configs() */
00049     /* Call the real provider->check_password() function */
00050     /* return the result of the above function call */
00051 
00052     const char *provider_name = apr_table_get(r->notes, AUTHN_PROVIDER_NAME_NOTE);
00053     authn_status ret = AUTH_USER_NOT_FOUND;
00054     authn_alias_srv_conf *authcfg =
00055         (authn_alias_srv_conf *)ap_get_module_config(r->server->module_config,
00056                                                      &authn_alias_module);
00057 
00058     if (provider_name) {
00059         provider_alias_rec *prvdraliasrec = apr_hash_get(authcfg->alias_rec,
00060                                                          provider_name, APR_HASH_KEY_STRING);
00061         ap_conf_vector_t *orig_dir_config = r->per_dir_config;
00062 
00063         /* If we found the alias provider in the list, then merge the directory
00064            configurations and call the real provider */
00065         if (prvdraliasrec) {
00066             r->per_dir_config = ap_merge_per_dir_configs(r->pool, orig_dir_config,
00067                                                          prvdraliasrec->sec_auth);
00068             ret = prvdraliasrec->provider->check_password(r,user,password);
00069             r->per_dir_config = orig_dir_config;
00070         }
00071     }
00072 
00073     return ret;
00074 }

static authn_status authn_alias_get_realm_hash request_rec r,
const char *  user,
const char *  realm,
char **  rethash
[static]
 

Definition at line 76 of file mod_authn_alias.c.

References authn_alias_srv_conf::alias_rec, ap_get_module_config, APR_HASH_KEY_STRING, AUTH_USER_NOT_FOUND, authn_alias_module, AUTHN_PROVIDER_NAME_NOTE, authn_provider::get_realm_hash, server_rec::module_config, request_rec::notes, request_rec::per_dir_config, request_rec::pool, provider_alias_rec::provider, provider_name, provider_alias_rec::sec_auth, and request_rec::server.

00078 {
00079     /* Look up the provider alias in the alias list */
00080     /* Get the the dir_config and call ap_Merge_per_dir_configs() */
00081     /* Call the real provider->get_realm_hash() function */
00082     /* return the result of the above function call */
00083 
00084     const char *provider_name = apr_table_get(r->notes, AUTHN_PROVIDER_NAME_NOTE);
00085     authn_status ret = AUTH_USER_NOT_FOUND;
00086     authn_alias_srv_conf *authcfg =
00087         (authn_alias_srv_conf *)ap_get_module_config(r->server->module_config,
00088                                                      &authn_alias_module);
00089 
00090     if (provider_name) {
00091         provider_alias_rec *prvdraliasrec = apr_hash_get(authcfg->alias_rec,
00092                                                          provider_name, APR_HASH_KEY_STRING);
00093         ap_conf_vector_t *orig_dir_config = r->per_dir_config;
00094 
00095         /* If we found the alias provider in the list, then merge the directory
00096            configurations and call the real provider */
00097         if (prvdraliasrec) {
00098             r->per_dir_config = ap_merge_per_dir_configs(r->pool, orig_dir_config,
00099                                                          prvdraliasrec->sec_auth);
00100             ret = prvdraliasrec->provider->get_realm_hash(r,user,realm,rethash);
00101             r->per_dir_config = orig_dir_config;
00102         }
00103     }
00104 
00105     return ret;
00106 }

static void* create_authn_alias_svr_config apr_pool_t p,
server_rec s
[static]
 

Definition at line 108 of file mod_authn_alias.c.

References authn_alias_srv_conf::alias_rec, and apr_pcalloc.

00109 {
00110 
00111     authn_alias_srv_conf *authcfg;
00112 
00113     authcfg = (authn_alias_srv_conf *) apr_pcalloc(p, sizeof(authn_alias_srv_conf));
00114     authcfg->alias_rec = apr_hash_make(p);
00115 
00116     return (void *) authcfg;
00117 }


Variable Documentation

const command_rec authn_alias_cmds[] [static]
 

Initial value:

{
    AP_INIT_RAW_ARGS("<AuthnProviderAlias", authaliassection, NULL, RSRC_CONF,
                     "Container for authentication directives grouped under "
                     "a provider alias"),
    {NULL}
}

Definition at line 205 of file mod_authn_alias.c.

module AP_MODULE_DECLARE_DATA authn_alias_module
 

Initial value:

Definition at line 214 of file mod_authn_alias.c.

Referenced by authaliassection(), authn_alias_check_password(), and authn_alias_get_realm_hash().

const authn_provider authn_alias_provider [static]
 

Initial value:

Definition at line 119 of file mod_authn_alias.c.


© sourcejam.com 2005-2008