libcli/security: rewrite SDDL tests for running on Windows
commit641981c4ad8bd3f031d8a23a76e70212dcef1924
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 3 Aug 2023 23:52:17 +0000 (4 11:52 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 24 Aug 2023 02:53:31 +0000 (24 02:53 +0000)
tree20710483b1060ad93300b9bbde9a292cec059a85
parentf58372cca5b59a5d4ed653ef53e69ea756940a68
libcli/security: rewrite SDDL tests for running on Windows

This script never worked well because it had to shell out to
Powershell, which never worked well due to syntax conflicts and
Powershell's specialness. The attempted ctypes version did not work,
due to the difficulty in expressing things like "relative
PSECURITY_DESCRIPTOR" in ctypes.

It turns out that pywin32 is easy to install and use, and we can
extract the NDR bytes which is far more useful than just testing if
the SDDL parses.

On Windows:

1. install Python from python.org
2. run `pip install pywin32`
3. copy e.g. libcli/security/tests/data/conditional-aces.txt to Windows
4. run `python windows-sddl-tests.py conditional-aces.txt`
5. add `--help` to see how to export descriptor bytes.

The default output is a whole lot of multi-coloured text, indicating
what failed and what didn't.

With --export-json it writes a JSON file mapping SDDL strings to NDR
byte sequences, which can be used to compare with Samba's attempts. If
you are only interested in --export-json, you might also like --quiet.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
libcli/security/tests/windows-sddl-test.py