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

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