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

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