Browse Source

[2314] Validate option space name received in a configuration.

Marcin Siodelski 12 years ago
parent
commit
77c9f2b09e
2 changed files with 17 additions and 13 deletions
  1. 9 7
      src/bin/dhcp4/config_parser.cc
  2. 8 6
      src/bin/dhcp6/config_parser.cc

+ 9 - 7
src/bin/dhcp4/config_parser.cc

@@ -768,7 +768,10 @@ private:
         }
         }
 
 
         std::string option_space = getParam<std::string>("space", string_values_);
         std::string option_space = getParam<std::string>("space", string_values_);
-        /// @todo Validate option space once #2313 is merged.
+        if (!OptionSpace::validateName(option_space)) {
+            isc_throw(DhcpConfigError, "invalid option space name'"
+                      << option_space << "'");
+        }
 
 
         OptionDefinitionPtr def;
         OptionDefinitionPtr def;
         if (option_space == "dhcp4" &&
         if (option_space == "dhcp4" &&
@@ -978,7 +981,7 @@ public:
 /// @brief Parser for a single option definition.
 /// @brief Parser for a single option definition.
 ///
 ///
 /// This parser creates an instance of a single option definition.
 /// This parser creates an instance of a single option definition.
-class OptionDefParser: DhcpConfigParser {
+class OptionDefParser : public DhcpConfigParser {
 public:
 public:
 
 
     /// @brief Constructor.
     /// @brief Constructor.
@@ -1055,8 +1058,8 @@ public:
 
 
     /// @brief Stores the parsed option definition in a storage.
     /// @brief Stores the parsed option definition in a storage.
     void commit() {
     void commit() {
-        // @todo validate option space name once 2313 is merged.
-        if (storage_ && option_definition_) {
+        if (storage_ && option_definition_ &&
+            OptionSpace::validateName(option_space_name_)) {
             storage_->addItem(option_definition_, option_space_name_);
             storage_->addItem(option_definition_, option_space_name_);
         }
         }
     }
     }
@@ -1078,11 +1081,10 @@ private:
     void createOptionDef() {
     void createOptionDef() {
         // Get the option space name and validate it.
         // Get the option space name and validate it.
         std::string space = getParam<std::string>("space", string_values_);
         std::string space = getParam<std::string>("space", string_values_);
-        // @todo uncomment the code below when the #2313 is merged.
-        /*        if (!OptionSpace::validateName()) {
+        if (!OptionSpace::validateName(space)) {
             isc_throw(DhcpConfigError, "invalid option space name '"
             isc_throw(DhcpConfigError, "invalid option space name '"
                       << space << "'");
                       << space << "'");
-                      } */
+        }
 
 
         // Get other parameters that are needed to create the
         // Get other parameters that are needed to create the
         // option definition.
         // option definition.

+ 8 - 6
src/bin/dhcp6/config_parser.cc

@@ -798,7 +798,10 @@ private:
         }
         }
 
 
         std::string option_space = getParam<std::string>("space", string_values_);
         std::string option_space = getParam<std::string>("space", string_values_);
-        /// @todo Validate option space once #2313 is merged.
+        if (!OptionSpace::validateName(option_space)) {
+            isc_throw(DhcpConfigError, "invalid option space name'"
+                      << option_space << "'");
+        }
 
 
         OptionDefinitionPtr def;
         OptionDefinitionPtr def;
         if (option_space == "dhcp6" &&
         if (option_space == "dhcp6" &&
@@ -1085,8 +1088,8 @@ public:
 
 
     /// @brief Stores the parsed option definition in the data store.
     /// @brief Stores the parsed option definition in the data store.
     void commit() {
     void commit() {
-        // @todo validate option space name once 2313 is merged.
-        if (storage_ && option_definition_) {
+        if (storage_ && option_definition_ &&
+            OptionSpace::validateName(option_space_name_)) {
             storage_->addItem(option_definition_, option_space_name_);
             storage_->addItem(option_definition_, option_space_name_);
         }
         }
     }
     }
@@ -1108,11 +1111,10 @@ private:
     void createOptionDef() {
     void createOptionDef() {
         // Get the option space name and validate it.
         // Get the option space name and validate it.
         std::string space = getParam<std::string>("space", string_values_);
         std::string space = getParam<std::string>("space", string_values_);
-        // @todo uncomment the code below when the #2313 is merged.
-        /*        if (!OptionSpace::validateName()) {
+        if (!OptionSpace::validateName(space)) {
             isc_throw(DhcpConfigError, "invalid option space name '"
             isc_throw(DhcpConfigError, "invalid option space name '"
                       << space << "'");
                       << space << "'");
-                      } */
+        }
 
 
         // Get other parameters that are needed to create the
         // Get other parameters that are needed to create the
         // option definition.
         // option definition.