zrhoffman / rpms / 389-ds-base

Forked from rpms/389-ds-base 3 years ago
Clone

Blame SOURCES/0002-Ticket-49165-pw_verify-did-not-handle-external-auth.patch

6f51e1
From 22f1ff8d87a7daf9fbbe2ddfbd195a6bfdae1cd6 Mon Sep 17 00:00:00 2001
6f51e1
From: William Brown <firstyear@redhat.com>
6f51e1
Date: Tue, 14 Mar 2017 14:01:33 +1000
6f51e1
Subject: [PATCH 3/5] Ticket 49165 pw_verify did not handle external auth
6f51e1
6f51e1
Bug Description:  During the change to improve sasl and simple bind,
6f51e1
we externalised the backend selection outside of do_bind. In an
6f51e1
auto_bind scenario however, this mean the be was null, causing the
6f51e1
dn to always be invalidated.
6f51e1
6f51e1
Fix Description:  Add a pw_validate_be_dn function, that correctly
6f51e1
checks if we are anonymous, a real be dn, or rootdn. This then allows
6f51e1
the correct authentication of autobinds.
6f51e1
6f51e1
https://pagure.io/389-ds-base/issue/49165
6f51e1
6f51e1
Author: wibrown
6f51e1
6f51e1
Review by: mreynolds (Thanks!)
6f51e1
6f51e1
(cherry picked from commit 8dbfff1ff4152afb018490886a612c448ea2a1b0)
6f51e1
---
6f51e1
 ldap/servers/slapd/bind.c         |  9 +++++--
6f51e1
 ldap/servers/slapd/dn.c           |  5 ++++
6f51e1
 ldap/servers/slapd/pw_verify.c    | 57 +++++++++++++++++++++++++++++++++++++--
6f51e1
 ldap/servers/slapd/pw_verify.h    |  1 +
6f51e1
 ldap/servers/slapd/slapi-plugin.h |  9 +++++++
6f51e1
 5 files changed, 77 insertions(+), 4 deletions(-)
6f51e1
6f51e1
diff --git a/ldap/servers/slapd/bind.c b/ldap/servers/slapd/bind.c
6f51e1
index b4bb363..5c4fada 100644
6f51e1
--- a/ldap/servers/slapd/bind.c
6f51e1
+++ b/ldap/servers/slapd/bind.c
6f51e1
@@ -656,7 +656,12 @@ do_bind( Slapi_PBlock *pb )
6f51e1
         /* We could be serving multiple database backends.  Select the appropriate one */
6f51e1
         /* pw_verify_be_dn will select the backend we need for us. */
6f51e1
 
6f51e1
-        rc = pw_verify_be_dn(pb, &referral);
6f51e1
+        if (auto_bind) {
6f51e1
+            /* We have no password material. We should just check who we are binding as. */
6f51e1
+            rc = pw_validate_be_dn(pb, &referral);
6f51e1
+        } else {
6f51e1
+            rc = pw_verify_be_dn(pb, &referral);
6f51e1
+        }
6f51e1
 
