/* Destroy a given cache context. */
void (*destroy)(void *context, server_rec *s);
/* Store an object in the cache. */
- BOOL (*store)(void *context, server_rec *s,
- UCHAR *id, int idlen, time_t expiry,
- unsigned char *data, unsigned int datalen);
+ apr_status_t (*store)(void *context, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ time_t expiry,
+ unsigned char *data, unsigned int datalen);
/* Retrieve cached data with key ID of length IDLEN,
* returning TRUE on success or FALSE otherwise. If
* TRUE, the data must be placed in DEST, which has length
* on entry of *DESTLEN. *DESTLEN must be updated to
* equal the length of data written on exit. */
- BOOL (*retrieve)(void *context, server_rec *s,
- const UCHAR *id, int idlen,
- unsigned char *dest, unsigned int *destlen,
- apr_pool_t *pool);
+ apr_status_t (*retrieve)(void *context, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ unsigned char *dest, unsigned int *destlen,
+ apr_pool_t *pool);
/* Remove an object from the cache. */
void (*delete)(void *context, server_rec *s,
- UCHAR *id, int idlen, apr_pool_t *pool);
+ const unsigned char *id, unsigned int idlen,
+ apr_pool_t *pool);
/* Dump cache status for mod_status output. */
- void (*status)(void *context, request_rec *r,
- int flags, apr_pool_t *pool);
+ void (*status)(void *context, request_rec *r, int flags);
} modssl_sesscache_provider;
typedef struct {
SSLModConfigRec *mc = myModConfig(s);
unsigned char encoded[SSL_SESSION_MAX_DER], *ptr;
unsigned int len;
- BOOL rv;
+ apr_status_t rv;
/* Serialise the session. */
len = i2d_SSL_SESSION(sess, NULL);
ssl_mutex_off(s);
}
- return rv;
+ return rv == APR_SUCCESS ? TRUE : FALSE;
}
SSL_SESSION *ssl_scache_retrieve(server_rec *s, UCHAR *id, int idlen,
unsigned char dest[SSL_SESSION_MAX_DER];
unsigned int destlen = SSL_SESSION_MAX_DER;
MODSSL_D2I_SSL_SESSION_CONST unsigned char *ptr;
- BOOL rv;
+ apr_status_t rv;
if (mc->sesscache->flags & MODSSL_SESSCACHE_FLAG_NOTMPSAFE) {
ssl_mutex_on(s);
ssl_mutex_off(s);
}
- if (rv == FALSE) {
+ if (rv != APR_SUCCESS) {
return NULL;
}
ssl_mutex_on(r->server);
}
- mc->sesscache->status(mc->sesscache_context, r, flags, r->pool);
+ mc->sesscache->status(mc->sesscache_context, r, flags);
if (mc->sesscache->flags & MODSSL_SESSCACHE_FLAG_NOTMPSAFE) {
ssl_mutex_off(r->server);
static void ssl_scache_dbm_expire(struct context *ctx, server_rec *s);
-static void ssl_scache_dbm_remove(void *context, server_rec *s, UCHAR *id, int idlen,
+static void ssl_scache_dbm_remove(void *context, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
apr_pool_t *p);
static const char *ssl_scache_dbm_create(void **context, const char *arg,
return;
}
-static BOOL ssl_scache_dbm_store(void *context, server_rec *s, UCHAR *id, int idlen,
- time_t expiry,
- unsigned char *ucaData, unsigned int nData)
+static apr_status_t ssl_scache_dbm_store(void *context, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ time_t expiry,
+ unsigned char *ucaData, unsigned int nData)
{
struct context *ctx = context;
apr_dbm_t *dbm;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
"data size too large for DBM session cache: %d >= %d",
(idlen + nData), PAIRMAX);
- return FALSE;
+ return APR_ENOSPC;
}
#else
if ((idlen + nData) >= 950 /* at least less than approx. 1KB */) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
"data size too large for DBM session cache: %d >= %d",
(idlen + nData), 950);
- return FALSE;
+ return APR_ENOSPC;
}
#endif
if (dbmval.dptr == NULL) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
"malloc error creating DBM value");
- return FALSE;
+ return APR_ENOMEM;
}
memcpy((char *)dbmval.dptr, &expiry, sizeof(time_t));
memcpy((char *)dbmval.dptr+sizeof(time_t), ucaData, nData);
"(store)",
ctx->data_file);
free(dbmval.dptr);
- return FALSE;
+ return rv;
}
if ((rv = apr_dbm_store(dbm, dbmkey, dbmval)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
ctx->data_file);
apr_dbm_close(dbm);
free(dbmval.dptr);
- return FALSE;
+ return rv;
}
apr_dbm_close(dbm);
/* allow the regular expiring to occur */
ssl_scache_dbm_expire(ctx, s);
- return TRUE;
+ return APR_SUCCESS;
}
-static BOOL ssl_scache_dbm_retrieve(void *context, server_rec *s, const UCHAR *id, int idlen,
- unsigned char *dest, unsigned int *destlen,
- apr_pool_t *p)
+static apr_status_t ssl_scache_dbm_retrieve(void *context, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ unsigned char *dest, unsigned int *destlen,
+ apr_pool_t *p)
{
struct context *ctx = context;
apr_dbm_t *dbm;
"Cannot open SSLSessionCache DBM file `%s' for reading "
"(fetch)",
ctx->data_file);
- return FALSE;
+ return rc;
}
rc = apr_dbm_fetch(dbm, dbmkey, &dbmval);
if (rc != APR_SUCCESS) {
apr_dbm_close(dbm);
- return FALSE;
+ return rc;
}
if (dbmval.dptr == NULL || dbmval.dsize <= sizeof(time_t)) {
apr_dbm_close(dbm);
- return FALSE;
+ return rc;
}
/* parse resulting data */
nData = dbmval.dsize-sizeof(time_t);
if (nData > *destlen) {
apr_dbm_close(dbm);
- return FALSE;
+ return APR_ENOSPC;
}
*destlen = nData;
/* make sure the stuff is still not expired */
now = time(NULL);
if (expiry <= now) {
- ssl_scache_dbm_remove(context, s, (UCHAR *)id, idlen, p);
- return FALSE;
+ ssl_scache_dbm_remove(context, s, id, idlen, p);
+ return APR_EGENERAL;
}
- return TRUE;
+ return APR_SUCCESS;
}
-static void ssl_scache_dbm_remove(void *context, server_rec *s, UCHAR *id, int idlen,
+static void ssl_scache_dbm_remove(void *context, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
apr_pool_t *p)
{
struct context *ctx = context;
nElements, nElements-nDeleted, nDeleted);
}
-static void ssl_scache_dbm_status(void *context, request_rec *r,
- int flags, apr_pool_t *p)
+static void ssl_scache_dbm_status(void *context, request_rec *r, int flags)
{
struct context *ctx = context;
apr_dbm_t *dbm;
}
}
-static BOOL ssl_scache_dc_store(void *context, server_rec *s, UCHAR *id, int idlen,
- time_t timeout,
- unsigned char *der, unsigned int der_len)
+static apr_status_t ssl_scache_dc_store(void *context, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ time_t timeout,
+ unsigned char *der, unsigned int der_len)
{
struct context *ctx = context;
if (!DC_CTX_add_session(ctx->dc, id, idlen, der, der_len,
(unsigned long)timeout * 1000)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'add_session' failed");
- return FALSE;
+ return APR_EGENERAL;
}
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "distributed scache 'add_session' successful");
- return TRUE;
+ return APR_SUCCESS;
}
-static BOOL ssl_scache_dc_retrieve(void *context,
- server_rec *s, const UCHAR *id, int idlen,
- unsigned char *dest, unsigned int *destlen,
- apr_pool_t *p)
+static apr_status_t ssl_scache_dc_retrieve(void *context, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ unsigned char *dest, unsigned int *destlen,
+ apr_pool_t *p)
{
unsigned int data_len;
struct context *ctx = context;
/* Retrieve any corresponding session from the distributed cache context */
if (!DC_CTX_get_session(ctx->dc, id, idlen, dest, *destlen, &data_len)) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "distributed scache 'get_session' MISS");
- return FALSE;
+ return APR_EGENERAL;
}
if (data_len > *destlen) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "distributed scache 'get_session' OVERFLOW");
- return FALSE;
+ return APR_ENOSPC;
}
*destlen = data_len;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "distributed scache 'get_session' HIT");
- return TRUE;
+ return APR_SUCCESS;
}
static void ssl_scache_dc_remove(void *context, server_rec *s,
- UCHAR *id, int idlen, apr_pool_t *p)
+ const unsigned char *id, unsigned int idlen,
+ apr_pool_t *p)
{
struct context *ctx = context;
}
}
-static void ssl_scache_dc_status(void *context, request_rec *r, int flags, apr_pool_t *pool)
+static void ssl_scache_dc_status(void *context, request_rec *r, int flags)
{
struct context *ctx = context;
/* noop. */
}
-static char *mc_session_id2sz(const unsigned char *id, int idlen,
+static char *mc_session_id2sz(const unsigned char *id, unsigned int idlen,
char *str, int strsize)
{
char *cp;
return str;
}
-static BOOL ssl_scache_mc_store(void *context, server_rec *s,
- UCHAR *id, int idlen,
- time_t timeout,
- unsigned char *ucaData, unsigned int nData)
+static apr_status_t ssl_scache_mc_store(void *context, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ time_t timeout,
+ unsigned char *ucaData, unsigned int nData)
{
struct context *ctx = context;
char buf[MC_KEY_LEN];
strkey = mc_session_id2sz(id, idlen, buf, sizeof(buf));
if(!strkey) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "scache_mc: Key generation borked.");
- return FALSE;
+ return APR_EGENERAL;
}
rv = apr_memcache_set(ctx->mc, strkey, (char*)ucaData, nData, timeout, 0);
ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
"scache_mc: error setting key '%s' "
"with %d bytes of data", strkey, nData);
- return FALSE;
+ return rv;
}
- return TRUE;
+ return APR_SUCCESS;
}
-static BOOL ssl_scache_mc_retrieve(void *context, server_rec *s,
- const UCHAR *id, int idlen,
- unsigned char *dest, unsigned int *destlen,
- apr_pool_t *p)
+static apr_status_t ssl_scache_mc_retrieve(void *context, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ unsigned char *dest, unsigned int *destlen,
+ apr_pool_t *p)
{
struct context *ctx = context;
apr_size_t der_len;
if (!strkey) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
"scache_mc: Key generation borked.");
- return FALSE;
+ return APR_EGENERAL;
}
/* ### this could do with a subpool, but _getp looks like it will
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
"scache_mc: 'get_session' FAIL");
}
- return FALSE;
+ return rv;
}
else if (der_len > *destlen) {
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
"scache_mc: 'get_session' OVERFLOW");
- return FALSE;
+ return rv;
}
memcpy(dest, der, der_len);
*destlen = der_len;
- return TRUE;
+ return APR_SUCCESS;
}
-static void ssl_scache_mc_remove(void *context, server_rec *s, UCHAR *id, int idlen, apr_pool_t *p)
+static void ssl_scache_mc_remove(void *context, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ apr_pool_t *p)
{
struct context *ctx = context;
char buf[MC_KEY_LEN];
}
}
-static void ssl_scache_mc_status(void *context, request_rec *r,
- int flags, apr_pool_t *pool)
+static void ssl_scache_mc_status(void *context, request_rec *r, int flags)
{
/* SSLModConfigRec *mc = myModConfig(r->server); */
/* TODO: Make a mod_status handler. meh. */
/* A "normal-to-cyclic" memcpy. */
static void shmcb_cyclic_ntoc_memcpy(unsigned int buf_size, unsigned char *data,
- unsigned int dest_offset, unsigned char *src,
+ unsigned int dest_offset, const unsigned char *src,
unsigned int src_len)
{
if (dest_offset + src_len < buf_size)
/* A "cyclic-to-normal" memcpy. */
static void shmcb_cyclic_cton_memcpy(unsigned int buf_size, unsigned char *dest,
- unsigned char *data, unsigned int src_offset,
+ const unsigned char *data, unsigned int src_offset,
unsigned int src_len)
{
if (src_offset + src_len < buf_size)
/* Prototypes for low-level subcache operations */
static void shmcb_subcache_expire(server_rec *, SHMCBHeader *, SHMCBSubcache *);
-static BOOL shmcb_subcache_store(server_rec *s, SHMCBHeader *header,
- SHMCBSubcache *subcache,
- UCHAR *data, unsigned int data_len,
- UCHAR *id, unsigned int id_len,
- time_t expiry);
-static BOOL shmcb_subcache_retrieve(server_rec *, SHMCBHeader *, SHMCBSubcache *,
- const UCHAR *id, unsigned int idlen,
- UCHAR *data, unsigned int *datalen);
-
-static BOOL shmcb_subcache_remove(server_rec *, SHMCBHeader *, SHMCBSubcache *,
- UCHAR *, unsigned int);
+/* Returns zero on success, non-zero on failure. */
+static int shmcb_subcache_store(server_rec *s, SHMCBHeader *header,
+ SHMCBSubcache *subcache,
+ unsigned char *data, unsigned int data_len,
+ const unsigned char *id, unsigned int id_len,
+ time_t expiry);
+/* Returns zero on success, non-zero on failure. */
+static int shmcb_subcache_retrieve(server_rec *, SHMCBHeader *, SHMCBSubcache *,
+ const unsigned char *id, unsigned int idlen,
+ unsigned char *data, unsigned int *datalen);
+/* Returns zero on success, non-zero on failure. */
+static int shmcb_subcache_remove(server_rec *, SHMCBHeader *, SHMCBSubcache *,
+ const unsigned char *, unsigned int);
/*
* High-Level "handlers" as per ssl_scache.c
}
}
-static BOOL ssl_scache_shmcb_store(void *context, server_rec *s,
- UCHAR *id, int idlen,
- time_t timeout,
- unsigned char *encoded,
- unsigned int len_encoded)
+static apr_status_t ssl_scache_shmcb_store(void *context, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ time_t timeout,
+ unsigned char *encoded,
+ unsigned int len_encoded)
{
struct context *ctx = context;
SHMCBHeader *header = ctx->header;
if (idlen < 4) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "unusably short session_id provided "
"(%u bytes)", idlen);
- return FALSE;
+ return APR_EINVAL;
}
- if (!shmcb_subcache_store(s, header, subcache, encoded,
- len_encoded, id, idlen, timeout)) {
+ if (shmcb_subcache_store(s, header, subcache, encoded,
+ len_encoded, id, idlen, timeout)) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
"can't store a session!");
- return FALSE;
+ return APR_ENOSPC;
}
header->stat_stores++;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
"leaving ssl_scache_shmcb_store successfully");
- return TRUE;
+ return APR_SUCCESS;
}
-static BOOL ssl_scache_shmcb_retrieve(void *context, server_rec *s,
- const UCHAR *id, int idlen,
- unsigned char *dest, unsigned int *destlen,
- apr_pool_t *p)
+static apr_status_t ssl_scache_shmcb_retrieve(void *context, server_rec *s,
+ const unsigned char *id, unsigned int idlen,
+ unsigned char *dest, unsigned int *destlen,
+ apr_pool_t *p)
{
struct context *ctx = context;
SHMCBHeader *header = ctx->header;
SHMCBSubcache *subcache = SHMCB_MASK(header, id);
- BOOL rv;
+ int rv;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
"ssl_scache_shmcb_retrieve (0x%02x -> subcache %d)",
SHMCB_MASK_DBG(header, id));
- /* Get the session corresponding to the session_id or NULL if it doesn't
- * exist (or is flagged as "removed"). */
+ /* Get the session corresponding to the session_id, if it exists. */
rv = shmcb_subcache_retrieve(s, header, subcache, id, idlen,
dest, destlen);
- if (rv)
+ if (rv == 0)
header->stat_retrieves_hit++;
else
header->stat_retrieves_miss++;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
"leaving ssl_scache_shmcb_retrieve successfully");
- return rv;
+ return rv == 0 ? APR_SUCCESS : APR_EGENERAL;
}
static void ssl_scache_shmcb_remove(void *context, server_rec *s,
- UCHAR *id, int idlen, apr_pool_t *p)
+ const unsigned char *id, unsigned int idlen,
+ apr_pool_t *p)
{
struct context *ctx = context;
SHMCBHeader *header = ctx->header;
"leaving ssl_scache_shmcb_remove successfully");
}
-static void ssl_scache_shmcb_status(void *context, request_rec *r,
- int flags, apr_pool_t *p)
+static void ssl_scache_shmcb_status(void *context, request_rec *r, int flags)
{
server_rec *s = r->server;
struct context *ctx = context;
"we now have %u sessions", subcache->idx_used);
}
-static BOOL shmcb_subcache_store(server_rec *s, SHMCBHeader *header,
- SHMCBSubcache *subcache,
- UCHAR *data, unsigned int data_len,
- UCHAR *id, unsigned int id_len,
- time_t expiry)
+static int shmcb_subcache_store(server_rec *s, SHMCBHeader *header,
+ SHMCBSubcache *subcache,
+ unsigned char *data, unsigned int data_len,
+ const unsigned char *id, unsigned int id_len,
+ time_t expiry)
{
unsigned int data_offset, new_idx, id_offset;
SHMCBIndex *idx;
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
"inserting session larger (%d) than subcache data area (%d)",
total_len, header->subcache_data_size);
- return FALSE;
+ return -1;
}
/* If there are entries to expire, ditch them first. */
"data_pos/data_used=%d/%d",
subcache->idx_pos, subcache->idx_used,
subcache->data_pos, subcache->data_used);
- return TRUE;
+ return 0;
}
-static BOOL shmcb_subcache_retrieve(server_rec *s, SHMCBHeader *header,
- SHMCBSubcache *subcache,
- const UCHAR *id, unsigned int idlen,
- UCHAR *dest, unsigned int *destlen)
+static int shmcb_subcache_retrieve(server_rec *s, SHMCBHeader *header,
+ SHMCBSubcache *subcache,
+ const unsigned char *id, unsigned int idlen,
+ unsigned char *dest, unsigned int *destlen)
{
unsigned int pos;
unsigned int loop = 0;
dest, SHMCB_DATA(header, subcache),
data_offset, *destlen);
- return TRUE;
+ return 0;
}
/* Increment */
loop++;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
"shmcb_subcache_retrieve found no match");
- return FALSE;
+ return -1;
+
}
-static BOOL shmcb_subcache_remove(server_rec *s, SHMCBHeader *header,
- SHMCBSubcache *subcache,
- UCHAR *id, unsigned int idlen)
+static int shmcb_subcache_remove(server_rec *s, SHMCBHeader *header,
+ SHMCBSubcache *subcache,
+ const unsigned char *id, unsigned int idlen)
{
unsigned int pos;
unsigned int loop = 0;
- BOOL to_return = FALSE;
/* Unlike the others, we don't do an expire-run first. This is to keep
* consistent statistics where a "remove" operation may actually be the
* intended session was in fact removed by an expiry run. */
pos = subcache->idx_pos;
- while (!to_return && (loop < subcache->idx_used)) {
+ while (loop < subcache->idx_used) {
SHMCBIndex *idx = SHMCB_INDEX(subcache, pos);
/* Only consider 'idx' if the id matches, and the "removed"
"possible match at idx=%d, data=%d", pos, idx->data_pos);
/* Found the matching session, remove it quietly. */
idx->removed = 1;
- to_return = TRUE;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
"shmcb_subcache_remove removing matching session");
+ return 0;
}
/* Increment */
loop++;
pos = SHMCB_CYCLIC_INCREMENT(pos, 1, header->index_num);
}
- return to_return;
+ return -1; /* failure */
}
const modssl_sesscache_provider modssl_sesscache_shmcb = {