ssl_scache_dbm.c revision 341bd61e8bccf51d8f2a5580168272e6e9098500
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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"
/* Use of the context structure must be thread-safe after the initial
struct context {
const char *data_file;
/* Pool must only be used with the mutex held. */
};
apr_pool_t *p);
{
}
return NULL;
}
{
/* for the DBM we need the data file */
"SSLSessionCache required");
return APR_EINVAL;
}
/* open it once to create it and to make sure it _can_ be created */
"Cannot create SSLSessionCache DBM file `%s'",
return rv;
}
/*
* 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_scache_dbm_expire(ctx, s);
return APR_SUCCESS;
}
{
/* the correct way */
/* the additional ways to be sure */
return;
}
{
/* 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 APR_ENOSPC;
}
#else
"data size too large for DBM session cache: %d >= %d",
return APR_ENOSPC;
}
#endif
/* create DBM key */
/* create DBM value */
"malloc error creating DBM value");
return APR_ENOMEM;
}
/* and store it to the DBM file */
"Cannot open SSLSessionCache DBM file `%s' for writing "
"(store)",
return rv;
}
"Cannot store SSL session to DBM file `%s'",
return rv;
}
/* free temporary buffers */
/* allow the regular expiring to occur */
ssl_scache_dbm_expire(ctx, s);
return APR_SUCCESS;
}
apr_pool_t *p)
{
unsigned int nData;
/* allow the regular expiring to occur */
ssl_scache_dbm_expire(ctx, s);
/* 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.
*/
"Cannot open SSLSessionCache DBM file `%s' for reading "
"(fetch)",
return rc;
}
if (rc != APR_SUCCESS) {
return rc;
}
return rc;
}
/* parse resulting data */
return APR_ENOSPC;
}
/* make sure the stuff is still not expired */
return APR_EGENERAL;
}
return APR_SUCCESS;
}
apr_pool_t *p)
{
/* create DBM key and values */
/* and delete it from the DBM file */
"Cannot open SSLSessionCache DBM file `%s' for writing "
"(delete)",
return;
}
return;
}
{
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
for (;;) {
/* allocate the key array in a memory sub pool */
break;
}
/* pass 1: scan DBM database */
keyidx = 0;
"Cannot open SSLSessionCache DBM file `%s' for "
"scanning",
break;
}
nElements++;
else {
if (tExpiresAt <= tNow)
}
if (bDelete) {
keyidx++;
break;
}
}
}
/* pass 2: delete expired elements */
"Cannot re-open SSLSessionCache DBM file `%s' for "
"expiring",
break;
}
for (i = 0; i < keyidx; i++) {
nDeleted++;
}
break;
}
"Inter-Process Session Cache (DBM) Expiry: "
"old: %d, new: %d, removed: %d",
}
{
int nElem;
int nSize;
int nAverage;
nElem = 0;
nSize = 0;
"Cannot open SSLSessionCache DBM file `%s' for status "
"retrival",
return;
}
/*
* XXX - Check the return value of apr_dbm_firstkey, apr_dbm_fetch - TBD
*/
continue;
nElem += 1;
}
else
nAverage = 0;
ap_rprintf(r, "cache type: <b>DBM</b>, maximum size: <b>unlimited</b><br>");
return;
}
"dbm",
};