651382
From 0987e0e137854285d4022f5a910e7923d4e663fd Mon Sep 17 00:00:00 2001
651382
From: Simo Sorce <simo@redhat.com>
651382
Date: Thu, 27 Aug 2020 17:01:39 -0400
651382
Subject: [PATCH] Return static oids for naming functions
651382
651382
gss_display_name and gss_inquire_name reteurn "static" oids, that are
651382
generally not freed by callers, so make sure to match and return actual
651382
static OIDs exported by GSSAPI.
651382
651382
Also remove gpm_equal_oids() and use the library provided gss_oid_equal
651382
function instead.
651382
651382
Signed-off-by: Simo Sorce <simo@redhat.com>
651382
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
651382
(cherry picked from commit 6ea8391257e687dfb3981b634c06cf7a55008eb0)
651382
(cherry picked from commit 41cb9683627d6c3b136a4b48e1b1842619132f16)
651382
---
651382
 src/client/gpm_import_and_canon_name.c | 28 ++++++++++++++++++++++++--
651382
 src/client/gpm_indicate_mechs.c        | 24 +++++-----------------
651382
 src/client/gssapi_gpm.h                |  1 +
651382
 3 files changed, 32 insertions(+), 21 deletions(-)
651382
651382
diff --git a/src/client/gpm_import_and_canon_name.c b/src/client/gpm_import_and_canon_name.c
651382
index 70149a3..88b8d7c 100644
651382
--- a/src/client/gpm_import_and_canon_name.c
651382
+++ b/src/client/gpm_import_and_canon_name.c
651382
@@ -2,6 +2,26 @@
651382
 
651382
 #include "gssapi_gpm.h"
651382
 
