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

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