Blame SOURCES/0002-Only-update-attributes-given-on-the-command-line.patch

539d92
From 5eca1f995ced1ce4ddead4471ac7ac9037bedb73 Mon Sep 17 00:00:00 2001
539d92
From: Sumit Bose <sbose@redhat.com>
539d92
Date: Fri, 1 Jun 2018 21:26:47 +0200
539d92
Subject: [PATCH 2/7] Only update attributes given on the command line
539d92
539d92
When updating attributes of the LDAP computer object we only want to
539d92
update attributes which are related to options given on the command
539d92
line. Otherwise a simple call of 'adcli update' to check if the machine
539d92
account password needs an update might unexpectedly reset other
539d92
attributes as well.
539d92
539d92
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1547013
539d92
           https://bugzilla.redhat.com/show_bug.cgi?id=1545568
539d92
           https://bugzilla.redhat.com/show_bug.cgi?id=1538730
539d92
---
539d92
 library/adenroll.c | 35 ++++++++++++++++++++++++++++++-----
539d92
 1 file changed, 30 insertions(+), 5 deletions(-)
539d92
539d92
diff --git a/library/adenroll.c b/library/adenroll.c
539d92
index 7c59078..2be6796 100644
539d92
--- a/library/adenroll.c
539d92
+++ b/library/adenroll.c
539d92
@@ -99,8 +99,11 @@ struct _adcli_enroll {
539d92
 	int user_princpal_generate;
539d92
 
539d92
 	char *os_name;
539d92
+	int os_name_explicit;
539d92
 	char *os_version;
539d92
+	int os_version_explicit;
539d92
 	char *os_service_pack;
539d92
+	int os_service_pack_explicit;
539d92
 
539d92
 	krb5_kvno kvno;
539d92
 	char *keytab_name;
539d92
@@ -113,6 +116,7 @@ struct _adcli_enroll {
539d92
 	int computer_password_lifetime_explicit;
539d92
 	char *samba_data_tool;
539d92
 	bool trusted_for_delegation;
539d92
+	int trusted_for_delegation_explicit;
539d92
 };
539d92
 
539d92
 static adcli_result
539d92
@@ -1212,7 +1216,11 @@ update_computer_account (adcli_enroll *enroll)
539d92
 	ldap = adcli_conn_get_ldap_connection (enroll->conn);
539d92
 	return_if_fail (ldap != NULL);
539d92
 
539d92
-	{
539d92
+	/* Only update attributes which are explicitly given on the command
539d92
+	 * line. Otherwise 'adcli update' must be always called with the same
539d92
+	 * set of options to make sure existing attributes are not deleted or
539d92
+	 * overwritten with different values. */
539d92
+	if (enroll->host_fqdn_explicit) {
539d92
 		char *vals_dNSHostName[] = { enroll->host_fqdn, NULL };
539d92
 		LDAPMod dNSHostName = { LDAP_MOD_REPLACE, "dNSHostName", { vals_dNSHostName, } };
539d92
 		LDAPMod *mods[] = { &dNSHostName, NULL };
539d92
@@ -1220,7 +1228,7 @@ update_computer_account (adcli_enroll *enroll)
539d92
 		res |= update_computer_attribute (enroll, ldap, mods);
539d92
 	}
539d92
 
539d92
-	if (res == ADCLI_SUCCESS) {
539d92
+	if (res == ADCLI_SUCCESS && enroll->trusted_for_delegation_explicit) {
539d92
 		char *vals_userAccountControl[] = { NULL , NULL };
539d92
 		LDAPMod userAccountControl = { LDAP_MOD_REPLACE, "userAccountControl", { vals_userAccountControl, } };
539d92
 		LDAPMod *mods[] = { &userAccountControl, NULL };
539d92
@@ -1240,12 +1248,25 @@ update_computer_account (adcli_enroll *enroll)
539d92
 		LDAPMod operatingSystemVersion = { LDAP_MOD_REPLACE, "operatingSystemVersion", { vals_operatingSystemVersion, } };
539d92
 		char *vals_operatingSystemServicePack[] = { enroll->os_service_pack, NULL };
539d92
 		LDAPMod operatingSystemServicePack = { LDAP_MOD_REPLACE, "operatingSystemServicePack", { vals_operatingSystemServicePack, } };
539d92
-		LDAPMod *mods[] = { &operatingSystem, &operatingSystemVersion, &operatingSystemServicePack, NULL };
539d92
+		LDAPMod *mods[] = { NULL, NULL, NULL, NULL };
539d92
+		size_t c = 0;
539d92
 
539d92
-		res |= update_computer_attribute (enroll, ldap, mods);
539d92
+		if (enroll->os_name_explicit) {
539d92
+			mods[c++] = &operatingSystem;
539d92
+		}
539d92
+		if (enroll->os_version_explicit) {
539d92
+			mods[c++] = &operatingSystemVersion;
539d92
+		}
539d92
+		if (enroll->os_service_pack_explicit) {
539d92
+			mods[c++] = &operatingSystemServicePack;
539d92
+		}
539d92
+
539d92
+		if (c != 0) {
539d92
+			res |= update_computer_attribute (enroll, ldap, mods);
539d92
+		}
539d92
 	}
539d92
 
539d92
-	if (res == ADCLI_SUCCESS) {
539d92
+	if (res == ADCLI_SUCCESS && !enroll->user_princpal_generate) {
539d92
 		char *vals_userPrincipalName[] = { enroll->user_principal, NULL };
539d92
 		LDAPMod userPrincipalName = { LDAP_MOD_REPLACE, "userPrincipalName", { vals_userPrincipalName, }, };
539d92
 		LDAPMod *mods[] = { &userPrincipalName, NULL, };
539d92
@@ -2337,6 +2358,7 @@ adcli_enroll_set_os_name (adcli_enroll *enroll,
539d92
 	if (value && value[0] == '\0')
539d92
 		value = NULL;
539d92
 	_adcli_str_set (&enroll->os_name, value);
539d92
+	enroll->os_name_explicit = 1;
539d92
 }
539d92
 
539d92
 const char *
539d92
@@ -2354,6 +2376,7 @@ adcli_enroll_set_os_version (adcli_enroll *enroll,
539d92
 	if (value && value[0] == '\0')
539d92
 		value = NULL;
539d92
 	_adcli_str_set (&enroll->os_version, value);
539d92
+	enroll->os_version_explicit = 1;
539d92
 }
539d92
 
539d92
 const char *
539d92
@@ -2371,6 +2394,7 @@ adcli_enroll_set_os_service_pack (adcli_enroll *enroll,
539d92
 	if (value && value[0] == '\0')
539d92
 		value = NULL;
539d92
 	_adcli_str_set (&enroll->os_service_pack, value);
539d92
+	enroll->os_service_pack_explicit = 1;
539d92
 }
539d92
 
539d92
 const char *
539d92
@@ -2450,4 +2474,5 @@ adcli_enroll_set_trusted_for_delegation (adcli_enroll *enroll,
539d92
 	return_if_fail (enroll != NULL);
539d92
 
539d92
 	enroll->trusted_for_delegation = value;
539d92
+	enroll->trusted_for_delegation_explicit = 1;
539d92
 }
539d92
-- 
539d92
2.14.4
539d92