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