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

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