File 0020-Do-not-add-service-principals-twice.patch of Package adcli.13386

From 85332e1818129ead6d9973b85918c54a04e3706e Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Mon, 13 Aug 2018 17:32:24 +0200
Subject: [PATCH 20/25] Do not add service principals twice

---
 library/adenroll.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/library/adenroll.c b/library/adenroll.c
index df1f551..f942ea2 100644
--- a/library/adenroll.c
+++ b/library/adenroll.c
@@ -308,6 +308,7 @@ add_service_names_to_service_principals (adcli_enroll *enroll)
 	char *name;
 	int length = 0;
 	int i;
+	size_t c;
 
 	if (enroll->service_principals != NULL) {
 		length = seq_count (enroll->service_principals);
@@ -316,14 +317,28 @@ add_service_names_to_service_principals (adcli_enroll *enroll)
 	for (i = 0; enroll->service_names[i] != NULL; i++) {
 		if (asprintf (&name, "%s/%s", enroll->service_names[i], enroll->computer_name) < 0)
 			return_unexpected_if_reached ();
-		enroll->service_principals = _adcli_strv_add (enroll->service_principals,
-			                                      name, &length);
+		for (c = 0; enroll->service_principals != NULL && enroll->service_principals[c] != NULL; c++) {
+			if (strcmp (name, enroll->service_principals[c]) == 0) {
+				break;
+			}
+		}
+		if (enroll->service_principals == NULL || enroll->service_principals[c] == NULL) {
+			enroll->service_principals = _adcli_strv_add (enroll->service_principals,
+				                                      name, &length);
+		}
 
 		if (enroll->host_fqdn) {
 			if (asprintf (&name, "%s/%s", enroll->service_names[i], enroll->host_fqdn) < 0)
 				return_unexpected_if_reached ();
-			enroll->service_principals = _adcli_strv_add (enroll->service_principals,
-				                                      name, &length);
+			for (c = 0; enroll->service_principals != NULL && enroll->service_principals[c] != NULL; c++) {
+				if (strcmp (name, enroll->service_principals[c]) == 0) {
+					break;
+				}
+			}
+			if (enroll->service_principals == NULL || enroll->service_principals[c] == NULL) {
+				enroll->service_principals = _adcli_strv_add (enroll->service_principals,
+					                                      name, &length);
+			}
 		}
 	}
 
-- 
2.16.4

openSUSE Build Service is sponsored by