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

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