Blame SOURCES/0005-join-add-all-attributes-while-creating-computer-obje.patch

59dcbd
From e9198751411d11785ac6e7e533d63911b6e51326 Mon Sep 17 00:00:00 2001
59dcbd
From: Sumit Bose <sbose@redhat.com>
59dcbd
Date: Mon, 11 Jun 2018 09:44:49 +0200
59dcbd
Subject: [PATCH 5/7] join: add all attributes while creating computer object
59dcbd
59dcbd
It is possible to create special accounts which can only join a computer
59dcbd
to a domain but is not allowed to do any further operations which the
59dcbd
computer object. As a result if such an account is used during the join
59dcbd
only the ldapadd operation is permitted but not any later ldapmodify
59dcbd
operation. To create the computer object correctly in this case all
59dcbd
attributes must be added while the object is created and not later.
59dcbd
59dcbd
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1542354
59dcbd
---
59dcbd
 library/adenroll.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++-----
59dcbd
 1 file changed, 47 insertions(+), 5 deletions(-)
59dcbd
59dcbd
diff --git a/library/adenroll.c b/library/adenroll.c
59dcbd
index 1ed94f2..3f8d017 100644
59dcbd
--- a/library/adenroll.c
59dcbd
+++ b/library/adenroll.c
59dcbd
@@ -573,7 +573,7 @@ calculate_enctypes (adcli_enroll *enroll, char **enctype)
59dcbd
 	is_2008_or_later = adcli_conn_server_has_capability (enroll->conn, ADCLI_CAP_V60_OID);
59dcbd
 
59dcbd
 	/* In 2008 or later, use the msDS-supportedEncryptionTypes attribute */
59dcbd
-	if (is_2008_or_later) {
59dcbd
+	if (is_2008_or_later && enroll->computer_attributes != NULL) {
59dcbd
 		value = _adcli_ldap_parse_value (ldap, enroll->computer_attributes,
59dcbd
 		                                 "msDS-supportedEncryptionTypes");
59dcbd
 
59dcbd
@@ -618,7 +618,6 @@ calculate_enctypes (adcli_enroll *enroll, char **enctype)
59dcbd
 	return ADCLI_SUCCESS;
59dcbd
 }
59dcbd
 
59dcbd
-
59dcbd
 static adcli_result
59dcbd
 create_computer_account (adcli_enroll *enroll,
59dcbd
                          LDAP *ldap)
59dcbd
@@ -628,22 +627,65 @@ create_computer_account (adcli_enroll *enroll,
59dcbd
 	char *vals_sAMAccountName[] = { enroll->computer_sam, NULL };
59dcbd
 	LDAPMod sAMAccountName = { LDAP_MOD_ADD, "sAMAccountName", { vals_sAMAccountName, } };
59dcbd
 	char *vals_userAccountControl[] = { "69632", NULL }; /* WORKSTATION_TRUST_ACCOUNT | DONT_EXPIRE_PASSWD */
59dcbd
-	LDAPMod userAccountControl = { LDAP_MOD_REPLACE, "userAccountControl", { vals_userAccountControl, } };
59dcbd
+	LDAPMod userAccountControl = { LDAP_MOD_ADD, "userAccountControl", { vals_userAccountControl, } };
59dcbd
+	char *vals_supportedEncryptionTypes[] = { NULL, NULL };
59dcbd
+	LDAPMod encTypes = { LDAP_MOD_ADD, "msDS-supportedEncryptionTypes", { vals_supportedEncryptionTypes, } };
59dcbd
+	char *vals_dNSHostName[] = { enroll->host_fqdn, NULL };
59dcbd
+	LDAPMod dNSHostName = { LDAP_MOD_ADD, "dNSHostName", { vals_dNSHostName, } };
59dcbd
+	char *vals_operatingSystem[] = { enroll->os_name, NULL };
59dcbd
+	LDAPMod operatingSystem = { LDAP_MOD_ADD, "operatingSystem", { vals_operatingSystem, } };
59dcbd
+	char *vals_operatingSystemVersion[] = { enroll->os_version, NULL };
59dcbd
+	LDAPMod operatingSystemVersion = { LDAP_MOD_ADD, "operatingSystemVersion", { vals_operatingSystemVersion, } };
59dcbd
+	char *vals_operatingSystemServicePack[] = { enroll->os_service_pack, NULL };
59dcbd
+	LDAPMod operatingSystemServicePack = { LDAP_MOD_ADD, "operatingSystemServicePack", { vals_operatingSystemServicePack, } };
59dcbd
+	char *vals_userPrincipalName[] = { enroll->user_principal, NULL };
59dcbd
+	LDAPMod userPrincipalName = { LDAP_MOD_ADD, "userPrincipalName", { vals_userPrincipalName, }, };
59dcbd
+	LDAPMod servicePrincipalName = { LDAP_MOD_ADD, "servicePrincipalName", { enroll->service_principals, } };
59dcbd
+
59dcbd
+	char *val = NULL;
59dcbd
 
59dcbd
 	int ret;
59dcbd
+	size_t c;
59dcbd
+	size_t m;
59dcbd
 
59dcbd
-	LDAPMod *mods[] = {
59dcbd
+	LDAPMod *all_mods[] = {
59dcbd
 		&objectClass,
59dcbd
 		&sAMAccountName,
59dcbd
 		&userAccountControl,
59dcbd
-		NULL,
59dcbd
+		&encTypes,
59dcbd
+		&dNSHostName,
59dcbd
+		&operatingSystem,
59dcbd
+		&operatingSystemVersion,
59dcbd
+		&operatingSystemServicePack,
59dcbd
+		&userPrincipalName,
59dcbd
+		&servicePrincipalName,
59dcbd
+		NULL
59dcbd
 	};
59dcbd
 
59dcbd
+	size_t mods_count = sizeof (all_mods) / sizeof (LDAPMod *);
59dcbd
+	LDAPMod *mods[mods_count];
59dcbd
+
59dcbd
 	if (adcli_enroll_get_trusted_for_delegation (enroll)) {
59dcbd
 		vals_userAccountControl[0] = "593920"; /* WORKSTATION_TRUST_ACCOUNT | DONT_EXPIRE_PASSWD | TRUSTED_FOR_DELEGATION */
59dcbd
 	}
59dcbd
 
59dcbd
+	ret = calculate_enctypes (enroll, &val;;
59dcbd
+	if (ret != ADCLI_SUCCESS) {
59dcbd
+		return ret;
59dcbd
+	}
59dcbd
+	vals_supportedEncryptionTypes[0] = val;
59dcbd
+
59dcbd
+	m = 0;
59dcbd
+	for (c = 0; c < mods_count - 1; c++) {
59dcbd
+		/* Skip empty LDAP sttributes */
59dcbd
+		if (all_mods[c]->mod_vals.modv_strvals[0] != NULL) {
59dcbd
+			mods[m++] = all_mods[c];
59dcbd
+		}
59dcbd
+	}
59dcbd
+	mods[m] = NULL;
59dcbd
+
59dcbd
 	ret = ldap_add_ext_s (ldap, enroll->computer_dn, mods, NULL, NULL);
59dcbd
+	free (val);
59dcbd
 
59dcbd
 	/*
59dcbd
 	 * Hand to head. This is really dumb... AD returns
59dcbd
-- 
59dcbd
2.14.4
59dcbd