2018-12-12 13:40:43 +13:00
#!/usr/bin/env python3
2017-02-16 16:41:00 +13:00
# -*- coding: utf-8 -*-
import sys
sys . path . insert ( 0 , ' bin/python ' )
import samba
import gzip
2024-01-04 01:51:56 +13:00
from samba . tests . subunitrun import TestProgram
2017-02-16 16:41:00 +13:00
from samba . ndr import ndr_pack , ndr_unpack
from samba . dcerpc import security
from samba . dcerpc import drsuapi
BIG_SD_SDDL = ' ' . join (
2018-07-30 18:14:21 +12:00
""" O:S-1-5-21-3328325300-3937145445-4190589019-512G:S-1-5-2
2017-02-16 16:41:00 +13:00
1 - 3328325300 - 3937145445 - 4190589019 - 512 D : AI ( A ; ; RPWPCRCCDCLCLORCWOWDSDDTSW ; ; ; S -
1 - 5 - 21 - 3328325300 - 3937145445 - 4190589019 - 512 ) ( A ; ; RPWPCRCCDCLCLORCWOWDSDDTSW ; ; ;
SY ) ( A ; ; RPLCLORC ; ; ; AU ) ( A ; ; RPWPCRCCDCLCLORCWOWDSDDTSW ; ; ; AO ) ( A ; ; RPLCLORC ; ; ; PS ) ( O
A ; ; CR ; ab721a55 - 1e2 f - 11 d0 - 9819 - 00 aa0040529b ; ; AU ) ( OA ; ; RP ; 46 a9b11d - 60 ae - 405 a - b7e
8 - ff8a58d456d2 ; ; S - 1 - 5 - 32 - 560 ) ( OA ; CIIOID ; RP ; 4 c164200 - 20 c0 - 11 d0 - a768 - 00 aa006e05
29 ; 4828 cc14 - 1437 - 45 bc - 9 b07 - ad6f015e5f28 ; RU ) ( OA ; CIIOID ; RP ; 4 c164200 - 20 c0 - 11 d0 - a
768 - 00 aa006e0529 ; bf967aba - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; RU ) ( OA ; CIIOID ; RP ; 5 f2020
10 - 79 a5 - 11 d0 - 9020 - 00 c04fc2d4cf ; 4828 cc14 - 1437 - 45 bc - 9 b07 - ad6f015e5f28 ; RU ) ( OA ; CI
IOID ; RP ; 5 f202010 - 79 a5 - 11 d0 - 9020 - 00 c04fc2d4cf ; bf967aba - 0 de6 - 11 d0 - a285 - 00 aa0030
49e2 ; RU ) ( OA ; CIIOID ; RP ; bc0ac240 - 79 a9 - 11 d0 - 9020 - 00 c04fc2d4cf ; 4828 cc14 - 1437 - 45 bc
- 9 b07 - ad6f015e5f28 ; RU ) ( OA ; CIIOID ; RP ; bc0ac240 - 79 a9 - 11 d0 - 9020 - 00 c04fc2d4cf ; bf96
7 aba - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; RU ) ( OA ; CIIOID ; RP ; 59 ba2f42 - 79 a2 - 11 d0 - 9020 - 00 c
04 fc2d3cf ; 4828 cc14 - 1437 - 45 bc - 9 b07 - ad6f015e5f28 ; RU ) ( OA ; CIIOID ; RP ; 59 ba2f42 - 79 a2
- 11 d0 - 9020 - 00 c04fc2d3cf ; bf967aba - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; RU ) ( OA ; CIIOID ; RP
; 037088 f8 - 0 ae1 - 11 d2 - b422 - 00 a0c968f939 ; 4828 cc14 - 1437 - 45 bc - 9 b07 - ad6f015e5f28 ; RU
) ( OA ; CIIOID ; RP ; 037088 f8 - 0 ae1 - 11 d2 - b422 - 00 a0c968f939 ; bf967aba - 0 de6 - 11 d0 - a285 - 0
0 aa003049e2 ; RU ) ( OA ; CIIOID ; RP ; b7c69e6d - 2 cc7 - 11 d2 - 854e-00 a0c983f608 ; bf967a86 - 0 d
e6 - 11 d0 - a285 - 00 aa003049e2 ; ED ) ( OA ; CIID ; RP ; b7c69e6d - 2 cc7 - 11 d2 - 854e-00 a0c983f608
; bf967a9c - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; ED ) ( OA ; CIIOID ; RP ; b7c69e6d - 2 cc7 - 11 d2 - 854
e - 00 a0c983f608 ; bf967aba - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; ED ) ( OA ; CIIOID ; RPLCLORC ; ; 4
828 cc14 - 1437 - 45 bc - 9 b07 - ad6f015e5f28 ; RU ) ( OA ; CIID ; RPLCLORC ; ; bf967a9c - 0 de6 - 11 d0 -
a285 - 00 aa003049e2 ; RU ) ( OA ; CIIOID ; RPLCLORC ; ; bf967aba - 0 de6 - 11 d0 - a285 - 00 aa003049e
2 ; RU ) ( OA ; CIID ; RPWPCR ; 91e647 de - d96f - 4 b70 - 9557 - d63ff4f3ccd8 ; ; PS ) ( A ; CIID ; RPWPCRC
CDCLCLORCWOWDSDDTSW ; ; ; S - 1 - 5 - 21 - 3328325300 - 3937145445 - 4190589019 - 519 ) ( A ; CIID ; L
C ; ; ; RU ) ( A ; CIID ; RPWPCRCCLCLORCWOWDSDSW ; ; ; BA ) ( OA ; CIIOID ; RP ; 4 c164200 - 20 c0 - 11 d0 - a
768 - 00 aa006e0529 ; 4828 cc14 - 1437 - 45 bc - 9 b07 - ad6f015e5f28 ; RU ) ( OA ; CIIOID ; RP ; 4 c1642
00 - 20 c0 - 11 d0 - a768 - 00 aa006e0529 ; bf967aba - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; RU ) ( OA ; CI
IOID ; RP ; 5 f202010 - 79 a5 - 11 d0 - 9020 - 00 c04fc2d4cf ; 4828 cc14 - 1437 - 45 bc - 9 b07 - ad6f015e
5 f28 ; RU ) ( OA ; CIIOID ; RP ; 5 f202010 - 79 a5 - 11 d0 - 9020 - 00 c04fc2d4cf ; bf967aba - 0 de6 - 11 d0
- a285 - 00 aa003049e2 ; RU ) ( OA ; CIIOID ; RP ; bc0ac240 - 79 a9 - 11 d0 - 9020 - 00 c04fc2d4cf ; 4828
cc14 - 1437 - 45 bc - 9 b07 - ad6f015e5f28 ; RU ) ( OA ; CIIOID ; RP ; bc0ac240 - 79 a9 - 11 d0 - 9020 - 00 c
04 fc2d4cf ; bf967aba - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; RU ) ( OA ; CIIOID ; RP ; 59 ba2f42 - 79 a2
- 11 d0 - 9020 - 00 c04fc2d3cf ; 4828 cc14 - 1437 - 45 bc - 9 b07 - ad6f015e5f28 ; RU ) ( OA ; CIIOID ; RP
; 59 ba2f42 - 79 a2 - 11 d0 - 9020 - 00 c04fc2d3cf ; bf967aba - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; RU
) ( OA ; CIIOID ; RP ; 037088 f8 - 0 ae1 - 11 d2 - b422 - 00 a0c968f939 ; 4828 cc14 - 1437 - 45 bc - 9 b07 - a
d6f015e5f28 ; RU ) ( OA ; CIIOID ; RP ; 037088 f8 - 0 ae1 - 11 d2 - b422 - 00 a0c968f939 ; bf967aba - 0 d
e6 - 11 d0 - a285 - 00 aa003049e2 ; RU ) ( OA ; CIIOID ; RP ; b7c69e6d - 2 cc7 - 11 d2 - 854e-00 a0c983f6
08 ; bf967a86 - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; ED ) ( OA ; CIID ; RP ; b7c69e6d - 2 cc7 - 11 d2 - 854
e - 00 a0c983f608 ; bf967a9c - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; ED ) ( OA ; CIIOID ; RP ; b7c69e6d
- 2 cc7 - 11 d2 - 854e-00 a0c983f608 ; bf967aba - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; ED ) ( OA ; CIIO
ID ; RPLCLORC ; ; 4828 cc14 - 1437 - 45 bc - 9 b07 - ad6f015e5f28 ; RU ) ( OA ; CIID ; RPLCLORC ; ; bf967
a9c - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; RU ) ( OA ; CIIOID ; RPLCLORC ; ; bf967aba - 0 de6 - 11 d0 - a2
85 - 00 aa003049e2 ; RU ) ( OA ; CIID ; RPWPCR ; 91e647 de - d96f - 4 b70 - 9557 - d63ff4f3ccd8 ; ; PS ) (
A ; CIID ; RPWPCRCCDCLCLORCWOWDSDDTSW ; ; ; S - 1 - 5 - 21 - 3328325300 - 3937145445 - 4190589019
- 519 ) ( A ; CIID ; LC ; ; ; RU ) ( A ; CIID ; RPWPCRCCLCLORCWOWDSDSW ; ; ; BA ) S : AI ( OU ; CIIOIDSA ; WP ;
f30e3bbe - 9 ff0 - 11 d1 - b603 - 0000 f80367c1 ; bf967aa5 - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; WD )
( OU ; CIIOIDSA ; WP ; f30e3bbf - 9 ff0 - 11 d1 - b603 - 0000 f80367c1 ; bf967aa5 - 0 de6 - 11 d0 - a285 -
00 aa003049e2 ; WD ) ( OU ; CIIOIDSA ; WP ; f30e3bbe - 9 ff0 - 11 d1 - b603 - 0000 f80367c1 ; bf967aa5
- 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; WD ) ( OU ; CIIOIDSA ; WP ; f30e3bbf - 9 ff0 - 11 d1 - b603 - 0000 f
80367 c1 ; bf967aa5 - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; WD ) """ .split())
LITTLE_SD_SDDL = ' ' . join (
2018-07-30 18:14:21 +12:00
""" O:S-1-5-21-3328325300-3937145445-4190589019-512G:S-1-5-2
2017-02-16 16:41:00 +13:00
1 - 3328325300 - 3937145445 - 4190589019 - 512 D : AI ( A ; ; RPWPCRCCDCLCLORCWOWDSDDTSW ; ; ; S -
1 - 5 - 21 - 3328325300 - 3937145445 - 4190589019 - 512 ) ( A ; ; RPWPCRCCDCLCLORCWOWDSDDTSW ; ; ;
SY ) ( A ; ; RPLCLORC ; ; ; AU ) ( A ; ; RPWPCRCCDCLCLORCWOWDSDDTSW ; ; ; AO ) ( A ; ; RPLCLORC ; ; ; PS ) ( O
A ; ; CR ; ab721a55 - 1e2 f - 11 d0 - 9819 - 00 aa0040529b ; ; AU ) ( OA ; ; RP ; 46 a9b11d - 60 ae - 405 a - b7e
8 - ff8a58d456d2 ; ; S - 1 - 5 - 32 - 560 ) ( OA ; CIIOID ; RP ; 4 c164200 - 20 c0 - 11 d0 - a768 - 00 aa006e05
29 ; 4828 cc14 - 1437 - 45 bc - 9 b07 - ad6f015e5f28 ; RU ) ( OA ; CIIOID ; RP ; 4 c164200 - 20 c0 - 11 d0 - a
768 - 00 aa006e0529 ; bf967aba - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; RU ) ( OA ; CIIOID ; RP ; 5 f2020
10 - 79 a5 - 11 d0 - 9020 - 00 c04fc2d4cf ; 4828 cc14 - 1437 - 45 bc - 9 b07 - ad6f015e5f28 ; RU ) ( OA ; CI
IOID ; RP ; 5 f202010 - 79 a5 - 11 d0 - 9020 - 00 c04fc2d4cf ; bf967aba - 0 de6 - 11 d0 - a285 - 00 aa0030
49e2 ; RU ) ( OA ; CIIOID ; RP ; bc0ac240 - 79 a9 - 11 d0 - 9020 - 00 c04fc2d4cf ; 4828 cc14 - 1437 - 45 bc
- 9 b07 - ad6f015e5f28 ; RU ) ( OA ; CIIOID ; RP ; bc0ac240 - 79 a9 - 11 d0 - 9020 - 00 c04fc2d4cf ; bf96
7 aba - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; RU ) ( OA ; CIIOID ; RP ; 59 ba2f42 - 79 a2 - 11 d0 - 9020 - 00 c
04 fc2d3cf ; 4828 cc14 - 1437 - 45 bc - 9 b07 - ad6f015e5f28 ; RU ) ( OA ; CIIOID ; RP ; 59 ba2f42 - 79 a2
- 11 d0 - 9020 - 00 c04fc2d3cf ; bf967aba - 0 de6 - 11 d0 - a285 - 00 aa003049e2 ; RU ) ( OA ; CIIOID ; RP
; 037088 f8 - 0 ae1 - 11 d2 - b422 - 00 a0c968f939 ; 4828 cc14 - 1437 - 45 bc - 9 b07 - ad6f015e5f28 ; RU
) ( OA ; CIIOID ; RP ; 037088 f8 - 0 ae1 - 11 d2 - b422 - 00 a0c968f939 ; bf967aba - 0 de6 - 11 d0 - a285 - 0
0 aa003049e2 ; RU ) ( OA ; CIIOID ; RP ; b7c69e6d - 2 cc7 - 11 d2 - 854e-00 a0c983f608 ; bf967a86 - 0 d
e6 - 11 d0 - a285 - 00 aa003049e2 ; ED ) """ .split())
2024-01-01 21:48:15 +13:00
CONDITIONAL_ACE_SDDL = ( ' O:SYG:SYD:(XA;OICI;CR;;;WD; '
' (@USER.ad://ext/AuthenticationSilo == " siloname " )) ' )
NON_OBJECT_SDDL = (
" O:S-1-5-21-2212615479-2695158682-2101375468-512 "
" G:S-1-5-21-2212615479-2695158682-2101375468-513 "
" D:P(A;OICI;FA;;;S-1-5-21-2212615479-2695158682-2101375468-512) "
" (A;OICI;FA;;;S-1-5-21-2212615479-2695158682-2101375468-519) "
" (A;OICIIO;FA;;;CO) "
" (A;OICI;FA;;;S-1-5-21-2212615479-2695158682-2101375468-512) "
" (A;OICI;FA;;;SY) "
" (A;OICI;0x1200a9;;;AU) "
" (A;OICI;0x1200a9;;;ED) " )
2017-02-16 16:41:00 +13:00
# set SCALE = 100 for normal test, or 1 for testing the test.
SCALE = 100
2018-07-30 18:20:39 +12:00
2017-02-16 16:41:00 +13:00
class UserTests ( samba . tests . TestCase ) :
def get_file_blob ( self , filename ) :
if filename . endswith ( ' .gz ' ) :
f = gzip . open ( filename )
else :
f = open ( filename )
return f . read ( )
def get_desc ( self , sddl ) :
2024-01-04 01:52:39 +13:00
dummy_sid = security . dom_sid ( " S-1-2-3 " )
2017-02-16 16:41:00 +13:00
return security . descriptor . from_sddl ( sddl , dummy_sid )
def get_blob ( self , sddl ) :
return ndr_pack ( self . get_desc ( sddl ) )
2024-01-04 01:54:29 +13:00
def test_00_00_do_nothing ( self , cycles = 10000 ) :
2017-02-16 16:41:00 +13:00
# this gives us an idea of the overhead
2024-01-04 01:54:29 +13:00
for i in range ( SCALE * cycles ) :
pass
2017-02-16 16:41:00 +13:00
def _test_pack ( self , unpacked , cycles = 10000 ) :
2024-01-03 09:43:01 +13:00
pack = unpacked . __ndr_pack__
2017-02-16 16:41:00 +13:00
for i in range ( SCALE * cycles ) :
2024-01-03 09:43:01 +13:00
pack ( )
2017-02-16 16:41:00 +13:00
def _test_unpack ( self , blob , cycles = 10000 , cls = security . descriptor ) :
for i in range ( SCALE * cycles ) :
2024-01-03 09:43:01 +13:00
cls ( ) . __ndr_unpack__ ( blob )
2017-02-16 16:41:00 +13:00
def _test_pack_unpack ( self , desc , cycles = 5000 , cls = security . descriptor ) :
blob2 = ndr_pack ( desc )
for i in range ( SCALE * cycles ) :
blob = ndr_pack ( desc )
desc = ndr_unpack ( cls , blob )
self . assertEqual ( blob , blob2 )
2024-01-03 09:26:51 +13:00
def test_pack_big_sd_with_object_aces ( self ) :
2017-02-16 16:41:00 +13:00
unpacked = self . get_desc ( BIG_SD_SDDL )
self . _test_pack ( unpacked )
2024-01-03 09:26:51 +13:00
def test_unpack_big_sd_with_object_aces ( self ) :
2017-02-16 16:41:00 +13:00
blob = self . get_blob ( BIG_SD_SDDL )
self . _test_unpack ( blob )
2024-01-03 09:26:51 +13:00
def test_pack_unpack_big_sd_with_object_aces ( self ) :
2017-02-16 16:41:00 +13:00
unpacked = self . get_desc ( BIG_SD_SDDL )
self . _test_pack_unpack ( unpacked )
2024-01-03 09:26:51 +13:00
def test_pack_little_sd_with_object_aces ( self ) :
2017-02-16 16:41:00 +13:00
unpacked = self . get_desc ( LITTLE_SD_SDDL )
self . _test_pack ( unpacked )
2024-01-03 09:26:51 +13:00
def test_unpack_little_sd_with_object_aces ( self ) :
2017-02-16 16:41:00 +13:00
blob = self . get_blob ( LITTLE_SD_SDDL )
self . _test_unpack ( blob )
2024-01-03 09:26:51 +13:00
def test_pack_unpack_little_sd_with_object_aces ( self ) :
2017-02-16 16:41:00 +13:00
unpacked = self . get_desc ( LITTLE_SD_SDDL )
self . _test_pack_unpack ( unpacked )
2024-01-01 21:48:15 +13:00
def test_pack_conditional_ace_sd ( self ) :
unpacked = self . get_desc ( CONDITIONAL_ACE_SDDL )
self . _test_pack ( unpacked )
def test_unpack_conditional_ace_sd ( self ) :
blob = self . get_blob ( CONDITIONAL_ACE_SDDL )
self . _test_unpack ( blob )
def test_pack_unpack_conditional_ace_sd ( self ) :
unpacked = self . get_desc ( CONDITIONAL_ACE_SDDL )
self . _test_pack_unpack ( unpacked )
def test_pack_non_object_sd ( self ) :
unpacked = self . get_desc ( NON_OBJECT_SDDL )
self . _test_pack ( unpacked )
def test_unpack_non_object_sd ( self ) :
blob = self . get_blob ( NON_OBJECT_SDDL )
self . _test_unpack ( blob )
def test_pack_unpack_non_object_sd ( self ) :
unpacked = self . get_desc ( NON_OBJECT_SDDL )
self . _test_pack_unpack ( unpacked )
2017-02-16 16:41:00 +13:00
def test_unpack_repl_sample ( self ) :
blob = self . get_file_blob ( ' testdata/replication-ndrpack-example.gz ' )
self . _test_unpack ( blob , cycles = 20 , cls = drsuapi . DsGetNCChangesCtr6 )
def test_pack_repl_sample ( self ) :
blob = self . get_file_blob ( ' testdata/replication-ndrpack-example.gz ' )
2018-07-30 18:17:44 +12:00
desc = ndr_unpack ( drsuapi . DsGetNCChangesCtr6 , blob )
2017-02-16 16:41:00 +13:00
self . _test_pack ( desc , cycles = 20 )
2018-07-30 18:21:29 +12:00
2024-01-04 01:51:56 +13:00
TestProgram ( module = __name__ )