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

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