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

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