ssl_scache_dbm.c revision 68d439bc0482b2e41053480f748edc2574c2ea7b
/* _ _
** _ __ ___ ___ __| | ___ ___| | mod_ssl
** | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
** | | | | | | (_) | (_| | \__ \__ \ | www.modssl.org
** |_| |_| |_|\___/ \__,_|___|___/___/_| ftp.modssl.org
** |_____|
** Session Cache via DBM
*/
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*/
#include "mod_ssl.h"
{
/* 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 */
return FALSE;
/* be careful: do not try to store too much bytes in a DBM file! */
#ifdef PAIRMAX
return FALSE;
#else
return FALSE;
#endif
/* create DBM key */
/* create 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;
}
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(s);
/*
* XXX - Check what pool is to be used - TBD
*/
"Cannot open SSLSessionCache DBM file `%s' for status "
"retrival",
ssl_mutex_off(s);
return;
}
/*
* XXX - Check the return value of apr_dbm_firstkey, apr_dbm_fetch - TBD
*/
continue;
nElem += 1;
}
ssl_mutex_off(s);
else
nAverage = 0;
func(apr_psprintf(p, "current sessions: <b>%d</b>, current size: <b>%d</b> bytes<br>", nElem, nSize), arg);
return;
}