From: Michael Friedrich Date: Tue, 28 Oct 2014 18:55:46 +0000 (+0100) Subject: Cli: Don't allow to override existing repository objects X-Git-Tag: v2.2.0~207 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2e6a604706c64c67d9c8405b2170759adf4882e2;p=icinga2 Cli: Don't allow to override existing repository objects refs #7255 --- diff --git a/lib/cli/repositoryutility.cpp b/lib/cli/repositoryutility.cpp index a98fdf059..5dc833d1e 100644 --- a/lib/cli/repositoryutility.cpp +++ b/lib/cli/repositoryutility.cpp @@ -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 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";