Blame SOURCES/Fix-KCM-flag-transmission-for-remove_cred.patch

27013b
From 261b0ed68fb83c34c70679ae8452cae2dba7e4e3 Mon Sep 17 00:00:00 2001
27013b
From: Greg Hudson <ghudson@mit.edu>
27013b
Date: Mon, 29 Mar 2021 14:32:56 -0400
27013b
Subject: [PATCH] Fix KCM flag transmission for remove_cred
27013b
27013b
MIT krb5 uses low bits for KRB5_TC flags, while Heimdal uses high bits
27013b
so that the same flag word can also hold KRB5_GC flags.  Add a mapping
27013b
function and send the Heimdal flag values when performing a
27013b
remove_cred operation.
27013b
27013b
ticket: 8995
27013b
(cherry picked from commit 11a82cf424f9c905bb73680c64524f087090d4ef)
27013b
(cherry picked from commit 04f0de4420508161ce439f262f2761ff51a07ab0)
27013b
(cherry picked from commit ddbb295dee2adcc6cec26944974420bba188f191)
27013b
---
27013b
 src/include/kcm.h            | 19 +++++++++++++++++++
27013b
 src/lib/krb5/ccache/cc_kcm.c | 36 +++++++++++++++++++++++++++++++++++-
27013b
 2 files changed, 54 insertions(+), 1 deletion(-)
27013b
27013b
diff --git a/src/include/kcm.h b/src/include/kcm.h
27013b
index e4140c3a0..9b66f1cbd 100644
27013b
--- a/src/include/kcm.h
27013b
+++ b/src/include/kcm.h
27013b
@@ -56,8 +56,27 @@
27013b
  * are marshalled as zero-terminated strings.  Principals and credentials are
27013b
  * marshalled in the v4 FILE ccache format.  UUIDs are 16 bytes.  UUID lists
27013b
  * are not delimited, so nothing can come after them.
27013b
+ *
27013b
+ * Flag words must use Heimdal flag values, which are not the same as MIT krb5
27013b
+ * values for KRB5_GC and KRB5_TC constants.  The same flag word may contain
27013b
+ * both kinds of flags in Heimdal, but not in MIT krb5.  Defines for the
27013b
+ * applicable Heimdal flag values are given below using KCM_GC and KCM_TC
27013b
+ * prefixes.
27013b
  */
27013b
 
27013b
+#define KCM_GC_CACHED                   (1U << 0)
27013b
+
27013b
+#define KCM_TC_DONT_MATCH_REALM         (1U << 31)
27013b
+#define KCM_TC_MATCH_KEYTYPE            (1U << 30)
27013b
+#define KCM_TC_MATCH_SRV_NAMEONLY       (1U << 29)
27013b
+#define KCM_TC_MATCH_FLAGS_EXACT        (1U << 28)
27013b
+#define KCM_TC_MATCH_FLAGS              (1U << 27)
27013b
+#define KCM_TC_MATCH_TIMES_EXACT        (1U << 26)
27013b
+#define KCM_TC_MATCH_TIMES              (1U << 25)
27013b
+#define KCM_TC_MATCH_AUTHDATA           (1U << 24)
27013b
+#define KCM_TC_MATCH_2ND_TKT            (1U << 23)
27013b
+#define KCM_TC_MATCH_IS_SKEY            (1U << 22)
27013b
+
27013b
 /* Opcodes without comments are currently unused in the MIT client
27013b
  * implementation. */
27013b
 typedef enum kcm_opcode {
27013b
diff --git a/src/lib/krb5/ccache/cc_kcm.c b/src/lib/krb5/ccache/cc_kcm.c
27013b
index 197a10fba..4141140c3 100644
27013b
--- a/src/lib/krb5/ccache/cc_kcm.c
27013b
+++ b/src/lib/krb5/ccache/cc_kcm.c
27013b
@@ -110,6 +110,40 @@ map_invalid(krb5_error_code code)
27013b
         KRB5_KCM_MALFORMED_REPLY : code;
27013b
 }
27013b
 
27013b
+/*
27013b
+ * Map an MIT krb5 KRB5_TC flag word to the equivalent Heimdal flag word.  Note
27013b
+ * that there is no MIT krb5 equivalent for Heimdal's KRB5_TC_DONT_MATCH_REALM
27013b
+ * (which is like KRB5_TC_MATCH_SRV_NAMEONLY but also applies to the client
27013b
+ * principal) and no Heimdal equivalent for MIT krb5's KRB5_TC_SUPPORTED_KTYPES
27013b
+ * (which matches against enctypes from the krb5_context rather than the
27013b
+ * matching cred).
27013b
+ */
27013b
+static inline krb5_flags
27013b
+map_tcflags(krb5_flags mitflags)
27013b
+{
27013b
+    krb5_flags heimflags = 0;
27013b
+
27013b
+    if (mitflags & KRB5_TC_MATCH_TIMES)
27013b
+        heimflags |= KCM_TC_MATCH_TIMES;
27013b
+    if (mitflags & KRB5_TC_MATCH_IS_SKEY)
27013b
+        heimflags |= KCM_TC_MATCH_IS_SKEY;
27013b
+    if (mitflags & KRB5_TC_MATCH_FLAGS)
27013b
+        heimflags |= KCM_TC_MATCH_FLAGS;
27013b
+    if (mitflags & KRB5_TC_MATCH_TIMES_EXACT)
27013b
+        heimflags |= KCM_TC_MATCH_TIMES_EXACT;
27013b
+    if (mitflags & KRB5_TC_MATCH_FLAGS_EXACT)
27013b
+        heimflags |= KCM_TC_MATCH_FLAGS_EXACT;
27013b
+    if (mitflags & KRB5_TC_MATCH_AUTHDATA)
27013b
+        heimflags |= KCM_TC_MATCH_AUTHDATA;
27013b
+    if (mitflags & KRB5_TC_MATCH_SRV_NAMEONLY)
27013b
+        heimflags |= KCM_TC_MATCH_SRV_NAMEONLY;
27013b
+    if (mitflags & KRB5_TC_MATCH_2ND_TKT)
27013b
+        heimflags |= KCM_TC_MATCH_2ND_TKT;
27013b
+    if (mitflags & KRB5_TC_MATCH_KTYPE)
27013b
+        heimflags |= KCM_TC_MATCH_KEYTYPE;
27013b
+    return heimflags;
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
@@ -936,7 +970,7 @@ kcm_remove_cred(krb5_context context, krb5_ccache cache, krb5_flags flags,
27013b
     struct kcmreq req;
27013b
 
27013b
     kcmreq_init(&req, KCM_OP_REMOVE_CRED, cache);
27013b
-    k5_buf_add_uint32_be(&req.reqbuf, flags);
27013b
+    k5_buf_add_uint32_be(&req.reqbuf, map_tcflags(flags));
27013b
     k5_marshal_mcred(&req.reqbuf, mcred);
27013b
     ret = cache_call(context, cache, &req;;
27013b
     kcmreq_free(&req;;