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

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