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