Skip to content

Commit c18ca3a

Browse files
committed
Set krb5 ccache only if krb5 is used
Check if the krb5 mechanism is present and only then set the cache, this avoid wasteful operations if we are not even using krb5. Signed-off-by: Simo Sorce <simo@redhat.com>
1 parent db999f9 commit c18ca3a

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

src/mod_auth_gssapi.c

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -411,27 +411,9 @@ static bool mag_auth_basic(request_rec *req,
411411
gss_OID_set actual_mechs = GSS_C_NO_OID_SET;
412412
uint32_t init_flags = 0;
413413
uint32_t maj, min;
414+
int present = 0;
414415
bool ret = false;
415416

416-
#ifdef HAVE_GSS_KRB5_CCACHE_NAME
417-
rs = apr_generate_random_bytes((unsigned char *)(&rndname),
418-
sizeof(long long unsigned int));
419-
if (rs != APR_SUCCESS) {
420-
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
421-
"Failed to generate random ccache name");
422-
goto done;
423-
}
424-
user_ccache = apr_psprintf(req->pool, "MEMORY:user_%qu", rndname);
425-
maj = gss_krb5_ccache_name(&min, user_ccache, &orig_ccache);
426-
if (GSS_ERROR(maj)) {
427-
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
428-
"In Basic Auth, %s",
429-
mag_error(req, "gss_krb5_ccache_name() "
430-
"failed", maj, min));
431-
goto done;
432-
}
433-
#endif
434-
435417
maj = gss_import_name(&min, &ba_user, GSS_C_NT_USER_NAME, &user);
436418
if (GSS_ERROR(maj)) {
437419
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
@@ -493,6 +475,42 @@ static bool mag_auth_basic(request_rec *req,
493475
allowed_mechs = filtered_mechs;
494476
}
495477

478+
#ifdef HAVE_GSS_KRB5_CCACHE_NAME
479+
/* If we are using the krb5 mechanism make sure to set a per thread
480+
* memory ccache so that there can't be interferences between threads.
481+
* Also make sure we have new cache so no cached results end up being
482+
* used. Some implementations of gss_acquire_cred_with_password() do
483+
* not reacquire creds if cached ones are around, failing to check
484+
* again for the password. */
485+
maj = gss_test_oid_set_member(&min, discard_const(gss_mech_krb5),
486+
allowed_mechs, &present);
487+
if (GSS_ERROR(maj)) {
488+
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
489+
"In Basic Auth, %s",
490+
mag_error(req, "gss_test_oid_set_member() failed",
491+
maj, min));
492+
goto done;
493+
}
494+
if (present) {
495+
rs = apr_generate_random_bytes((unsigned char *)(&rndname),
496+
sizeof(long long unsigned int));
497+
if (rs != APR_SUCCESS) {
498+
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
499+
"Failed to generate random ccache name");
500+
goto done;
501+
}
502+
user_ccache = apr_psprintf(req->pool, "MEMORY:user_%qu", rndname);
503+
maj = gss_krb5_ccache_name(&min, user_ccache, &orig_ccache);
504+
if (GSS_ERROR(maj)) {
505+
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, req,
506+
"In Basic Auth, %s",
507+
mag_error(req, "gss_krb5_ccache_name() "
508+
"failed", maj, min));
509+
goto done;
510+
}
511+
}
512+
#endif
513+
496514
maj = gss_acquire_cred_with_password(&min, user, &ba_pwd,
497515
GSS_C_INDEFINITE,
498516
allowed_mechs,

0 commit comments

Comments
 (0)