From: Francis Dupont Date: Fri, 22 Jul 2022 08:38:19 +0000 (+0200) Subject: [#2475] Added optional handle reset X-Git-Tag: Kea-2.2.0~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29b372c4b41e2f4e8ffc0fd77293647c4a7fb9f5;p=thirdparty%2Fkea.git [#2475] Added optional handle reset --- diff --git a/src/bin/agent/agent_hooks.dox b/src/bin/agent/agent_hooks.dox index 2433963232..c0d352c912 100644 --- a/src/bin/agent/agent_hooks.dox +++ b/src/bin/agent/agent_hooks.dox @@ -1,4 +1,4 @@ -// Copyright (C) 2017-2021 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2017-2022 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -35,9 +35,9 @@ command. PostHttpRequestJsonPtr. The "response" argument is the response in case of errors. The purpose of this callout is to implement authentication and authorization. It is called after basic HTTP authentication. - The next step status is ignored: if the response is set the processing - will stop and the response is returned. In particular the command is not - forwarded. + The next step status is used only to ask to reset the handle : if + the response is set the processing will stop and the response is + returned. In particular the command is not forwarded. @subsection agentHooksResponse response @@ -53,4 +53,17 @@ command. called after command processing. The next step status is ignored: the response possibly modified will be sent back. -*/ \ No newline at end of file +@section agentHooksHandle Handle and hook unload + +The callout handle attached to the "request" argument can keep a pointer +to the hook address space which prevents the hook to be unloaded +when the "config-get" or "config-reload" command is executed. + +The "next step status" of the "auth" callout point can be set to any +value other than CONTINUE to ask the callout handle to be reset. This +must be done when the command is "config-get" or "config-reload" or +when the "response" callout point is not used or when the callout +context does not transmit values between the "auth" and "response" +callout points. + +*/ diff --git a/src/bin/agent/ca_response_creator.cc b/src/bin/agent/ca_response_creator.cc index 93021dbe45..5da0e4c407 100644 --- a/src/bin/agent/ca_response_creator.cc +++ b/src/bin/agent/ca_response_creator.cc @@ -117,6 +117,7 @@ createDynamicHttpResponse(HttpRequestPtr request) { } // Callout point for "auth". + bool reset_handle = false; if (HooksManager::calloutsPresent(Hooks.hook_index_auth_)) { // Get callout handle. CalloutHandlePtr callout_handle = request->getCalloutHandle(); @@ -131,7 +132,10 @@ createDynamicHttpResponse(HttpRequestPtr request) { callout_handle->getArgument("request", request); callout_handle->getArgument("response", http_response); - // Ignore status as the HTTP response is used instead. + // Status other than continue means 'please reset the handle'. + if (callout_handle->getStatus() != CalloutHandle::NEXT_STEP_CONTINUE) { + reset_handle = true; + } } // The basic HTTP authentication check or a callout failed and @@ -140,6 +144,11 @@ createDynamicHttpResponse(HttpRequestPtr request) { return (http_response); } + // Reset the handle when a hook asks for. + if (reset_handle) { + request->resetCalloutHandle(); + } + // The request is always non-null, because this is verified by the // createHttpResponse method. Let's try to convert it to the // PostHttpRequestJson type as this is the type generated by the diff --git a/src/lib/hooks/callout_handle_associate.cc b/src/lib/hooks/callout_handle_associate.cc index 6573fd9372..dc6a3dcef3 100644 --- a/src/lib/hooks/callout_handle_associate.cc +++ b/src/lib/hooks/callout_handle_associate.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -25,5 +25,10 @@ CalloutHandleAssociate::getCalloutHandle() { return (callout_handle_); } +void +CalloutHandleAssociate::resetCalloutHandle() { + callout_handle_.reset(); +} + } // end of namespace isc::hooks } // end of namespace isc diff --git a/src/lib/hooks/callout_handle_associate.h b/src/lib/hooks/callout_handle_associate.h index 7445bbbb3b..c222590f31 100644 --- a/src/lib/hooks/callout_handle_associate.h +++ b/src/lib/hooks/callout_handle_associate.h @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -48,12 +48,13 @@ public: /// @return Pointer to the callout handle. CalloutHandlePtr getCalloutHandle(); + /// @brief Reset callout handle. + void resetCalloutHandle(); + protected: /// @brief Callout handle stored. CalloutHandlePtr callout_handle_; - - }; } // end of isc::hooks