From 771ca63efe669f8b0a3ffaeba1f3be7e3688b35f Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Thu, 23 Sep 2010 09:27:03 +0200 Subject: The GnuTLSCache variable now can be given the specific option "sdbm" instead of "dbm". "dbm" will use the default dbm type of libapr while sdbm will force sdbm to be used. --- src/gnutls_cache.c | 28 +++++++++++++++++----------- src/gnutls_config.c | 10 +++++++--- 2 files changed, 24 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/gnutls_cache.c b/src/gnutls_cache.c index 3ca8cb5..7bcb697 100644 --- a/src/gnutls_cache.c +++ b/src/gnutls_cache.c @@ -35,8 +35,6 @@ /* it seems the default has some strange errors. Use SDBM */ -#define ODB "SDBM" - #define MC_TAG "mod_gnutls:" #define MC_TAG_LEN sizeof(MC_TAG) #define STR_SESSION_LEN (GNUTLS_SESSION_ID_STRING_LEN + MC_TAG_LEN) @@ -296,6 +294,14 @@ static int mc_cache_delete(void* baton, gnutls_datum_t key) #endif /* have_apr_memcache */ +const char* db_type(mgs_srvconf_rec * sc) +{ + if (sc->cache_type == mgs_cache_sdbm) + return "sdbm"; + else + return "default"; +} + #define SSL_DBM_FILE_MODE ( APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD ) static void dbm_cache_expire(mgs_handle_t *ctxt) @@ -321,7 +327,7 @@ static void dbm_cache_expire(mgs_handle_t *ctxt) total = 0; deleted = 0; - rv = apr_dbm_open_ex(&dbm, ODB, ctxt->sc->cache_config, APR_DBM_RWCREATE, + rv = apr_dbm_open_ex(&dbm, db_type(ctxt->sc), ctxt->sc->cache_config, APR_DBM_RWCREATE, SSL_DBM_FILE_MODE, spool); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_NOTICE, rv, @@ -374,7 +380,7 @@ static gnutls_datum_t dbm_cache_fetch(void* baton, gnutls_datum_t key) if (mgs_session_id2dbm(ctxt->c, key.data, key.size, &dbmkey) < 0) return data; - rv = apr_dbm_open_ex(&dbm, ODB, ctxt->sc->cache_config, + rv = apr_dbm_open_ex(&dbm, db_type(ctxt->sc), ctxt->sc->cache_config, APR_DBM_READONLY, SSL_DBM_FILE_MODE, ctxt->c->pool); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_NOTICE, rv, @@ -444,7 +450,7 @@ static int dbm_cache_store(void* baton, gnutls_datum_t key, memcpy((char *)dbmval.dptr+sizeof(apr_time_t), data.data, data.size); - rv = apr_dbm_open_ex(&dbm, ODB, ctxt->sc->cache_config, + rv = apr_dbm_open_ex(&dbm, db_type(ctxt->sc), ctxt->sc->cache_config, APR_DBM_RWCREATE, SSL_DBM_FILE_MODE, ctxt->c->pool); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_NOTICE, rv, @@ -484,7 +490,7 @@ static int dbm_cache_delete(void* baton, gnutls_datum_t key) if (mgs_session_id2dbm(ctxt->c, key.data, key.size, &dbmkey) < 0) return -1; - rv = apr_dbm_open_ex(&dbm, ODB, ctxt->sc->cache_config, + rv = apr_dbm_open_ex(&dbm, db_type(ctxt->sc), ctxt->sc->cache_config, APR_DBM_RWCREATE, SSL_DBM_FILE_MODE, ctxt->c->pool); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_NOTICE, rv, @@ -518,7 +524,7 @@ static int dbm_cache_post_config(apr_pool_t *p, server_rec *s, const char* path1; const char* path2; - rv = apr_dbm_open_ex(&dbm, ODB, sc->cache_config, APR_DBM_RWCREATE, + rv = apr_dbm_open_ex(&dbm, db_type(sc), sc->cache_config, APR_DBM_RWCREATE, SSL_DBM_FILE_MODE, p); if (rv != APR_SUCCESS) { @@ -530,7 +536,7 @@ static int dbm_cache_post_config(apr_pool_t *p, server_rec *s, apr_dbm_close(dbm); - apr_dbm_get_usednames_ex(p, ODB, sc->cache_config, &path1, &path2); + apr_dbm_get_usednames_ex(p, db_type(sc), sc->cache_config, &path1, &path2); /* The Following Code takes logic directly from mod_ssl's DBM Cache */ #if !defined(OS2) && !defined(WIN32) && !defined(BEOS) && !defined(NETWARE) @@ -549,7 +555,7 @@ static int dbm_cache_post_config(apr_pool_t *p, server_rec *s, int mgs_cache_post_config(apr_pool_t *p, server_rec *s, mgs_srvconf_rec *sc) { - if (sc->cache_type == mgs_cache_dbm) { + if (sc->cache_type == mgs_cache_dbm || sc->cache_type == mgs_cache_sdbm) { return dbm_cache_post_config(p, s, sc); } return 0; @@ -558,7 +564,7 @@ int mgs_cache_post_config(apr_pool_t *p, server_rec *s, int mgs_cache_child_init(apr_pool_t *p, server_rec *s, mgs_srvconf_rec *sc) { - if (sc->cache_type == mgs_cache_dbm) { + if (sc->cache_type == mgs_cache_dbm || sc->cache_type == mgs_cache_sdbm) { return 0; } #if HAVE_APR_MEMCACHE @@ -573,7 +579,7 @@ int mgs_cache_child_init(apr_pool_t *p, server_rec *s, int mgs_cache_session_init(mgs_handle_t *ctxt) { - if (ctxt->sc->cache_type == mgs_cache_dbm) { + if (ctxt->sc->cache_type == mgs_cache_dbm || ctxt->sc->cache_type == mgs_cache_sdbm) { gnutls_db_set_retrieve_function(ctxt->session, dbm_cache_fetch); gnutls_db_set_remove_function(ctxt->session, dbm_cache_delete); gnutls_db_set_store_function(ctxt->session, dbm_cache_store); diff --git a/src/gnutls_config.c b/src/gnutls_config.c index 6c8d427..4bb523f 100644 --- a/src/gnutls_config.c +++ b/src/gnutls_config.c @@ -343,10 +343,14 @@ const char *mgs_set_cache(cmd_parms * parms, void *dummy, return err; } - sc->cache_type = mgs_cache_none; - if (strcasecmp("dbm", type) == 0) { + if (strcasecmp("none", type) == 0) { + sc->cache_type = mgs_cache_none; + } else if (strcasecmp("dbm", type) == 0) { sc->cache_type = mgs_cache_dbm; } + else if (strcasecmp("sdbm", type) == 0) { + sc->cache_type = mgs_cache_sdbm; + } #if HAVE_APR_MEMCACHE else if (strcasecmp("memcache", type) == 0) { sc->cache_type = mgs_cache_memcache; @@ -356,7 +360,7 @@ const char *mgs_set_cache(cmd_parms * parms, void *dummy, return "Invalid Type for GnuTLSCache!"; } - if (sc->cache_type == mgs_cache_dbm) { + if (sc->cache_type == mgs_cache_dbm || sc->cache_type == mgs_cache_sdbm) { sc->cache_config = ap_server_root_relative(parms->pool, arg); } else { sc->cache_config = apr_pstrdup(parms->pool, arg); -- cgit