]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2475] Added optional handle reset
authorFrancis Dupont <fdupont@isc.org>
Fri, 22 Jul 2022 08:38:19 +0000 (10:38 +0200)
committerRazvan Becheriu <razvan@isc.org>
Fri, 22 Jul 2022 12:02:25 +0000 (15:02 +0300)
src/bin/agent/agent_hooks.dox
src/bin/agent/ca_response_creator.cc
src/lib/hooks/callout_handle_associate.cc
src/lib/hooks/callout_handle_associate.h

index 2433963232c6a54a94e8ec21dd4f7b6d76724858..c0d352c912ede2d4d42ef610043889fff3740ea4 100644 (file)
@@ -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.
+
+*/
index 93021dbe453336f1fff14cf581eb63b128ebe569..5da0e4c4073e8a2ca61fd6eb5bc1439ab413f0df 100644 (file)
@@ -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
index 6573fd93724d0897c7df020018ed113ffcdea176..dc6a3dcef39314c82ae5b4d21ecafe7537542d26 100644 (file)
@@ -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
index 7445bbbb3bfd30913ee9b97cadf8aa9aaa122227..c222590f31d1c3c7f53e542fe273a5fc2d40b7a9 100644 (file)
@@ -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