6f51e1
         if (rc == SLAPI_BIND_NO_BACKEND) {
6f51e1
             send_nobackend_ldap_result( pb );
6f51e1
@@ -715,7 +720,7 @@ do_bind( Slapi_PBlock *pb )
6f51e1
                  *
6f51e1
                  */
6f51e1
                 slapi_pblock_get(pb, SLAPI_BACKEND, &be);
6f51e1
-                if (!slapi_be_is_flag_set(be, SLAPI_BE_FLAG_REMOTE_DATA)) {
6f51e1
+                if (!isroot && !slapi_be_is_flag_set(be, SLAPI_BE_FLAG_REMOTE_DATA)) {
6f51e1
                     bind_target_entry = get_entry(pb, slapi_sdn_get_ndn(sdn));
6f51e1
                     myrc = slapi_check_account_lock(pb, bind_target_entry, pw_response_requested, 1, 1);
6f51e1
                     if (1 == myrc) { /* account is locked */
6f51e1
diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c
6f51e1
index d043f2a..fa3909f 100644
6f51e1
--- a/ldap/servers/slapd/dn.c
6f51e1
+++ b/ldap/servers/slapd/dn.c
6f51e1
@@ -1738,6 +1738,11 @@ slapi_dn_isroot( const char *dn )
6f51e1
 	return( rc );
6f51e1
 }
6f51e1
 
6f51e1
+int32_t
6f51e1
+slapi_sdn_isroot(const Slapi_DN *sdn) {
6f51e1
+    return slapi_dn_isroot(slapi_sdn_get_ndn(sdn));
6f51e1
+}
6f51e1
+
6f51e1
 int
6f51e1
 slapi_is_rootdse( const char *dn )
6f51e1
 {
6f51e1
diff --git a/ldap/servers/slapd/pw_verify.c b/ldap/servers/slapd/pw_verify.c
6f51e1
index 93e5ff3..529bb83 100644
6f51e1
--- a/ldap/servers/slapd/pw_verify.c
6f51e1
+++ b/ldap/servers/slapd/pw_verify.c
6f51e1
@@ -88,8 +88,61 @@ pw_verify_be_dn(Slapi_PBlock *pb, Slapi_Entry **referral)
6f51e1
     return rc;
6f51e1
 }
6f51e1
 
6f51e1
+/*
6f51e1
+ * Resolve the dn we have been requested to bind with and verify it's
6f51e1
+ * valid, and has a backend.
6f51e1
+ *
6f51e1
+ * We are checking:
6f51e1
+ * * is this anonymous?
6f51e1
+ * * is this the rootdn?
6f51e1
+ * * is this a real dn, which associates to a real backend.
6f51e1
+ *
6f51e1
+ * This is used in SASL autobinds, so we need to handle this validation.
6f51e1
+ */
6f51e1
+
6f51e1
 int
6f51e1
-pw_verify_dn()
6f51e1
+pw_validate_be_dn(Slapi_PBlock *pb, Slapi_Entry **referral)
6f51e1
 {
6f51e1
-    return LDAP_OPERATIONS_ERROR;
6f51e1
+    int rc = 0;
6f51e1
+    Slapi_Backend *be = NULL;
6f51e1
+    Slapi_DN *pb_sdn;
6f51e1
+    struct berval *cred;
6f51e1
+    ber_tag_t method;
6f51e1
+
6f51e1
+
6f51e1
+    slapi_pblock_get(pb, SLAPI_BIND_TARGET_SDN, &pb_sdn);
6f51e1
+    slapi_pblock_get(pb, SLAPI_BIND_CREDENTIALS, &cred);
6f51e1
+    slapi_pblock_get(pb, SLAPI_BIND_METHOD, &method);
6f51e1
+
6f51e1
+    if (pb_sdn != NULL || cred != NULL) {
6f51e1
+        return LDAP_OPERATIONS_ERROR;
6f51e1
+    }
6f51e1
+
6f51e1
+    if (*referral) {
6f51e1
+        return SLAPI_BIND_REFERRAL;
6f51e1
+    }
6f51e1
+
6f51e1
+    /* We need a slapi_sdn_isanon? */
6f51e1
+    if (method == LDAP_AUTH_SIMPLE && cred->bv_len == 0) {
6f51e1
+        return SLAPI_BIND_ANONYMOUS;
6f51e1
+    }
6f51e1
+
6f51e1
+    if (slapi_sdn_isroot(pb_sdn)) {
6f51e1
+        /* This is a real identity */
6f51e1
+        return SLAPI_BIND_SUCCESS;
6f51e1
+    }
6f51e1
+
6f51e1
+    if (slapi_mapping_tree_select(pb, &be, referral, NULL, 0) != LDAP_SUCCESS) {
6f51e1
+        return SLAPI_BIND_NO_BACKEND;
6f51e1
+    }
6f51e1
+    slapi_be_Unlock(be);
6f51e1
+
6f51e1
+    slapi_pblock_set(pb, SLAPI_BACKEND, be);
6f51e1
+    slapi_pblock_set(pb, SLAPI_PLUGIN, be->be_database);
6f51e1
+    /* Make sure the result handlers are setup */
6f51e1
+    set_db_default_result_handlers(pb);
6f51e1
+
6f51e1
+    /* The backend associated with this identity is real. */
6f51e1
+
6f51e1
+    return SLAPI_BIND_SUCCESS;
6f51e1
 }
6f51e1
diff --git a/ldap/servers/slapd/pw_verify.h b/ldap/servers/slapd/pw_verify.h
6f51e1
index fc34fd1..5137027 100644
6f51e1
--- a/ldap/servers/slapd/pw_verify.h
6f51e1
+++ b/ldap/servers/slapd/pw_verify.h
6f51e1
@@ -11,5 +11,6 @@
6f51e1
 
6f51e1
 int pw_verify_root_dn(const char *dn, const Slapi_Value *cred);
6f51e1
 int pw_verify_be_dn(Slapi_PBlock *pb, Slapi_Entry **referral);
6f51e1
+int pw_validate_be_dn(Slapi_PBlock *pb, Slapi_Entry **referral);
6f51e1
 
6f51e1
 #endif /* _SLAPD_PW_VERIFY_H_ */
6f51e1
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
6f51e1
index b223f65..1bd8fc8 100644
6f51e1
--- a/ldap/servers/slapd/slapi-plugin.h
6f51e1
+++ b/ldap/servers/slapd/slapi-plugin.h
6f51e1
@@ -3800,6 +3800,15 @@ int slapi_dn_isparent( const char *parentdn, const char *childdn );
6f51e1
 int slapi_dn_isroot( const char *dn );
6f51e1
 
6f51e1
 /**
6f51e1
+ * Determines if an SDN is the root DN.
6f51e1
+ *
6f51e1
+ * \param sdn The DN to check
6f51e1
+ * \return \c 1 if the DN is the root DN.
6f51e1
+ * \return \c 0 if the DN is not the root DN.
6f51e1
+ */
6f51e1
+int32_t slapi_sdn_isroot( const Slapi_DN *sdn );
6f51e1
+
6f51e1
+/**
6f51e1
  * Checks if a DN is the backend suffix.
6f51e1
  *
6f51e1
  * \param pb A parameter block with the backend set.
6f51e1
-- 
6f51e1
2.9.3
6f51e1