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

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