Blame SOURCES/Fix-mag_auth_basic-function-call.patch

8f2224
From 1941fd1545b4786fee9464881239d74a91c55723 Mon Sep 17 00:00:00 2001
8f2224
From: Simo Sorce <simo@redhat.com>
8f2224
Date: Thu, 7 Feb 2019 14:48:56 -0500
8f2224
Subject: [PATCH] Fix mag_auth_basic function call.
8f2224
8f2224
In order to respect the API we'd have to return nech_type as a copy of
8f2224
the mech found to correctly complete authentication.
8f2224
It would need to be a copy because the actual_mechs variable is an array
8f2224
of statically copied OIDs not an array of pointers.
8f2224
8f2224
Instead change mag_auth_basic to directly call mag_complete() and
8f2224
mag_cache_basic on success. This is easier than attempting to handle
8f2224
copying out OIDs and then freeing them in the caller as GSSAPI does not
8f2224
offer standard APIs for copying OIDs.
8f2224
8f2224
As a side-effect we reduce the number of arguments to mag_auth_gssapi,
8f2224
which is good, to the slight detriment of legibility in the main
8f2224
function as now you need to know mag_auth_basic() is already calling
8f2224
mag_complete(). The trade off is worth it though.
8f2224
8f2224
Signed-off-by: Simo Sorce <simo@redhat.com>
8f2224
(cherry picked from commit 318db0b0e3777d4cfdc09eeef98e28c478607271)
8f2224
---
8f2224
 src/mod_auth_gssapi.c | 47 ++++++++++++++++++++-----------------------
8f2224
 1 file changed, 22 insertions(+), 25 deletions(-)
8f2224
8f2224
diff --git a/src/mod_auth_gssapi.c b/src/mod_auth_gssapi.c
8f2224
index 4048ee7..9e42ef4 100644
8f2224
--- a/src/mod_auth_gssapi.c
8f2224
+++ b/src/mod_auth_gssapi.c
8f2224
@@ -493,15 +493,15 @@ done:
8f2224
     return maj;
8f2224
 }
8f2224
 
8f2224
-static bool mag_auth_basic(request_rec *req,
8f2224
-                           struct mag_config *cfg,
8f2224
-                           gss_buffer_desc ba_user,
8f2224
-                           gss_buffer_desc ba_pwd,
8f2224
-                           gss_name_t *client,
8f2224
-                           gss_OID *mech_type,
8f2224
-                           gss_cred_id_t *delegated_cred,
8f2224
-                           uint32_t *vtime)
8f2224
+static int mag_complete(struct mag_req_cfg *req_cfg, struct mag_conn *mc,
8f2224
+                        gss_name_t client, gss_OID mech_type,
8f2224
+                        uint32_t vtime, gss_cred_id_t delegated_cred);
8f2224
+
8f2224
+static int mag_auth_basic(struct mag_req_cfg *req_cfg, struct mag_conn *mc,
8f2224
+                          gss_buffer_desc ba_user, gss_buffer_desc ba_pwd)
8f2224
 {
8f2224
+    struct mag_config *cfg = req_cfg->cfg;
8f2224
+    request_rec *req = req_cfg->req;
8f2224
     const char *user_ccache = NULL;
8f2224
     const char *orig_ccache = NULL;
8f2224
     long long unsigned int rndname;
8f2224
@@ -512,9 +512,12 @@ static bool mag_auth_basic(request_rec *req,
8f2224
     gss_OID_set allowed_mechs;
8f2224
     gss_OID_set filtered_mechs;
8f2224
     gss_OID_set actual_mechs = GSS_C_NO_OID_SET;
8f2224
+    gss_cred_id_t delegated_cred = GSS_C_NO_CREDENTIAL;
8f2224
+    gss_name_t client = GSS_C_NO_NAME;
8f2224
+    uint32_t vtime;
8f2224
     uint32_t maj, min;
8f2224
     int present = 0;
8f2224
-    bool ret = false;
8f2224
+    int ret = HTTP_UNAUTHORIZED;
8f2224
 
8f2224
     maj = gss_import_name(&min, &ba_user, GSS_C_NT_USER_NAME, &user);
8f2224
     if (GSS_ERROR(maj)) {
8f2224
@@ -616,15 +619,21 @@ static bool mag_auth_basic(request_rec *req,
8f2224
 
8f2224
     for (int i = 0; i < actual_mechs->count; i++) {
8f2224
         maj = mag_context_loop(&min, req, cfg, user_cred, server_cred,
8f2224
-                               &actual_mechs->elements[i], 300, client, vtime,
8f2224
-                               delegated_cred);
8f2224
+                               &actual_mechs->elements[i], 300, &client,
8f2224
+                               &vtime, &delegated_cred);
8f2224
         if (maj == GSS_S_COMPLETE) {
8f2224
-            ret = true;
8f2224
+            ret = mag_complete(req_cfg, mc, client, &actual_mechs->elements[i],
8f2224
+                               vtime, delegated_cred);
8f2224
+            if (ret == OK) {
8f2224
+                mag_basic_cache(req_cfg, mc, ba_user, ba_pwd);
8f2224
+            }
8f2224
             break;
8f2224
         }
8f2224
     }
8f2224
 
8f2224
 done:
8f2224
+    gss_release_cred(&min, &delegated_cred);
8f2224
+    gss_release_name(&min, &client);
8f2224
     gss_release_cred(&min, &server_cred);
8f2224
     gss_release_name(&min, &user);
8f2224
     gss_release_cred(&min, &user_cred);
8f2224
@@ -683,10 +692,6 @@ struct mag_req_cfg *mag_init_cfg(request_rec *req)
8f2224
     return req_cfg;
8f2224
 }
8f2224
 
8f2224
-static int mag_complete(struct mag_req_cfg *req_cfg, struct mag_conn *mc,
8f2224
-                        gss_name_t client, gss_OID mech_type,
8f2224
-                        uint32_t vtime, gss_cred_id_t delegated_cred);
8f2224
-
8f2224
 #ifdef HAVE_CRED_STORE
8f2224
 static bool use_s4u2proxy(struct mag_req_cfg *req_cfg) {
8f2224
     if (req_cfg->cfg->use_s4u2proxy) {
8f2224
@@ -1105,15 +1110,7 @@ static int mag_auth(request_rec *req)
8f2224
 #endif
8f2224
 
8f2224
     if (auth_type == AUTH_TYPE_BASIC) {
8f2224
-        if (mag_auth_basic(req, cfg, ba_user, ba_pwd,
8f2224
-                           &client, &mech_type,
8f2224
-                           &delegated_cred, &vtime)) {
8f2224
-
8f2224
-            ret = mag_complete(req_cfg, mc, client, mech_type, vtime,
8f2224
-                               delegated_cred);
8f2224
-            if (ret == OK)
8f2224
-                mag_basic_cache(req_cfg, mc, ba_user, ba_pwd);
8f2224
-        }
8f2224
+        ret = mag_auth_basic(req_cfg, mc, ba_user, ba_pwd);
8f2224
         goto done;
8f2224
     }
8f2224