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

mod_authn_dbm.c File Reference

#include "apr_want.h"
#include "apr_strings.h"
#include "apr_dbm.h"
#include "apr_md5.h"
#include "ap_provider.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_protocol.h"
#include "http_request.h"
#include "mod_auth.h"

Go to the source code of this file.

Classes

struct  authn_dbm_config_rec

Defines

#define APR_WANT_STRFUNC

Functions

static void * create_authn_dbm_dir_config (apr_pool_t *p, char *d)
static const char * set_dbm_type (cmd_parms *cmd, void *dir_config, const char *arg)
static apr_status_t fetch_dbm_value (const char *dbmtype, const char *dbmfile, const char *user, char **value, apr_pool_t *pool)
static authn_status check_dbm_pw (request_rec *r, const char *user, const char *password)
static authn_status get_dbm_realm_hash (request_rec *r, const char *user, const char *realm, char **rethash)
static void register_hooks (apr_pool_t *p)

Variables

static const command_rec authn_dbm_cmds []
module AP_MODULE_DECLARE_DATA authn_dbm_module
static const authn_provider authn_dbm_provider


Define Documentation

#define APR_WANT_STRFUNC
 

Definition at line 26 of file mod_authn_dbm.c.


Function Documentation

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

Definition at line 113 of file mod_authn_dbm.c.

References ap_get_module_config, ap_strchr, APLOG_ERR, APLOG_MARK, APR_SUCCESS, AUTH_DENIED, AUTH_GENERAL_ERROR, AUTH_GRANTED, AUTH_USER_NOT_FOUND, authn_dbm_module, conf, authn_dbm_config_rec::dbmtype, fetch_dbm_value(), request_rec::per_dir_config, request_rec::pool, and authn_dbm_config_rec::pwfile.

00115 {
00116     authn_dbm_config_rec *conf = ap_get_module_config(r->per_dir_config,
00117                                                       &authn_dbm_module);
00118     apr_status_t rv;
00119     char *dbm_password;
00120     char *colon_pw;
00121 
00122     rv = fetch_dbm_value(conf->dbmtype, conf->pwfile, user, &dbm_password,
00123                          r->pool);
00124 
00125     if (rv != APR_SUCCESS) {
00126         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
00127                       "could not open dbm (type %s) auth file: %s",
00128                       conf->dbmtype, conf->pwfile);
00129         return AUTH_GENERAL_ERROR;
00130     }
00131 
00132     if (!dbm_password) {
00133         return AUTH_USER_NOT_FOUND;
00134     }
00135 
00136     colon_pw = ap_strchr(dbm_password, ':');
00137     if (colon_pw) {
00138         *colon_pw = '\0';
00139     }
00140 
00141     rv = apr_password_validate(password, dbm_password);
00142 
00143     if (rv != APR_SUCCESS) {
00144         return AUTH_DENIED;
00145     }
00146 
00147     return AUTH_GRANTED;
00148 }

static void* create_authn_dbm_dir_config apr_pool_t p,
char *  d
[static]
 

Definition at line 47 of file mod_authn_dbm.c.

References conf, and NULL.

00048 {
00049     authn_dbm_config_rec *conf = apr_palloc(p, sizeof(*conf));
00050 
00051     conf->pwfile = NULL;
00052     conf->dbmtype = "default";
00053 
00054     return conf;
00055 }

static apr_status_t fetch_dbm_value const char *  dbmtype,
const char *  dbmfile,
const char *  user,
char **  value,
apr_pool_t pool
[static]
 

Definition at line 80 of file mod_authn_dbm.c.

References APR_DBM_READONLY, APR_OS_DEFAULT, APR_SUCCESS, apr_datum_t::dptr, apr_datum_t::dsize, f, key, NULL, and val.

Referenced by check_dbm_pw(), and get_dbm_realm_hash().

