krb5_wrap: pass client_realm to smb_krb5_get_realm_from_hostname()
authorAndreas Schneider <asn@samba.org>
Wed, 8 Mar 2017 10:56:30 +0000 (11:56 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 10 Mar 2017 10:37:21 +0000 (11:37 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12554

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
lib/krb5_wrap/krb5_samba.c

index 92af8c609790f8ca837051e29daa261c11ebc7b4..c2d0d7263cb3fdf67977e6b6c4b50546e1becf32 100644 (file)
@@ -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());