From: Francis Dupont Date: Thu, 6 Jun 2019 07:20:41 +0000 (+0200) Subject: [576-cb-cmds-empty-value-for-next-server-parameter-is-accepted-which-causes-misconfig... X-Git-Tag: Kea-1.6.0-beta2~77 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5ad31c23351714342f918f38fb7e249fdda951d7;p=thirdparty%2Fkea.git [576-cb-cmds-empty-value-for-next-server-parameter-is-accepted-which-causes-misconfiguration] Specialized the getGlobalProperty template for Optional --- diff --git a/src/lib/dhcpsrv/network.h b/src/lib/dhcpsrv/network.h index 58b4e6a9a5..0d795d6a9a 100644 --- a/src/lib/dhcpsrv/network.h +++ b/src/lib/dhcpsrv/network.h @@ -8,7 +8,6 @@ #define NETWORK_H #include -#include #include #include #include @@ -34,8 +33,9 @@ template<> class ElementValue { public: - /// @brief Function operator extracting an @c Element value as - /// string. + /// @brief Function operator extracting an @c Element value as string. + /// + /// @note This does NOT support empty string value. /// /// @param el Element holding a value to be extracted. asiolink::IOAddress operator()(ConstElementPtr el) const { @@ -585,6 +585,37 @@ protected: return (property); } + /// @brief The @c getGlobalProperty specialization for Optional. + /// + /// This does two things: + /// - uses the string value of the parameter + /// - falls back when the value is empty + /// + /// @param property Value to be returned when it is specified or when + /// no global value is found. + /// @param global_name Name of the global parameter which value should + /// be returned + /// + /// @return Optional value fetched from the global level or the value + /// of @c property. + template<> util::Optional + getGlobalProperty(util::Optional property, + const std::string& global_name) const { + if (!global_name.empty() && fetch_globals_fn_) { + data::ConstElementPtr globals = fetch_globals_fn_(); + if (globals && (globals->getType() == data::Element::map)) { + data::ConstElementPtr global_param = globals->get(global_name); + if (global_param) { + std::string global_str = global_param->stringValue(); + if (!global_str.empty()) { + return (asiolink::IOAddress(global_str)); + } + } + } + } + return (property); + } + /// @brief Returns a value associated with a network using inheritance. /// /// This template method provides a generic mechanism to retrieve a @@ -851,13 +882,8 @@ public: /// @return siaddr value util::Optional getSiaddr(const Inheritance& inheritance = Inheritance::ALL) const { - // Temporary fix for global next-server being the empty string. - try { - return (getProperty(&Network4::getSiaddr, siaddr_, - inheritance, "next-server")); - } catch (asiolink::IOError) { - return (siaddr_); - } + return (getProperty(&Network4::getSiaddr, siaddr_, + inheritance, "next-server")); } /// @brief Sets server hostname for the network.