3
# Unix SMB/CIFS implementation. Tests for ntacls manipulation
4
# Copyright (C) Matthieu Patou <mat@matws.net> 2009-2010
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
"""Tests for samba.ntacls."""
22
from samba.ntacls import setntacl, getntacl, XattrBackendError
23
from samba.dcerpc import xattr, security
24
from samba.param import LoadParm
25
from samba.tests import TestCase, TestSkipped
29
class NtaclsTests(TestCase):
31
def test_setntacl(self):
34
path = os.environ['SELFTEST_PREFIX']
35
acl = "O:S-1-5-21-2212615479-2695158682-2101375467-512G:S-1-5-21-2212615479-2695158682-2101375467-513D:(A;OICI;0x001f01ff;;;S-1-5-21-2212615479-2695158682-2101375467-512)"
36
tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
39
open(tempf, 'w').write("empty")
40
lp.set("posix:eadb",os.path.join(path,"eadbtest.tdb"))
41
setntacl(lp, tempf, acl, "S-1-5-21-2212615479-2695158682-2101375467")
44
def test_setntacl_getntacl(self):
48
path = os.environ['SELFTEST_PREFIX']
49
acl = "O:S-1-5-21-2212615479-2695158682-2101375467-512G:S-1-5-21-2212615479-2695158682-2101375467-513D:(A;OICI;0x001f01ff;;;S-1-5-21-2212615479-2695158682-2101375467-512)"
50
tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
53
open(tempf, 'w').write("empty")
54
lp.set("posix:eadb",os.path.join(path,"eadbtest.tdb"))
55
setntacl(lp,tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467")
56
facl = getntacl(lp,tempf)
57
anysid = security.dom_sid(security.SID_NT_SELF)
58
self.assertEquals(facl.info.as_sddl(anysid),acl)
61
def test_setntacl_getntacl_param(self):
64
acl = "O:S-1-5-21-2212615479-2695158682-2101375467-512G:S-1-5-21-2212615479-2695158682-2101375467-513D:(A;OICI;0x001f01ff;;;S-1-5-21-2212615479-2695158682-2101375467-512)"
65
path = os.environ['SELFTEST_PREFIX']
66
tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
69
open(tempf, 'w').write("empty")
70
setntacl(lp,tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467","tdb",os.path.join(path,"eadbtest.tdb"))
71
facl=getntacl(lp,tempf,"tdb",os.path.join(path,"eadbtest.tdb"))
72
domsid=security.dom_sid(security.SID_NT_SELF)
73
self.assertEquals(facl.info.as_sddl(domsid),acl)
76
def test_setntacl_invalidbackend(self):
79
acl = "O:S-1-5-21-2212615479-2695158682-2101375467-512G:S-1-5-21-2212615479-2695158682-2101375467-513D:(A;OICI;0x001f01ff;;;S-1-5-21-2212615479-2695158682-2101375467-512)"
80
path = os.environ['SELFTEST_PREFIX']
81
tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
84
open(tempf, 'w').write("empty")
85
self.assertRaises(XattrBackendError, setntacl, lp, tempf, acl, "S-1-5-21-2212615479-2695158682-2101375467","ttdb", os.path.join(path,"eadbtest.tdb"))
87
def test_setntacl_forcenative(self):
89
raise TestSkipped("Running test as root, test skipped")
92
acl = "O:S-1-5-21-2212615479-2695158682-2101375467-512G:S-1-5-21-2212615479-2695158682-2101375467-513D:(A;OICI;0x001f01ff;;;S-1-5-21-2212615479-2695158682-2101375467-512)"
93
path = os.environ['SELFTEST_PREFIX']
94
tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
97
open(tempf, 'w').write("empty")
98
lp.set("posix:eadb", os.path.join(path,"eadbtest.tdb"))
99
self.assertRaises(Exception, setntacl, lp, tempf ,acl,
100
"S-1-5-21-2212615479-2695158682-2101375467","native")