Blame SOURCES/0004-library-make-sure-server-side-SPNs-are-preserved.patch

341f9a
From 972f1a2f35829ed89f5353bd204683aa9ad6a2d2 Mon Sep 17 00:00:00 2001
341f9a
From: Sumit Bose <sbose@redhat.com>
341f9a
Date: Fri, 22 Mar 2019 10:37:57 +0100
341f9a
Subject: [PATCH 4/4] library: make sure server side SPNs are preserved
341f9a
341f9a
adcli should not delete service principal names (SPNs) unexpectedly. If
341f9a
a SPN was added on the server while presetting a host or updating an
341f9a
existing entry and upcoming adcli join or update should preserver this
341f9a
change.
341f9a
341f9a
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1630187
341f9a
---
341f9a
 library/adenroll.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
341f9a
 1 file changed, 46 insertions(+)
341f9a
341f9a
diff --git a/library/adenroll.c b/library/adenroll.c
341f9a
index 48cb4cf..1cce86a 100644
341f9a
--- a/library/adenroll.c
341f9a
+++ b/library/adenroll.c
341f9a
@@ -1961,6 +1961,47 @@ adcli_enroll_prepare (adcli_enroll *enroll,
341f9a
 	return res;
341f9a
 }
341f9a
 
341f9a
+static adcli_result
341f9a
+add_server_side_service_principals (adcli_enroll *enroll)
341f9a
+{
341f9a
+	char **spn_list;
341f9a
+	LDAP *ldap;
341f9a
+	size_t c;
341f9a
+	int length = 0;
341f9a
+	adcli_result res;
341f9a
+
341f9a
+	ldap = adcli_conn_get_ldap_connection (enroll->conn);
341f9a
+	assert (ldap != NULL);
341f9a
+
341f9a
+	spn_list = _adcli_ldap_parse_values (ldap, enroll->computer_attributes,
341f9a
+	                                     "servicePrincipalName");
341f9a
+	if (spn_list == NULL) {
341f9a
+		return ADCLI_SUCCESS;
341f9a
+	}
341f9a
+
341f9a
+	if (enroll->service_principals != NULL) {
341f9a
+		length = seq_count (enroll->service_principals);
341f9a
+	}
341f9a
+
341f9a
+	for (c = 0; spn_list[c] != NULL; c++) {
341f9a
+		_adcli_info ("Checking %s", spn_list[c]);
341f9a
+		if (!_adcli_strv_has_ex (enroll->service_principals_to_remove, spn_list[c], strcasecmp)) {
341f9a
+			enroll->service_principals = _adcli_strv_add_unique (enroll->service_principals,
341f9a
+		                                                             spn_list[c], &length, false);
341f9a
+			assert (enroll->service_principals != NULL);
341f9a
+			_adcli_info ("   Added %s", spn_list[c]);
341f9a
+		}
341f9a
+	}
341f9a
+	_adcli_strv_free (spn_list);
341f9a
+
341f9a
+	res = ensure_keytab_principals (ADCLI_SUCCESS, enroll);
341f9a
+	if (res != ADCLI_SUCCESS) {
341f9a
+		return res;
341f9a
+	}
341f9a
+
341f9a
+	return ADCLI_SUCCESS;
341f9a
+}
341f9a
+
341f9a
 static adcli_result
341f9a
 enroll_join_or_update_tasks (adcli_enroll *enroll,
341f9a
 		             adcli_enroll_flags flags)
341f9a
@@ -2019,6 +2060,11 @@ enroll_join_or_update_tasks (adcli_enroll *enroll,
341f9a
 	update_and_calculate_enctypes (enroll);
341f9a
 	update_computer_account (enroll);
341f9a
 
341f9a
+	res = add_server_side_service_principals (enroll);
341f9a
+	if (res != ADCLI_SUCCESS) {
341f9a
+		return res;
341f9a
+	}
341f9a
+
341f9a
 	/* service_names is only set from input on the command line, so no
341f9a
 	 * additional check for explicit is needed here */
341f9a
 	if (enroll->service_names != NULL) {
341f9a
-- 
341f9a
2.20.1
341f9a