Blame SOURCES/0001-join-update-set-dNSHostName-if-not-set.patch

e06942
From beb7abfacc0010987d2cd8ab70f7c373d309eed9 Mon Sep 17 00:00:00 2001
e06942
From: Sumit Bose <sbose@redhat.com>
e06942
Date: Thu, 15 Oct 2020 18:01:12 +0200
e06942
Subject: [PATCH] join/update: set dNSHostName if not set
e06942
e06942
If during a join or update an existing AD computer object does not have
e06942
the dNSHostName attribute set it will be set with the current hostname.
e06942
This is important for cases where the user doing the join or update only
e06942
has "Validated write to service principal name" for the computer object.
e06942
The validated write with fully-qualified names can only be successful if
e06942
dNSHostName is set, see [MS-ADTS] section 3.1.1.5.3.1.1.4 "Validated
e06942
Writes - servicePrincipalName" for details.
e06942
e06942
Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1734764
e06942
---
e06942
 library/adenroll.c | 16 ++++++++++++----
e06942
 1 file changed, 12 insertions(+), 4 deletions(-)
e06942
e06942
diff --git a/library/adenroll.c b/library/adenroll.c
e06942
index 246f658..e745295 100644
e06942
--- a/library/adenroll.c
e06942
+++ b/library/adenroll.c
e06942
@@ -1403,21 +1403,29 @@ update_computer_account (adcli_enroll *enroll)
e06942
 {
e06942
 	int res = 0;
e06942
 	LDAP *ldap;
e06942
+	char *value = NULL;
e06942
 
e06942
 	ldap = adcli_conn_get_ldap_connection (enroll->conn);
e06942
 	return_if_fail (ldap != NULL);
e06942
 
e06942
 	/* Only update attributes which are explicitly given on the command
e06942
-	 * line. Otherwise 'adcli update' must be always called with the same
e06942
-	 * set of options to make sure existing attributes are not deleted or
e06942
-	 * overwritten with different values. */
e06942
-	if (enroll->host_fqdn_explicit) {
e06942
+	 * line or not set in the existing AD object. Otherwise 'adcli update'
e06942
+	 * must be always called with the same set of options to make sure
e06942
+	 * existing attributes are not deleted or overwritten with different
e06942
+	 * values. */
e06942
+	if (enroll->computer_attributes != NULL) {
e06942
+		value = _adcli_ldap_parse_value (ldap,
e06942
+		                                 enroll->computer_attributes,
e06942
+		                                 "dNSHostName");
e06942
+	}
e06942
+	if (enroll->host_fqdn_explicit || value == NULL ) {
e06942
 		char *vals_dNSHostName[] = { enroll->host_fqdn, NULL };
e06942
 		LDAPMod dNSHostName = { LDAP_MOD_REPLACE, "dNSHostName", { vals_dNSHostName, } };
e06942
 		LDAPMod *mods[] = { &dNSHostName, NULL };
e06942
 
e06942
 		res |= update_computer_attribute (enroll, ldap, mods);
e06942
 	}
e06942
+	free (value);
e06942
 
e06942
 	if (res == ADCLI_SUCCESS && enroll->trusted_for_delegation_explicit) {
e06942
 		char *vals_userAccountControl[] = { NULL , NULL };
e06942
-- 
e06942
2.28.0
e06942