651382
+static int gpm_name_oid_to_static(gss_OID name_type, gss_OID *name_static)
651382
+{
651382
+#define ret_static(b) \
651382
+    if (gss_oid_equal(name_type, b)) { \
651382
+        *name_static = b; \
651382
+        return 0; \
651382
+    }
651382
+    ret_static(GSS_C_NT_USER_NAME);
651382
+    ret_static(GSS_C_NT_MACHINE_UID_NAME);
651382
+    ret_static(GSS_C_NT_STRING_UID_NAME);
651382
+    ret_static(GSS_C_NT_HOSTBASED_SERVICE_X);
651382
+    ret_static(GSS_C_NT_HOSTBASED_SERVICE);
651382
+    ret_static(GSS_C_NT_ANONYMOUS);
651382
+    ret_static(GSS_C_NT_EXPORT_NAME);
651382
+    ret_static(GSS_C_NT_COMPOSITE_EXPORT);
651382
+    ret_static(GSS_KRB5_NT_PRINCIPAL_NAME);
651382
+    ret_static(gss_nt_krb5_name);
651382
+    return ENOENT;
651382
+}
651382
+
651382
 OM_uint32 gpm_display_name(OM_uint32 *minor_status,
651382
                            gssx_name *in_name,
651382
                            gss_buffer_t output_name_buffer,
651382
@@ -57,7 +77,9 @@ OM_uint32 gpm_display_name(OM_uint32 *minor_status,
651382
     }
651382
 
651382
     if (output_name_type) {
651382
-        ret = gp_conv_gssx_to_oid_alloc(&in_name->name_type, output_name_type);
651382
+        gss_OID_desc oid;
651382
+        gp_conv_gssx_to_oid(&in_name->name_type, &oid;;
651382
+        ret = gpm_name_oid_to_static(&oid, output_name_type);
651382
         if (ret) {
651382
             gss_release_buffer(&discard, output_name_buffer);
651382
             ret_min = ret;
651382
@@ -285,7 +307,9 @@ OM_uint32 gpm_inquire_name(OM_uint32 *minor_status,
651382
     }
651382
 
651382
     if (MN_mech != NULL) {
651382
-        ret = gp_conv_gssx_to_oid_alloc(&name->name_type, MN_mech);
651382
+        gss_OID_desc oid;
651382
+        gp_conv_gssx_to_oid(&name->name_type, &oid;;
651382
+        ret = gpm_name_oid_to_static(&oid, MN_mech);
651382
         if (ret) {
651382
             *minor_status = ret;
651382
             return GSS_S_FAILURE;
651382
diff --git a/src/client/gpm_indicate_mechs.c b/src/client/gpm_indicate_mechs.c
651382
index 86c7de3..4041dcd 100644
651382
--- a/src/client/gpm_indicate_mechs.c
651382
+++ b/src/client/gpm_indicate_mechs.c
651382
@@ -95,20 +95,6 @@ static uint32_t gpm_copy_gss_buffer(uint32_t *minor_status,
651382
     return GSS_S_COMPLETE;
651382
 }
651382
 
651382
-static bool gpm_equal_oids(gss_const_OID a, gss_const_OID b)
651382
-{
651382
-    int ret;
651382
-
651382
-    if (a->length == b->length) {
651382
-        ret = memcmp(a->elements, b->elements, a->length);
651382
-        if (ret == 0) {
651382
-            return true;
651382
-        }
651382
-    }
651382
-
651382
-    return false;
651382
-}
651382
-
651382
 static void gpmint_indicate_mechs(void)
651382
 {
651382
     union gp_rpc_arg uarg;
651382
@@ -313,7 +299,7 @@ int gpm_mech_to_static(gss_OID mech_type, gss_OID *mech_static)
651382
 
651382
     *mech_static = GSS_C_NO_OID;
651382
     for (size_t i = 0; i < global_mechs.mech_set->count; i++) {
651382
-        if (gpm_equal_oids(&global_mechs.mech_set->elements[i], mech_type)) {
651382
+        if (gss_oid_equal(&global_mechs.mech_set->elements[i], mech_type)) {
651382
             *mech_static = &global_mechs.mech_set->elements[i];
651382
             return 0;
651382
         }
651382
@@ -383,7 +369,7 @@ OM_uint32 gpm_inquire_names_for_mech(OM_uint32 *minor_status,
651382
     }
651382
 
651382
     for (unsigned i = 0; i < global_mechs.info_len; i++) {
651382
-        if (!gpm_equal_oids(global_mechs.info[i].mech, mech_type)) {
651382
+        if (!gss_oid_equal(global_mechs.info[i].mech, mech_type)) {
651382
             continue;
651382
         }
651382
         ret_maj = gpm_copy_gss_OID_set(&ret_min,
651382
@@ -481,7 +467,7 @@ OM_uint32 gpm_inquire_attrs_for_mech(OM_uint32 *minor_status,
651382
     }
651382
 
651382
     for (unsigned i = 0; i < global_mechs.info_len; i++) {
651382
-        if (!gpm_equal_oids(global_mechs.info[i].mech, mech)) {
651382
+        if (!gss_oid_equal(global_mechs.info[i].mech, mech)) {
651382
             continue;
651382
         }
651382
 
651382
@@ -540,7 +526,7 @@ OM_uint32 gpm_inquire_saslname_for_mech(OM_uint32 *minor_status,
651382
     }
651382
 
651382
     for (unsigned i = 0; i < global_mechs.info_len; i++) {
651382
-        if (!gpm_equal_oids(global_mechs.info[i].mech, desired_mech)) {
651382
+        if (!gss_oid_equal(global_mechs.info[i].mech, desired_mech)) {
651382
             continue;
651382
         }
651382
         ret_maj = gpm_copy_gss_buffer(&ret_min,
651382
@@ -598,7 +584,7 @@ OM_uint32 gpm_display_mech_attr(OM_uint32 *minor_status,
651382
     }
651382
 
651382
     for (unsigned i = 0; i < global_mechs.desc_len; i++) {
651382
-        if (!gpm_equal_oids(global_mechs.desc[i].attr, mech_attr)) {
651382
+        if (!gss_oid_equal(global_mechs.desc[i].attr, mech_attr)) {
651382
             continue;
651382
         }
651382
         ret_maj = gpm_copy_gss_buffer(&ret_min,
651382
diff --git a/src/client/gssapi_gpm.h b/src/client/gssapi_gpm.h
651382
index b7ba04b..bdf12e1 100644
651382
--- a/src/client/gssapi_gpm.h
651382
+++ b/src/client/gssapi_gpm.h
651382
@@ -10,6 +10,7 @@
651382
 #include <string.h>
651382
 #include <gssapi/gssapi.h>
651382
 #include <gssapi/gssapi_ext.h>
651382
+#include <gssapi/gssapi_krb5.h>
651382
 #include "rpcgen/gp_rpc.h"
651382
 #include "rpcgen/gss_proxy.h"
651382
 #include "src/gp_common.h"