[PATCH] Remove ip_service from get_kdc_list

Volker Lendecke Volker.Lendecke at SerNet.DE
Wed Jan 29 04:20:15 MST 2014


Hi!

Attached find a small patchset that removes "struct
ip_service" from the get_kdc_list routine. "struct
ip_service" is wrong in the sense that "struct
sockaddr_storage" does exactly the same and I would like to
step by step remove it from our code base.

Please review & push!

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 8a7eecee8daacf620358480a6740cdf6509f20db Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 28 Jan 2014 21:25:09 +0100
Subject: [PATCH 1/5] libsmb: Add get_kdc_list_ss

Wrapper around get_kdc_list on the way to get rid of ip_service

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/proto.h    |  4 ++++
 source3/libsmb/namequery.c | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/source3/include/proto.h b/source3/include/proto.h
index ceaa902..435c5b2 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -905,6 +905,10 @@ NTSTATUS get_kdc_list( const char *realm,
 			const char *sitename,
 			struct ip_service **ip_list,
 			int *count);
+NTSTATUS get_kdc_list_ss(TALLOC_CTX *mem_ctx,
+			 const char *realm, const char *sitename,
+			 struct sockaddr_storage **kdcs,
+			 unsigned *num_kdcs);
 
 /* The following definitions come from libsmb/namequery_dc.c  */
 
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index 7d6d6bb..a159399 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -3349,3 +3349,44 @@ NTSTATUS get_kdc_list( const char *realm,
 
 	return NT_STATUS_OK;
 }
+
+static NTSTATUS convert_service2ss(TALLOC_CTX *mem_ctx,
+				   const struct ip_service *ip_list, int count,
+				   struct sockaddr_storage **addrs,
+				   size_t *num_addrs)
+{
+	struct sockaddr_storage *result;
+	int i;
+
+	result = talloc_array(mem_ctx, struct sockaddr_storage, count);
+	if (result == NULL) {
+		return NT_STATUS_NO_MEMORY;
+	}
+
+	for (i=0; i<count; i++) {
+		result[i] = ip_list[i].ss;
+	}
+
+	*addrs = result;
+	*num_addrs = count;
+	return NT_STATUS_OK;
+}
+
+NTSTATUS get_kdc_list_ss(TALLOC_CTX *mem_ctx,
+			 const char *realm, const char *sitename,
+			 struct sockaddr_storage **kdcs,
+			 unsigned *num_kdcs)
+{
+	struct ip_service *ip_list;
+	int count;
+	NTSTATUS status;
+
+	status = get_kdc_list(realm, sitename, &ip_list, &count);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
+	}
+	status = convert_service2ss(mem_ctx, ip_list, count,
+				    kdcs, num_kdcs);
+	SAFE_FREE(ip_list);
+	return status;
+}
-- 
1.8.1.2


From e0fca4bbba2df1d7c163365dd6c75e8ca368f1ae Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 28 Jan 2014 21:43:17 +0100
Subject: [PATCH 2/5] net_lookup: Use get_kdc_list_ss

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/utils/net_lookup.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/source3/utils/net_lookup.c b/source3/utils/net_lookup.c
index 9d61be2..5030852 100644
--- a/source3/utils/net_lookup.c
+++ b/source3/utils/net_lookup.c
@@ -273,10 +273,10 @@ static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
 #ifdef HAVE_KRB5
 	krb5_error_code rc;
 	krb5_context ctx;
-	struct ip_service *kdcs;
+	struct sockaddr_storage *kdcs;
 	const char *realm;
-	int num_kdcs = 0;
-	int i;
+	size_t num_kdcs;
+	size_t i;
 	NTSTATUS status;
 
 	initialize_krb5_error_table();
@@ -303,7 +303,7 @@ static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
 		realm = (const char *) *realms;
 	}
 
-	status = get_kdc_list(realm, NULL, &kdcs, &num_kdcs);
+	status = get_kdc_list_ss(talloc_tos(), realm, NULL, &kdcs, &num_kdcs);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(1,("get_kdc_list failed (%s)\n", nt_errstr(status)));
 		return -1;
@@ -312,11 +312,13 @@ static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
 	for (i = 0; i < num_kdcs; i++) {
 		char addr[INET6_ADDRSTRLEN];
 
-		print_sockaddr(addr, sizeof(addr), &kdcs[i].ss);
+		print_sockaddr(addr, sizeof(addr), &kdcs[i]);
 
-		d_printf("%s:%u\n", addr, kdcs[i].port);
+		d_printf("%s:%u\n", addr, get_sockaddr_port(&kdcs[i]));
 	}
 
