Blame SOURCES/0002-adenroll-use-_adcli_strv_add_unique-for-service-prin.patch

ee8dc1
From 0c027538f398b3823bedbfbf5f388ad97784a0ec Mon Sep 17 00:00:00 2001
ee8dc1
From: Sumit Bose <sbose@redhat.com>
ee8dc1
Date: Fri, 16 Nov 2018 13:32:59 +0100
ee8dc1
Subject: [PATCH 2/2] adenroll: use _adcli_strv_add_unique for service
ee8dc1
 principals
ee8dc1
ee8dc1
Check if service principals is already in the list before adding it.
ee8dc1
ee8dc1
Related to https://gitlab.freedesktop.org/realmd/adcli/issues/16
ee8dc1
---
ee8dc1
 library/adenroll.c | 31 ++++++++-----------------------
ee8dc1
 1 file changed, 8 insertions(+), 23 deletions(-)
ee8dc1
ee8dc1
diff --git a/library/adenroll.c b/library/adenroll.c
ee8dc1
index de2242a..e02f403 100644
ee8dc1
--- a/library/adenroll.c
ee8dc1
+++ b/library/adenroll.c
ee8dc1
@@ -313,7 +313,6 @@ add_service_names_to_service_principals (adcli_enroll *enroll)
ee8dc1
 	char *name;
ee8dc1
 	int length = 0;
ee8dc1
 	int i;
ee8dc1
-	size_t c;
ee8dc1
 
ee8dc1
 	if (enroll->service_principals != NULL) {
ee8dc1
 		length = seq_count (enroll->service_principals);
ee8dc1
@@ -322,28 +321,14 @@ add_service_names_to_service_principals (adcli_enroll *enroll)
ee8dc1
 	for (i = 0; enroll->service_names[i] != NULL; i++) {
ee8dc1
 		if (asprintf (&name, "%s/%s", enroll->service_names[i], enroll->computer_name) < 0)
ee8dc1
 			return_unexpected_if_reached ();
ee8dc1
-		for (c = 0; enroll->service_principals != NULL && enroll->service_principals[c] != NULL; c++) {
ee8dc1
-			if (strcmp (name, enroll->service_principals[c]) == 0) {
ee8dc1
-				break;
ee8dc1
-			}
ee8dc1
-		}
ee8dc1
-		if (enroll->service_principals == NULL || enroll->service_principals[c] == NULL) {
ee8dc1
-			enroll->service_principals = _adcli_strv_add (enroll->service_principals,
ee8dc1
-				                                      name, &length);
ee8dc1
-		}
ee8dc1
+		enroll->service_principals = _adcli_strv_add_unique (enroll->service_principals,
ee8dc1
+		                                                     name, &length, false);
ee8dc1
 
ee8dc1
 		if (enroll->host_fqdn) {
ee8dc1
 			if (asprintf (&name, "%s/%s", enroll->service_names[i], enroll->host_fqdn) < 0)
ee8dc1
 				return_unexpected_if_reached ();
ee8dc1
-			for (c = 0; enroll->service_principals != NULL && enroll->service_principals[c] != NULL; c++) {
ee8dc1
-				if (strcmp (name, enroll->service_principals[c]) == 0) {
ee8dc1
-					break;
ee8dc1
-				}
ee8dc1
-			}
ee8dc1
-			if (enroll->service_principals == NULL || enroll->service_principals[c] == NULL) {
ee8dc1
-				enroll->service_principals = _adcli_strv_add (enroll->service_principals,
ee8dc1
-					                                      name, &length);
ee8dc1
-			}
ee8dc1
+			enroll->service_principals = _adcli_strv_add_unique (enroll->service_principals,
ee8dc1
+			                                                     name, &length, false);
ee8dc1
 		}
ee8dc1
 	}
ee8dc1
 
ee8dc1
@@ -364,9 +349,9 @@ add_and_remove_service_principals (adcli_enroll *enroll)
ee8dc1
 	list = adcli_enroll_get_service_principals_to_add (enroll);
ee8dc1
 	if (list != NULL) {
ee8dc1
 		for (c = 0; list[c] != NULL; c++) {
ee8dc1
-			enroll->service_principals = _adcli_strv_add (enroll->service_principals,
ee8dc1
-			                                              strdup (list[c]),
ee8dc1
-			                                              &length);
ee8dc1
+			enroll->service_principals = _adcli_strv_add_unique (enroll->service_principals,
ee8dc1
+			                                                     strdup (list[c]),
ee8dc1
+			                                                     &length, false);
ee8dc1
 			if (enroll->service_principals == NULL) {
ee8dc1
 				return ADCLI_ERR_UNEXPECTED;
ee8dc1
 			}
ee8dc1
@@ -1525,7 +1510,7 @@ load_keytab_entry (krb5_context k5,
ee8dc1
 			value = strdup (name);
ee8dc1
 			return_val_if_fail (value != NULL, FALSE);
ee8dc1
 			_adcli_info ("Found service principal in keytab: %s", value);
ee8dc1
-			enroll->service_principals = _adcli_strv_add (enroll->service_principals, value, NULL);
ee8dc1
+			enroll->service_principals = _adcli_strv_add_unique (enroll->service_principals, value, NULL, false);
ee8dc1
 		}
ee8dc1
 	}
ee8dc1
 
ee8dc1
-- 
ee8dc1
2.20.1
ee8dc1