pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0178-ipa-kdb-add-pkinit-authentication-indicator-in-case-.patch

483b06
From 5e052107dcb70630c1cccee191ae5317a43ec2cf Mon Sep 17 00:00:00 2001
483b06
From: Alexander Bokovoy <abokovoy@redhat.com>
483b06
Date: Sun, 4 Jun 2017 22:49:13 +0300
483b06
Subject: [PATCH] ipa-kdb: add pkinit authentication indicator in case of a
483b06
 successful certauth
483b06
483b06
We automatically add 'otp' and 'radius' authentication indicators when
483b06
pre-authentication with OTP or RADIUS did succeed. Do the same for
483b06
certauth-based pre-authentication (PKINIT).
483b06
483b06
A default PKINIT configuration does not add any authentication
483b06
indicators unless 'pkinit_indicator = pkinit' is set in kdc.conf.
483b06
Unfortunately, modifying kdc.conf automatically is a bit more
483b06
complicated than modifying krb5.conf. Given that we have 'otp' and
483b06
'radius' authentication indicators also defined in the code not in the
483b06
kdc.conf, this change is following an established trend.
483b06
483b06
SSSD certauth interface does not provide additional information about
483b06
which rule(s) succeeded in matching the incoming certificate. Thus,
483b06
there is not much information we can automatically provide in the
483b06
indicator. It would be good to generate indicators that include some
483b06
information from the certmapping rules in future but for now a single
483b06
'pkinit' indicator is enough.
483b06
483b06
Fixes https://pagure.io/freeipa/issue/6736
483b06
483b06
Reviewed-By: Simo Sorce <ssorce@redhat.com>
483b06
---
483b06
 daemons/ipa-kdb/ipa_kdb_certauth.c | 36 ++++++++++++++++++++++++++++++++++--
483b06
 1 file changed, 34 insertions(+), 2 deletions(-)
483b06
483b06
diff --git a/daemons/ipa-kdb/ipa_kdb_certauth.c b/daemons/ipa-kdb/ipa_kdb_certauth.c
483b06
index dbe7a0443700784d2b8dbb1fb9196d6249e5522a..da9a9cb87feca68ee591da70a3239dc86749bae5 100644
483b06
--- a/daemons/ipa-kdb/ipa_kdb_certauth.c
483b06
+++ b/daemons/ipa-kdb/ipa_kdb_certauth.c
483b06
@@ -267,6 +267,7 @@ static krb5_error_code ipa_certauth_authorize(krb5_context context,
483b06
     int ret;
483b06
     size_t c;
483b06
     char *principal = NULL;
483b06
+    char **auth_inds = NULL;
483b06
     LDAPMessage *res = NULL;
483b06
     krb5_error_code kerr;
483b06
     LDAPMessage *lentry;
483b06
@@ -350,6 +351,20 @@ static krb5_error_code ipa_certauth_authorize(krb5_context context,
483b06
         goto done;
483b06
     }
483b06
 
483b06
+    /* Associate authentication indicator "pkinit" with the successful match.
483b06
+     * SSSD interface doesn't give us a clue which rule did match
483b06
+     * so there is nothing more to add here. */
483b06
+    auth_inds = calloc(2, sizeof(char *));
483b06
+    if (auth_inds != NULL) {
483b06
+	ret = asprintf(&auth_inds[0], "pkinit");
483b06
+	if (ret != -1) {
483b06
+            auth_inds[1] = NULL;
483b06
+            *authinds_out = auth_inds;
483b06
+	} else {
483b06
+	    free(auth_inds);
483b06
+        }
483b06
+    }
483b06
+
483b06
     /* TODO: add more tests ? */
483b06
 
483b06
     ret = 0;
483b06
@@ -384,6 +399,24 @@ static void ipa_certauth_fini(krb5_context context,
483b06
     return;
483b06
 }
483b06
 
483b06
+static void ipa_certauth_free_indicator(krb5_context context,
483b06
+                                        krb5_certauth_moddata moddata,
483b06
+                                        char **authinds)
483b06
+{
483b06
+    size_t i = 0;
483b06
+
483b06
+    if ((authinds == NULL) || (moddata == NULL)) {
483b06
+	return;
483b06
+    }
483b06
+
483b06
+    for(i=0; authinds[i]; i++) {
483b06
+	free(authinds[i]);
483b06
+	authinds[i] = NULL;
483b06
+    }
483b06
+
483b06
+    free(authinds);
483b06
+}
483b06
+
483b06
 
483b06
 krb5_error_code certauth_ipakdb_initvt(krb5_context context,
483b06
                                           int maj_ver, int min_ver,
483b06
@@ -401,7 +434,6 @@ krb5_error_code certauth_ipakdb_initvt(krb5_context context,
483b06
     vt->authorize = ipa_certauth_authorize;
483b06
     vt->init = ipa_certauth_init;
483b06
     vt->fini = ipa_certauth_fini;
483b06
-    /* currently we do not return authentication indicators */
483b06
-    vt->free_ind = NULL;
483b06
+    vt->free_ind = ipa_certauth_free_indicator;
483b06
     return 0;
483b06
 }
483b06
-- 
483b06
2.9.4
483b06