From f0c4fcace586197d5c170f6a9dcc175df23e3802 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 8 Mar 2017 11:56:30 +0100 Subject: [PATCH] krb5_wrap: pass client_realm to smb_krb5_get_realm_from_hostname() BUG: https://bugzilla.samba.org/show_bug.cgi?id=12554 Pair-Programmed-With: Stefan Metzmacher Signed-off-by: Andreas Schneider Signed-off-by: Stefan Metzmacher --- lib/krb5_wrap/krb5_samba.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/krb5_wrap/krb5_samba.c b/lib/krb5_wrap/krb5_samba.c index 92af8c60979..c2d0d7263cb 100644 --- a/lib/krb5_wrap/krb5_samba.c +++ b/lib/krb5_wrap/krb5_samba.c @@ -2688,7 +2688,8 @@ static char *smb_krb5_get_default_realm_from_ccache(TALLOC_CTX *mem_ctx) ************************************************************************/ static char *smb_krb5_get_realm_from_hostname(TALLOC_CTX *mem_ctx, - const char *hostname) + const char *hostname, + const char *client_realm) { #if defined(HAVE_KRB5_REALM_TYPE) /* Heimdal. */ @@ -2719,6 +2720,9 @@ static char *smb_krb5_get_realm_from_hostname(TALLOC_CTX *mem_ctx, realm_list[0] != NULL && realm_list[0][0] != '\0') { realm = talloc_strdup(mem_ctx, realm_list[0]); + if (realm == NULL) { + goto out; + } } else { const char *p = NULL; @@ -2731,9 +2735,16 @@ static char *smb_krb5_get_realm_from_hostname(TALLOC_CTX *mem_ctx, p = strchr_m(hostname, '.'); if (p != NULL && p[1] != '\0') { realm = talloc_strdup_upper(mem_ctx, p + 1); + if (realm == NULL) { + goto out; + } } } + if (realm == NULL) { + realm = talloc_strdup(mem_ctx, client_realm); + } + out: if (ctx) { @@ -2776,7 +2787,8 @@ char *smb_krb5_get_principal_from_service_hostname(TALLOC_CTX *mem_ctx, if (host) { /* DNS name. */ realm = smb_krb5_get_realm_from_hostname(talloc_tos(), - remote_name); + remote_name, + default_realm); } else { /* NetBIOS name - use our realm. */ realm = smb_krb5_get_default_realm_from_ccache(talloc_tos());