Commit Graph
3 Commits
Author SHA1 Message Date
Hamza El-Saawy 9f0d5dc7d2 Switch from sycall to windows (#295)
Where ever possible, use `golang.org/x/sys/windows` instead of `syscall`
(which has been deprecated since go1.11).

Using `windows.LocalFree` requires using `unsafe.Pointer`, which ensures
that the Go garbage collector does not try to free memory pre-maturely
if it was previously declared as a pointer.

Since `syscall.Handle` is part of API for `vhd` package, it was left
unchanged.

For security descriptor functions, switch to using
`windows.SECURITY_DESCRIPTOR` to avoid unnecessary byte manipulation and
panics due to missing input validation and error checking.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
2023-08-07 14:06:05 -04:00
Hamza El-Saawy 19a9f656e1 Update tests; run fuzzing (#294)
Run fuzzing tests in CI.

Use race detector when running tests.

Add missing `t.Helper()` calls.

Update test helpers in `pkg/bindfilter` to use `RtlGetNtVersionNumbers`
instead of reading registry, and skip tests if not running as admin.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
2023-07-21 18:06:41 -04:00
Gabriel dd5de6900b Add some basic bind filter functions (#274)
* Add some basic bind filter functions

This change adds the ability to mount a a single folder or a volume
inside another folder, using the bind filter API.

While the API allows mounting multiple sources inside a single mount
point, acting as an overlay, we disable this functionality in the ApplyFileBinding
function.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>

* Add some tests

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>

* Move bind filter to different package

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>

* Use string in signature and fix getFinalPath

  * Properly close handle in getFinalPath()
  * Use string in function signature. mksyscall generates proper code to
    convert to utf16
  * Enable TestRemoveFileBinding on Windows Server 2019

Windows Server 2019 only exposes 2 function in bindfltapi.dll:

  * BfRemoveMapping
  * BfSetupFilter

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>

* Use windows.UTF16ToString to decode string

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>

* Optimize bfGetMappings signature

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>

* Skip unsupported tests on ltsc2019

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>

* Fix typo, add testcase

  * Additionally check if we can write to a read-only mount point, not
    just delete from it
  * No need to set FILE_FLAG_OPEN_REPARSE_POINT when opening a file

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>

* Remove extra flags

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>

* Add test to account for symlinks as sources

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>

---------

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-02-28 11:37:19 -05:00