From: Marcin Siodelski Date: Tue, 25 Jun 2019 17:10:13 +0000 (+0200) Subject: [#642,!373] Do not allow to update the logical server 'all'. X-Git-Tag: Kea-1.6.0-beta2~163 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d0b6efdc92a400e6bedb310e7281e1f61d55584;p=thirdparty%2Fkea.git [#642,!373] Do not allow to update the logical server 'all'. --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h index afda51a52b..e0f9e05baf 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h @@ -329,6 +329,8 @@ public: /// @brief Creates or updates a server. /// /// @param server Instance of the server to be stored. + /// @throw InvalidOperation when trying to create a duplicate or + /// update the logical server 'all'. virtual void createUpdateServer4(const db::ServerPtr& server); diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.h b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.h index 1e8983f6e3..ac126d735d 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.h +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp6.h @@ -344,6 +344,8 @@ public: /// @brief Creates or updates a server. /// /// @param server Instance of the server to be stored. + /// @throw InvalidOperation when trying to create a duplicate or + /// update the logical server 'all'. virtual void createUpdateServer6(const db::ServerPtr& server); diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc index 30301fc0df..8e761e2e20 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc @@ -934,6 +934,13 @@ MySqlConfigBackendImpl::createUpdateServer(const int& create_audit_revision, const int& create_index, const int& update_index, const ServerPtr& server) { + // The server tag 'all' is reserved. + if (server->getServerTag().amAll()) { + isc_throw(InvalidOperation, "'all' is a name reserved for the server tag which" + " associates the configuration elements with all servers connecting" + " to the database and a server with this name can't be created"); + } + // Create scoped audit revision. As long as this instance exists // no new audit revisions are created in any subsequent calls. ScopedAuditRevision audit_revision(this, diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h index f910af865b..ad584b82c4 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h @@ -643,6 +643,8 @@ public: /// @param create_index Index of the INSERT query to be used. /// @param update_index Index of the UPDATE query to be used. /// @param server Pointer to the server to be inserted or updated. + /// @throw InvalidOperation when trying to create a duplicate or + /// update the logical server 'all'. void createUpdateServer(const int& create_audit_revision, const int& create_index, const int& update_index, diff --git a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc index 5c2d874664..8175ad75ae 100644 --- a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc +++ b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp4_unittest.cc @@ -468,6 +468,11 @@ TEST_F(MySqlConfigBackendDHCPv4Test, createUpdateDeleteServer) { "server set"); } + // It should not be possible to create a duplicate of the logical + // server 'all'. + auto all_server = Server::create(ServerTag("all"), "this is logical server all"); + EXPECT_THROW(cbptr_->createUpdateServer4(all_server), isc::InvalidOperation); + ServerPtr returned_server; // An attempt to fetch the server that hasn't been inserted should return diff --git a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc index f6636112c2..78ac3b5012 100644 --- a/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc +++ b/src/hooks/dhcp/mysql_cb/tests/mysql_cb_dhcp6_unittest.cc @@ -509,6 +509,11 @@ TEST_F(MySqlConfigBackendDHCPv6Test, createUpdateDeleteServer) { "server set"); } + // It should not be possible to create a duplicate of the logical + // server 'all'. + auto all_server = Server::create(ServerTag("all"), "this is logical server all"); + EXPECT_THROW(cbptr_->createUpdateServer6(all_server), isc::InvalidOperation); + ServerPtr returned_server; // An attempt to fetch the server that hasn't been inserted should return