Skip to content

Commit 46c0a47

Browse files
iboukrissimo5
authored andcommitted
Retrieve default mechs at server init
This avoids the need to retrieve the list on every auth attempt, and then free it every time. Implemented by adding a server config struct and populating it at server init with gss_indicate_mechs(). Reviewed-by: Simo Sorce <simo@redhat.com>
1 parent c27219c commit 46c0a47

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

src/mod_auth_gssapi.c

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ static bool mag_auth_basic(request_rec *req,
407407
gss_cred_id_t acquired_cred = GSS_C_NO_CREDENTIAL;
408408
gss_buffer_desc input = GSS_C_EMPTY_BUFFER;
409409
gss_buffer_desc output = GSS_C_EMPTY_BUFFER;
410-
gss_OID_set indicated_mechs = GSS_C_NO_OID_SET;
411410
gss_OID_set allowed_mechs;
412411
gss_OID_set filtered_mechs;
413412
gss_OID_set actual_mechs = GSS_C_NO_OID_SET;
@@ -430,24 +429,19 @@ static bool mag_auth_basic(request_rec *req,
430429
} else if (cfg->allowed_mechs) {
431430
allowed_mechs = cfg->allowed_mechs;
432431
} else {
432+
struct mag_server_config *scfg;
433433
/* Try to fetch the default set if not explicitly configured,
434434
* We need to do this because gss_acquire_cred_with_password()
435435
* is currently limited to acquire creds for a single "default"
436436
* mechanism if no desired mechanisms are passed in. This causes
437437
* authentication to fail for secondary mechanisms as no user
438438
* credentials are generated for those. */
439-
maj = gss_indicate_mechs(&min, &indicated_mechs);
440-
if (maj != GSS_S_COMPLETE) {
441-
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, req, "%s",
442-
mag_error(req, "gss_indicate_mechs() failed",
443-
maj, min));
444-
/* if indicated _mechs failed, set GSS_C_NO_OID_SET. This
445-
* generally causes only the krb5 mechanism to be tried due
446-
* to implementation constraints, but may change in future. */
447-
allowed_mechs = GSS_C_NO_OID_SET;
448-
} else {
449-
allowed_mechs = indicated_mechs;
450-
}
439+
scfg = ap_get_module_config(req->server->module_config,
440+
&auth_gssapi_module);
441+
/* In the worst case scenario default_mechs equals to GSS_C_NO_OID_SET.
442+
* This generally causes only the krb5 mechanism to be tried due
443+
* to implementation constraints, but may change in future. */
444+
allowed_mechs = scfg->default_mechs;
451445
}
452446