+	TALLOC_FREE(kdcs);
+
 	return 0;
 #endif
 	DEBUG(1, ("No kerberos support\n"));
-- 
1.8.1.2


From 161ebea0431286dc6ddad82aa56cd579768eec4b Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 28 Jan 2014 21:43:17 +0100
Subject: [PATCH 3/5] libads: Use get_kdc_list_ss

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/libads/kerberos.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/source3/libads/kerberos.c b/source3/libads/kerberos.c
index b026e09..93bf079 100644
--- a/source3/libads/kerberos.c
+++ b/source3/libads/kerberos.c
@@ -687,10 +687,10 @@ static char *get_kdc_ip_string(char *mem_ctx,
 {
 	TALLOC_CTX *frame = talloc_stackframe();
 	int i;
-	struct ip_service *ip_srv_site = NULL;
-	struct ip_service *ip_srv_nonsite = NULL;
-	int count_site = 0;
-	int count_nonsite;
+	struct sockaddr_storage *ip_srv_site = NULL;
+	struct sockaddr_storage *ip_srv_nonsite = NULL;
+	size_t count_site = 0;
+	size_t count_nonsite = 0;
 	int num_dcs;
 	struct sockaddr_storage *dc_addrs;
 	struct tsocket_address **dc_addrs2 = NULL;
@@ -711,12 +711,13 @@ static char *get_kdc_ip_string(char *mem_ctx,
 	 */
 
 	if (sitename) {
-		get_kdc_list(realm, sitename, &ip_srv_site, &count_site);
+		get_kdc_list_ss(frame, realm, sitename,
+				&ip_srv_site, &count_site);
 	}
 
 	/* Get all KDC's. */
 
-	get_kdc_list(realm, NULL, &ip_srv_nonsite, &count_nonsite);
+	get_kdc_list_ss(frame, realm, NULL, &ip_srv_nonsite, &count_nonsite);
 
 	dc_addrs = talloc_array(talloc_tos(), struct sockaddr_storage,
 				1 + count_site + count_nonsite);
@@ -728,11 +729,11 @@ static char *get_kdc_ip_string(char *mem_ctx,
 	num_dcs = 1;
 
 	for (i=0; i<count_site; i++) {
-		add_sockaddr_unique(dc_addrs, &num_dcs, &ip_srv_site[i].ss);
+		add_sockaddr_unique(dc_addrs, &num_dcs, &ip_srv_site[i]);
 	}
 
 	for (i=0; i<count_nonsite; i++) {
-		add_sockaddr_unique(dc_addrs, &num_dcs, &ip_srv_nonsite[i].ss);
+		add_sockaddr_unique(dc_addrs, &num_dcs, &ip_srv_nonsite[i]);
 	}
 
 	dc_addrs2 = talloc_zero_array(talloc_tos(),
@@ -803,8 +804,6 @@ static char *get_kdc_ip_string(char *mem_ctx,
 
 	result = kdc_str;
 fail:
-	SAFE_FREE(ip_srv_site);
-	SAFE_FREE(ip_srv_nonsite);
 	TALLOC_FREE(frame);
 	return result;
 }
-- 
1.8.1.2


From 778f125b9ec81acfcdd08a399d0c17729f39ac01 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 28 Jan 2014 21:54:33 +0100
Subject: [PATCH 4/5] libsmb: Make get_kdc_list static and rename it

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/proto.h    | 4 ----
 source3/libsmb/namequery.c | 4 ++--
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/source3/include/proto.h b/source3/include/proto.h
index 435c5b2..653f0b0 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -901,10 +901,6 @@ NTSTATUS get_sorted_dc_list( const char *domain,
 			struct ip_service **ip_list,
 			int *count,
 			bool ads_only );
-NTSTATUS get_kdc_list( const char *realm,
-			const char *sitename,
-			struct ip_service **ip_list,
-			int *count);
 NTSTATUS get_kdc_list_ss(TALLOC_CTX *mem_ctx,
 			 const char *realm, const char *sitename,
 			 struct sockaddr_storage **kdcs,
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index a159399..99f35df 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -3322,7 +3322,7 @@ NTSTATUS get_sorted_dc_list( const char *domain,
  Get the KDC list - re-use all the logic in get_dc_list.
 *********************************************************************/
 
-NTSTATUS get_kdc_list( const char *realm,
+static NTSTATUS get_kdc_list_ip_service( const char *realm,
 			const char *sitename,
 			struct ip_service **ip_list,
 			int *count)
@@ -3381,7 +3381,7 @@ NTSTATUS get_kdc_list_ss(TALLOC_CTX *mem_ctx,
 	int count;
 	NTSTATUS status;
 
-	status = get_kdc_list(realm, sitename, &ip_list, &count);
+	status = get_kdc_list_ip_service(realm, sitename, &ip_list, &count);
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}
-- 
1.8.1.2


From 10d66f4458b271afd4f8945adb6befc6939989ef Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 28 Jan 2014 21:59:55 +0100
Subject: [PATCH 5/5] libsmb: get_kdc_list_ss->get_kdc_list

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/proto.h    | 8 ++++----
 source3/libads/kerberos.c  | 6 +++---
 source3/libsmb/namequery.c | 8 ++++----
 source3/utils/net_lookup.c | 2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/source3/include/proto.h b/source3/include/proto.h
index 653f0b0..d899869 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -901,10 +901,10 @@ NTSTATUS get_sorted_dc_list( const char *domain,
 			struct ip_service **ip_list,
 			int *count,
 			bool ads_only );
-NTSTATUS get_kdc_list_ss(TALLOC_CTX *mem_ctx,
-			 const char *realm, const char *sitename,
-			 struct sockaddr_storage **kdcs,
-			 unsigned *num_kdcs);
+NTSTATUS get_kdc_list(TALLOC_CTX *mem_ctx,
+		      const char *realm, const char *sitename,
+		      struct sockaddr_storage **kdcs,
+		      unsigned *num_kdcs);
 
 /* The following definitions come from libsmb/namequery_dc.c  */
 
diff --git a/source3/libads/kerberos.c b/source3/libads/kerberos.c
index 93bf079..7dcdc00 100644
--- a/source3/libads/kerberos.c
+++ b/source3/libads/kerberos.c
@@ -711,13 +711,13 @@ static char *get_kdc_ip_string(char *mem_ctx,
 	 */
 
 	if (sitename) {
-		get_kdc_list_ss(frame, realm, sitename,
-				&ip_srv_site, &count_site);
+		get_kdc_list(frame, realm, sitename,
+			     &ip_srv_site, &count_site);
 	}
 
 	/* Get all KDC's. */
 
-	get_kdc_list_ss(frame, realm, NULL, &ip_srv_nonsite, &count_nonsite);
+	get_kdc_list(frame, realm, NULL, &ip_srv_nonsite, &count_nonsite);
 
 	dc_addrs = talloc_array(talloc_tos(), struct sockaddr_storage,
 				1 + count_site + count_nonsite);
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index 99f35df..3cadb97 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -3372,10 +3372,10 @@ static NTSTATUS convert_service2ss(TALLOC_CTX *mem_ctx,
 	return NT_STATUS_OK;
 }
 
-NTSTATUS get_kdc_list_ss(TALLOC_CTX *mem_ctx,
-			 const char *realm, const char *sitename,
-			 struct sockaddr_storage **kdcs,
-			 unsigned *num_kdcs)
+NTSTATUS get_kdc_list(TALLOC_CTX *mem_ctx,
+		      const char *realm, const char *sitename,
+		      struct sockaddr_storage **kdcs,
+		      unsigned *num_kdcs)
 {
 	struct ip_service *ip_list;
 	int count;
diff --git a/source3/utils/net_lookup.c b/source3/utils/net_lookup.c
index 5030852..620fcbb 100644
--- a/source3/utils/net_lookup.c
+++ b/source3/utils/net_lookup.c
@@ -303,7 +303,7 @@ static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
 		realm = (const char *) *realms;
 	}
 
-	status = get_kdc_list_ss(talloc_tos(), realm, NULL, &kdcs, &num_kdcs);
+	status = get_kdc_list(talloc_tos(), realm, NULL, &kdcs, &num_kdcs);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(1,("get_kdc_list failed (%s)\n", nt_errstr(status)));
 		return -1;
-- 
1.8.1.2



More information about the samba-technical mailing list