From a305318aee1fef6528370d60221e3529cc598f98 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Sun, 3 Nov 2019 18:01:54 +0100 Subject: [PATCH] Add easier handling to set user permissions --- .../icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 | 6 +----- .../icingaagent/setters/Set-IcingaAgentServiceUser.psm1 | 8 +++++++- .../icingaagent/setters/Set-IcingaUserPermissions.psm1 | 7 +++++++ 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 lib/core/icingaagent/setters/Set-IcingaUserPermissions.psm1 diff --git a/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 b/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 index 7cddad4..19057d9 100644 --- a/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 +++ b/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 @@ -421,11 +421,7 @@ function Start-IcingaAgentInstallWizard() if ($RunInstaller) { if ((Install-IcingaAgent -Version $AgentVersion -Source $PackageSource -AllowUpdates $AllowVersionChanges) -Or $Reconfigure) { Move-IcingaAgentDefaultConfig; - Set-IcingaAgentServiceUser -User $ServiceUser -Password $ServicePass | Out-Null; - Set-IcingaAgentServicePermission | Out-Null; - Set-IcingaAcl "$Env:ProgramData\icinga2\etc"; - Set-IcingaAcl "$Env:ProgramData\icinga2\var"; - Set-IcingaAcl (Get-IcingaCacheDir); + Set-IcingaAgentServiceUser -User $ServiceUser -Password $ServicePass -SetPermission | Out-Null; Install-IcingaFrameworkService -Path $ServiceBin -User $ServiceUser -Password $ServicePass | Out-Null; Register-IcingaBackgroundDaemon -Command 'Start-IcingaServiceCheckDaemon'; Install-IcingaAgentBaseFeatures; diff --git a/lib/core/icingaagent/setters/Set-IcingaAgentServiceUser.psm1 b/lib/core/icingaagent/setters/Set-IcingaAgentServiceUser.psm1 index d627efe..b105821 100644 --- a/lib/core/icingaagent/setters/Set-IcingaAgentServiceUser.psm1 +++ b/lib/core/icingaagent/setters/Set-IcingaAgentServiceUser.psm1 @@ -3,7 +3,8 @@ function Set-IcingaAgentServiceUser() param( [string]$User, [securestring]$Password, - [string]$Service = 'icinga2' + [string]$Service = 'icinga2', + [switch]$SetPermission ); if ([string]::IsNullOrEmpty($User)) { @@ -26,6 +27,11 @@ function Set-IcingaAgentServiceUser() -FlushNewLines $TRUE; if ($Output.ExitCode -eq 0) { + + if ($SetPermission) { + Set-IcingaUserPermissions; + } + Write-Host 'Service User successfully updated' return $TRUE; } else { diff --git a/lib/core/icingaagent/setters/Set-IcingaUserPermissions.psm1 b/lib/core/icingaagent/setters/Set-IcingaUserPermissions.psm1 new file mode 100644 index 0000000..e1123d0 --- /dev/null +++ b/lib/core/icingaagent/setters/Set-IcingaUserPermissions.psm1 @@ -0,0 +1,7 @@ +function Set-IcingaUserPermissions() +{ + Set-IcingaAgentServicePermission | Out-Null; + Set-IcingaAcl "$Env:ProgramData\icinga2\etc"; + Set-IcingaAcl "$Env:ProgramData\icinga2\var"; + Set-IcingaAcl (Get-IcingaCacheDir); +}