1 /* _ _
2 ** _ __ ___ ___ __| | ___ ___| | mod_ssl
3 ** | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
4 ** | | | | | | (_) | (_| | \__ \__ \ | www.modssl.org
5 ** |_| |_| |_|\___/ \__,_|___|___/___/_| ftp.modssl.org
6 ** |_____|
7 ** ssl_scache.c
8 ** Session Cache Abstraction
9 */
10
11 /* ====================================================================
12 * Copyright (c) 1998-2003 Ralf S. Engelschall. All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 *
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
25 *
26 * 3. All advertising materials mentioning features or use of this
27 * software must display the following acknowledgment:
28 * "This product includes software developed by
29 * Ralf S. Engelschall <rse@engelschall.com> for use in the
30 * mod_ssl project (http://www.modssl.org/)."
31 *
32 * 4. The names "mod_ssl" must not be used to endorse or promote
33 * products derived from this software without prior written
34 * permission. For written permission, please contact
35 * rse@engelschall.com.
36 *
37 * 5. Products derived from this software may not be called "mod_ssl"
38 * nor may "mod_ssl" appear in their names without prior
39 * written permission of Ralf S. Engelschall.
40 *
41 * 6. Redistributions of any form whatsoever must retain the following
42 * acknowledgment:
43 * "This product includes software developed by
44 * Ralf S. Engelschall <rse@engelschall.com> for use in the
45 * mod_ssl project (http://www.modssl.org/)."
46 *
47 * THIS SOFTWARE IS PROVIDED BY RALF S. ENGELSCHALL ``AS IS'' AND ANY
48 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RALF S. ENGELSCHALL OR
51 * HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
53 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
54 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
56 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
58 * OF THE POSSIBILITY OF SUCH DAMAGE.
59 * ====================================================================
60 */
61 /* ``Open-Source Software: generous
62 programmers from around the world all
63 join forces to help you shoot
64 yourself in the foot for free.''
65 -- Unknown */
66 #include "mod_ssl.h"
67
68 /* _________________________________________________________________
69 **
70 ** Session Cache: Common Abstraction Layer
71 ** _________________________________________________________________
72 */
73
ssl_scache_init(server_rec * s,pool * p)74 void ssl_scache_init(server_rec *s, pool *p)
75 {
76 SSLModConfigRec *mc = myModConfig();
77
78 if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
79 ssl_scache_dbm_init(s, p);
80 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
81 ssl_scache_shmht_init(s, p);
82 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
83 ssl_scache_shmcb_init(s, p);
84 #ifdef SSL_VENDOR
85 else
86 ap_hook_use("ap::mod_ssl::vendor::scache_init",
87 AP_HOOK_SIG3(void,ptr,ptr), AP_HOOK_ALL, s, p);
88 #endif
89 return;
90 }
91
ssl_scache_kill(server_rec * s)92 void ssl_scache_kill(server_rec *s)
93 {
94 SSLModConfigRec *mc = myModConfig();
95
96 if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
97 ssl_scache_dbm_kill(s);
98 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
99 ssl_scache_shmht_kill(s);
100 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
101 ssl_scache_shmcb_kill(s);
102 #ifdef SSL_VENDOR
103 else
104 ap_hook_use("ap::mod_ssl::vendor::scache_kill",
105 AP_HOOK_SIG2(void,ptr), AP_HOOK_ALL, s);
106 #endif
107 return;
108 }
109
ssl_scache_store(server_rec * s,UCHAR * id,int idlen,time_t expiry,SSL_SESSION * sess)110 BOOL ssl_scache_store(server_rec *s, UCHAR *id, int idlen, time_t expiry, SSL_SESSION *sess)
111 {
112 SSLModConfigRec *mc = myModConfig();
113 BOOL rv = FALSE;
114
115 if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
116 rv = ssl_scache_dbm_store(s, id, idlen, expiry, sess);
117 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
118 rv = ssl_scache_shmht_store(s, id, idlen, expiry, sess);
119 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
120 rv = ssl_scache_shmcb_store(s, id, idlen, expiry, sess);
121 #ifdef SSL_VENDOR
122 else
123 ap_hook_use("ap::mod_ssl::vendor::scache_store",
124 AP_HOOK_SIG6(int,ptr,ptr,int,int,ptr), AP_HOOK_ALL,
125 (int *)&rv, s, id, idlen, (int)expiry, sess);
126 #endif
127 return rv;
128 }
129
ssl_scache_retrieve(server_rec * s,UCHAR * id,int idlen)130 SSL_SESSION *ssl_scache_retrieve(server_rec *s, UCHAR *id, int idlen)
131 {
132 SSLModConfigRec *mc = myModConfig();
133 SSL_SESSION *sess = NULL;
134
135 if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
136 sess = ssl_scache_dbm_retrieve(s, id, idlen);
137 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
138 sess = ssl_scache_shmht_retrieve(s, id, idlen);
139 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
140 sess = ssl_scache_shmcb_retrieve(s, id, idlen);
141 #ifdef SSL_VENDOR
142 else
143 ap_hook_use("ap::mod_ssl::vendor::scache_retrieve",
144 AP_HOOK_SIG4(ptr,ptr,ptr,int), AP_HOOK_ALL,
145 &sess, s, id, idlen);
146 #endif
147 return sess;
148 }
149
ssl_scache_remove(server_rec * s,UCHAR * id,int idlen)150 void ssl_scache_remove(server_rec *s, UCHAR *id, int idlen)
151 {
152 SSLModConfigRec *mc = myModConfig();
153
154 if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
155 ssl_scache_dbm_remove(s, id, idlen);
156 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
157 ssl_scache_shmht_remove(s, id, idlen);
158 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
159 ssl_scache_shmcb_remove(s, id, idlen);
160 #ifdef SSL_VENDOR
161 else
162 ap_hook_use("ap::mod_ssl::vendor::scache_remove",
163 AP_HOOK_SIG4(void,ptr,ptr,int), AP_HOOK_ALL, s, id, idlen);
164 #endif
165 return;
166 }
167
ssl_scache_status(server_rec * s,pool * p,void (* func)(char *,void *),void * arg)168 void ssl_scache_status(server_rec *s, pool *p, void (*func)(char *, void *), void *arg)
169 {
170 SSLModConfigRec *mc = myModConfig();
171
172 if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
173 ssl_scache_dbm_status(s, p, func, arg);
174 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
175 ssl_scache_shmht_status(s, p, func, arg);
176 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
177 ssl_scache_shmcb_status(s, p, func, arg);
178 #ifdef SSL_VENDOR
179 else
180 ap_hook_use("ap::mod_ssl::vendor::scache_status",
181 AP_HOOK_SIG5(void,ptr,ptr,ptr,ptr), AP_HOOK_ALL,
182 s, p, func, arg);
183 #endif
184 return;
185 }
186
ssl_scache_expire(server_rec * s)187 void ssl_scache_expire(server_rec *s)
188 {
189 SSLModConfigRec *mc = myModConfig();
190
191 if (mc->nSessionCacheMode == SSL_SCMODE_DBM)
192 ssl_scache_dbm_expire(s);
193 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMHT)
194 ssl_scache_shmht_expire(s);
195 else if (mc->nSessionCacheMode == SSL_SCMODE_SHMCB)
196 ssl_scache_shmcb_expire(s);
197 #ifdef SSL_VENDOR
198 else
199 ap_hook_use("ap::mod_ssl::vendor::scache_expire",
200 AP_HOOK_SIG2(void,ptr), AP_HOOK_ALL, s);
201 #endif
202 return;
203 }
204
205