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

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