ssl_scache_dbm.c revision 08cb74ca432a8c24e39f17dedce527e6a47b8001
/* Copyright 2001-2005 The Apache Software Foundation or its licensors, as
* applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* _ _
* _ __ ___ ___ __| | ___ ___| | mod_ssl
* | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
* | | | | | | (_) | (_| | \__ \__ \ |
* |_| |_| |_|\___/ \__,_|___|___/___/_|
* |_____|
* Session Cache via DBM
*/
#include "ssl_private.h"
static void ssl_scache_dbm_expire(server_rec *s);
{
/* for the DBM we need the data file */
"SSLSessionCache required");
ssl_die();
}
/* open it once to create it and to make sure it _can_ be created */
ssl_mutex_on(s);
"Cannot create SSLSessionCache DBM file `%s'",
ssl_mutex_off(s);
return;
}
/*
* We have to make sure the Apache child processes have access to
* the DBM file. But because there are brain-dead platforms where we
* cannot exactly determine the suffixes we try all possibilities.
*/
if (geteuid() == 0 /* is superuser */) {
}
}
}
#endif
ssl_mutex_off(s);
return;
}
void ssl_scache_dbm_kill(server_rec *s)
{
apr_pool_t *p;
if (p != NULL) {
/* the correct way */
/* the additional ways to be sure */
apr_pool_destroy(p);
}
return;
}
{
int nData;
/* streamline session data */
"streamline session data size too large: %d > "
"%" APR_SIZE_T_FMT,
return FALSE;
}
/* be careful: do not try to store too much bytes in a DBM file! */
#ifdef PAIRMAX
"data size too large for DBM session cache: %d >= %d",
return FALSE;
}
#else
"data size too large for DBM session cache: %d >= %d",
return FALSE;
}
#endif
/* create DBM key */
/* create DBM value */
"malloc error creating DBM value");
return FALSE;
}
/* and store it to the DBM file */
ssl_mutex_on(s);
"Cannot open SSLSessionCache DBM file `%s' for writing "
"(store)",
ssl_mutex_off(s);
return FALSE;
}
"Cannot store SSL session to DBM file `%s'",
ssl_mutex_off(s);
return FALSE;
}
ssl_mutex_off(s);
/* free temporary buffers */
/* allow the regular expiring to occur */
return TRUE;
}
{
int nData;
/* allow the regular expiring to occur */
/* create DBM key and values */
/* and fetch it from the DBM file
* XXX: Should we open the dbm against r->pool so the cleanup will
* do the apr_dbm_close? This would make the code a bit cleaner.
*/
ssl_mutex_on(s);
"Cannot open SSLSessionCache DBM file `%s' for reading "
"(fetch)",
ssl_mutex_off(s);
return NULL;
}
if (rc != APR_SUCCESS) {
ssl_mutex_off(s);
return NULL;
}
ssl_mutex_off(s);
return NULL;
}
/* parse resulting data */
ssl_mutex_off(s);
return NULL;
}
ssl_mutex_off(s);
/* make sure the stuff is still not expired */
return NULL;
}
/* unstreamed SSL_SESSION */
return sess;
}
{
/* create DBM key and values */
/* and delete it from the DBM file */
ssl_mutex_on(s);
"Cannot open SSLSessionCache DBM file `%s' for writing "
"(delete)",
ssl_mutex_off(s);
return;
}
ssl_mutex_off(s);
return;
}
static void ssl_scache_dbm_expire(server_rec *s)
{
apr_pool_t *p;
int nElements = 0;
int nDeleted = 0;
int bDelete;
int keyidx;
int i;
/*
* make sure the expiration for still not-accessed session
* cache entries is done only from time to time
*/
return;
/*
* Here we have to be very carefully: Not all DBM libraries are
* smart enough to allow one to iterate over the elements and at the
* same time delete expired ones. Some of them get totally crazy
* while others have no problems. So we have to do it the slower but
* more safe way: we first iterate over all elements and remember
* those which have to be expired. Then in a second pass we delete
* all those expired elements. Additionally we reopen the DBM file
* to be really safe in state.
*/
#define KEYMAX 1024
ssl_mutex_on(s);
for (;;) {
/* allocate the key array in a memory sub pool */
if (p == NULL)
break;
apr_pool_destroy(p);
break;
}
/* pass 1: scan DBM database */
keyidx = 0;
p)) != APR_SUCCESS) {
"Cannot open SSLSessionCache DBM file `%s' for "
"scanning",
apr_pool_destroy(p);
break;
}
nElements++;
else {
if (tExpiresAt <= tNow)
}
if (bDelete) {
keyidx++;
break;
}
}
}
/* pass 2: delete expired elements */
"Cannot re-open SSLSessionCache DBM file `%s' for "
"expiring",
apr_pool_destroy(p);
break;
}
for (i = 0; i < keyidx; i++) {
nDeleted++;
}
/* destroy temporary pool */
apr_pool_destroy(p);
break;
}
ssl_mutex_off(s);
"Inter-Process Session Cache (DBM) Expiry: "
"old: %d, new: %d, removed: %d",
return;
}
{
int nElem;
int nSize;
int nAverage;
nElem = 0;
nSize = 0;
ssl_mutex_on(r->server);
/*
* XXX - Check what pool is to be used - TBD
*/
"Cannot open SSLSessionCache DBM file `%s' for status "
"retrival",
ssl_mutex_off(r->server);
return;
}
/*
* XXX - Check the return value of apr_dbm_firstkey, apr_dbm_fetch - TBD
*/
continue;
nElem += 1;
}
ssl_mutex_off(r->server);
else
nAverage = 0;
ap_rprintf(r, "cache type: <b>DBM</b>, maximum size: <b>unlimited</b><br>");
return;
}