Blame SOURCES/Fix-KCM-retrieval-support-for-sssd.patch

27013b
From 0bfe0b2bc0a8ee0e9a8cee26528030c16d4fd15f Mon Sep 17 00:00:00 2001
27013b
From: Greg Hudson <ghudson@mit.edu>
27013b
Date: Tue, 11 May 2021 14:04:07 -0400
27013b
Subject: [PATCH] Fix KCM retrieval support for sssd
27013b
27013b
Commit 795ebba8c039be172ab93cd41105c73ffdba0fdb added a retrieval
27013b
handler using KCM_OP_RETRIEVE, falling back on the same error codes as
27013b
the previous KCM_OP_GET_CRED_LIST support.  But sssd (as of 2.4)
27013b
returns KRB5_CC_NOSUPP instead of KRB5_CC_IO if it recognizes an
27013b
opcode but does not implement it.  Add a helper function to recognize
27013b
all known unsupported-opcode error codes, and use it in kcm_retrieve()
27013b
and kcm_start_seq_get().
27013b
27013b
ticket: 8997
27013b
(cherry picked from commit da103e36e13f3c846bcddbe38dd518a21e5260a0)
27013b
(cherry picked from commit a5b2cff51808cd86fe8195e7ac074ecd25c3344d)
27013b
(cherry picked from commit 6a00fd149edd017ece894566771e2e9d4ba089f4)
27013b
---
27013b
 src/lib/krb5/ccache/cc_kcm.c | 18 ++++++++++++++++--
27013b
 1 file changed, 16 insertions(+), 2 deletions(-)
27013b
27013b
diff --git a/src/lib/krb5/ccache/cc_kcm.c b/src/lib/krb5/ccache/cc_kcm.c
27013b
index b600c6f15..6a36cfdce 100644
27013b
--- a/src/lib/krb5/ccache/cc_kcm.c
27013b
+++ b/src/lib/krb5/ccache/cc_kcm.c
27013b
@@ -144,6 +144,20 @@ map_tcflags(krb5_flags mitflags)
27013b
     return heimflags;
27013b
 }
27013b
 
27013b
+/*
27013b
+ * Return true if code could indicate an unsupported operation.  Heimdal's KCM
27013b
+ * returns KRB5_FCC_INTERNAL.  sssd's KCM daemon (as of sssd 2.4) returns
27013b
+ * KRB5_CC_NO_SUPP if it recognizes the operation but does not implement it,
27013b
+ * and KRB5_CC_IO if it doesn't recognize the operation (which is unfortunate
27013b
+ * since it could also indicate a communication failure).
27013b
+ */
27013b
+static krb5_boolean
27013b
+unsupported_op_error(krb5_error_code code)
27013b
+{
27013b
+    return code == KRB5_FCC_INTERNAL || code == KRB5_CC_IO ||
27013b
+        code == KRB5_CC_NOSUPP;
27013b
+}
27013b
+
27013b
 /* Begin a request for the given opcode.  If cache is non-null, supply the
27013b
  * cache name as a request parameter. */
27013b
 static void
27013b
@@ -841,7 +855,7 @@ kcm_retrieve(krb5_context context, krb5_ccache cache, krb5_flags flags,
27013b
     ret = cache_call(context, cache, &req;;
27013b
 
27013b
     /* Fall back to iteration if the server does not support retrieval. */
27013b
-    if (ret == KRB5_FCC_INTERNAL || ret == KRB5_CC_IO) {
27013b
+    if (unsupported_op_error(ret)) {
27013b
         ret = k5_cc_retrieve_cred_default(context, cache, flags, mcred,
27013b
                                           cred_out);
27013b
         goto cleanup;
27013b
@@ -922,7 +936,7 @@ kcm_start_seq_get(krb5_context context, krb5_ccache cache,
27013b
         ret = kcmreq_get_cred_list(&req, &creds);
27013b
         if (ret)
27013b
             goto cleanup;
27013b
-    } else if (ret == KRB5_FCC_INTERNAL || ret == KRB5_CC_IO) {
27013b
+    } else if (unsupported_op_error(ret)) {
27013b
         /* Fall back to GET_CRED_UUID_LIST. */
27013b
         kcmreq_free(&req;;
27013b
         kcmreq_init(&req, KCM_OP_GET_CRED_UUID_LIST, cache);