Blame SOURCES/0003-Do-not-add-service-principals-twice.patch

f441eb
From f05adc23d5cc9f1dfa5638e31949dcd81d632df9 Mon Sep 17 00:00:00 2001
f441eb
From: Sumit Bose <sbose@redhat.com>
f441eb
Date: Mon, 13 Aug 2018 17:32:24 +0200
f441eb
Subject: [PATCH 3/4] Do not add service principals twice
f441eb
f441eb
---
f441eb
 library/adenroll.c | 23 +++++++++++++++++++----
f441eb
 1 file changed, 19 insertions(+), 4 deletions(-)
f441eb
f441eb
diff --git a/library/adenroll.c b/library/adenroll.c
f441eb
index c4ba537..bb50365 100644
f441eb
--- a/library/adenroll.c
f441eb
+++ b/library/adenroll.c
f441eb
@@ -313,6 +313,7 @@ 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
@@ -321,14 +322,28 @@ 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
-		enroll->service_principals = _adcli_strv_add (enroll->service_principals,
f441eb
-			                                      name, &length);
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
 
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
-			enroll->service_principals = _adcli_strv_add (enroll->service_principals,
f441eb
-				                                      name, &length);
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
 		}
f441eb
 	}
f441eb
 
f441eb
-- 
f441eb
2.17.1
f441eb