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

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