Skip to content

Commit 318db0b

Browse files
simo5frozencemetery
authored andcommitted
Fix mag_auth_basic function call.
In order to respect the API we'd have to return nech_type as a copy of the mech found to correctly complete authentication. It would need to be a copy because the actual_mechs variable is an array of statically copied OIDs not an array of pointers. Instead change mag_auth_basic to directly call mag_complete() and mag_cache_basic on success. This is easier than attempting to handle copying out OIDs and then freeing them in the caller as GSSAPI does not offer standard APIs for copying OIDs. As a side-effect we reduce the number of arguments to mag_auth_gssapi, which is good, to the slight detriment of legibility in the main function as now you need to know mag_auth_basic() is already calling mag_complete(). The trade off is worth it though. Signed-off-by: Simo Sorce <simo@redhat.com>
1 parent d535dd4 commit 318db0b

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

src/mod_auth_gssapi.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,15 @@ static uint32_t mag_context_loop(uint32_t *min,
498498
return maj;
499499
}
500500

501-
static bool mag_auth_basic(request_rec *req,
502-
struct mag_config *cfg,
503-
gss_buffer_desc ba_user,
504-
gss_buffer_desc ba_pwd,
505-
gss_name_t *client,
506-
gss_OID *mech_type,
507-
gss_cred_id_t *delegated_cred,
508-
uint32_t *vtime)
501+
static int mag_complete(struct mag_req_cfg *req_cfg, struct mag_conn *mc,
502+
gss_name_t client, gss_OID mech_type,
503+
uint32_t vtime, gss_cred_id_t delegated_cred);
504+
505+
static int mag_auth_basic(struct mag_req_cfg *req_cfg, struct mag_conn *mc,
506+
gss_buffer_desc ba_user, gss_buffer_desc ba_pwd)
509507
{
508+
struct mag_config *cfg = req_cfg->cfg;
509+
request_rec *req = req_cfg->req;
510510
const char *user_ccache = NULL;
511511
const char *orig_ccache = NULL;
512512
long long unsigned int rndname;
@@ -517,9 +517,12 @@ static bool mag_auth_basic(request_rec *req,
517517
gss_OID_set allowed_mechs;
518518
gss_OID_set filtered_mechs;
519519
gss_OID_set actual_mechs = GSS_C_NO_OID_SET;
520+
gss_cred_id_t delegated_cred = GSS_C_NO_CREDENTIAL;
521+
gss_name_t client = GSS_C_NO_NAME;
522+
uint32_t vtime;
520523
uint32_t maj, min;
521524
int present = 0;
522-
bool ret = false;
525+
int ret = HTTP_UNAUTHORIZED;
523526

524527
maj = gss_import_name(&min, &ba_user, GSS_C_NT_USER_NAME, &user);
525528
if (GSS_ERROR(maj)) {
@@ -621,15 +624,21 @@ static bool mag_auth_basic(request_rec *req,
621624

622625
for (int i = 0; i < actual_mechs->count; i++) {
623626
maj = mag_context_loop(&min, req, cfg, user_cred, server_cred,
624-
&actual_mechs->elements[i], 300, client, vtime,
625-
delegated_cred);
627+
&actual_mechs->elements[i], 300, &client,
628+
&vtime, &delegated_cred);
626629
if (maj == GSS_S_COMPLETE) {
627-
ret = true;
630+
ret = mag_complete(req_cfg, mc, client, &actual_mechs->elements[i],
631+
vtime, delegated_cred);
632+
if (ret == OK) {
633+
mag_basic_cache(req_cfg, mc, ba_user, ba_pwd);
634+
}
628635
break;
629636
}
630637
}
631638

632639
done:
640+
gss_release_cred(&min, &delegated_cred);
641+
gss_release_name(&min, &client);
633642
gss_release_cred(&min, &server_cred);
634643
gss_release_name(&min, &user);
635644
gss_release_cred(&min, &user_cred);
@@ -688,10 +697,6 @@ struct mag_req_cfg *mag_init_cfg(request_rec *req)
688697
return req_cfg;
689698
}
690699

691-
static int mag_complete(struct mag_req_cfg *req_cfg, struct mag_conn *mc,
692-
gss_name_t client, gss_OID mech_type,
693-
uint32_t vtime, gss_cred_id_t delegated_cred);
694-
695700
#ifdef HAVE_CRED_STORE
696701
static bool use_s4u2proxy(struct mag_req_cfg *req_cfg) {
697702
if (req_cfg->cfg->use_s4u2proxy) {
@@ -1110,15 +1115,7 @@ static int mag_auth(request_rec *req)
11101115
#endif
11111116

11121117
if (auth_type == AUTH_TYPE_BASIC) {
1113-
if (mag_auth_basic(req, cfg, ba_user, ba_pwd,
1114-
&client, &mech_type,
1115-
&delegated_cred, &vtime)) {
1116-
1117-
ret = mag_complete(req_cfg, mc, client, mech_type, vtime,
1118-
delegated_cred);
1119-
if (ret == OK)
1120-
mag_basic_cache(req_cfg, mc, ba_user, ba_pwd);
1121-
}
1118+
ret = mag_auth_basic(req_cfg, mc, ba_user, ba_pwd);
11221119
goto done;
11231120
}
11241121

0 commit comments

Comments
 (0)