]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3831] leaseX-write restricted to supported path
authorThomas Markwalder <tmark@isc.org>
Wed, 14 May 2025 12:44:26 +0000 (08:44 -0400)
committerAndrei Pavel <andrei@isc.org>
Fri, 16 May 2025 09:20:43 +0000 (12:20 +0300)
modified:   hooks-lease-cmds.rst
modified:   ../../../src/hooks/dhcp/lease_cmds/lease_cmds.cc
modified:   ../../../src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc
modified:   ../../../src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc

doc/sphinx/arm/hooks-lease-cmds.rst
src/hooks/dhcp/lease_cmds/lease_cmds.cc
src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc
src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc

index a559d73f724b3c2c2d2b14ed0f585898cb4898f0..04c3c1d023f54ff5c743b62776920d44bd0c2a55 100644 (file)
@@ -1093,6 +1093,17 @@ the file in an attempt to synchronize both the files and the in-memory images
 of the lease database. The extension ``.bak`` and the server PID number are added
 to the previous filename: for example, ``.bak14326``.
 
+.. note::
+
+    As of Kea 2.7.9, the lease file may only be written to the data directory
+    determined during compilation: ``"[kea-install-dir]/var/lib/kea"``. This
+    path may be overridden at startup by setting the environment variable
+    ``KEA_DHCP_DATA_DIRECTORY`` to the desired path.  If a path other than
+    this value is used in ``name``, Kea will emit an error and refuse to start
+    or, if already running, log an unrecoverable error.  For ease of use in
+    specifying a custom file name simply omit the path portion from ``filename``.
+
+
 .. note::
 
    These commands do not replace the LFC mechanism; they should be used
index 9079f61c4d06bc43bc8b5ff5c2af06f735edb661..bd82a102100ab1689b0e7d77fff0e66aa2c2bee3 100644 (file)
@@ -2757,9 +2757,12 @@ LeaseCmdsImpl::leaseWriteHandler(CalloutHandle& handle) {
         if (file->getType() != Element::string) {
             isc_throw(BadValue, "'filename' parameter must be a string");
         }
-        string filename = file->stringValue();
-        if (filename.empty()) {
-            isc_throw(BadValue, "'filename' parameter is empty");
+
+        std::string filename;
+        try {
+          filename = CfgMgr::instance().validatePath(file->stringValue());
+        } catch (const std::exception& ex) {
+            isc_throw(BadValue, "'filename' parameter is invalid: " << ex.what());
         }
 
         if (v4) {
@@ -2767,6 +2770,7 @@ LeaseCmdsImpl::leaseWriteHandler(CalloutHandle& handle) {
         } else {
             LeaseMgrFactory::instance().writeLeases6(filename);
         }
+
         ostringstream s;
         s << (v4 ? "IPv4" : "IPv6")
           << " lease database into '"
index 91025b23ca9790cf8683c820dd2b91c68b4c5e2c..64492a3c60e31a13b3f0d67321862c7a690194ee 100644 (file)
@@ -3482,8 +3482,23 @@ void Lease4CmdsTest::testLease4Write() {
         "        \"filename\": \"\"\n"
         "    }\n"
         "}";
-    exp_rsp = "'filename' parameter is empty";
+    exp_rsp = "'filename' parameter is invalid: path: '' has no filename";
     testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
+
+    // Filename must use supported path.
+    txt =
+        "{\n"
+        "    \"command\": \"lease4-write\",\n"
+        "    \"arguments\": {"
+        "        \"filename\": \"/tmp/myleases.txt\"\n"
+        "    }\n"
+        "}";
+
+    std::ostringstream os;
+    os << "'filename' parameter is invalid: invalid path specified:"
+       << " '/tmp', supported path is '" << CfgMgr::instance().getDataDir() << "'";
+
+    testCommand(txt, CONTROL_RESULT_ERROR, os.str());
 }
 
 TEST_F(Lease4CmdsTest, lease4AddMissingParams) {
index 635b5e6e2fceb2898b8b0a8176c711c90d226e3a..f07514a3345f1ef2ceee8d64b5b64e35a8d22e27 100644 (file)
@@ -4409,7 +4409,7 @@ void Lease6CmdsTest::testLease6ConflictingBulkApplyAdd() {
 }
 
 void Lease6CmdsTest::testLease6Write() {
-    // lease4-write negative tests. Positive tests are in the
+    // lease6-write negative tests. Positive tests are in the
     // memfile_lease_mgr_unittest.cc file.
 
     // Initialize lease manager (true = v6, false = don't add leases)
@@ -4444,8 +4444,22 @@ void Lease6CmdsTest::testLease6Write() {
         "        \"filename\": \"\"\n"
         "    }\n"
         "}";
-    exp_rsp = "'filename' parameter is empty";
+    exp_rsp = "'filename' parameter is invalid: path: '' has no filename";
     testCommand(txt, CONTROL_RESULT_ERROR, exp_rsp);
+
+    // Filename must use supported path.
+    txt =
+        "{\n"
+        "    \"command\": \"lease6-write\",\n"
+        "    \"arguments\": {"
+        "        \"filename\": \"/tmp/myleases.txt\"\n"
+        "    }\n"
+        "}";
+
+    std::ostringstream os;
+    os << "'filename' parameter is invalid: invalid path specified:"
+       << " '/tmp', supported path is '" << CfgMgr::instance().getDataDir() << "'";
+
 }
 
 TEST_F(Lease6CmdsTest, lease6AddMissingParams) {