6729ff
From 168627e1877317db86471a4b0360dccd9f469aaa Mon Sep 17 00:00:00 2001
6729ff
From: =?UTF-8?q?G=C3=BCnther=20Deschner?= <gd@samba.org>
6729ff
Date: Mon, 13 Jan 2014 15:59:26 +0100
6729ff
Subject: [PATCH 1/2] s3-kerberos: remove print_kdc_line() completely.
6729ff
MIME-Version: 1.0
6729ff
Content-Type: text/plain; charset=UTF-8
6729ff
Content-Transfer-Encoding: 8bit
6729ff
6729ff
Just calling print_canonical_sockaddr() is sufficient, as it already deals with
6729ff
ipv6 as well. The port handling, which was only done for IPv6 (not IPv4), is
6729ff
removed as well. It was pointless because it always derived the port number from
6729ff
the provided address which was either a SMB (usually port 445) or LDAP
6729ff
connection. No KDC will ever run on port 389 or 445 on a Windows/Samba DC.
6729ff
Finally, the kerberos libraries that we support and build with, can deal with
6729ff
ipv6 addresses in krb5.conf, so we no longer put the (unnecessary) burden of
6729ff
resolving the DC name on the kerberos library anymore.
6729ff
6729ff
Guenther
6729ff
6729ff
Signed-off-by: Günther Deschner <gd@samba.org>
6729ff
Reviewed-by: Andreas Schneider <asn@samba.org>
6729ff
---
6729ff
 source3/libads/kerberos.c | 73 ++++-------------------------------------------
6729ff
 1 file changed, 5 insertions(+), 68 deletions(-)
