[PATCH] utils: net_lookup_kdc

swen swen at linux.ibm.com
Wed Nov 21 12:35:23 UTC 2018


Another 2 small fixes.

Please review and push if happy.

Sorry for all the noise, I won't send another patch today.

Thanks for the support in advance.

Cheers Swen
-------------- next part --------------
From eb3903913e122fce8b676c874b4d0d3cfe5d2725 Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at linux.ibm.com>
Date: Wed, 21 Nov 2018 13:17:38 +0100
Subject: [PATCH 1/2] utils: Free krb5 context for net_lookup_kdc

In case of an error while processing and at the end of processing
the krb5 conext must be free'd.

Signed-off-by: Swen Schillig <swen at linux.ibm.com>
---
 source3/utils/net_lookup.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/source3/utils/net_lookup.c b/source3/utils/net_lookup.c
index 6c51390753d..3a5b5020d20 100644
--- a/source3/utils/net_lookup.c
+++ b/source3/utils/net_lookup.c
@@ -306,6 +306,7 @@ static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
 		if (rc) {
 			DEBUG(1,("krb5_gethost_realm failed (%s)\n",
 				 error_message(rc)));
+			krb5_free_context(ctx);
 			return -1;
 		}
 		realm = (const char *) *realms;
@@ -314,6 +315,7 @@ static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
 	status = get_kdc_list(realm, NULL, &kdcs, &num_kdcs);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(1,("get_kdc_list failed (%s)\n", nt_errstr(status)));
+		krb5_free_context(ctx);
 		return -1;
 	}
 
@@ -325,6 +327,7 @@ static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
 		d_printf("%s:%u\n", addr, kdcs[i].port);
 	}
 
+	krb5_free_context(ctx);
 	return 0;
 #endif
 	DEBUG(1, ("No kerberos support\n"));
-- 
2.17.2


From 0cab3e9944d32106670c559b2884071baa446a1c Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at linux.ibm.com>
Date: Wed, 21 Nov 2018 13:30:08 +0100
Subject: [PATCH 2/2] utils: Free host realm after processing

In case of error and at the end of processing the list
of realms have to be free'd again.

Signed-off-by: Swen Schillig <swen at linux.ibm.com>
---
 source3/utils/net_lookup.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/source3/utils/net_lookup.c b/source3/utils/net_lookup.c
index 3a5b5020d20..dc9aeb9719c 100644
--- a/source3/utils/net_lookup.c
+++ b/source3/utils/net_lookup.c
@@ -281,6 +281,7 @@ static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
 	krb5_context ctx;
 	struct ip_service *kdcs;
 	const char *realm;
+	char **get_host_realms = NULL;
 	int num_kdcs = 0;
 	int i;
 	NTSTATUS status;
@@ -300,21 +301,20 @@ static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
 	} else if (lp_realm() && *lp_realm()) {
 		realm = lp_realm();
 	} else {
-		char **realms;
-
-		rc = krb5_get_host_realm(ctx, NULL, &realms);
+		rc = krb5_get_host_realm(ctx, NULL, &get_host_realms);
 		if (rc) {
 			DEBUG(1,("krb5_gethost_realm failed (%s)\n",
 				 error_message(rc)));
 			krb5_free_context(ctx);
 			return -1;
 		}
-		realm = (const char *) *realms;
+		realm = (const char *) *get_host_realms;
 	}
 
 	status = get_kdc_list(realm, NULL, &kdcs, &num_kdcs);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(1,("get_kdc_list failed (%s)\n", nt_errstr(status)));
+		krb5_free_host_realm(ctx, get_host_realms);
 		krb5_free_context(ctx);
 		return -1;
 	}
@@ -327,6 +327,7 @@ static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
 		d_printf("%s:%u\n", addr, kdcs[i].port);
 	}
 
+	krb5_free_host_realm(ctx, get_host_realms);
 	krb5_free_context(ctx);
 	return 0;
 #endif
-- 
2.17.2



More information about the samba-technical mailing list