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

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