diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 1811c8e0740..a6cc9517258 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -298,7 +298,9 @@ static int Main() ("include,I", po::value >(), "add include search directory") ("log-level,x", po::value(), "specify the log level for the console log.\n" "The valid value is either debug, notice, information (default), warning, or critical") - ("script-debugger,X", "whether to enable the script debugger"); + ("script-debugger,X", "whether to enable the script debugger") + ("no-impersonate", ("run as current user, never impersonate " + + Configuration::RunAsUser + ":" + Configuration::RunAsGroup).CStr()); po::options_description hiddenDesc("Hidden options"); diff --git a/lib/cli/apisetupcommand.cpp b/lib/cli/apisetupcommand.cpp index 81b9d8db603..023fb56d5f6 100644 --- a/lib/cli/apisetupcommand.cpp +++ b/lib/cli/apisetupcommand.cpp @@ -22,11 +22,6 @@ String ApiSetupCommand::GetShortDescription() const return "setup for API"; } -ImpersonationLevel ApiSetupCommand::GetImpersonationLevel() const -{ - return ImpersonateIcinga; -} - void ApiSetupCommand::InitParameters(boost::program_options::options_description& visibleDesc, boost::program_options::options_description& hiddenDesc) const { diff --git a/lib/cli/apisetupcommand.hpp b/lib/cli/apisetupcommand.hpp index be2693d1304..f86528e73c0 100644 --- a/lib/cli/apisetupcommand.hpp +++ b/lib/cli/apisetupcommand.hpp @@ -23,7 +23,6 @@ class ApiSetupCommand final : public CLICommand void InitParameters(boost::program_options::options_description& visibleDesc, boost::program_options::options_description& hiddenDesc) const override; int Run(const boost::program_options::variables_map& vm, const std::vector& ap) const override; - ImpersonationLevel GetImpersonationLevel() const override; }; } diff --git a/lib/cli/caremovecommand.cpp b/lib/cli/caremovecommand.cpp index d8944944eaf..91e571c7151 100644 --- a/lib/cli/caremovecommand.cpp +++ b/lib/cli/caremovecommand.cpp @@ -40,16 +40,6 @@ int CARemoveCommand::GetMinArguments() const return 1; } -/** - * Impersonate as Icinga user. - * - * @return impersonate level - */ -ImpersonationLevel CARemoveCommand::GetImpersonationLevel() const -{ - return ImpersonateIcinga; -} - /** * The entry point for the "ca remove" CLI command. * diff --git a/lib/cli/caremovecommand.hpp b/lib/cli/caremovecommand.hpp index 2da92d39e74..63f62630c83 100644 --- a/lib/cli/caremovecommand.hpp +++ b/lib/cli/caremovecommand.hpp @@ -21,7 +21,6 @@ class CARemoveCommand final : public CLICommand String GetDescription() const override; String GetShortDescription() const override; int GetMinArguments() const override; - ImpersonationLevel GetImpersonationLevel() const override; int Run(const boost::program_options::variables_map& vm, const std::vector& ap) const override; }; diff --git a/lib/cli/carestorecommand.cpp b/lib/cli/carestorecommand.cpp index 502036830e7..8845608ec3b 100644 --- a/lib/cli/carestorecommand.cpp +++ b/lib/cli/carestorecommand.cpp @@ -40,16 +40,6 @@ int CARestoreCommand::GetMinArguments() const return 1; } -/** - * Impersonate as Icinga user. - * - * @return impersonate level - */ -ImpersonationLevel CARestoreCommand::GetImpersonationLevel() const -{ - return ImpersonateIcinga; -} - /** * The entry point for the "ca restore" CLI command. * diff --git a/lib/cli/carestorecommand.hpp b/lib/cli/carestorecommand.hpp index 74a27dff642..455daf453f4 100644 --- a/lib/cli/carestorecommand.hpp +++ b/lib/cli/carestorecommand.hpp @@ -21,7 +21,6 @@ class CARestoreCommand final : public CLICommand String GetDescription() const override; String GetShortDescription() const override; int GetMinArguments() const override; - ImpersonationLevel GetImpersonationLevel() const override; int Run(const boost::program_options::variables_map& vm, const std::vector& ap) const override; }; diff --git a/lib/cli/casigncommand.cpp b/lib/cli/casigncommand.cpp index 96d2c2c870f..8fbffcfdba7 100644 --- a/lib/cli/casigncommand.cpp +++ b/lib/cli/casigncommand.cpp @@ -40,16 +40,6 @@ int CASignCommand::GetMinArguments() const return 1; } -/** - * Impersonate as Icinga user. - * - * @return impersonate level - */ -ImpersonationLevel CASignCommand::GetImpersonationLevel() const -{ - return ImpersonateIcinga; -} - /** * The entry point for the "ca sign" CLI command. * diff --git a/lib/cli/casigncommand.hpp b/lib/cli/casigncommand.hpp index 0089af76c7c..7db76792e23 100644 --- a/lib/cli/casigncommand.hpp +++ b/lib/cli/casigncommand.hpp @@ -21,7 +21,6 @@ class CASignCommand final : public CLICommand String GetDescription() const override; String GetShortDescription() const override; int GetMinArguments() const override; - ImpersonationLevel GetImpersonationLevel() const override; int Run(const boost::program_options::variables_map& vm, const std::vector& ap) const override; }; diff --git a/lib/cli/clicommand.cpp b/lib/cli/clicommand.cpp index cfdce094665..9058210286f 100644 --- a/lib/cli/clicommand.cpp +++ b/lib/cli/clicommand.cpp @@ -147,7 +147,7 @@ void CLICommand::InitParameters(boost::program_options::options_description& vis ImpersonationLevel CLICommand::GetImpersonationLevel() const { - return ImpersonateIcinga; + return m_ImpersonationLevel; } bool CLICommand::ParseCommand(int argc, char **argv, po::options_description& visibleDesc, @@ -216,6 +216,10 @@ bool CLICommand::ParseCommand(int argc, char **argv, po::options_description& vi po::store(po::command_line_parser(argc - arg_end, argv + arg_end).options(adesc).positional(positionalDesc).run(), vm); po::notify(vm); + if (vm.count("no-impersonate")) { + command->m_ImpersonationLevel = ImpersonateNone; + } + return true; } diff --git a/lib/cli/clicommand.hpp b/lib/cli/clicommand.hpp index ce58b54b878..849d400885f 100644 --- a/lib/cli/clicommand.hpp +++ b/lib/cli/clicommand.hpp @@ -64,6 +64,8 @@ class CLICommand : public Object bool autocomplete = false, int autoindex = -1); private: + ImpersonationLevel m_ImpersonationLevel = ImpersonateIcinga; + static std::mutex& GetRegistryMutex(); static std::map, CLICommand::Ptr>& GetRegistry(); }; diff --git a/lib/cli/featuredisablecommand.cpp b/lib/cli/featuredisablecommand.cpp index 95a4a26d77d..23e2a1c9e6a 100644 --- a/lib/cli/featuredisablecommand.cpp +++ b/lib/cli/featuredisablecommand.cpp @@ -34,11 +34,6 @@ int FeatureDisableCommand::GetMaxArguments() const return -1; } -ImpersonationLevel FeatureDisableCommand::GetImpersonationLevel() const -{ - return ImpersonateIcinga; -} - /** * The entry point for the "feature disable" CLI command. * diff --git a/lib/cli/featuredisablecommand.hpp b/lib/cli/featuredisablecommand.hpp index b24655de629..b2c418b1cca 100644 --- a/lib/cli/featuredisablecommand.hpp +++ b/lib/cli/featuredisablecommand.hpp @@ -23,7 +23,6 @@ class FeatureDisableCommand final : public CLICommand int GetMinArguments() const override; int GetMaxArguments() const override; std::vector GetPositionalSuggestions(const String& word) const override; - ImpersonationLevel GetImpersonationLevel() const override; int Run(const boost::program_options::variables_map& vm, const std::vector& ap) const override; }; diff --git a/lib/cli/featureenablecommand.cpp b/lib/cli/featureenablecommand.cpp index 0cf906648e4..4c09d20395a 100644 --- a/lib/cli/featureenablecommand.cpp +++ b/lib/cli/featureenablecommand.cpp @@ -34,11 +34,6 @@ int FeatureEnableCommand::GetMaxArguments() const return -1; } -ImpersonationLevel FeatureEnableCommand::GetImpersonationLevel() const -{ - return ImpersonateIcinga; -} - /** * The entry point for the "feature enable" CLI command. * diff --git a/lib/cli/featureenablecommand.hpp b/lib/cli/featureenablecommand.hpp index fc917787d16..ae3b5a2697f 100644 --- a/lib/cli/featureenablecommand.hpp +++ b/lib/cli/featureenablecommand.hpp @@ -23,7 +23,6 @@ class FeatureEnableCommand final : public CLICommand int GetMinArguments() const override; int GetMaxArguments() const override; std::vector GetPositionalSuggestions(const String& word) const override; - ImpersonationLevel GetImpersonationLevel() const override; int Run(const boost::program_options::variables_map& vm, const std::vector& ap) const override; }; diff --git a/lib/cli/internalsignalcommand.cpp b/lib/cli/internalsignalcommand.cpp index b98e6c6217e..577bdd51a89 100644 --- a/lib/cli/internalsignalcommand.cpp +++ b/lib/cli/internalsignalcommand.cpp @@ -19,11 +19,6 @@ String InternalSignalCommand::GetShortDescription() const return "Send signal as Icinga user"; } -ImpersonationLevel InternalSignalCommand::GetImpersonationLevel() const -{ - return ImpersonateIcinga; -} - bool InternalSignalCommand::IsHidden() const { return true; diff --git a/lib/cli/internalsignalcommand.hpp b/lib/cli/internalsignalcommand.hpp index d599b80cd31..ba1df618952 100644 --- a/lib/cli/internalsignalcommand.hpp +++ b/lib/cli/internalsignalcommand.hpp @@ -20,7 +20,6 @@ class InternalSignalCommand final : public CLICommand String GetDescription() const override; String GetShortDescription() const override; - ImpersonationLevel GetImpersonationLevel() const override; bool IsHidden() const override; void InitParameters(boost::program_options::options_description& visibleDesc, boost::program_options::options_description& hiddenDesc) const override; diff --git a/lib/cli/nodesetupcommand.cpp b/lib/cli/nodesetupcommand.cpp index 2a685b503b4..ad331eb98d3 100644 --- a/lib/cli/nodesetupcommand.cpp +++ b/lib/cli/nodesetupcommand.cpp @@ -70,11 +70,6 @@ std::vector NodeSetupCommand::GetArgumentSuggestions(const String& argum return CLICommand::GetArgumentSuggestions(argument, word); } -ImpersonationLevel NodeSetupCommand::GetImpersonationLevel() const -{ - return ImpersonateIcinga; -} - /** * The entry point for the "node setup" CLI command. * diff --git a/lib/cli/nodesetupcommand.hpp b/lib/cli/nodesetupcommand.hpp index d25d21e11e8..932857ecdfb 100644 --- a/lib/cli/nodesetupcommand.hpp +++ b/lib/cli/nodesetupcommand.hpp @@ -23,7 +23,6 @@ class NodeSetupCommand final : public CLICommand void InitParameters(boost::program_options::options_description& visibleDesc, boost::program_options::options_description& hiddenDesc) const override; std::vector GetArgumentSuggestions(const String& argument, const String& word) const override; - ImpersonationLevel GetImpersonationLevel() const override; int Run(const boost::program_options::variables_map& vm, const std::vector& ap) const override; private: diff --git a/lib/cli/nodewizardcommand.cpp b/lib/cli/nodewizardcommand.cpp index 3a3cd42bd60..58e87c24d76 100644 --- a/lib/cli/nodewizardcommand.cpp +++ b/lib/cli/nodewizardcommand.cpp @@ -36,11 +36,6 @@ String NodeWizardCommand::GetShortDescription() const return "wizard for node setup"; } -ImpersonationLevel NodeWizardCommand::GetImpersonationLevel() const -{ - return ImpersonateIcinga; -} - int NodeWizardCommand::GetMaxArguments() const { return -1; diff --git a/lib/cli/nodewizardcommand.hpp b/lib/cli/nodewizardcommand.hpp index dfda70c8a36..721f2b33ce2 100644 --- a/lib/cli/nodewizardcommand.hpp +++ b/lib/cli/nodewizardcommand.hpp @@ -22,7 +22,6 @@ class NodeWizardCommand final : public CLICommand String GetShortDescription() const override; int GetMaxArguments() const override; int Run(const boost::program_options::variables_map& vm, const std::vector& ap) const override; - ImpersonationLevel GetImpersonationLevel() const override; void InitParameters(boost::program_options::options_description& visibleDesc, boost::program_options::options_description& hiddenDesc) const override;