]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
curl: Similar signal fix for smtp and imap
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 8 Dec 2022 17:18:49 +0000 (11:18 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 8 Dec 2022 17:18:49 +0000 (11:18 -0600)
src/modules/rlm_imap/rlm_imap.c
src/modules/rlm_smtp/rlm_smtp.c

index b520875e0d8289bb28e9f44afda6a5ce1a661a10..9fe2a2a9478960b98a8aeeaa2368c48f11fd1ad5 100644 (file)
@@ -73,6 +73,25 @@ static const CONF_PARSER module_config[] = {
        CONF_PARSER_TERMINATOR
 };
 
+static void imap_io_module_signal(module_ctx_t const *mctx, request_t *request, fr_state_signal_t action)
+{
+       fr_curl_io_request_t    *randle = talloc_get_type_abort(mctx->rctx, fr_curl_io_request_t);
+       rlm_imap_thread_t       *t = talloc_get_type_abort(mctx->thread, rlm_imap_thread_t);
+       CURLMcode               ret;
+
+       if (action != FR_SIGNAL_CANCEL) return;
+
+       RDEBUG2("Forcefully cancelling pending IMAP request");
+
+       ret = curl_multi_remove_handle(t->mhandle->mandle, randle->candle);     /* Gracefully terminate the request */
+       if (ret != CURLM_OK) {
+               RERROR("Failed removing curl handle from multi-handle: %s (%i)", curl_multi_strerror(ret), ret);
+               /* Not much we can do */
+       }
+       t->mhandle->transfers--;
+       talloc_free(randle);
+}
+
 /*
  *     Called when the IMAP server responds
  *     It checks if the response was CURLE_OK
@@ -168,7 +187,7 @@ static unlang_action_t CC_HINT(nonnull(1,2)) mod_authenticate(rlm_rcode_t *p_res
 
        if (fr_curl_io_request_enqueue(t->mhandle, request, randle)) RETURN_MODULE_INVALID;
 
-       return unlang_module_yield(request, mod_authenticate_resume, NULL, randle);
+       return unlang_module_yield(request, mod_authenticate_resume, imap_io_module_signal, randle);
 }
 
 /*
index 7c081fd17a16dc0449b0d0f3c934a957e11a39b3..e34b1efd80bd78e874825f5f6e5fe0fd0855e34f 100644 (file)
@@ -755,6 +755,25 @@ static int _free_mail_ctx(fr_mail_ctx_t *uctx)
        return 0;
 }
 
+static void smtp_io_module_signal(module_ctx_t const *mctx, request_t *request, fr_state_signal_t action)
+{
+       fr_curl_io_request_t    *randle = talloc_get_type_abort(mctx->rctx, fr_curl_io_request_t);
+       rlm_smtp_thread_t       *t = talloc_get_type_abort(mctx->thread, rlm_smtp_thread_t);
+       CURLMcode               ret;
+
+       if (action != FR_SIGNAL_CANCEL) return;
+
+       RDEBUG2("Forcefully cancelling pending SMTP request");
+
+       ret = curl_multi_remove_handle(t->mhandle->mandle, randle->candle);     /* Gracefully terminate the request */
+       if (ret != CURLM_OK) {
+               RERROR("Failed removing curl handle from multi-handle: %s (%i)", curl_multi_strerror(ret), ret);
+               /* Not much we can do */
+       }
+       t->mhandle->transfers--;
+       talloc_free(randle);
+}
+
 /*
  *     Check if the email was successfully sent, and if the certificate information was extracted
  */
@@ -919,7 +938,7 @@ static unlang_action_t CC_HINT(nonnull) mod_authorize(rlm_rcode_t *p_result, mod
 
        if (fr_curl_io_request_enqueue(t->mhandle, request, randle)) RETURN_MODULE_INVALID;
 
-       return unlang_module_yield(request, mod_authorize_result, NULL, mail_ctx);
+       return unlang_module_yield(request, mod_authorize_result, smtp_io_module_signal, mail_ctx);
 }
 
 /*
@@ -1012,7 +1031,7 @@ static unlang_action_t CC_HINT(nonnull(1,2)) mod_authenticate(rlm_rcode_t *p_res
 
        if (fr_curl_io_request_enqueue(t->mhandle, request, randle)) RETURN_MODULE_INVALID;
 
-       return unlang_module_yield(request, mod_authenticate_resume, NULL, randle);
+       return unlang_module_yield(request, mod_authenticate_resume, smtp_io_module_signal, randle);
 }
 
 /** Verify that a map in the header section makes sense