s4:gensec/gssapi: use gensec_gssapi_max_{input,wrapped}_size() for all backends
[Samba.git] / python / samba / tests / ntacls.py
blob8cd09fbcc54d1551c8b23bec979629192ae13b6e
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."""
21 from samba.ntacls import setntacl, getntacl, XattrBackendError
22 from samba.param import LoadParm
23 from samba.dcerpc import security
24 from samba.tests import TestCaseInTempDir, SkipTest
25 import os
27 class NtaclsTests(TestCaseInTempDir):
29 def test_setntacl(self):
30 lp = LoadParm()
31 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)"
32 open(self.tempf, 'w').write("empty")
33 lp.set("posix:eadb",os.path.join(self.tempdir,"eadbtest.tdb"))
34 setntacl(lp, self.tempf, acl, "S-1-5-21-2212615479-2695158682-2101375467")
35 os.unlink(os.path.join(self.tempdir,"eadbtest.tdb"))
37 def test_setntacl_getntacl(self):
38 lp = LoadParm()
39 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)"
40 open(self.tempf, 'w').write("empty")
41 lp.set("posix:eadb",os.path.join(self.tempdir,"eadbtest.tdb"))
42 setntacl(lp,self.tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467")
43 facl = getntacl(lp,self.tempf)
44 anysid = security.dom_sid(security.SID_NT_SELF)
45 self.assertEquals(facl.as_sddl(anysid),acl)
46 os.unlink(os.path.join(self.tempdir,"eadbtest.tdb"))
48 def test_setntacl_getntacl_param(self):
49 lp = LoadParm()
50 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)"
51 open(self.tempf, 'w').write("empty")
52 setntacl(lp,self.tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467","tdb",os.path.join(self.tempdir,"eadbtest.tdb"))
53 facl=getntacl(lp,self.tempf,"tdb",os.path.join(self.tempdir,"eadbtest.tdb"))
54 domsid=security.dom_sid(security.SID_NT_SELF)
55 self.assertEquals(facl.as_sddl(domsid),acl)
56 os.unlink(os.path.join(self.tempdir,"eadbtest.tdb"))
58 def test_setntacl_invalidbackend(self):
59 lp = LoadParm()
60 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)"
61 open(self.tempf, 'w').write("empty")
62 self.assertRaises(XattrBackendError, setntacl, lp, self.tempf, acl, "S-1-5-21-2212615479-2695158682-2101375467","ttdb", os.path.join(self.tempdir,"eadbtest.tdb"))
64 def test_setntacl_forcenative(self):
65 if os.getuid() == 0:
66 raise SkipTest("Running test as root, test skipped")
67 lp = LoadParm()
68 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)"
69 open(self.tempf, 'w').write("empty")
70 lp.set("posix:eadb", os.path.join(self.tempdir,"eadbtest.tdb"))
71 self.assertRaises(Exception, setntacl, lp, self.tempf ,acl,
72 "S-1-5-21-2212615479-2695158682-2101375467","native")
75 def setUp(self):
76 super(NtaclsTests, self).setUp()
77 self.tempf = os.path.join(self.tempdir, "test")
78 open(self.tempf, 'w').write("empty")
80 def tearDown(self):
81 os.unlink(self.tempf)
82 super(NtaclsTests, self).tearDown()