Blame SOURCES/0003-ldap_child-do-not-try-PKINIT.patch

213fc2
From 580d61884b6c0a81357d8f9fa69fe69d1f017185 Mon Sep 17 00:00:00 2001
213fc2
From: Sumit Bose <sbose@redhat.com>
213fc2
Date: Fri, 6 Dec 2019 12:29:49 +0100
213fc2
Subject: [PATCH] ldap_child: do not try PKINIT
213fc2
213fc2
if the PKINIT plugin is installed and pkinit_identities is set in
213fc2
/etc/krb5.conf libkrb5 will try to do PKINIT although ldap_child only
213fc2
wants to authenticate with a keytab. As a result ldap_child might try to
213fc2
access a Smartcard which is either not allowed at all or might cause
213fc2
unexpected delays.
213fc2
213fc2
To avoid this the current patch sets pkinit_identities for LDAP child
213fc2
explicitly to make the PKINIT plugin fail because if installed libkrb5
213fc2
will always use it.
213fc2
213fc2
It turned out the setting pre-authentication options requires some
213fc2
internal flags to be set and krb5_get_init_creds_opt_alloc() must be
213fc2
used to initialize the options struct.
213fc2
213fc2
Related to https://pagure.io/SSSD/sssd/issue/4126
213fc2
213fc2
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
213fc2
---
213fc2
 src/providers/ldap/ldap_child.c | 30 ++++++++++++++++++++++--------
213fc2
 1 file changed, 22 insertions(+), 8 deletions(-)
213fc2
213fc2
diff --git a/src/providers/ldap/ldap_child.c b/src/providers/ldap/ldap_child.c
213fc2
index 408d64db4..b081df90f 100644
213fc2
--- a/src/providers/ldap/ldap_child.c
213fc2
+++ b/src/providers/ldap/ldap_child.c
213fc2
@@ -277,7 +277,7 @@ static krb5_error_code ldap_child_get_tgt_sync(TALLOC_CTX *memctx,
213fc2
     krb5_ccache ccache = NULL;
213fc2
     krb5_principal kprinc;
213fc2
     krb5_creds my_creds;
213fc2
-    krb5_get_init_creds_opt options;
213fc2
+    krb5_get_init_creds_opt *options = NULL;
213fc2
     krb5_error_code krberr;
213fc2
     krb5_timestamp kdc_time_offset;
213fc2
     int canonicalize = 0;
213fc2
@@ -392,19 +392,32 @@ static krb5_error_code ldap_child_get_tgt_sync(TALLOC_CTX *memctx,
213fc2
     }
213fc2
 
213fc2
     memset(&my_creds, 0, sizeof(my_creds));
213fc2
-    memset(&options, 0, sizeof(options));
213fc2
 
213fc2
-    krb5_get_init_creds_opt_set_address_list(&options, NULL);
213fc2
-    krb5_get_init_creds_opt_set_forwardable(&options, 0);
213fc2
-    krb5_get_init_creds_opt_set_proxiable(&options, 0);
213fc2
-    krb5_get_init_creds_opt_set_tkt_life(&options, lifetime);
213fc2
+    krberr = krb5_get_init_creds_opt_alloc(context, &options);
213fc2
+    if (krberr != 0) {
213fc2
+        DEBUG(SSSDBG_OP_FAILURE, "krb5_get_init_creds_opt_alloc failed.\n");
213fc2
+        goto done;
213fc2
+    }
213fc2
+
213fc2
+    krb5_get_init_creds_opt_set_address_list(options, NULL);
213fc2
+    krb5_get_init_creds_opt_set_forwardable(options, 0);
213fc2
+    krb5_get_init_creds_opt_set_proxiable(options, 0);
213fc2
+    krb5_get_init_creds_opt_set_tkt_life(options, lifetime);
213fc2
+    krberr = krb5_get_init_creds_opt_set_pa(context, options,
213fc2
+                                            "X509_user_identity", "");
213fc2
+    if (krberr != 0) {
213fc2
+        DEBUG(SSSDBG_OP_FAILURE,
213fc2
+              "krb5_get_init_creds_opt_set_pa failed [%d], ignored.\n",
213fc2
+              krberr);
213fc2
+    }
213fc2
+
213fc2
 
213fc2
     tmp_str = getenv("KRB5_CANONICALIZE");
213fc2
     if (tmp_str != NULL && strcasecmp(tmp_str, "true") == 0) {
213fc2
         DEBUG(SSSDBG_CONF_SETTINGS, "Will canonicalize principals\n");
213fc2
         canonicalize = 1;
213fc2
     }
213fc2
-    sss_krb5_get_init_creds_opt_set_canonicalize(&options, canonicalize);
213fc2
+    sss_krb5_get_init_creds_opt_set_canonicalize(options, canonicalize);
213fc2
 
213fc2
     ccname_file = talloc_asprintf(tmp_ctx, "%s/ccache_%s",
213fc2
                                   DB_PATH, realm_name);
213fc2
@@ -433,7 +446,7 @@ static krb5_error_code ldap_child_get_tgt_sync(TALLOC_CTX *memctx,
213fc2
     }
213fc2
 
213fc2
     krberr = krb5_get_init_creds_keytab(context, &my_creds, kprinc,
213fc2
-                                        keytab, 0, NULL, &options);
213fc2
+                                        keytab, 0, NULL, options);
213fc2
     if (krberr != 0) {
213fc2
         DEBUG(SSSDBG_OP_FAILURE,
213fc2
               "krb5_get_init_creds_keytab() failed: %d\n", krberr);
213fc2
@@ -513,6 +526,7 @@ static krb5_error_code ldap_child_get_tgt_sync(TALLOC_CTX *memctx,
213fc2
     *expire_time_out = my_creds.times.endtime - kdc_time_offset;
213fc2
 
213fc2
 done:
213fc2
+    krb5_get_init_creds_opt_free(context, options);
213fc2
     if (krberr != 0) {
213fc2
         if (*_krb5_msg == NULL) {
213fc2
             /* no custom error message provided hence get one from libkrb5 */
213fc2
-- 
213fc2
2.20.1
213fc2