00083 {
00084     apr_dbm_t *f;
00085     apr_datum_t key, val;
00086     apr_status_t rv;
00087 
00088     rv = apr_dbm_open_ex(&f, dbmtype, dbmfile, APR_DBM_READONLY,
00089                          APR_OS_DEFAULT, pool);
00090 
00091     if (rv != APR_SUCCESS) {
00092         return rv;
00093     }
00094 
00095     key.dptr = (char*)user;
00096 #ifndef NETSCAPE_DBM_COMPAT
00097     key.dsize = strlen(key.dptr);
00098 #else
00099     key.dsize = strlen(key.dptr) + 1;
00100 #endif
00101 
00102     *value = NULL;
00103 
00104     if (apr_dbm_fetch(f, key, &val) == APR_SUCCESS && val.dptr) {
00105         *value = apr_pstrmemdup(pool, val.dptr, val.dsize);
00106     }
00107 
00108     apr_dbm_close(f);
00109 
00110     return rv;
00111 }

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

Definition at line 150 of file mod_authn_dbm.c.

References ap_get_module_config, ap_strchr, APLOG_ERR, APLOG_MARK, APR_SUCCESS, AUTH_GENERAL_ERROR, AUTH_USER_FOUND, AUTH_USER_NOT_FOUND, authn_dbm_module, conf, authn_dbm_config_rec::dbmtype, fetch_dbm_value(), NULL, request_rec::per_dir_config, request_rec::pool, and authn_dbm_config_rec::pwfile.

00152 {
00153     authn_dbm_config_rec *conf = ap_get_module_config(r->per_dir_config,
00154                                                       &authn_dbm_module);
00155     apr_status_t rv;
00156     char *dbm_hash;
00157     char *colon_hash;
00158 
00159     rv = fetch_dbm_value(conf->dbmtype, conf->pwfile,
00160                          apr_pstrcat(r->pool, user, ":", realm, NULL),
00161                          &dbm_hash, r->pool);
00162 
00163     if (rv != APR_SUCCESS) {
00164         ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
00165                       "Could not open dbm (type %s) hash file: %s",
00166                       conf->dbmtype, conf->pwfile);
00167         return AUTH_GENERAL_ERROR;
00168     }
00169 
00170     if (!dbm_hash) {
00171         return AUTH_USER_NOT_FOUND;
00172     }
00173 
00174     colon_hash = ap_strchr(dbm_hash, ':');
00175     if (colon_hash) {
00176         *colon_hash = '\0';
00177     }
00178 
00179     *rethash = dbm_hash;
00180 
00181     return AUTH_USER_FOUND;
00182 }

static void register_hooks apr_pool_t p  )  [static]
 

Definition at line 190 of file mod_authn_dbm.c.

References AUTHN_PROVIDER_GROUP.

00191 {
00192     ap_register_provider(p, AUTHN_PROVIDER_GROUP, "dbm", "0",
00193                          &authn_dbm_provider);
00194 }

static const char* set_dbm_type cmd_parms cmd,
void *  dir_config,
const char *  arg
[static]
 

Definition at line 57 of file mod_authn_dbm.c.

References conf, authn_dbm_config_rec::dbmtype, NULL, and cmd_parms_struct::pool.

00060 {
00061     authn_dbm_config_rec *conf = dir_config;
00062 
00063     conf->dbmtype = apr_pstrdup(cmd->pool, arg);
00064     return NULL;
00065 }


Variable Documentation

const command_rec authn_dbm_cmds[] [static]
 

Initial value:

{
    AP_INIT_TAKE1("AuthDBMUserFile", ap_set_file_slot,
     (void *)APR_OFFSETOF(authn_dbm_config_rec, pwfile),
     OR_AUTHCFG, "dbm database file containing user IDs and passwords"),
    AP_INIT_TAKE1("AuthDBMType", set_dbm_type,
     NULL,
     OR_AUTHCFG, "what type of DBM file the user file is"),
    {NULL}
}

Definition at line 67 of file mod_authn_dbm.c.

module AP_MODULE_DECLARE_DATA authn_dbm_module
 

Initial value:

Definition at line 196 of file mod_authn_dbm.c.

Referenced by check_dbm_pw(), and get_dbm_realm_hash().

const authn_provider authn_dbm_provider [static]
 

Initial value:

Definition at line 184 of file mod_authn_dbm.c.


© sourcejam.com 2005-2008