Blame SOURCES/0004-Calculate-enctypes-in-a-separate-function.patch

776d17
From 8d36c3e07a6efc65aadd218c28e2f864db15b7fd Mon Sep 17 00:00:00 2001
776d17
From: Sumit Bose <sbose@redhat.com>
776d17
Date: Wed, 6 Jun 2018 16:31:32 +0200
776d17
Subject: [PATCH 4/7] Calculate enctypes in a separate function
776d17
776d17
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1542354
776d17
---
776d17
 library/adenroll.c | 137 +++++++++++++++++++++++++++++++----------------------
776d17
 1 file changed, 81 insertions(+), 56 deletions(-)
776d17
776d17
diff --git a/library/adenroll.c b/library/adenroll.c
776d17
index 1221e89..1ed94f2 100644
776d17
--- a/library/adenroll.c
776d17
+++ b/library/adenroll.c
776d17
@@ -542,6 +542,83 @@ calculate_computer_account (adcli_enroll *enroll,
776d17
 	return ADCLI_SUCCESS;
776d17
 }
776d17
 
776d17
+static adcli_result
776d17
+calculate_enctypes (adcli_enroll *enroll, char **enctype)
776d17
+{
776d17
+	char *value = NULL;
776d17
+	krb5_enctype *read_enctypes;
776d17
+	char *new_value = NULL;
776d17
+	int is_2008_or_later;
776d17
+	LDAP *ldap;
776d17
+
776d17
+	*enctype = NULL;
776d17
+	/*
776d17
+	 * Because we're using a keytab we want the server to be aware of the
776d17
+	 * encryption types supported on the client, because we can't dynamically
776d17
+	 * use a new one that's thrown at us.
776d17
+	 *
776d17
+	 * If the encryption types are not explicitly set by the caller of this
776d17
+	 * library, then see if the account already has some encryption types
776d17
+	 * marked on it.
776d17
+	 *
776d17
+	 * If not, write our default set to the account.
776d17
+	 *
776d17
+	 * Note that Windows 2003 and earlier have a standard set of encryption
776d17
+	 * types, and no msDS-supportedEncryptionTypes attribute.
776d17
+	 */
776d17
+
776d17
+	ldap = adcli_conn_get_ldap_connection (enroll->conn);
776d17
+	return_unexpected_if_fail (ldap != NULL);
776d17
+
776d17
+	is_2008_or_later = adcli_conn_server_has_capability (enroll->conn, ADCLI_CAP_V60_OID);
776d17
+
776d17
+	/* In 2008 or later, use the msDS-supportedEncryptionTypes attribute */
776d17
+	if (is_2008_or_later) {
776d17
+		value = _adcli_ldap_parse_value (ldap, enroll->computer_attributes,
776d17
+		                                 "msDS-supportedEncryptionTypes");
776d17
+
776d17
+		if (!enroll->keytab_enctypes_explicit && value != NULL) {
776d17
+			read_enctypes = _adcli_krb5_parse_enctypes (value);
776d17
+			if (read_enctypes == NULL) {
776d17
+				_adcli_warn ("Invalid or unsupported encryption types are set on "
776d17
+				             "the computer account (%s).", value);
776d17
+			} else {
776d17
+				free (enroll->keytab_enctypes);
776d17
+				enroll->keytab_enctypes = read_enctypes;
776d17
+			}
776d17
+		}
776d17
+
776d17
+	/* In 2003 or earlier, standard set of enc types */
776d17
+	} else {
776d17
+		value = _adcli_krb5_format_enctypes (v51_earlier_enctypes);
776d17
+	}
776d17
+
776d17
+	new_value = _adcli_krb5_format_enctypes (adcli_enroll_get_keytab_enctypes (enroll));
776d17
+	if (new_value == NULL) {
776d17
+		free (value);
776d17
+		_adcli_warn ("The encryption types desired are not available in active directory");
776d17
+		return ADCLI_ERR_CONFIG;
776d17
+	}
776d17
+
776d17
+	/* If we already have this value, then don't need to update */
776d17
+	if (value && strcmp (new_value, value) == 0) {
776d17
+		free (value);
776d17
+		free (new_value);
776d17
+		return ADCLI_SUCCESS;
776d17
+	}
776d17
+	free (value);
776d17
+
776d17
+	if (!is_2008_or_later) {
776d17
+		free (new_value);
776d17
+		_adcli_warn ("Server does not support setting encryption types");
776d17
+		return ADCLI_SUCCESS;
776d17
+	}
776d17
+
776d17
+	*enctype = new_value;
776d17
+	return ADCLI_SUCCESS;
776d17
+}
776d17
+
776d17
+
776d17
 static adcli_result
