Blame SOURCES/Fix-kadmin-k-with-fallback-or-referral-realm.patch

cb4cef
From ddbd548562d951d327a10c9dcb975418427f6fea Mon Sep 17 00:00:00 2001
cb4cef
From: Greg Hudson <ghudson@mit.edu>
cb4cef
Date: Mon, 7 Jun 2021 15:00:41 -0400
cb4cef
Subject: [PATCH] Fix kadmin -k with fallback or referral realm
cb4cef
cb4cef
kadmin -k produces a client principal name with
cb4cef
krb5_sname_to_principal(), but it gets converted to a string and back
cb4cef
due to the signature of kadm5_init_with_skey(), which loses track of
cb4cef
the name type, so no canonicalization is performed.
cb4cef
cb4cef
In libkadm5clnt initialization, recognize the important subset of this
cb4cef
case--an empty realm indicates either fallback processing or the
cb4cef
referral realm--and restore the host-based name type so that the
cb4cef
client principal can be canonicalized against the keytab.
cb4cef
cb4cef
ticket: 9013 (new)
cb4cef
(cherry picked from commit dcb79089276624d7ddf44e08d35bd6d7d7e557d2)
cb4cef
(cherry picked from commit cd8ff035f5b4720a8fc457355726f7bd0eab5eaa)
cb4cef
---
cb4cef
 src/lib/kadm5/clnt/client_init.c |  7 +++++++
cb4cef
 src/tests/t_kadmin.py            | 12 ++++++++++++
cb4cef
 2 files changed, 19 insertions(+)
cb4cef
cb4cef
diff --git a/src/lib/kadm5/clnt/client_init.c b/src/lib/kadm5/clnt/client_init.c
cb4cef
index aa1223bb3..0aaca701f 100644
cb4cef
--- a/src/lib/kadm5/clnt/client_init.c
cb4cef
+++ b/src/lib/kadm5/clnt/client_init.c
cb4cef
@@ -221,9 +221,16 @@ init_any(krb5_context context, char *client_name, enum init_type init_type,
cb4cef
         return KADM5_MISSING_KRB5_CONF_PARAMS;
cb4cef
     }
cb4cef
 
cb4cef
+    /*
cb4cef
+     * Parse the client name.  If it has an empty realm, it is almost certainly
cb4cef
+     * a host-based principal using DNS fallback processing or the referral
cb4cef
+     * realm, so give it the appropriate name type for canonicalization.
cb4cef
+     */
cb4cef
     code = krb5_parse_name(handle->context, client_name, &client);
cb4cef
     if (code)
cb4cef
         goto error;
cb4cef
+    if (init_type == INIT_SKEY && client->realm.length == 0)
cb4cef
+        client->type = KRB5_NT_SRV_HST;
cb4cef
 
cb4cef
     /*
cb4cef
      * Get credentials.  Also does some fallbacks in case kadmin/fqdn
cb4cef
diff --git a/src/tests/t_kadmin.py b/src/tests/t_kadmin.py
cb4cef
index fe6a3cc2e..98453d92e 100644
cb4cef
--- a/src/tests/t_kadmin.py
cb4cef
+++ b/src/tests/t_kadmin.py
cb4cef
@@ -51,4 +51,16 @@ for i in range(200):
cb4cef
     realm.run_kadmin(['addprinc', '-randkey', 'foo%d' % i])
cb4cef
 realm.run_kadmin(['listprincs'], expected_msg='foo199')
cb4cef
 
cb4cef
+# Test kadmin -k with the default principal, with and without
cb4cef
+# fallback.  This operation requires canonicalization against the
cb4cef
+# keytab in krb5_get_init_creds_keytab() as the
cb4cef
+# krb5_sname_to_principal() result won't have a realm.  Try with and
cb4cef
+# without without fallback processing since the code paths are
cb4cef
+# different.
cb4cef
+mark('kadmin -k')
cb4cef
+realm.run([kadmin, '-k', 'getprinc', realm.host_princ])
cb4cef
+no_canon_conf = {'libdefaults': {'dns_canonicalize_hostname': 'false'}}
cb4cef
+no_canon = realm.special_env('no_canon', False, krb5_conf=no_canon_conf)
cb4cef
+realm.run([kadmin, '-k', 'getprinc', realm.host_princ], env=no_canon)
cb4cef
+
cb4cef
 success('kadmin and kpasswd tests')