From: Douglas Bagnall Date: Sun, 3 Sep 2023 22:11:51 +0000 (+1200) Subject: pytest: assembler for conditional ACEs X-Git-Tag: tevent-0.16.0~438 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15fe49a2f9ba006f298616ff7376a7bb4cb4178e;p=thirdparty%2Fsamba.git pytest: assembler for conditional ACEs This is a helper module to construct conditional ACEs that can't be created from SDDL. There is a semi-infinite number of valid conditional ACEs that don't have SDDL representations, and an even larger number of invalid (or borderline invalid) ACEs. This allows us to create those ACEs without having to deal with too many array of numbers. The next commit provides an example of its use. Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/conditional_ace_assembler.py b/python/samba/tests/conditional_ace_assembler.py new file mode 100644 index 00000000000..c1ddc6939df --- /dev/null +++ b/python/samba/tests/conditional_ace_assembler.py @@ -0,0 +1,196 @@ +# Unix SMB/CIFS implementation. +# Copyright © Catalyst IT 2023 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +"""Fine-grained control over conditional ACE contents. + +This deliberately allows you to do broken things that SDDL doesn't. + +- token sequences that make no real sense +- sequences that make sense which SDDL can't encode +- strings that aren't proper utf-16 +- etc. +""" + +import struct +from samba.dcerpc import security, conditional_ace as ca +from samba.ndr import ndr_pack + + +class Composite: + token = ca.CONDITIONAL_ACE_TOKEN_COMPOSITE + + def __init__(self, *tokens): + self.members = [] + for t in tokens: + self.members.append(dwim_one_token(t)) + + def __bytes__(self): + v = [] + for x in self.members: + v.extend(bytes(x)) + + return (bytes([self.token]) + + struct.pack(" 255 or min(self.value) < 0: + raise ValueError("bytes do need to be bytes (0-255)") + + def __bytes__(self): + header = struct.pack('