]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pytest/sddl: environment option for exporting as fuzz seeds
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 18 Aug 2023 01:09:13 +0000 (13:09 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 24 Aug 2023 02:53:30 +0000 (02:53 +0000)
We want realistic examples for sddl fuzzing seeds, and we want
realistic examples for sddl tests, so hopefully we only need to get
it right once.

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

index 800d3570aaf48c44e84c2a3da6921777a578b0da..af0528875919871c6af2f7ce4ac45dc37e97e9f9 100644 (file)
@@ -20,6 +20,7 @@
 from samba.dcerpc import security
 from samba.tests import TestCase, DynamicTestCase, get_env_dir
 from samba.colour import c_RED, c_GREEN
+import os
 
 
 class SddlDecodeEncodeBase(TestCase):
@@ -32,7 +33,9 @@ class SddlDecodeEncodeBase(TestCase):
                 ("SAMBA_WRITE_WINDOWS_STRINGS_DIR",
                  cls.write_windows_strings),
                 ("SAMBA_READ_WINDOWS_STRINGS_DIR",
-                 cls.read_windows_strings)]:
+                 cls.read_windows_strings),
+                ("SAMBA_WRITE_FUZZ_STRINGS_DIR",
+                 cls.write_sddl_strings_for_fuzz_seeds)]:
             dir = get_env_dir(key)
             if dir is not None:
                 fn(dir)
@@ -77,6 +80,24 @@ class SddlDecodeEncodeBase(TestCase):
             sd = security.descriptor.from_sddl(s, self.domain_sid)
             print(sd.as_sddl(self.domain_sid))
 
+    @classmethod
+    def write_sddl_strings_for_fuzz_seeds(cls, dir):
+        """write all the SDDL strings we have into a directory as individual
+        files, using a naming convention beloved of fuzzing engines.
+
+        To run this set an environment variable; see
+        cls.setUpDynamicTestCases(), above.
+
+        Note this will only run in subclasses annotated with @DynamicTestCase.
+        """
+        from hashlib import md5
+        for sddl in cls.strings:
+            if not isinstance(sddl, str):
+                sddl = sddl[0]
+            name = md5(sddl.encode()).hexdigest()
+            with open(os.path.join(dir, name), 'w') as f:
+                f.write(sddl)
+
     @classmethod
     def write_windows_strings(cls, dir):
         """Write all test cases in the format used by