Changeset e376ed8 in mod_gnutls for src/gnutls_cache.c
- Timestamp:
- Nov 29, 2019, 4:30:08 PM (15 months ago)
- Branches:
- asyncio, master, proxy-ticket
- Children:
- 618ee14
- Parents:
- d4c9331 (diff), 556783e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/gnutls_cache.c
rd4c9331 re376ed8 52 52 /** Maximum length of the hex string representation of a GnuTLS 53 53 * session ID: two characters per byte, plus one more for `\0` */ 54 #if GNUTLS_VERSION_NUMBER >= 0x03040055 54 #define GNUTLS_SESSION_ID_STRING_LEN ((GNUTLS_MAX_SESSION_ID_SIZE * 2) + 1) 56 #else57 #define GNUTLS_SESSION_ID_STRING_LEN ((GNUTLS_MAX_SESSION_ID * 2) + 1)58 #endif59 55 60 56 #ifdef APLOG_USE_MODULE … … 179 175 #define SOCACHE_FETCH_BUF_SIZE (8 * 1024) 180 176 181 gnutls_datum_t mgs_cache_fetch(mgs_cache_t cache, server_rec *server, 182 gnutls_datum_t key, apr_pool_t *pool) 183 { 184 gnutls_datum_t data = {NULL, 0}; 185 data.data = gnutls_malloc(SOCACHE_FETCH_BUF_SIZE); 186 if (data.data == NULL) 187 return data; 188 data.size = SOCACHE_FETCH_BUF_SIZE; 189 177 apr_status_t mgs_cache_fetch(mgs_cache_t cache, server_rec *server, 178 gnutls_datum_t key, gnutls_datum_t *output, 179 apr_pool_t *pool) 180 { 190 181 apr_pool_t *spool; 191 182 apr_pool_create(&spool, pool); … … 195 186 apr_status_t rv = cache->prov->retrieve(cache->socache, server, 196 187 key.data, key.size, 197 data.data, &data.size,188 output->data, &output->size, 198 189 spool); 199 190 if (cache->prov->flags & AP_SOCACHE_FLAG_NOTMPSAFE) … … 211 202 "error fetching from cache '%s:%s'", 212 203 cache->prov->name, cache->config); 204 } 205 else 206 { 207 ap_log_error(APLOG_MARK, APLOG_TRACE1, rv, server, 208 "fetched %u bytes from cache '%s:%s'", 209 output->size, cache->prov->name, cache->config); 210 } 211 apr_pool_destroy(spool); 212 213 return rv; 214 } 215 216 217 218 /** 219 * Fetch function for the GnuTLS session cache, see 220 * gnutls_db_set_retrieve_function(). 221 * 222 * *Warning*: The `data` element of the returned `gnutls_datum_t` is 223 * allocated using `gnutls_malloc()` for compatibility with the GnuTLS 224 * session caching API, and must be released using `gnutls_free()`. 225 * 226 * @param baton mgs_handle_t for the connection, as set via 227 * gnutls_db_set_ptr() 228 * 229 * @param key object key to fetch 230 * 231 * @return the requested cache entry, or `{NULL, 0}` 232 */ 233 static gnutls_datum_t socache_fetch_session(void *baton, gnutls_datum_t key) 234 { 235 gnutls_datum_t data = {NULL, 0}; 236 gnutls_datum_t dbmkey; 237 mgs_handle_t *ctxt = baton; 238 239 if (mgs_session_id2dbm(ctxt->c, key.data, key.size, &dbmkey) < 0) 240 return data; 241 242 data.data = gnutls_malloc(SOCACHE_FETCH_BUF_SIZE); 243 if (data.data == NULL) 244 return data; 245 data.size = SOCACHE_FETCH_BUF_SIZE; 246 247 apr_status_t rv = mgs_cache_fetch(ctxt->sc->cache, ctxt->c->base_server, 248 dbmkey, &data, ctxt->c->pool); 249 250 if (rv != APR_SUCCESS) 251 { 213 252 /* free unused buffer */ 214 253 gnutls_free(data.data); … … 218 257 else 219 258 { 220 ap_log_error(APLOG_MARK, APLOG_TRACE1, rv, server,221 "fetched %u bytes from cache '%s:%s'",222 data.size, cache->prov->name, cache->config);223 224 259 /* Realloc buffer to data.size. Data size must be less than or 225 260 * equal to the initial buffer size, so this REALLY should not … … 228 263 if (__builtin_expect(data.data == NULL, 0)) 229 264 { 230 ap_log_ error(APLOG_MARK, APLOG_CRIT, APR_ENOMEM, server,265 ap_log_cerror(APLOG_MARK, APLOG_CRIT, APR_ENOMEM, ctxt->c, 231 266 "%s: Could not realloc fetch buffer to data size!", 232 267 __func__); … … 234 269 } 235 270 } 236 apr_pool_destroy(spool);237 271 238 272 return data; 239 }240 241 242 243 /**244 * Fetch function for the GnuTLS session cache, see245 * gnutls_db_set_retrieve_function().246 *247 * *Warning*: The `data` element of the returned `gnutls_datum_t` is248 * allocated using `gnutls_malloc()` for compatibility with the GnuTLS249 * session caching API, and must be released using `gnutls_free()`.250 *251 * @param baton mgs_handle_t for the connection, as set via252 * gnutls_db_set_ptr()253 *254 * @param key object key to fetch255 *256 * @return the requested cache entry, or `{NULL, 0}`257 */258 static gnutls_datum_t socache_fetch_session(void *baton, gnutls_datum_t key)259 {260 gnutls_datum_t data = {NULL, 0};261 gnutls_datum_t dbmkey;262 mgs_handle_t *ctxt = baton;263 264 if (mgs_session_id2dbm(ctxt->c, key.data, key.size, &dbmkey) < 0)265 return data;266 267 return mgs_cache_fetch(ctxt->sc->cache, ctxt->c->base_server,268 dbmkey, ctxt->c->pool);269 273 } 270 274
Note: See TracChangeset
for help on using the changeset viewer.