3da750655480901e71051cc2352504f4f6b6b6eb
[garming/samba-autobuild/.git] / python / samba / tests / samba_tool / ntacl.py
1 # Unix SMB/CIFS implementation.
2 # Copyright (C) Andrew Bartlett 2012
3 #
4 # Based on user.py:
5 # Copyright (C) Sean Dague <sdague@linux.vnet.ibm.com> 2011
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 import os
22 import time
23 import ldb
24 from samba.tests.samba_tool.base import SambaToolCmdTest
25 import random
26
27 class NtACLCmdSysvolTestCase(SambaToolCmdTest):
28     """Tests for samba-tool ntacl sysvol* subcommands"""
29
30
31     def test_ntvfs(self):
32         (result, out, err) = self.runsubcmd("ntacl", "sysvolreset",
33                                              "--use-ntvfs")
34         self.assertCmdSuccess(result, out, err)
35         self.assertEquals(out,"","Shouldn't be any output messages")
36         self.assertIn("Please note that POSIX permissions have NOT been changed, only the stored NT ACL", err)
37
38     def test_s3fs(self):
39         (result, out, err) = self.runsubcmd("ntacl", "sysvolreset",
40                                              "--use-s3fs")
41
42         self.assertCmdSuccess(result, out, err)
43         self.assertEquals(err,"","Shouldn't be any error messages")
44         self.assertEquals(out,"","Shouldn't be any output messages")
45
46     def test_ntvfs_check(self):
47         (result, out, err) = self.runsubcmd("ntacl", "sysvolreset",
48                                              "--use-ntvfs")
49         self.assertCmdSuccess(result, out, err)
50         self.assertEquals(out,"","Shouldn't be any output messages")
51         self.assertIn("Please note that POSIX permissions have NOT been changed, only the stored NT ACL", err)
52         # Now check they were set correctly
53         (result, out, err) = self.runsubcmd("ntacl", "sysvolcheck")
54         self.assertCmdSuccess(result, out, err)
55         self.assertEquals(err,"","Shouldn't be any error messages")
56         self.assertEquals(out,"","Shouldn't be any output messages")
57
58     def test_s3fs_check(self):
59         (result, out, err) = self.runsubcmd("ntacl", "sysvolreset",
60                                              "--use-s3fs")
61
62         self.assertCmdSuccess(result, out, err)
63         self.assertEquals(err,"","Shouldn't be any error messages")
64         self.assertEquals(out,"","Shouldn't be any output messages")
65
66         # Now check they were set correctly
67         (result, out, err) = self.runsubcmd("ntacl", "sysvolcheck")
68         self.assertCmdSuccess(result, out, err)
69         self.assertEquals(err,"","Shouldn't be any error messages")
70         self.assertEquals(out,"","Shouldn't be any output messages")
71
72 class NtACLCmdGetSetTestCase(SambaToolCmdTest):
73     """Tests for samba-tool ntacl get/set subcommands"""
74
75     acl = "O:DAG:DUD:P(A;OICI;0x001f01ff;;;DA)(A;OICI;0x001f01ff;;;EA)(A;OICIIO;0x001f01ff;;;CO)(A;OICI;0x001f01ff;;;DA)(A;OICI;0x001f01ff;;;SY)(A;OICI;0x001200a9;;;AU)(A;OICI;0x001200a9;;;ED)S:AI(OU;CIIDSA;WP;f30e3bbe-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)(OU;CIIDSA;WP;f30e3bbf-9ff0-11d1-b603-0000f80367c1;bf967aa5-0de6-11d0-a285-00aa003049e2;WD)"
76
77
78     def test_ntvfs(self):
79         path = os.environ['SELFTEST_PREFIX']
80         tempf = os.path.join(path,"pytests" +str(int(100000 * random.random())))
81         open(tempf, 'w').write("empty")
82
83         (result, out, err) = self.runsubcmd("ntacl", "set", self.acl, tempf,
84                                              "--use-ntvfs")
85         self.assertCmdSuccess(result, out, err)
86         self.assertEquals(out,"","Shouldn't be any output messages")
87         self.assertIn("Please note that POSIX permissions have NOT been changed, only the stored NT ACL", err)
88
89     def test_s3fs(self):
90         path = os.environ['SELFTEST_PREFIX']
91         tempf = os.path.join(path,"pytests" +str(int(100000 * random.random())))
92         open(tempf, 'w').write("empty")
93
94         (result, out, err) = self.runsubcmd("ntacl", "set", self.acl, tempf,
95                                              "--use-s3fs")
96
97         self.assertCmdSuccess(result, out, err)
98         self.assertEquals(err,"","Shouldn't be any error messages")
99         self.assertEquals(out,"","Shouldn't be any output messages")
100
101     def test_ntvfs_check(self):
102         path = os.environ['SELFTEST_PREFIX']
103         tempf = os.path.join(path,"pytests" +str(int(100000 * random.random())))
104         open(tempf, 'w').write("empty")
105
106         (result, out, err) = self.runsubcmd("ntacl", "set", self.acl, tempf,
107                                              "--use-ntvfs")
108         self.assertCmdSuccess(result, out, err)
109         self.assertEquals(out,"","Shouldn't be any output messages")
110         self.assertIn("Please note that POSIX permissions have NOT been changed, only the stored NT ACL", err)
111
112         # Now check they were set correctly
113         (result, out, err) = self.runsubcmd("ntacl",  "get", tempf,
114                                              "--use-ntvfs", "--as-sddl")
115         self.assertCmdSuccess(result, out, err)
116         self.assertEquals(err,"","Shouldn't be any error messages")
117         self.assertEquals(self.acl + "\n", out, "Output should be the ACL")
118
119     def test_s3fs_check(self):
120         path = os.environ['SELFTEST_PREFIX']
121         tempf = os.path.join(path,"pytests" + str(int(100000 *random.random())))
122         open(tempf, 'w').write("empty")
123
124         (result, out, err) = self.runsubcmd("ntacl", "set", self.acl, tempf,
125                                              "--use-s3fs")
126         self.assertCmdSuccess(result, out, err)
127         self.assertEquals(out,"","Shouldn't be any output messages")
128         self.assertEquals(err,"","Shouldn't be any error messages")
129
130         # Now check they were set correctly
131         (result, out, err) = self.runsubcmd("ntacl",  "get", tempf,
132                                              "--use-s3fs", "--as-sddl")
133         self.assertCmdSuccess(result, out, err)
134         self.assertEquals(err,"","Shouldn't be any error messages")
135         self.assertEquals(self.acl + "\n", out,"Output should be the ACL")