776d17
 create_computer_account (adcli_enroll *enroll,
776d17
                          LDAP *ldap)
776d17
@@ -1053,75 +1130,23 @@ retrieve_computer_account (adcli_enroll *enroll)
776d17
 static adcli_result
776d17
 update_and_calculate_enctypes (adcli_enroll *enroll)
776d17
 {
776d17
-	char *value = NULL;
776d17
-	krb5_enctype *read_enctypes;
776d17
 	char *vals_supportedEncryptionTypes[] = { NULL, NULL };
776d17
 	LDAPMod mod = { LDAP_MOD_REPLACE, "msDS-supportedEncryptionTypes", { vals_supportedEncryptionTypes, } };
776d17
 	LDAPMod *mods[2] = { &mod, NULL };
776d17
-	int is_2008_or_later;
776d17
 	char *new_value;
776d17
 	LDAP *ldap;
776d17
 	int ret;
776d17
 
776d17
-	/*
776d17
-	 * Because we're using a keytab we want the server to be aware of the
776d17
-	 * encryption types supported on the client, because we can't dynamically
776d17
-	 * use a new one that's thrown at us.
776d17
-	 *
776d17
-	 * If the encryption types are not explicitly set by the caller of this
776d17
-	 * library, then see if the account already has some encryption types
776d17
-	 * marked on it.
776d17
-	 *
776d17
-	 * If not, write our default set to the account.
776d17
-	 *
776d17
-	 * Note that Windows 2003 and earlier have a standard set of encryption
776d17
-	 * types, and no msDS-supportedEncryptionTypes attribute.
776d17
-	 */
776d17
-
776d17
 	ldap = adcli_conn_get_ldap_connection (enroll->conn);
776d17
 	return_unexpected_if_fail (ldap != NULL);
776d17
 
776d17
-	is_2008_or_later = adcli_conn_server_has_capability (enroll->conn, ADCLI_CAP_V60_OID);
776d17
-
776d17
-	/* In 2008 or later, use the msDS-supportedEncryptionTypes attribute */
776d17
-	if (is_2008_or_later) {
776d17
-		value = _adcli_ldap_parse_value (ldap, enroll->computer_attributes,
776d17
-		                                 "msDS-supportedEncryptionTypes");
776d17
-
776d17
-		if (!enroll->keytab_enctypes_explicit && value != NULL) {
776d17
-			read_enctypes = _adcli_krb5_parse_enctypes (value);
776d17
-			if (read_enctypes == NULL) {
776d17
-				_adcli_warn ("Invalid or unsupported encryption types are set on "
776d17
-				             "the computer account (%s).", value);
776d17
-			} else {
776d17
-				free (enroll->keytab_enctypes);
776d17
-				enroll->keytab_enctypes = read_enctypes;
776d17
-			}
776d17
-		}
776d17
-
776d17
-	/* In 2003 or earlier, standard set of enc types */
776d17
-	} else {
776d17
-		value = _adcli_krb5_format_enctypes (v51_earlier_enctypes);
776d17
-	}
776d17
-
776d17
-	new_value = _adcli_krb5_format_enctypes (adcli_enroll_get_keytab_enctypes (enroll));
776d17
-	if (new_value == NULL) {
776d17
-		free (value);
776d17
-		_adcli_warn ("The encryption types desired are not available in active directory");
776d17
-		return ADCLI_ERR_CONFIG;
776d17
-	}
776d17
-
776d17
-	/* If we already have this value, then don't need to update */
776d17
-	if (value && strcmp (new_value, value) == 0) {
776d17
-		free (value);
776d17
+	ret = calculate_enctypes (enroll, &new_value);
776d17
+	if (ret != ADCLI_SUCCESS) {
776d17
 		free (new_value);
776d17
-		return ADCLI_SUCCESS;
776d17
+		return ret;
776d17
 	}
776d17
-	free (value);
776d17
 
776d17
-	if (!is_2008_or_later) {
776d17
-		free (new_value);
776d17
-		_adcli_warn ("Server does not support setting encryption types");
776d17
+	if (new_value == NULL) {
776d17
 		return ADCLI_SUCCESS;
776d17
 	}
776d17
 
776d17
-- 
776d17
2.14.4
776d17