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

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