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

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