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

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