Skip to content

Commit 3cbc706

Browse files
authored
Improvements to user credential check (#24)
1 parent 67e2c01 commit 3cbc706

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

Grafana/Alloy/Scripts/Install-Alloy.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
.\Install-Alloy.ps1
77
88
.NOTES
9-
Version : 1.0.0.25340
9+
Version : 1.0.1.26130
1010
#>
1111

1212
Import-Module "$PSScriptRoot\Install-Alloy.psm1"

Grafana/Alloy/Scripts/Install-Alloy.psm1

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Functions for installing Grafana Alloy.
44
55
.NOTES
6-
Version : 1.0.0.25340
6+
Version : 1.0.1.26130
77
#>
88

99
#region Internal Functions
@@ -155,7 +155,16 @@ function Test-ServiceUser {
155155
)
156156

157157
process {
158-
(New-Object DirectoryServices.DirectoryEntry "",$($ServiceUser.UserName),$($ServiceUser.GetNetworkCredential().Password)).psbase.name -ne $null
158+
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
159+
160+
$contextType = [System.DirectoryServices.AccountManagement.ContextType]::Domain
161+
$domainName, $Username = $ServiceUser.Username -split '\\'
162+
$password = $ServiceUser.GetNetworkCredential().Password
163+
164+
$principalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($contextType, $domainName)
165+
166+
$isValid = $principalContext.ValidateCredentials($userName, $password)
167+
$isValid
159168
}
160169
}
161170

@@ -332,9 +341,7 @@ function Set-LocalSecurityPolicy {
332341

333342
process {
334343
Write-Output "Verifying Local Security Policy for $Username"
335-
336-
$FQDN = (Get-ADDomainController -Discover -DomainName $Username.substring(0, $Username.IndexOf("\"))).Domain
337-
$UserSID = (Get-ADUser -ErrorAction Stop -Server "$FQDN" -Identity $Username.substring($Username.IndexOf("\") + 1)).SID
344+
$UserSID = (New-Object System.Security.Principal.NTAccount($Username.substring($Username.IndexOf("\") + 1))).Translate([System.Security.Principal.SecurityIdentifier]).Value
338345

339346
$secEditConfigurationExport = Export-LocalSecurityPolicy
340347

0 commit comments

Comments
 (0)