cleanup.ps1 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <#
  2. Best-effort teardown of any state smoke.ps1/smoke-exec.ps1/
  3. smoke-aces.ps1 may have left behind. Intended for `if: always()`
  4. in CI; safe to run locally too.
  5. Targets the same fixed test sublayers as the smoke scripts (NOT
  6. the production default).
  7. Usage:
  8. pwsh vendor/srt-win-src/ci/cleanup.ps1 <path-to-srt-win.exe>
  9. #>
  10. param(
  11. [Parameter(Mandatory = $true)]
  12. [string]$Exe,
  13. # Must match smoke.ps1's default.
  14. [string]$InstallSublayer = 'b2e8a6c4-1f73-4d09-9e25-c7b0d3a48f61',
  15. # Must match smoke-exec.ps1's default.
  16. [string]$ExecSublayer = '5b0e64f4-09f1-4c2e-8c97-4d2c0f4e9b7d',
  17. # Must match smoke-aces.ps1's default.
  18. [string]$AcesSublayer = 'd3a85b1c-7e92-4f6a-b1d4-8e0c5f2a9b3e',
  19. # Must match smoke-kill.ps1's default.
  20. [string]$KillSublayer = '4c1f7a2e-8b9d-4e3a-9f6c-1d7e5a0b8c4f',
  21. # Must match test/sandbox/winsrt.test.ts.
  22. [string]$TsSublayer = '7c1f0e90-3a2b-4f5d-9e8c-1d2e3f4a5b6c',
  23. [string]$AmbientSublayer = '9e4b2d7a-6c05-4f18-8a3d-2b9e7c1f5a0d',
  24. # Must match smoke-machine-store.ps1.
  25. [string]$MachineStoreSublayer = '4c7d9b21-3e58-4a06-9d17-8f2a6c40be93'
  26. )
  27. $ErrorActionPreference = 'SilentlyContinue'
  28. if (-not (Test-Path $Exe)) {
  29. Write-Host "cleanup: $Exe not found; nothing to do"
  30. exit 0
  31. }
  32. & $Exe wfp uninstall --sublayer-guid $InstallSublayer
  33. & $Exe wfp uninstall --sublayer-guid $ExecSublayer
  34. & $Exe wfp uninstall --sublayer-guid $AcesSublayer
  35. & $Exe wfp uninstall --sublayer-guid $KillSublayer
  36. & $Exe wfp uninstall --sublayer-guid $TsSublayer
  37. & $Exe wfp uninstall --sublayer-guid $AmbientSublayer
  38. & $Exe wfp uninstall --sublayer-guid $MachineStoreSublayer
  39. # winsrt.test.ts installWindowsSandbox round-trip rows use these
  40. # sublayers; the test tears down via uninstallWindowsSandbox(). This
  41. # is belt-and-braces in case it crashed mid-row.
  42. & $Exe wfp uninstall --sublayer-guid 8d2f1e91-4b3c-5a6e-af9d-2e3f4a5b6c7d
  43. & $Exe wfp uninstall --sublayer-guid 9e3a2fa2-5c4d-6b7f-ba0e-3f4a5b6c7d8e
  44. # winsrt.test.ts verifyWindowsWfpEgress row.
  45. & $Exe wfp uninstall --sublayer-guid 6a1e0f80-2b3c-4d5e-9f8a-1b2c3d4e5f60
  46. # Orphaned sandbox-user ACEs (working_aces rows whose holder PID
  47. # died mid-test). Best-effort — this only matters if a G-row
  48. # (smoke-exec) / A-row (smoke-aces) / H-row (winsrt.test.ts) threw
  49. # mid-section before its `finally` ran.
  50. & $Exe acl recover --force
  51. # Sandbox user + credential/marker rows in state.db — `srt-win
  52. # install` provisions these; `uninstall` (no --keep-user) removes
  53. # them, so this only matters if a smoke script threw mid-section.
  54. & $Exe uninstall --sublayer-guid $InstallSublayer
  55. Remove-LocalUser -Name srt-sandbox -ea SilentlyContinue
  56. Remove-LocalGroup -Name sandbox-runtime-users -ea SilentlyContinue
  57. Remove-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList' `
  58. -Name srt-sandbox -ea SilentlyContinue
  59. exit 0