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

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