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