| 290 | } |
| 291 | |
| 292 | static void ap_authn_cache_store(request_rec *r, const char *module, |
| 293 | const char *user, const char *realm, |
| 294 | const char* data) |
| 295 | { |
| 296 | apr_status_t rv; |
| 297 | authn_cache_dircfg *dcfg; |
| 298 | const char *key; |
| 299 | apr_time_t expiry; |
| 300 | |
| 301 | /* first check whether we're caching for this module */ |
| 302 | dcfg = ap_get_module_config(r->per_dir_config, &authn_socache_module); |
| 303 | if (!configured || !dcfg->providers) { |
| 304 | return; |
| 305 | } |
| 306 | if (!ap_array_str_contains(dcfg->providers, module)) { |
| 307 | return; |
| 308 | } |
| 309 | |
| 310 | /* OK, we're on. Grab mutex to do our business */ |
| 311 | rv = apr_global_mutex_trylock(authn_cache_mutex); |
| 312 | if (APR_STATUS_IS_EBUSY(rv)) { |
| 313 | /* don't wait around; just abandon it */ |
| 314 | ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv, r, APLOGNO(01679) |
| 315 | "authn credentials for %s not cached (mutex busy)", user); |
| 316 | return; |
| 317 | } |
| 318 | else if (rv != APR_SUCCESS) { |
| 319 | ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01680) |
| 320 | "Failed to cache authn credentials for %s in %s", |
| 321 | module, dcfg->context); |
| 322 | return; |
| 323 | } |
| 324 | |
| 325 | /* We have the mutex, so go ahead */ |
| 326 | /* first build our key and determine expiry time */ |
| 327 | key = construct_key(r, dcfg->context, user, realm); |
| 328 | expiry = apr_time_now() + dcfg->timeout; |
| 329 | |
| 330 | /* store it */ |
| 331 | rv = socache_provider->store(socache_instance, r->server, |
| 332 | (unsigned char*)key, strlen(key), expiry, |
| 333 | (unsigned char*)data, strlen(data), r->pool); |
| 334 | if (rv == APR_SUCCESS) { |
| 335 | ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01681) |
| 336 | "Cached authn credentials for %s in %s", |
| 337 | user, dcfg->context); |
| 338 | } |
| 339 | else { |
| 340 | ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01682) |
| 341 | "Failed to cache authn credentials for %s in %s", |
| 342 | module, dcfg->context); |
| 343 | } |
| 344 | |
| 345 | /* We're done with the mutex */ |
| 346 | rv = apr_global_mutex_unlock(authn_cache_mutex); |
| 347 | if (rv != APR_SUCCESS) { |
| 348 | ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01683) "Failed to release mutex!"); |
| 349 | } |
nothing calls this directly
no test coverage detected