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
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) {
} else {
LeaseMgrFactory::instance().writeLeases6(filename);
}
+
ostringstream s;
s << (v4 ? "IPv4" : "IPv6")
<< " lease database into '"
" \"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) {
}
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)
" \"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) {