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

a302cd
From f05adc23d5cc9f1dfa5638e31949dcd81d632df9 Mon Sep 17 00:00:00 2001
a302cd
From: Sumit Bose <sbose@redhat.com>
a302cd
Date: Mon, 13 Aug 2018 17:32:24 +0200
a302cd
Subject: [PATCH 3/4] Do not add service principals twice
a302cd
a302cd
---
a302cd
 library/adenroll.c | 23 +++++++++++++++++++----
a302cd
 1 file changed, 19 insertions(+), 4 deletions(-)
a302cd
a302cd
diff --git a/library/adenroll.c b/library/adenroll.c
a302cd
index c4ba537..bb50365 100644
a302cd
--- a/library/adenroll.c
a302cd
+++ b/library/adenroll.c
a302cd
@@ -313,6 +313,7 @@ add_service_names_to_service_principals (adcli_enroll *enroll)
a302cd
 	char *name;
a302cd
 	int length = 0;
a302cd
 	int i;
a302cd
+	size_t c;
a302cd
 
a302cd
 	if (enroll->service_principals != NULL) {
a302cd
 		length = seq_count (enroll->service_principals);
a302cd
@@ -321,14 +322,28 @@ add_service_names_to_service_principals (adcli_enroll *enroll)
a302cd
 	for (i = 0; enroll->service_names[i] != NULL; i++) {
a302cd
 		if (asprintf (&name, "%s/%s", enroll->service_names[i], enroll->computer_name) < 0)
a302cd
 			return_unexpected_if_reached ();
a302cd
-		enroll->service_principals = _adcli_strv_add (enroll->service_principals,
a302cd
-			                                      name, &length);
a302cd
+		for (c = 0; enroll->service_principals != NULL && enroll->service_principals[c] != NULL; c++) {
a302cd
+			if (strcmp (name, enroll->service_principals[c]) == 0) {
a302cd
+				break;
a302cd
+			}
a302cd
+		}
a302cd
+		if (enroll->service_principals == NULL || enroll->service_principals[c] == NULL) {
a302cd
+			enroll->service_principals = _adcli_strv_add (enroll->service_principals,
a302cd
+				                                      name, &length);
a302cd
+		}
a302cd
 
a302cd
 		if (enroll->host_fqdn) {
a302cd
 			if (asprintf (&name, "%s/%s", enroll->service_names[i], enroll->host_fqdn) < 0)
a302cd
 				return_unexpected_if_reached ();
a302cd
-			enroll->service_principals = _adcli_strv_add (enroll->service_principals,
a302cd
-				                                      name, &length);
a302cd
+			for (c = 0; enroll->service_principals != NULL && enroll->service_principals[c] != NULL; c++) {
a302cd
+				if (strcmp (name, enroll->service_principals[c]) == 0) {
a302cd
+					break;
a302cd
+				}
a302cd
+			}
a302cd
+			if (enroll->service_principals == NULL || enroll->service_principals[c] == NULL) {
a302cd
+				enroll->service_principals = _adcli_strv_add (enroll->service_principals,
a302cd
+					                                      name, &length);
a302cd
+			}
a302cd
 		}
a302cd
 	}
a302cd
 
a302cd
-- 
a302cd
2.17.1
a302cd