|
|
a53771 |
From 8f70ad82a645ccb7fb1677d260baa5e4112890d4 Mon Sep 17 00:00:00 2001
|
|
|
a53771 |
From: Greg Hudson <ghudson@mit.edu>
|
|
|
a53771 |
Date: Mon, 7 Jun 2021 13:27:29 -0400
|
|
|
a53771 |
Subject: [PATCH] Fix some principal realm canonicalization cases
|
|
|
a53771 |
|
|
|
a53771 |
The no_hostrealm and subst_defrealm flags in struct canonprinc were
|
|
|
a53771 |
only applied when dns_canonicalize_hostname=fallback; in the other
|
|
|
a53771 |
cases, the initial krb5_sname_to_principal() result is treated as
|
|
|
a53771 |
canonical. For no_hostrealm this limitation doesn't currently matter,
|
|
|
a53771 |
because all uses pass a principal with no realm as input. However,
|
|
|
a53771 |
subst_defrealm is used to convert the referral realm to the default
|
|
|
a53771 |
realm in krb5_get_init_creds_keytab(), krb5_cc_cache_match(), and
|
|
|
a53771 |
gss_acquire_cred() when it needs to check the desired name against a
|
|
|
a53771 |
specified ccache.
|
|
|
a53771 |
|
|
|
a53771 |
In k5_canonprinc(), if the input principal is a
|
|
|
a53771 |
krb5_sname_to_principal() result and fallback isn't in effect, apply
|
|
|
a53771 |
subst_defrealm. Document in os-proto.h that no_hostrealm doesn't
|
|
|
a53771 |
remove an existing realm and that krb5_sname_to_principal() may
|
|
|
a53771 |
already have looked one up.
|
|
|
a53771 |
|
|
|
a53771 |
ticket: 9011 (new)
|
|
|
a53771 |
(cherry picked from commit c077d0c6430c4ac163443aacc03d14d206a4cbb8)
|
|
|
a53771 |
(cherry picked from commit 5ae9bc98f23aeaa2ce17debe5a9b0cf1130e54ed)
|
|
|
a53771 |
---
|
|
|
a53771 |
src/lib/krb5/os/os-proto.h | 13 +++++++++----
|
|
|
a53771 |
src/lib/krb5/os/sn2princ.c | 24 +++++++++++++++++++++---
|
|
|
a53771 |
2 files changed, 30 insertions(+), 7 deletions(-)
|
|
|
a53771 |
|
|
|
a53771 |
diff --git a/src/lib/krb5/os/os-proto.h b/src/lib/krb5/os/os-proto.h
|
|
|
a53771 |
index 7d5e7978f..a985f2aec 100644
|
|
|
a53771 |
--- a/src/lib/krb5/os/os-proto.h
|
|
|
a53771 |
+++ b/src/lib/krb5/os/os-proto.h
|
|
|
a53771 |
@@ -85,10 +85,15 @@ struct sendto_callback_info {
|
|
|
a53771 |
|
|
|
a53771 |
/*
|
|
|
a53771 |
* Initialize with all zeros except for princ. Set no_hostrealm to disable
|
|
|
a53771 |
- * host-to-realm lookup, which ordinarily happens after canonicalizing the host
|
|
|
a53771 |
- * part. Set subst_defrealm to substitute the default realm for the referral
|
|
|
a53771 |
- * realm after realm lookup (this has no effect if no_hostrealm is set). Free
|
|
|
a53771 |
- * with free_canonprinc() when done.
|
|
|
a53771 |
+ * host-to-realm lookup, which ordinarily happens during fallback processing
|
|
|
a53771 |
+ * after canonicalizing the host part. Set subst_defrealm to substitute the
|
|
|
a53771 |
+ * default realm for the referral realm after realm lookup. Do not set both
|
|
|
a53771 |
+ * flags. Free with free_canonprinc() when done.
|
|
|
a53771 |
+ *
|
|
|
a53771 |
+ * no_hostrealm only applies if fallback processing is in use
|
|
|
a53771 |
+ * (dns_canonicalize_hostname = fallback). It will not remove the realm if
|
|
|
a53771 |
+ * krb5_sname_to_principal() already canonicalized the hostname and looked up a
|
|
|
a53771 |
+ * realm. subst_defrealm applies whether or not fallback processing is in use.
|
|
|
a53771 |
*/
|
|
|
a53771 |
struct canonprinc {
|
|
|
a53771 |
krb5_const_principal princ;
|
|
|
a53771 |
diff --git a/src/lib/krb5/os/sn2princ.c b/src/lib/krb5/os/sn2princ.c
|
|
|
a53771 |
index c99b7da17..93c155932 100644
|
|
|
a53771 |
--- a/src/lib/krb5/os/sn2princ.c
|
|
|
a53771 |
+++ b/src/lib/krb5/os/sn2princ.c
|
|
|
a53771 |
@@ -271,18 +271,36 @@ krb5_error_code
|
|
|
a53771 |
k5_canonprinc(krb5_context context, struct canonprinc *iter,
|
|
|
a53771 |
krb5_const_principal *princ_out)
|
|
|
a53771 |
{
|
|
|
a53771 |
+ krb5_error_code ret;
|
|
|
a53771 |
int step = ++iter->step;
|
|
|
a53771 |
|
|
|
a53771 |
*princ_out = NULL;
|
|
|
a53771 |
|
|
|
a53771 |
- /* If we're not doing fallback, the input principal is canonical. */
|
|
|
a53771 |
- if (context->dns_canonicalize_hostname != CANONHOST_FALLBACK ||
|
|
|
a53771 |
- iter->princ->type != KRB5_NT_SRV_HST || iter->princ->length != 2 ||
|
|
|
a53771 |
+ /* If the hostname isn't from krb5_sname_to_principal(), the input
|
|
|
a53771 |
+ * principal is canonical. */
|
|
|
a53771 |
+ if (iter->princ->type != KRB5_NT_SRV_HST || iter->princ->length != 2 ||
|
|
|
a53771 |
iter->princ->data[1].length == 0) {
|
|
|
a53771 |
*princ_out = (step == 1) ? iter->princ : NULL;
|
|
|
a53771 |
return 0;
|
|
|
a53771 |
}
|
|
|
a53771 |
|
|
|
a53771 |
+ /* If we're not doing fallback, the hostname is canonical, but we may need
|
|
|
a53771 |
+ * to substitute the default realm. */
|
|
|
a53771 |
+ if (context->dns_canonicalize_hostname != CANONHOST_FALLBACK) {
|
|
|
a53771 |
+ if (step > 1)
|
|
|
a53771 |
+ return 0;
|
|
|
a53771 |
+ iter->copy = *iter->princ;
|
|
|
a53771 |
+ if (iter->subst_defrealm && iter->copy.realm.length == 0) {
|
|
|
a53771 |
+ ret = krb5_get_default_realm(context, &iter->realm);
|
|
|
a53771 |
+ if (ret)
|
|
|
a53771 |
+ return ret;
|
|
|
a53771 |
+ iter->copy = *iter->princ;
|
|
|
a53771 |
+ iter->copy.realm = string2data(iter->realm);
|
|
|
a53771 |
+ }
|
|
|
a53771 |
+ *princ_out = &iter->copy;
|
|
|
a53771 |
+ return 0;
|
|
|
a53771 |
+ }
|
|
|
a53771 |
+
|
|
|
a53771 |
/* Canonicalize without DNS at step 1, with DNS at step 2. */
|
|
|
a53771 |
if (step > 2)
|
|
|
a53771 |
return 0;
|