# Conflicts: # docs/windows-time-profile-config.md
This commit is contained in:
@@ -128,22 +128,29 @@ public static class RmmInitialProfileFile {
|
||||
'@
|
||||
}
|
||||
|
||||
function Get-HeldProfileIdentity([IO.FileStream]$Stream) {
|
||||
[RmmInitialProfileFile]::CheckSingleFile($Stream.SafeFileHandle, 1177)
|
||||
function Get-HeldProfileFileId([IO.FileStream]$Stream) {
|
||||
$id = New-Object RmmPipeNative+FileId
|
||||
if (![RmmPipeNative]::GetFileInformationByHandleEx($Stream.SafeFileHandle, 18, [ref]$id, 24)) {
|
||||
throw 'New file identity unavailable'
|
||||
}
|
||||
return @{
|
||||
volume_serial=$id.Volume.ToString([Globalization.CultureInfo]::InvariantCulture)
|
||||
file_id=([BitConverter]::ToString($id.Id)).Replace('-','').ToLowerInvariant()
|
||||
}
|
||||
}
|
||||
|
||||
function Get-HeldProfileIdentity([IO.FileStream]$Stream) {
|
||||
[RmmInitialProfileFile]::CheckSingleFile($Stream.SafeFileHandle, 1177)
|
||||
$identity = Get-HeldProfileFileId $Stream
|
||||
$Stream.Position = 0
|
||||
$algorithm = [Security.Cryptography.SHA256]::Create()
|
||||
try { $digest = [BitConverter]::ToString($algorithm.ComputeHash($Stream)).Replace('-','').ToLowerInvariant() }
|
||||
finally { $algorithm.Dispose() }
|
||||
$sddl = $Stream.GetAccessControl().GetSecurityDescriptorSddlForm($aclSections)
|
||||
return @{
|
||||
volume_serial=$id.Volume.ToString([Globalization.CultureInfo]::InvariantCulture)
|
||||
file_id=([BitConverter]::ToString($id.Id)).Replace('-','').ToLowerInvariant()
|
||||
bytes=$Stream.Length; sha256=$digest; acl_sha256=(BytesHash ([Text.Encoding]::UTF8.GetBytes($sddl)))
|
||||
}
|
||||
$identity.bytes = $Stream.Length
|
||||
$identity.sha256 = $digest
|
||||
$identity.acl_sha256 = BytesHash ([Text.Encoding]::UTF8.GetBytes($sddl))
|
||||
return $identity
|
||||
}
|
||||
|
||||
function New-OriginalPublicProfile {
|
||||
@@ -165,6 +172,7 @@ function New-OriginalPublicProfile {
|
||||
$since = [DateTime]::UtcNow.ToString('o')
|
||||
WriteNew $initialReservation @{id=$caseId; config_sha256=$configHash; utc=$since; staged=$expected; create_new=$true}
|
||||
$phase = 'CreateNew'
|
||||
$descriptorFailure = $null
|
||||
try {
|
||||
$rights = [Security.AccessControl.FileSystemRights]'ReadData,WriteData,ReadAttributes,ReadPermissions,ChangePermissions,Synchronize'
|
||||
$stream = [IO.FileStream]::new($target, [IO.FileMode]::CreateNew,
|
||||
@@ -172,7 +180,17 @@ function New-OriginalPublicProfile {
|
||||
[IO.FileOptions]::WriteThrough, $draftAcl)
|
||||
try {
|
||||
$phase = 'verify_creation'
|
||||
if ($stream.GetAccessControl().GetSecurityDescriptorSddlForm($aclSections) -cne $draftSddl) {
|
||||
$actualSddl = $stream.GetAccessControl().GetSecurityDescriptorSddlForm($aclSections)
|
||||
if ($actualSddl -cne $draftSddl) {
|
||||
$descriptorFailure = @{expected_sddl=$draftSddl; actual_sddl=$actualSddl; bytes=$null}
|
||||
try {
|
||||
$descriptorFailure.bytes = $stream.Length
|
||||
$fileId = Get-HeldProfileFileId $stream
|
||||
$descriptorFailure.file_id = $fileId.file_id
|
||||
$descriptorFailure.volume_serial = $fileId.volume_serial
|
||||
} catch {
|
||||
$descriptorFailure.metadata_hresult = '0x{0:X8}' -f $_.Exception.GetBaseException().HResult
|
||||
}
|
||||
throw 'Unexpected security descriptor on new file'
|
||||
}
|
||||
[RmmInitialProfileFile]::CheckSingleFile($stream.SafeFileHandle, 0)
|
||||
@@ -222,7 +240,9 @@ function New-OriginalPublicProfile {
|
||||
}
|
||||
} catch {
|
||||
$cause = $_.Exception.GetBaseException()
|
||||
WriteNew $initialError @{id=$caseId; phase=$phase; hresult=('0x{0:X8}' -f $cause.HResult); exception=$cause.GetType().FullName}
|
||||
$failure = @{id=$caseId; phase=$phase; hresult=('0x{0:X8}' -f $cause.HResult); exception=$cause.GetType().FullName}
|
||||
if ($null -ne $descriptorFailure) { $failure.creation_descriptor = $descriptorFailure }
|
||||
WriteNew $initialError $failure
|
||||
throw
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user