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

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