453447
/* Remove Spnego if present, or we'd repeat failed authentiations
@@ -461,19 +455,14 @@ static bool mag_auth_basic(request_rec *req,
461455
* multiple times uselessly.
462456
*/
463457
filtered_mechs = mag_filter_unwanted_mechs(allowed_mechs);
464-
if ((allowed_mechs != GSS_C_NO_OID_SET) &&
465-
(filtered_mechs == GSS_C_NO_OID_SET)) {
458+
if (filtered_mechs == allowed_mechs) {
459+
/* in case filtered_mechs was not allocated here don't free it */
460+
filtered_mechs = GSS_C_NO_OID_SET;
461+
} else if (filtered_mechs == GSS_C_NO_OID_SET) {
466462
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, req, "Fatal "
467463
"failure while filtering mechs, aborting");
468464
goto done;
469-
} else if (filtered_mechs != allowed_mechs) {
470-
/* if indicated_mechs where sourced then free them here before
471-
* reusing the pointer */
472-
gss_release_oid_set(&min, &indicated_mechs);
473-
474-
/* mark the list of mechs needs to be freed */
475-
indicated_mechs = filtered_mechs;
476-
465+
} else {
477466
/* use the filtered list */
478467
allowed_mechs = filtered_mechs;
479468
}
@@ -611,7 +600,7 @@ static bool mag_auth_basic(request_rec *req,
611600
gss_release_cred(&min, &user_cred);
612601
gss_delete_sec_context(&min, &user_ctx, GSS_C_NO_BUFFER);
613602
gss_release_oid_set(&min, &actual_mechs);
614-
gss_release_oid_set(&min, &indicated_mechs);
603+
gss_release_oid_set(&min, &filtered_mechs);
615604
#ifdef HAVE_GSS_KRB5_CCACHE_NAME
616605
if (user_ccache != NULL) {
617606
maj = gss_krb5_ccache_name(&min, orig_ccache, NULL);
@@ -653,7 +642,6 @@ static int mag_auth(request_rec *req)
653642
char *clientname;
654643
gss_OID mech_type = GSS_C_NO_OID;
655644
gss_OID_set desired_mechs = GSS_C_NO_OID_SET;
656-
gss_OID_set indicated_mechs = GSS_C_NO_OID_SET;
657645
gss_buffer_desc lname = GSS_C_EMPTY_BUFFER;
658646
struct mag_conn *mc = NULL;
659647
time_t expiration;
@@ -669,14 +657,11 @@ static int mag_auth(request_rec *req)
669657
if (cfg->allowed_mechs) {
670658
desired_mechs = cfg->allowed_mechs;
671659
} else {
660+
struct mag_server_config *scfg;
672661
/* Try to fetch the default set if not explicitly configured */
673-
maj = gss_indicate_mechs(&min, &indicated_mechs);
674-
if (maj != GSS_S_COMPLETE) {
675-
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, req, "%s",
676-
mag_error(req, "gss_indicate_mechs() failed",
677-
maj, min));
678-
}
679-
desired_mechs = indicated_mechs;
662+
scfg = ap_get_module_config(req->server->module_config,
663+
&auth_gssapi_module);
664+
desired_mechs = scfg->default_mechs;
680665
}
681666

682667
/* implicit auth for subrequests if main auth already happened */
@@ -970,7 +955,7 @@ static int mag_auth(request_rec *req)
970955
ap_auth_name(req)));
971956
}
972957
}
973-
gss_release_oid_set(&min, &indicated_mechs);
958+
974959
if (ctx != GSS_C_NO_CONTEXT)
975960
gss_delete_sec_context(&min, &ctx, GSS_C_NO_BUFFER);
976961
gss_release_cred(&min, &acquired_cred);
@@ -1246,6 +1231,26 @@ static const char *mag_basic_auth_mechs(cmd_parms *parms, void *mconfig,
12461231
}
12471232
#endif
12481233

1234+
static void *mag_create_server_config(apr_pool_t *p, server_rec *s)
1235+
{
1236+
struct mag_server_config *scfg;
1237+
uint32_t maj, min;
1238+
1239+
scfg = apr_pcalloc(p, sizeof(struct mag_server_config));
1240+
1241+
maj = gss_indicate_mechs(&min, &scfg->default_mechs);
1242+
if (maj != GSS_S_COMPLETE) {
1243+
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
1244+
"gss_indicate_mechs() failed");
1245+
} else {
1246+
/* Register the set in pool */
1247+
apr_pool_cleanup_register(p, (void *)scfg->default_mechs,
1248+
mag_oid_set_destroy, apr_pool_cleanup_null);
1249+
}
1250+
1251+
return scfg;
1252+
}
1253+
12491254
static const command_rec mag_commands[] = {
12501255
AP_INIT_FLAG("GssapiSSLonly", mag_ssl_only, NULL, OR_AUTHCFG,
12511256
"Work only if connection is SSL Secured"),
@@ -1291,7 +1296,7 @@ module AP_MODULE_DECLARE_DATA auth_gssapi_module =
12911296
STANDARD20_MODULE_STUFF,
12921297
mag_create_dir_config,
12931298
NULL,
1294-
NULL,
1299+
mag_create_server_config,
12951300
NULL,
12961301
mag_commands,
12971302
mag_register_hooks

src/mod_auth_gssapi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ struct mag_config {
6161
gss_OID_set_desc *basic_mechs;
6262
};
6363

64+
struct mag_server_config {
65+
gss_OID_set default_mechs;
66+
};
67+
6468
struct mag_conn {
6569
apr_pool_t *pool;
6670
gss_ctx_id_t ctx;

0 commit comments

Comments
 (0)