6729ff
6729ff
diff --git a/source3/libads/kerberos.c b/source3/libads/kerberos.c
6729ff
index b026e09..ea14350 100644
6729ff
--- a/source3/libads/kerberos.c
6729ff
+++ b/source3/libads/kerberos.c
6729ff
@@ -592,70 +592,6 @@ int kerberos_kinit_password(const char *principal,
6729ff
 /************************************************************************
6729ff
 ************************************************************************/
6729ff
 
6729ff
-static char *print_kdc_line(char *mem_ctx,
6729ff
-			const char *prev_line,
6729ff
-			const struct sockaddr_storage *pss,
6729ff
-			const char *kdc_name)
6729ff
-{
6729ff
-	char addr[INET6_ADDRSTRLEN];
6729ff
-	uint16_t port = get_sockaddr_port(pss);
6729ff
-
6729ff
-	if (pss->ss_family == AF_INET) {
6729ff
-		return talloc_asprintf(mem_ctx, "%s\tkdc = %s\n",
6729ff
-				       prev_line,
6729ff
-				       print_canonical_sockaddr(mem_ctx, pss));
6729ff
-	}
6729ff
-
6729ff
-	/*
6729ff
-	 * IPv6 starts here
6729ff
-	 */
6729ff
-
6729ff
-	DEBUG(10, ("print_kdc_line: IPv6 case for kdc_name: %s, port: %d\n",
6729ff
-		   kdc_name, port));
6729ff
-
6729ff
-	if (port != 0 && port != DEFAULT_KRB5_PORT) {
6729ff
-		/* Currently for IPv6 we can't specify a non-default
6729ff
-		   krb5 port with an address, as this requires a ':'.
6729ff
-		   Resolve to a name. */
6729ff
-		char hostname[MAX_DNS_NAME_LENGTH];
6729ff
-		int ret = sys_getnameinfo((const struct sockaddr *)pss,
6729ff
-					  sizeof(*pss),
6729ff
-					  hostname, sizeof(hostname),
6729ff
-					  NULL, 0,
6729ff
-					  NI_NAMEREQD);
6729ff
-		if (ret) {
6729ff
-			DEBUG(0,("print_kdc_line: can't resolve name "
6729ff
-				 "for kdc with non-default port %s. "
6729ff
-				 "Error %s\n.",
6729ff
-				 print_canonical_sockaddr(mem_ctx, pss),
6729ff
-				 gai_strerror(ret)));
6729ff
-			return NULL;
6729ff
-		}
6729ff
-		/* Success, use host:port */
6729ff
-		return talloc_asprintf(mem_ctx,
6729ff
-				       "%s\tkdc = %s:%u\n",
6729ff
-				       prev_line,
6729ff
-				       hostname,
6729ff
-				       (unsigned int)port);
6729ff
-	}
6729ff
-
6729ff
-	/* no krb5 lib currently supports "kdc = ipv6 address"
6729ff
-	 * at all, so just fill in just the kdc_name if we have
6729ff
-	 * it and let the krb5 lib figure out the appropriate
6729ff
-	 * ipv6 address - gd */
6729ff
-
6729ff
-	if (kdc_name) {
6729ff
-		return talloc_asprintf(mem_ctx, "%s\tkdc = %s\n",
6729ff
-				       prev_line, kdc_name);
6729ff
-	}
6729ff
-
6729ff
-	return talloc_asprintf(mem_ctx, "%s\tkdc = %s\n",
6729ff
-			       prev_line,
6729ff
-			       print_sockaddr(addr,
6729ff
-					      sizeof(addr),
6729ff
-					      pss));
6729ff
-}
6729ff
-
6729ff
 /************************************************************************
6729ff
  Create a string list of available kdc's, possibly searching by sitename.
6729ff
  Does DNS queries.
6729ff
@@ -698,7 +634,8 @@ static char *get_kdc_ip_string(char *mem_ctx,
6729ff
 	char *result = NULL;
6729ff
 	struct netlogon_samlogon_response **responses = NULL;
6729ff
 	NTSTATUS status;
6729ff
-	char *kdc_str = print_kdc_line(mem_ctx, "", pss, kdc_name);
6729ff
+	char *kdc_str = talloc_asprintf(mem_ctx, "%s\tkdc = %s\n", "",
6729ff
+					print_canonical_sockaddr(mem_ctx, pss));
6729ff
 
6729ff
 	if (kdc_str == NULL) {
6729ff
 		TALLOC_FREE(frame);
6729ff
@@ -788,9 +725,9 @@ static char *get_kdc_ip_string(char *mem_ctx,
6729ff
 		}
6729ff
 
6729ff
 		/* Append to the string - inefficient but not done often. */
6729ff
-		new_kdc_str = print_kdc_line(mem_ctx, kdc_str,
6729ff
-					     &dc_addrs[i],
6729ff
-					     kdc_name);
6729ff
+		new_kdc_str = talloc_asprintf(mem_ctx, "%s\tkdc = %s\n",
6729ff
+					      kdc_str,
6729ff
+					      print_canonical_sockaddr(mem_ctx, &dc_addrs[i]));
6729ff
 		if (new_kdc_str == NULL) {
6729ff
 			goto fail;
6729ff
 		}
6729ff
-- 
6729ff
1.8.5.3
6729ff
6729ff
6729ff
From 3edb3d4084548960f03356cf4c44a6892e6efb84 Mon Sep 17 00:00:00 2001
6729ff
From: =?UTF-8?q?G=C3=BCnther=20Deschner?= <gd@samba.org>
6729ff
Date: Fri, 7 Mar 2014 14:47:31 +0100
6729ff
Subject: [PATCH 2/2] s3-kerberos: remove unused kdc_name from
6729ff
 create_local_private_krb5_conf_for_domain().
6729ff
MIME-Version: 1.0
6729ff
Content-Type: text/plain; charset=UTF-8
6729ff
Content-Transfer-Encoding: 8bit
6729ff
6729ff
Guenther
6729ff
6729ff
Signed-off-by: Günther Deschner <gd@samba.org>
6729ff
Reviewed-by: Andreas Schneider <asn@samba.org>
6729ff
---
6729ff
 source3/libads/kerberos.c       | 10 ++++------
6729ff
 source3/libads/kerberos_proto.h |  3 +--
6729ff
 source3/libnet/libnet_join.c    |  3 +--
6729ff
 source3/libsmb/namequery_dc.c   |  6 ++----
6729ff
 source3/winbindd/winbindd_cm.c  |  6 ++----
6729ff
 5 files changed, 10 insertions(+), 18 deletions(-)
6729ff
6729ff
diff --git a/source3/libads/kerberos.c b/source3/libads/kerberos.c
6729ff
index ea14350..649e568 100644
6729ff
--- a/source3/libads/kerberos.c
6729ff
+++ b/source3/libads/kerberos.c
6729ff
@@ -618,8 +618,7 @@ static void add_sockaddr_unique(struct sockaddr_storage *addrs, int *num_addrs,
6729ff
 static char *get_kdc_ip_string(char *mem_ctx,
6729ff
 		const char *realm,
6729ff
 		const char *sitename,
6729ff
-		const struct sockaddr_storage *pss,
6729ff
-		const char *kdc_name)
6729ff
+		const struct sockaddr_storage *pss)
6729ff
 {
6729ff
 	TALLOC_CTX *frame = talloc_stackframe();
6729ff
 	int i;
6729ff
@@ -756,8 +755,7 @@ fail:
6729ff
 bool create_local_private_krb5_conf_for_domain(const char *realm,
6729ff
 						const char *domain,
6729ff
 						const char *sitename,
6729ff
-					        const struct sockaddr_storage *pss,
6729ff
-						const char *kdc_name)
6729ff
+					        const struct sockaddr_storage *pss)
6729ff
 {
6729ff
 	char *dname;
6729ff
 	char *tmpname = NULL;
6729ff
@@ -782,7 +780,7 @@ bool create_local_private_krb5_conf_for_domain(const char *realm,
6729ff
 		return false;
6729ff
 	}
6729ff
 
6729ff
-	if (domain == NULL || pss == NULL || kdc_name == NULL) {
6729ff
+	if (domain == NULL || pss == NULL) {
6729ff
 		return false;
6729ff
 	}
6729ff
 
6729ff
@@ -815,7 +813,7 @@ bool create_local_private_krb5_conf_for_domain(const char *realm,
6729ff
 		goto done;
6729ff
 	}
6729ff
 
6729ff
-	kdc_ip_string = get_kdc_ip_string(dname, realm, sitename, pss, kdc_name);
6729ff
+	kdc_ip_string = get_kdc_ip_string(dname, realm, sitename, pss);
6729ff
 	if (!kdc_ip_string) {
6729ff
 		goto done;
6729ff
 	}
6729ff
diff --git a/source3/libads/kerberos_proto.h b/source3/libads/kerberos_proto.h
6729ff
index f7470d2..2559634 100644
6729ff
--- a/source3/libads/kerberos_proto.h
6729ff
+++ b/source3/libads/kerberos_proto.h
6729ff
@@ -62,8 +62,7 @@ int kerberos_kinit_password(const char *principal,
6729ff
 bool create_local_private_krb5_conf_for_domain(const char *realm,
6729ff
 						const char *domain,
6729ff
 						const char *sitename,
6729ff
-					        const struct sockaddr_storage *pss,
6729ff
-						const char *kdc_name);
6729ff
+					        const struct sockaddr_storage *pss);
6729ff
 
6729ff
 /* The following definitions come from libads/authdata.c  */
6729ff
 
6729ff
diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c
6729ff
index a87eb38..68884cd 100644
6729ff
--- a/source3/libnet/libnet_join.c
6729ff
+++ b/source3/libnet/libnet_join.c
6729ff
@@ -2152,8 +2152,7 @@ static WERROR libnet_DomainJoin(TALLOC_CTX *mem_ctx,
6729ff
 
6729ff
 	create_local_private_krb5_conf_for_domain(
6729ff
 		r->out.dns_domain_name, r->out.netbios_domain_name,
6729ff
-		NULL, smbXcli_conn_remote_sockaddr(cli->conn),
6729ff
-		smbXcli_conn_remote_name(cli->conn));
6729ff
+		NULL, smbXcli_conn_remote_sockaddr(cli->conn));
6729ff
 
6729ff
 	if (r->out.domain_is_ad && r->in.account_ou &&
6729ff
 	    !(r->in.join_flags & WKSSVC_JOIN_FLAGS_JOIN_UNSECURE)) {
6729ff
diff --git a/source3/libsmb/namequery_dc.c b/source3/libsmb/namequery_dc.c
6729ff
index 3cfae79..eb34741 100644
6729ff
--- a/source3/libsmb/namequery_dc.c
6729ff
+++ b/source3/libsmb/namequery_dc.c
6729ff
@@ -112,14 +112,12 @@ static bool ads_dc_name(const char *domain,
6729ff
 				create_local_private_krb5_conf_for_domain(realm,
6729ff
 									domain,
6729ff
 									sitename,
6729ff
-									&ads->ldap.ss,
6729ff
-									ads->config.ldap_server_name);
6729ff
+									&ads->ldap.ss);
6729ff
 			} else {
6729ff
 				create_local_private_krb5_conf_for_domain(realm,
6729ff
 									domain,
6729ff
 									NULL,
6729ff
-									&ads->ldap.ss,
6729ff
-									ads->config.ldap_server_name);
6729ff
+									&ads->ldap.ss);
6729ff
 			}
6729ff
 		}
6729ff
 #endif
6729ff
diff --git a/source3/winbindd/winbindd_cm.c b/source3/winbindd/winbindd_cm.c
6729ff
index 669a43e..be13a57 100644
6729ff
--- a/source3/winbindd/winbindd_cm.c
6729ff
+++ b/source3/winbindd/winbindd_cm.c
6729ff
@@ -1233,8 +1233,7 @@ static bool dcip_to_name(TALLOC_CTX *mem_ctx,
6729ff
 					create_local_private_krb5_conf_for_domain(domain->alt_name,
6729ff
 									domain->name,
6729ff
 									sitename,
6729ff
-									pss,
6729ff
-									*name);
6729ff
+									pss);
6729ff
 
6729ff
 					SAFE_FREE(sitename);
6729ff
 				} else {
6729ff
@@ -1242,8 +1241,7 @@ static bool dcip_to_name(TALLOC_CTX *mem_ctx,
6729ff
 					create_local_private_krb5_conf_for_domain(domain->alt_name,
6729ff
 									domain->name,
6729ff
 									NULL,
6729ff
-									pss,
6729ff
-									*name);
6729ff
+									pss);
6729ff
 				}
6729ff
 				winbindd_set_locator_kdc_envs(domain);
6729ff
 
6729ff
-- 
6729ff
1.8.5.3
6729ff