]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Define thread specific trunk to use for LDAP bind auth
authorNick Porter <nick@portercomputing.co.uk>
Tue, 11 Apr 2023 14:57:09 +0000 (15:57 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Thu, 4 May 2023 14:27:22 +0000 (15:27 +0100)
And associated function to allocate / retrieve the trunk

src/lib/ldap/base.h
src/lib/ldap/connection.c

index 976117658610b83828d515f62076b125a10471bd..7e010a4873c30b0831600f552a615408c7aa35a0 100644 (file)
@@ -382,6 +382,7 @@ typedef struct {
        fr_trunk_conf_t         *bind_trunk_conf;       //!< Trunk config for bind auth trunk
        fr_event_list_t         *el;            //!< Thread event list for callbacks / timeouts
        fr_connection_t         *conn;          //!< LDAP connection used for bind auths
+       fr_ldap_thread_trunk_t  *bind_trunk;    //!< LDAP trunk used for bind auths
        fr_rb_tree_t            *binds;         //!< Tree of outstanding bind auths
 } fr_ldap_thread_t;
 
@@ -852,6 +853,8 @@ fr_ldap_thread_trunk_t      *fr_thread_ldap_trunk_get(fr_ldap_thread_t *thread, char
 
 fr_trunk_state_t fr_thread_ldap_trunk_state(fr_ldap_thread_t *thread, char const *uri, char const *bind_dn);
 
+fr_ldap_thread_trunk_t *fr_thread_ldap_bind_trunk_get(fr_ldap_thread_t *thread);
+
 /*
  *     state.c - Connection state machine
  */
index fe122c124dc0415a6e472a36db4c1ca763fadd1c..38f2c77e99a910253be7518af85fba071aa548a7 100644 (file)
@@ -1047,3 +1047,44 @@ fr_trunk_state_t fr_thread_ldap_trunk_state(fr_ldap_thread_t *thread, char const
 
        return (found) ? found->trunk->state : FR_TRUNK_STATE_MAX;
 }
+
+/** Find the thread specific trunk to use for LDAP bind auths
+ *
+ * If there is no current trunk then a new one is created.
+ *
+ * @param[in] thread   to which the connection belongs
+ * @return
+ *     - an existing or new trunk.
+ *     - NULL on failure
+ */
+fr_ldap_thread_trunk_t *fr_thread_ldap_bind_trunk_get(fr_ldap_thread_t *thread)
+{
+       fr_ldap_thread_trunk_t  *ttrunk;
+
+       if (thread->bind_trunk) return (thread->bind_trunk);
+
+       MEM(ttrunk = talloc_zero(thread, fr_ldap_thread_trunk_t));
+       memcpy(&ttrunk->config, thread->config, sizeof(fr_ldap_config_t));
+
+       ttrunk->uri = ttrunk->config.server;
+       ttrunk->bind_dn = ttrunk->config.admin_identity;
+
+       ttrunk->trunk = fr_trunk_alloc(ttrunk, thread->el,
+                                      &(fr_trunk_io_funcs_t){
+                                             .connection_alloc = ldap_trunk_connection_alloc,
+                                             .connection_notify = ldap_trunk_connection_notify,
+                                       },
+                                      thread->bind_trunk_conf,
+                                      "rlm_ldap bind auth", ttrunk, false);
+
+       if (!ttrunk->trunk) {
+               ERROR("Unable to create LDAP connection");
+               talloc_free(ttrunk);
+               return NULL;
+       }
+
+       ttrunk->t = thread;
+       thread->bind_trunk = ttrunk;
+
+       return ttrunk;
+}