Blame SOURCES/0004-adenroll-use-only-enctypes-permitted-by-Kerberos-con.patch

f441eb
From cc3ef52884a48863a81acbfc741735fe09cd85f7 Mon Sep 17 00:00:00 2001
f441eb
From: Sumit Bose <sbose@redhat.com>
f441eb
Date: Thu, 13 Jun 2019 18:27:49 +0200
f441eb
Subject: [PATCH 4/4] adenroll: use only enctypes permitted by Kerberos config
f441eb
f441eb
Realted to https://gitlab.freedesktop.org/realmd/adcli/issues/3
f441eb
---
f441eb
 doc/adcli.xml      | 10 ++++++++++
f441eb
 library/adenroll.c | 22 +++++++++++++++++++---
f441eb
 2 files changed, 29 insertions(+), 3 deletions(-)
f441eb
f441eb
diff --git a/doc/adcli.xml b/doc/adcli.xml
f441eb
index 9605b4a..094f577 100644
f441eb
--- a/doc/adcli.xml
f441eb
+++ b/doc/adcli.xml
f441eb
@@ -342,6 +342,11 @@ Password for Administrator:
f441eb
 		</varlistentry>
f441eb
 	</variablelist>
f441eb
 
f441eb
+	<para>If supported on the AD side the
f441eb
+	<option>msDS-supportedEncryptionTypes</option> attribute will be set as
f441eb
+	well. Either the current value or the default list of AD's supported
f441eb
+	encryption types filtered by the permitted encryption types of the
f441eb
+	client's Kerberos configuration are written.</para>
f441eb
 </refsect1>
f441eb
 
f441eb
 <refsect1 id='updating'>
f441eb
@@ -475,6 +480,11 @@ $ adcli update --login-ccache=/tmp/krbcc_123
f441eb
 		</varlistentry>
f441eb
 	</variablelist>
f441eb
 
f441eb
+	<para>If supported on the AD side the
f441eb
+	<option>msDS-supportedEncryptionTypes</option> attribute will be set as
f441eb
+	well. Either the current value or the default list of AD's supported
f441eb
+	encryption types filtered by the permitted encryption types of the
f441eb
+	client's Kerberos configuration are written.</para>
f441eb
 </refsect1>
f441eb
 
f441eb
 <refsect1 id='testjoin'>
f441eb
diff --git a/library/adenroll.c b/library/adenroll.c
f441eb
index 95c07cd..53cd812 100644
f441eb
--- a/library/adenroll.c
f441eb
+++ b/library/adenroll.c
f441eb
@@ -639,6 +639,7 @@ calculate_enctypes (adcli_enroll *enroll, char **enctype)
f441eb
 {
f441eb
 	char *value = NULL;
f441eb
 	krb5_enctype *read_enctypes;
f441eb
+	krb5_enctype *new_enctypes;
f441eb
 	char *new_value = NULL;
f441eb
 	int is_2008_or_later;
f441eb
 	LDAP *ldap;
f441eb
@@ -685,7 +686,14 @@ calculate_enctypes (adcli_enroll *enroll, char **enctype)
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
+	new_enctypes = adcli_enroll_get_permitted_keytab_enctypes (enroll);
f441eb
+	if (new_enctypes == NULL) {
f441eb
+		_adcli_warn ("No permitted encryption type found.");
f441eb
+		return ADCLI_ERR_UNEXPECTED;
f441eb
+	}
f441eb
+
f441eb
+	new_value = _adcli_krb5_format_enctypes (new_enctypes);
f441eb
+	krb5_free_enctypes (adcli_conn_get_krb5_context (enroll->conn), new_enctypes);
f441eb
 	if (new_value == NULL) {
f441eb
 		free (value);
f441eb
 		_adcli_warn ("The encryption types desired are not available in active directory");
f441eb
@@ -1758,7 +1766,11 @@ add_principal_to_keytab (adcli_enroll *enroll,
f441eb
 		             enroll->keytab_name);
f441eb
 	}
f441eb
 
f441eb
-	enctypes = adcli_enroll_get_keytab_enctypes (enroll);
f441eb
+	enctypes = adcli_enroll_get_permitted_keytab_enctypes (enroll);
f441eb
+	if (enctypes == NULL) {
f441eb
+		_adcli_warn ("No permitted encryption type found.");
f441eb
+		return ADCLI_ERR_UNEXPECTED;
f441eb
+	}
f441eb
 
f441eb
 	if (flags & ADCLI_ENROLL_PASSWORD_VALID) {
f441eb
 		code = _adcli_krb5_keytab_copy_entries (k5, enroll->keytab, principal,
f441eb
@@ -1774,7 +1786,10 @@ add_principal_to_keytab (adcli_enroll *enroll,
f441eb
 		 */
f441eb
 
f441eb
 		salts = build_principal_salts (enroll, k5, principal);
f441eb
-		return_unexpected_if_fail (salts != NULL);
f441eb
+		if (salts == NULL) {
f441eb
+			krb5_free_enctypes (k5, enctypes);
f441eb
+			return ADCLI_ERR_UNEXPECTED;
f441eb
+		}
f441eb
 
f441eb
 		if (*which_salt < 0) {
f441eb
 			code = _adcli_krb5_keytab_discover_salt (k5, principal, enroll->kvno, &password,
f441eb
@@ -1794,6 +1809,7 @@ add_principal_to_keytab (adcli_enroll *enroll,
f441eb
 
f441eb
 		free_principal_salts (k5, salts);
f441eb
 	}
f441eb
+	krb5_free_enctypes (k5, enctypes);
f441eb
 
f441eb
 	if (code != 0) {
f441eb
 		_adcli_err ("Couldn't add keytab entries: %s: %s",
f441eb
-- 
f441eb
2.21.0
f441eb