Skip to content

Commit 72dc4c0

Browse files
committed
Fixes handling for LocalSystem account if set as service user
Fixes #51
1 parent 1864b7c commit 72dc4c0

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

lib/core/icingaagent/getters/Get-IcingaServiceUser.psm1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@ function Get-IcingaServiceUser()
66
}
77

88
$Services = $Services.GetEnumerator() | Select-Object -First 1;
9-
return ($Services.Value.configuration.ServiceUser).Replace('.\', '');
9+
$ServiceUser = ($Services.Value.configuration.ServiceUser).Replace('.\', '');
10+
11+
if ($ServiceUser -eq 'LocalSystem') {
12+
$ServiceUser = 'NT Authority\SYSTEM';
13+
}
14+
15+
return $ServiceUser;
1016
}

lib/core/icingaagent/tests/Test-IcingaAcl.psm1

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,26 @@ function Test-IcingaAcl()
99
throw 'The specified directory was not found';
1010
}
1111

12-
$FolderACL = Get-Acl $Directory;
13-
$ServiceUser = Get-IcingaServiceUser;
14-
$UserFound = $FALSE;
15-
$HasAccess = $FALSE;
12+
$FolderACL = Get-Acl $Directory;
13+
$ServiceUser = Get-IcingaServiceUser;
14+
$UserFound = $FALSE;
15+
$HasAccess = $FALSE;
16+
$ServiceUserSID = Get-IcingaUserSID $ServiceUser;
17+
1618
foreach ($user in $FolderACL.Access) {
1719
# Not only check here for the exact name but also for included strings like NT AU or NT-AU or even further later on
1820
# As the Get-Acl Cmdlet will translate usernames into the own language, resultng in 'NT AUTHORITY\NetworkService' being translated
1921
# to 'NT-AUTORITÄT\Netzwerkdienst' for example
20-
if ($user.IdentityReference -like "*$ServiceUser" -Or ($ServiceUser -Like '*NT AU*' -And ($user.IdentityReference -Like '*NT AU*' -Or $user.IdentityReference -Like '*NT-AU*'))) {
22+
$UserSID = $null;
23+
try {
24+
$UserSID = Get-IcingaUserSID $user.IdentityReference;
25+
} catch {
26+
$UserSID = $null;
27+
}
28+
29+
if ($ServiceUserSID -eq $UserSID) {
2130
$UserFound = $TRUE;
22-
if ($user.FileSystemRights -Like '*Modify*' -And $user.FileSystemRights -Like '*Synchronize*') {
31+
if (($user.FileSystemRights -Like '*Modify*' -And $user.FileSystemRights -Like '*Synchronize*') -Or $user.FileSystemRights -like '*FullControl*') {
2332
$HasAccess = $TRUE;
2433
}
2534
}

lib/core/icingaagent/tests/Test-IcingaAgentServicePermission.psm1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ function Test-IcingaAgentServicePermission()
99
$SystemContent = Get-IcingaAgentServicePermission;
1010
[bool]$FoundSID = $FALSE;
1111

12+
if ($ServiceUser -eq 'NT Authority\SYSTEM') {
13+
return $TRUE;
14+
}
15+
1216
if ([string]::IsNullOrEmpty($ServiceUser)) {
1317
if (-Not $Silent) {
1418
Write-IcingaTestOutput -Severity 'FAILED' -Message 'There is no user assigned to the Icinga 2 service or the service is not yet installed';

lib/core/tools/Get-IcingaUserSID.psm1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ function Get-IcingaUserSID()
44
[string]$User
55
);
66

7+
if ($User -eq 'LocalSystem') {
8+
$User = 'NT Authority\SYSTEM';
9+
}
10+
711
[string]$Username = '';
812
[string]$Domain = '';
913

0 commit comments

Comments
 (0)