]> granicus.if.org Git - pdns/commitdiff
Warn when no rule was matched by uuid in rm...Rule()
authorChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Fri, 19 Jan 2018 22:23:44 +0000 (23:23 +0100)
committerChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Fri, 19 Jan 2018 22:39:41 +0000 (23:39 +0100)
pdns/dnsdist-lua-rules.cc

index 66c7955cdf63106df1a055ec57edc749a1dc2973..f2b83662035336d8f2bd279582703babd2d78775 100644 (file)
@@ -950,10 +950,12 @@ void setupLuaRules()
       if (auto str = boost::get<std::string>(&id)) {
         boost::uuids::string_generator gen;
         const auto uuid = gen(*str);
-        rules.erase(std::remove_if(rules.begin(),
-                                   rules.end(),
-                                   [uuid](const DNSDistResponseRuleAction& a) { return a.d_id == uuid; }),
-                    rules.end());
+        if (rules.erase(std::remove_if(rules.begin(),
+                                       rules.end(),
+                                       [uuid](const DNSDistResponseRuleAction& a) { return a.d_id == uuid; }),
+                        rules.end()) == rules.end()) {
+          g_outputBuffer = "Error: no rule matched\n";
+        }
       }
       else if (auto pos = boost::get<unsigned int>(&id)) {
         if (*pos >= rules.size()) {
@@ -1024,10 +1026,12 @@ void setupLuaRules()
       if (auto str = boost::get<std::string>(&id)) {
         boost::uuids::string_generator gen;
         const auto uuid = gen(*str);
-        rules.erase(std::remove_if(rules.begin(),
-                                   rules.end(),
-                                   [uuid](const DNSDistResponseRuleAction& a) { return a.d_id == uuid; }),
-                    rules.end());
+        if (rules.erase(std::remove_if(rules.begin(),
+                                       rules.end(),
+                                       [uuid](const DNSDistResponseRuleAction& a) { return a.d_id == uuid; }),
+                        rules.end()) == rules.end()) {
+          g_outputBuffer = "Error: no rule matched\n";
+        }
       }
       else if (auto pos = boost::get<unsigned int>(&id)) {
         if (*pos >= rules.size()) {
@@ -1075,10 +1079,12 @@ void setupLuaRules()
       if (auto str = boost::get<std::string>(&id)) {
         boost::uuids::string_generator gen;
         const auto uuid = gen(*str);
-        rules.erase(std::remove_if(rules.begin(),
-                                   rules.end(),
-                                   [uuid](const DNSDistRuleAction& a) { return a.d_id == uuid; }),
-                    rules.end());
+        if (rules.erase(std::remove_if(rules.begin(),
+                                       rules.end(),
+                                       [uuid](const DNSDistRuleAction& a) { return a.d_id == uuid; }),
+                        rules.end()) == rules.end()) {
+          g_outputBuffer = "Error: no rule matched\n";
+        }
       }
       else if (auto pos = boost::get<unsigned int>(&id)) {
         if (*pos >= rules.size()) {