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

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