From: Andreas Schneider Date: Wed, 8 Mar 2017 09:48:52 +0000 (+0100) Subject: krb5_wrap: Try to guess the correct realm from the service hostname X-Git-Tag: tdb-1.3.13~532 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=65228925ab3c4da4ae299f77cae219fc7d37cc68;p=thirdparty%2Fsamba.git krb5_wrap: Try to guess the correct realm from the service hostname If we do not get a realm mapping from the krb5.conf or from the Kerberos library try to guess it from the service hostname. The guessing of the realm from the service hostname is already implemented in Heimdal. This makes the behavior of smb_krb5_get_realm_from_hostname() consistent with both MIT and Heimdal. 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 --- diff --git a/lib/krb5_wrap/krb5_samba.c b/lib/krb5_wrap/krb5_samba.c index 780a7a4adf5..92af8c60979 100644 --- a/lib/krb5_wrap/krb5_samba.c +++ b/lib/krb5_wrap/krb5_samba.c @@ -2719,6 +2719,19 @@ 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]); + } else { + const char *p = NULL; + + /* + * "dc6.samba2003.example.com" + * returns a realm of "SAMBA2003.EXAMPLE.COM" + * + * "dc6." returns realm as NULL + */ + p = strchr_m(hostname, '.'); + if (p != NULL && p[1] != '\0') { + realm = talloc_strdup_upper(mem_ctx, p + 1); + } } out: