]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Rework LDAP xlat timeout / cancel callbacks
authorNick Porter <nick@portercomputing.co.uk>
Wed, 23 Aug 2023 18:34:08 +0000 (19:34 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Thu, 24 Aug 2023 09:20:36 +0000 (10:20 +0100)
To handle the case where the request has returned but the query has not
yet resumed.

In this case there is no outstanding request to cancel.

src/modules/rlm_ldap/rlm_ldap.c

index 21c11c9b10cfd0de6c42e564d37dca4603b06895..73af686490bfb55e6c872c697c06b3989315dda1 100644 (file)
@@ -465,14 +465,22 @@ static int uri_part_escape(fr_value_box_t *vb, UNUSED void *uctx)
  */
 static void ldap_query_timeout(UNUSED fr_event_list_t *el, UNUSED fr_time_t now, void *uctx)
 {
-       fr_trunk_request_t      *treq = talloc_get_type_abort(uctx, fr_trunk_request_t);
-       fr_ldap_query_t         *query = talloc_get_type_abort(treq->preq, fr_ldap_query_t);
-       request_t               *request = treq->request;
+       fr_ldap_query_t         *query = talloc_get_type_abort(uctx, fr_ldap_query_t);
+       fr_trunk_request_t      *treq;
+       request_t               *request;
+
+       /*
+        *      If the trunk request has completed but the query
+        *      has not yet resumed, query->treq will be NULL
+        */
+       if (!query->treq) return;
+
+       treq = talloc_get_type_abort(query->treq, fr_trunk_request_t);
+       request = treq->request;
 
        ROPTIONAL(RERROR, ERROR, "Timeout waiting for LDAP query");
-       if (query->msgid) {
-               fr_trunk_request_signal_cancel(query->treq);
-       }
+
+       fr_trunk_request_signal_cancel(query->treq);
 
        query->ret = LDAP_RESULT_TIMEOUT;
        unlang_interpret_mark_runnable(request);
@@ -532,6 +540,8 @@ static void ldap_xlat_signal(xlat_ctx_t const *xctx, request_t *request, UNUSED
 {
        fr_ldap_query_t         *query = talloc_get_type_abort(xctx->rctx, fr_ldap_query_t);
 
+       if (!query->treq)       return;
+
        RDEBUG2("Forcefully cancelling pending LDAP query");
 
        fr_trunk_request_signal_cancel(query->treq);
@@ -669,7 +679,7 @@ static xlat_action_t ldap_xlat(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out,
        }
 
        if (fr_event_timer_in(query, unlang_interpret_event_list(request), &query->ev, handle_config->res_timeout,
-                             ldap_query_timeout, query->treq) < 0) {
+                             ldap_query_timeout, query) < 0) {
                REDEBUG("Unable to set timeout for LDAP query");
                fr_trunk_request_signal_cancel(query->treq);
                goto query_error;