diff options
author | Stef Walter <stef@memberwebs.com> | 2009-06-18 20:54:10 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2009-06-18 20:54:10 +0000 |
commit | 3296c112b6f3cb45e195958c3e8ab8a533aaf35f (patch) | |
tree | b883ff1a2edbbac29a7764c0397537d2e1bff8f8 | |
parent | b1e37043ded3470146bc0a6f5d81bb2456a809f1 (diff) |
Implement config for shared memory.
-rw-r--r-- | module/mod_auth_singleid.c | 70 |
1 files changed, 45 insertions, 25 deletions
diff --git a/module/mod_auth_singleid.c b/module/mod_auth_singleid.c index bdd8f6d..541ded1 100644 --- a/module/mod_auth_singleid.c +++ b/module/mod_auth_singleid.c @@ -96,10 +96,9 @@ typedef struct sid_context { static apr_global_mutex_t *shared_lock = NULL; static const char *shared_lock_name = NULL; -static size_t shared_size = 64 * 1024; static int -shared_initialize (apr_pool_t *p, server_rec *s) +shared_initialize (apr_pool_t *p) { apr_file_t *file = NULL; char *lock_name = NULL; @@ -112,7 +111,7 @@ shared_initialize (apr_pool_t *p, server_rec *s) rc = apr_temp_dir_get (&tmpdir, p); if (rc != APR_SUCCESS) - ap_log_error (APLOG_MARK, APLOG_ERR, rc, s, + ap_log_error (APLOG_MARK, APLOG_ERR, rc, NULL, "auth-singleid: couldn't get temporary directory"); if (rc == APR_SUCCESS) { @@ -129,7 +128,7 @@ shared_initialize (apr_pool_t *p, server_rec *s) if (rc == APR_SUCCESS) { rc = apr_global_mutex_create (&shared_lock, lock_name, APR_LOCK_DEFAULT, p); if (rc != APR_SUCCESS) - ap_log_error (APLOG_MARK, APLOG_ERR, rc, s, + ap_log_error (APLOG_MARK, APLOG_ERR, rc, NULL, "auth-singleid: couldn't create shared memory lock: %s", lock_name); } @@ -137,7 +136,7 @@ shared_initialize (apr_pool_t *p, server_rec *s) if (rc == APR_SUCCESS) { rc = unixd_set_global_mutex_perms (shared_lock); if (rc != APR_SUCCESS) - ap_log_error (APLOG_MARK, APLOG_ERR, rc, s, + ap_log_error (APLOG_MARK, APLOG_ERR, rc, NULL, "auth-singleid: Could not set permissions on lock. " "check User and Group directives"); } @@ -177,6 +176,8 @@ shared_create (apr_pool_t* p, size_t size) int rc; if (!shared_lock) + shared_initialize (p); + if (!shared_lock) return NULL; /* Get the temp directory */ @@ -247,23 +248,9 @@ sid_shared_unlock (void) static void* dir_config_creator (apr_pool_t* p, char* dir) { - sid_context_t* ctx; - void *shared; - - ctx = (sid_context_t*)apr_pcalloc(p, sizeof(*ctx)); - memset(ctx, 0, sizeof(*ctx)); - - ctx->identifier = NULL; - ctx->store = NULL; - ctx->trust_root = NULL; - - if (!dir) - return ctx; - - shared = shared_create (p, shared_size); - ctx->store = sid_storage_initialize (shared, shared_size); - - return ctx; + sid_context_t* ctx = apr_pcalloc (p, sizeof (*ctx)); + memset (ctx, 0, sizeof (*ctx)); + return ctx; } static const char* @@ -293,7 +280,7 @@ set_user_match (cmd_parms *cmd, void *config, const char *val) while (isspace (*val)) ++val; - if (strcmp (val, "suffix") == 0 && !isalpha (val[6])) { + if (strcasecmp (val, "suffix") == 0 && !isalpha (val[6])) { ctx->user_match = SUFFIX; return NULL; } @@ -307,11 +294,44 @@ set_user_match (cmd_parms *cmd, void *config, const char *val) return NULL; } +static const char* +set_cache_size (cmd_parms *cmd, void *config, const char *val) +{ + sid_context_t *ctx = config; + char *end; + int size = 0; + void *shared; + size_t page; + + if (strcasecmp (val, "on") == 0) { + size = 64 * 1024; + } else if (strcasecmp (val, "off") == 0) { + size = 0; + } else { + size = strtol (val, &end, 10); + if (*end != '\0') + return "Invalid number specified for SingleCache"; + } + + if (size == 0) + return NULL; + + /* Align to a page size */ + page = getpagesize (); + size = ((size + (page - 1)) / page) * page; + + shared = shared_create (cmd->pool, size); + ctx->store = sid_storage_initialize (shared, size); + return NULL; +} + static const command_rec command_table[] = { AP_INIT_TAKE1 ("SingleIdentifier", set_identifier, NULL, OR_AUTHCFG, "The OpenID identifier we should perform ID selection on when authenticating" ), AP_INIT_TAKE1 ("SingleTrustRoot", set_trust_root, NULL, OR_AUTHCFG, "The OpenID trust root of this site."), + AP_INIT_TAKE1 ("SingleCache", set_cache_size, NULL, OR_AUTHCFG, + "Enable and optionally set the size of the OpenID association cache"), AP_INIT_RAW_ARGS ("SingleUserMatch", set_user_match, NULL, OR_AUTHCFG, "How to convert an OpenID identifier into a user name" ), { NULL } @@ -475,7 +495,7 @@ session_send_info (request_rec *r, sid_session_t *sess) static sid_session_t* session_copy_info (apr_pool_t *p, sid_session_t *sess) { - sid_session_t *copy = apr_palloc (p, sizeof (*sess)); + sid_session_t *copy = apr_pcalloc (p, sizeof (*sess)); copy->expiry = sess->expiry; copy->identifier = apr_pstrdup (p, sess->identifier); return copy; @@ -620,7 +640,7 @@ hook_initialize (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec { int rc; - rc = shared_initialize (p, s); + rc = shared_initialize (p); if (rc != OK) return rc; |