]> granicus.if.org Git - icinga2/commitdiff
Cli: Don't allow to override existing repository objects
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 28 Oct 2014 18:55:46 +0000 (19:55 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 28 Oct 2014 18:55:46 +0000 (19:55 +0100)
refs #7255

lib/cli/repositoryutility.cpp

index a98fdf05910718d30790f09896157451fde2b82c..5dc833d1ed67ad0fda996b2960d3e62757ba811f 100644 (file)
@@ -192,6 +192,22 @@ public:
 /* modify objects and write changelog */
 bool RepositoryUtility::AddObject(const String& name, const String& type, const Dictionary::Ptr& attrs)
 {
+       std::vector<String> object_paths = GetObjects();
+       String pattern;
+
+       if (type == "Service")
+               pattern = attrs->Get("host_name") + "/" + name + ".conf";
+       else
+               pattern = name + ".conf";
+
+       BOOST_FOREACH(const String& object_path, object_paths) {
+               if (object_path.Contains(pattern)) {
+                       Log(LogWarning, "cli")
+                           << type << " '" << name << "' already exists. Skipping creation.";
+                       return false;
+               }
+       }
+
        /* add a new changelog entry by timestamp */
        String path = GetRepositoryChangeLogPath() + "/" + Convert::ToString(Utility::GetTime()) + "-" + type + "-" + SHA256(name) + ".change";