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

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