1 # Unix SMB/CIFS implementation. Tests for ntacls manipulation
2 # Copyright (C) Matthieu Patou <mat@matws.net> 2009-2010
3 # Copyright (C) Andrew Bartlett 2012
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 """Tests for samba.ntacls."""
23 from samba.ntacls import setntacl, getntacl, XattrBackendError
24 from samba.param import LoadParm
25 from samba.dcerpc import security
26 from samba.tests import TestCaseInTempDir, SkipTest
27 from samba.auth_util import system_session_unix
29 NTACL_SDDL = "O:S-1-5-21-2212615479-2695158682-2101375467-512G:S-1-5-21-2212615479-2695158682-2101375467-513D:(A;OICI;FA;;;S-1-5-21-2212615479-2695158682-2101375467-512)"
30 DOMAIN_SID = "S-1-5-21-2212615479-2695158682-2101375467"
33 class NtaclsTests(TestCaseInTempDir):
36 super(NtaclsTests, self).setUp()
37 self.tempf = os.path.join(self.tempdir, "test")
38 open(self.tempf, 'w').write("empty")
39 self.session_info = system_session_unix()
43 super(NtaclsTests, self).tearDown()
45 def test_setntacl(self):
47 open(self.tempf, 'w').write("empty")
48 lp.set("posix:eadb", os.path.join(self.tempdir, "eadbtest.tdb"))
49 setntacl(lp, self.tempf, NTACL_SDDL, DOMAIN_SID, self.session_info)
50 os.unlink(os.path.join(self.tempdir, "eadbtest.tdb"))
52 def test_setntacl_getntacl(self):
54 open(self.tempf, 'w').write("empty")
55 lp.set("posix:eadb", os.path.join(self.tempdir, "eadbtest.tdb"))
56 setntacl(lp, self.tempf, NTACL_SDDL, DOMAIN_SID, self.session_info)
57 facl = getntacl(lp, self.tempf, self.session_info)
58 anysid = security.dom_sid(security.SID_NT_SELF)
59 self.assertEqual(facl.as_sddl(anysid), NTACL_SDDL)
60 os.unlink(os.path.join(self.tempdir, "eadbtest.tdb"))
62 def test_setntacl_getntacl_param(self):
64 open(self.tempf, 'w').write("empty")
65 setntacl(lp, self.tempf, NTACL_SDDL, DOMAIN_SID, self.session_info, "tdb",
66 os.path.join(self.tempdir, "eadbtest.tdb"))
67 facl = getntacl(lp, self.tempf, self.session_info, "tdb", os.path.join(
68 self.tempdir, "eadbtest.tdb"))
69 domsid = security.dom_sid(security.SID_NT_SELF)
70 self.assertEqual(facl.as_sddl(domsid), NTACL_SDDL)
71 os.unlink(os.path.join(self.tempdir, "eadbtest.tdb"))
73 def test_setntacl_invalidbackend(self):
75 open(self.tempf, 'w').write("empty")
76 self.assertRaises(XattrBackendError, setntacl, lp, self.tempf,
77 NTACL_SDDL, DOMAIN_SID, self.session_info, "ttdb",
78 os.path.join(self.tempdir, "eadbtest.tdb"))
80 def test_setntacl_forcenative(self):
82 raise SkipTest("Running test as root, test skipped")
84 open(self.tempf, 'w').write("empty")
85 lp.set("posix:eadb", os.path.join(self.tempdir, "eadbtest.tdb"))
86 self.assertRaises(Exception, setntacl, lp, self.tempf, NTACL_SDDL,
87 DOMAIN_SID, self.session_info, "native")