From: Arran Cudbard-Bell Date: Thu, 8 Dec 2022 17:18:49 +0000 (-0600) Subject: curl: Similar signal fix for smtp and imap X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31b3bedb32c1b292f6b3a1b7caef62f3dabb4381;p=thirdparty%2Ffreeradius-server.git curl: Similar signal fix for smtp and imap --- diff --git a/src/modules/rlm_imap/rlm_imap.c b/src/modules/rlm_imap/rlm_imap.c index b520875e0d8..9fe2a2a9478 100644 --- a/src/modules/rlm_imap/rlm_imap.c +++ b/src/modules/rlm_imap/rlm_imap.c @@ -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); } /* diff --git a/src/modules/rlm_smtp/rlm_smtp.c b/src/modules/rlm_smtp/rlm_smtp.c index 7c081fd17a1..e34b1efd80b 100644 --- a/src/modules/rlm_smtp/rlm_smtp.c +++ b/src/modules/rlm_smtp/rlm_smtp.c @@ -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