[Mod-auth-commit] mod_authn_cache/src mod_authn_cache.c,1.3,1.4
Brought to you by:
firechipmunk,
honx
From: <fir...@us...> - 2003-12-30 01:13:58
|
Update of /cvsroot/mod-auth/mod_authn_cache/src In directory sc8-pr-cvs1:/tmp/cvs-serv24798 Modified Files: mod_authn_cache.c Log Message: working on memcached version Index: mod_authn_cache.c =================================================================== RCS file: /cvsroot/mod-auth/mod_authn_cache/src/mod_authn_cache.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** mod_authn_cache.c 17 Nov 2003 04:07:37 -0000 1.3 --- mod_authn_cache.c 30 Dec 2003 01:13:54 -0000 1.4 *************** *** 85,96 **** #include "util_md5.h" ! #if !APR_HAS_SHARED_MEMORY ! #error Shared Memory is required to use authn_cache ! #endif ! #include "util_authn_cache.h" module AP_MODULE_DECLARE_DATA authn_cache_module; typedef struct authn_cache_conf_t { authn_provider_list *providers; --- 85,166 ---- #include "util_md5.h" ! #define DFLT_HOSTNAME "localhost" ! #define DFLT_PORT (8008) ! #define DFLT_CONN_MIN (1) ! #define DFLT_CONN_SOFT (5) ! #define DFLT_CONN_MAX (25) ! #define DFLT_CONN_TTL (600) ! #define DFLT_TIMEOUT (6) ! #define DFLT_OPTIONS (0) ! static int mcd_conn_count = 0; ! static apr_reslist_t *reslist_pool; module AP_MODULE_DECLARE_DATA authn_cache_module; + typedef struct mcd_rest_struct + { + apr_sockaddr_t *sockaddr; + apr_socket_t *sock; + } mcd_res_t; + + + static apr_status_t mcd_new_conn(void **resource, void *params, apr_pool_t * pool) + { + apr_status_t rv = APR_SUCCESS; + mcd_res_t *mcdres; + + mcdres = apr_palloc(pool, sizeof(*mcdres)); + + rv = apr_sockaddr_info_get(&mcdres->sockaddr, DFLT_HOSTNAME, APR_UNSPEC, DFLT_PORT, 0, pool); + if (rv != APR_SUCCESS) { + ap_log_perror(APLOG_MARK, APLOG_ERR, rv, pool, "apr_sockaddr_info_get"); + return rv; + } + if (apr_socket_create(&mcdres->sock, mcdres->sockaddr->family, SOCK_STREAM, 0, + pool) != APR_SUCCESS) { + ap_log_perror(APLOG_MARK, APLOG_ERR, rv, pool, "apr_socket_create"); + return rv; + } + + rv = apr_socket_timeout_set(mcdres->sock, DFLT_TIMEOUT); + if (rv != APR_SUCCESS) { + ap_log_perror(APLOG_MARK, APLOG_ERR, rv, pool, "apr_socket_timeout_set"); + return rv; + } + + rv = apr_socket_connect(mcdres->sock, mcdres->sockaddr); + if (rv != APR_SUCCESS) { + ap_log_perror(APLOG_MARK, APLOG_ERR, rv, pool, "apr_socket_connect"); + return rv; + } + + *resource = mcdres; + return rv; + } + + static apr_status_t mcd_kill_conn(void *resource, void *params, apr_pool_t * pool) + { + apr_status_t rv = APR_SUCCESS; + mcd_res_t *mcd = resource; + + rv = apr_socket_close(mcd->sock); + + return rv; + } + + static apr_status_t mcd_get(mcd_res_t mcd, const char* key) { + apr_status_t rv = APR_SUCCESS; + + return rv; + } + + static apr_status_t mcd_put(mcd_res_t mcd, const char* key) { + apr_status_t rv = APR_SUCCESS; + + return rv; + } + + typedef struct authn_cache_conf_t { authn_provider_list *providers; *************** *** 111,128 **** - static void *create_authn_cache_config(apr_pool_t *p, server_rec *s) - { - util_cache_state_t *st; - st = (util_cache_state_t *) apr_pcalloc(p, sizeof(util_cache_state_t)); - if (st == NULL) { - return NULL; - } - - st->pool = p; - st->cache_bytes = 100000; - st->cache_size = 1000; - return st; - } - static const char *add_authn_provider(cmd_parms *cmd, void *config, const char *arg) --- 181,184 ---- *************** *** 178,203 **** } - static const char *util_authn_set_cache_file(cmd_parms *cmd, void *dummy, const char *file) - { - util_cache_state_t *st = - (util_cache_state_t *)ap_get_module_config(cmd->server->module_config, - &authn_cache_module); - - if (file) { - st->cache_file = ap_server_root_relative(st->pool, file); - } - else { - st->cache_file = NULL; - } - - ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, cmd->server, - "AuthnCache: Setting shared memory cache file to '%s'", - st->cache_file); - - return NULL; - } - - - static const command_rec authn_cache_cmds[] = { /* per auth section */ --- 234,237 ---- *************** *** 205,212 **** "The name of the configuration to use for this section"), /* global config */ - AP_INIT_TAKE1("AuthnCacheSharedCacheFile", util_authn_set_cache_file, NULL, RSRC_CONF, - "Sets the file of the shared memory cache." - "Nothing means disable the shared memory cache."), - {NULL} --- 239,242 ---- *************** *** 219,269 **** { authn_status auth_result; ! util_authn_any_node_t newnode; ! util_authn_any_node_t *node = NULL; ! util_authn_vhost_node_t *curl = NULL; ! util_authn_vhost_node_t curnode; authn_provider_list *current_provider; authn_cache_conf_t *conf = ap_get_module_config(r->per_dir_config, &authn_cache_module); - util_cache_state_t *st = ap_get_module_config(r->server->module_config, - &authn_cache_module); - - AUTHN_CACHE_RDLOCK(); - curnode.vhost = r->server->server_hostname; - - if(st->util_authn_cache_d == NULL) - { - util_authn_cache_init(st->pool, st); - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, - "creating a new util_authn_cache_d!"); - } - - curl = (util_authn_vhost_node_t* )util_authn_fetch(st->util_authn_cache_d, &curnode); - if (curl == NULL) { - curl = util_authn_create_caches(st, curnode.vhost); - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, - "creating new cache on vhost: %s cache: 0x%08x", r->server->server_hostname,curl); - } - else - { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, - "existing cache on vhost: %s! cache: 0x%08x", r->server->server_hostname,curl); - } - newnode.username = user; - newnode.realm = ap_auth_name(r); - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, - "checking cache for username: %s in realm: %s on vhost: %s cache: 0x%08x node: 0x%08x", newnode.username, newnode.realm, r->server->server_hostname, curl->auth_cache, node); - node = util_authn_fetch(curl->auth_cache, &newnode); - if (node != NULL) { - AUTHN_CACHE_UNLOCK(); - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, - "used cached auth!"); - return AUTH_GRANTED; - } - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, - "NOT used cached auth! node: 0x%08x newnode.user:%s newnode.realm:%s",node,newnode.username,newnode.realm); - AUTHN_CACHE_UNLOCK(); - current_provider = conf->providers; --- 249,257 ---- { authn_status auth_result; ! authn_provider_list *current_provider; authn_cache_conf_t *conf = ap_get_module_config(r->per_dir_config, &authn_cache_module); current_provider = conf->providers; *************** *** 305,321 **** if(auth_result == AUTH_GRANTED) { ! ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, ! "adding user: %s to cache for realm: %s cache: 0x%08x auth cache: 0x%08x",user,ap_auth_name(r), curl, curl->auth_cache); ! // add to cache ! AUTHN_CACHE_WRLOCK(); ! newnode.username = user; ! newnode.realm = ap_auth_name(r); ! util_authn_insert(curl->auth_cache, &newnode); ! AUTHN_CACHE_UNLOCK(); ! } ! else { ! ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, ! "NOT adding user(but auth good?): %s to cache for realm: %s!",user,ap_auth_name(r)); ! } return auth_result; --- 293,302 ---- if(auth_result == AUTH_GRANTED) { ! ! } ! else { ! ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, ! "NOT adding user(but auth good?): %s to cache for realm: %s!",user,ap_auth_name(r)); ! } return auth_result; *************** *** 328,375 **** return AUTH_USER_NOT_FOUND; } static int init_authn_cache(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { ! char buf[MAX_STRING_LEN]; ! apr_status_t result; ! ! util_cache_state_t *st = (util_cache_state_t *)ap_get_module_config(s->module_config, &authn_cache_module); ! ! ! st->pool = p; ! #if APR_HAS_SHARED_MEMORY ! server_rec *s_vhost; ! util_cache_state_t *st_vhost; ! ! /* initializing cache if file is here and we already don't have shm addr*/ ! if (st->cache_file && !st->cache_shm) { ! #endif ! AUTHN_CACHE_LOCK_CREATE(p); ! result = util_authn_cache_init(p, st); ! apr_strerror(result, buf, sizeof(buf)); ! ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, result, s, ! "AuthnCache init: %s", buf); ! #if APR_HAS_SHARED_MEMORY ! /* merge config in all vhost */ ! s_vhost = s->next; ! while (s_vhost) { ! ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, result, s, ! "Authn merging Shared Cache conf: shm=0x%x rmm=0x%x for VHOST: %s", ! st->cache_shm, st->cache_rmm, s_vhost->server_hostname); ! st_vhost = (util_cache_state_t *)ap_get_module_config(s_vhost->module_config, &authn_cache_module); ! st_vhost->cache_shm = st->cache_shm; ! st_vhost->cache_rmm = st->cache_rmm; ! st_vhost->cache_file = st->cache_file; ! s_vhost = s_vhost->next; ! } ! } ! else { ! ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0 , s, "AuthnCache: Unable to init Shared Cache: no file"); ! } ! #endif return 0; --- 309,346 ---- return AUTH_USER_NOT_FOUND; } + static apr_status_t kill_mcd(void *p) + { + apr_status_t rv = APR_SUCCESS; + apr_reslist_destroy(reslist_pool); + return rv; + } static int init_authn_cache(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { + apr_status_t rv; ! void *data; ! const char *userdata_key = "mod_authn_dbi_init"; ! ! apr_pool_userdata_get(&data, userdata_key, s->process->pool); ! ! if (!data) { ! apr_pool_userdata_set((const void *) 1, userdata_key, ! apr_pool_cleanup_null, s->process->pool); ! return OK; ! } ! apr_reslist_create(&reslist_pool, DFLT_CONN_MIN, /* hard minimum */ ! DFLT_CONN_SOFT, /* soft maximum */ ! DFLT_CONN_MAX, /* hard maximum */ ! DFLT_CONN_TTL, /* Time to live -- mcd server might override/disconnect! */ ! mcd_new_conn, /* Make a New Connection */ ! mcd_kill_conn, /* Kill Old Connection */ ! (void *) NULL, p); ! apr_pool_cleanup_register(p, p, kill_mcd, apr_pool_cleanup_null); ! ! ap_add_version_component(p, "mod_authn_cache_mcd/0.1"); return 0; *************** *** 385,427 **** { ap_hook_post_config(init_authn_cache, NULL, NULL, APR_HOOK_MIDDLE); ! ap_register_provider(p, AUTHN_PROVIDER_GROUP, "cache", "0", &authn_cache_provider); } - int authn_mutex_on(server_rec *s) - { - SSLModConfigRec *mc = myModConfig(s); - apr_status_t rv; - - if (mc->nMutexMode == SSL_MUTEXMODE_NONE) - return TRUE; - if ((rv = apr_global_mutex_lock(mc->pMutex)) != APR_SUCCESS) { - ap_log_error(APLOG_MARK, APLOG_WARNING, rv, s, - "Failed to acquire global mutex lock"); - return FALSE; - } - return TRUE; - } - - int authn_mutex_off(server_rec *s) - { - SSLModConfigRec *mc = myModConfig(s); - apr_status_t rv; - - if (mc->nMutexMode == SSL_MUTEXMODE_NONE) - return TRUE; - if ((rv = apr_global_mutex_unlock(mc->pMutex)) != APR_SUCCESS) { - ap_log_error(APLOG_MARK, APLOG_WARNING, rv, s, - "Failed to release global mutex lock"); - return FALSE; - } - return TRUE; - } - module AP_MODULE_DECLARE_DATA authn_cache_module = { STANDARD20_MODULE_STUFF, ! create_authn_cache_dconfig, /* dir config creater */ NULL, /* dir merger --- default is to override */ ! create_authn_cache_config, /* server config creator */ NULL, /* merge server config */ authn_cache_cmds, /* command apr_table_t */ --- 356,368 ---- { ap_hook_post_config(init_authn_cache, NULL, NULL, APR_HOOK_MIDDLE); ! ap_register_provider(p, AUTHN_PROVIDER_GROUP, "cache_mcd", "0", &authn_cache_provider); } module AP_MODULE_DECLARE_DATA authn_cache_module = { STANDARD20_MODULE_STUFF, ! create_authn_cache_dconfig, /* dir config creater */ NULL, /* dir merger --- default is to override */ ! NULL, /* server config creator */ NULL, /* merge server config */ authn_cache_cmds, /* command apr_table_t */ |