1 # Unix SMB/CIFS implementation. Tests for NT and posix ACL 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 the Samba3 NT -> posix ACL layer"""
21 from samba.ntacls import setntacl, getntacl, checkset_backend
22 from samba.dcerpc import xattr, security, smb_acl, idmap
23 from samba.param import LoadParm
24 from samba.tests import TestCase
25 from samba import provision
28 from samba.samba3 import smbd, passdb
29 from samba.samba3 import param as s3param
31 # To print a posix ACL use:
32 # for entry in posix_acl.acl:
33 # print "a_type: %d" % entry.a_type
34 # print "a_perm: %o" % entry.a_perm
35 # print "uid: %d" % entry.uid
36 # print "gid: %d" % entry.gid
38 class PosixAclMappingTests(TestCase):
40 def test_setntacl(self):
43 path = os.environ['SELFTEST_PREFIX']
44 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)"
45 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
46 open(tempf, 'w').write("empty")
47 setntacl(lp, tempf, acl, "S-1-5-21-2212615479-2695158682-2101375467", use_ntvfs=False)
50 def test_setntacl_smbd_getntacl(self):
54 path = os.environ['SELFTEST_PREFIX']
55 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)"
56 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
57 open(tempf, 'w').write("empty")
58 setntacl(lp,tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467", use_ntvfs=True)
59 facl = getntacl(lp,tempf, direct_db_access=True)
60 anysid = security.dom_sid(security.SID_NT_SELF)
61 self.assertEquals(facl.as_sddl(anysid),acl)
64 def test_setntacl_smbd_setposixacl_getntacl(self):
68 path = os.environ['SELFTEST_PREFIX']
69 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)"
70 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
71 open(tempf, 'w').write("empty")
72 setntacl(lp,tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467", use_ntvfs=True)
74 # This will invalidate the ACL, as we have a hook!
75 smbd.set_simple_acl(tempf, 0640)
77 # However, this only asks the xattr
79 facl = getntacl(lp,tempf, direct_db_access=True)
80 self.assertTrue(False)
85 def test_setntacl_invalidate_getntacl(self):
89 path = os.environ['SELFTEST_PREFIX']
90 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)"
91 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
92 open(tempf, 'w').write("empty")
93 setntacl(lp,tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467", use_ntvfs=True)
95 # This should invalidate the ACL, as we include the posix ACL in the hash
96 (backend_obj, dbname) = checkset_backend(lp, None, None)
97 backend_obj.wrap_setxattr(dbname,
98 tempf, "system.fake_access_acl", "")
100 #however, as this is direct DB access, we do not notice it
101 facl = getntacl(lp,tempf, direct_db_access=True)
102 anysid = security.dom_sid(security.SID_NT_SELF)
103 self.assertEquals(acl, facl.as_sddl(anysid))
106 def test_setntacl_invalidate_getntacl_smbd(self):
110 path = os.environ['SELFTEST_PREFIX']
111 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)"
112 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
113 open(tempf, 'w').write("empty")
114 setntacl(lp,tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467", use_ntvfs=False)
116 # This should invalidate the ACL, as we include the posix ACL in the hash
117 (backend_obj, dbname) = checkset_backend(lp, None, None)
118 backend_obj.wrap_setxattr(dbname,
119 tempf, "system.fake_access_acl", "")
121 #the hash would break, and we return an ACL based only on the mode, except we set the ACL using the 'ntvfs' mode that doesn't include a hash
122 facl = getntacl(lp,tempf)
123 anysid = security.dom_sid(security.SID_NT_SELF)
124 self.assertEquals(acl, facl.as_sddl(anysid))
127 def test_setntacl_smbd_invalidate_getntacl_smbd(self):
131 path = os.environ['SELFTEST_PREFIX']
132 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)"
133 simple_acl_from_posix = "O:S-1-5-21-2212615479-2695158682-2101375467-512G:S-1-5-21-2212615479-2695158682-2101375467-513D:(A;;0x001f01ff;;;S-1-5-21-2212615479-2695158682-2101375467-512)(A;;0x001200a9;;;S-1-5-21-2212615479-2695158682-2101375467-513)(A;;WO;;;WD)"
134 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
135 open(tempf, 'w').write("empty")
136 os.chmod(tempf, 0750)
137 setntacl(lp,tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467", use_ntvfs=False)
139 # This should invalidate the ACL, as we include the posix ACL in the hash
140 (backend_obj, dbname) = checkset_backend(lp, None, None)
141 backend_obj.wrap_setxattr(dbname,
142 tempf, "system.fake_access_acl", "")
144 #the hash will break, and we return an ACL based only on the mode
145 facl = getntacl(lp,tempf, direct_db_access=False)
146 anysid = security.dom_sid(security.SID_NT_SELF)
147 self.assertEquals(simple_acl_from_posix, facl.as_sddl(anysid))
150 def test_setntacl_getntacl_smbd(self):
154 path = os.environ['SELFTEST_PREFIX']
155 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)"
156 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
157 open(tempf, 'w').write("empty")
158 setntacl(lp,tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467", use_ntvfs=True)
159 facl = getntacl(lp,tempf, direct_db_access=False)
160 anysid = security.dom_sid(security.SID_NT_SELF)
161 self.assertEquals(facl.as_sddl(anysid),acl)
164 def test_setntacl_smbd_getntacl_smbd(self):
168 path = os.environ['SELFTEST_PREFIX']
169 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)"
170 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
171 open(tempf, 'w').write("empty")
172 setntacl(lp,tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467", use_ntvfs=False)
173 facl = getntacl(lp,tempf, direct_db_access=False)
174 anysid = security.dom_sid(security.SID_NT_SELF)
175 self.assertEquals(facl.as_sddl(anysid),acl)
178 def test_setntacl_smbd_setposixacl_getntacl_smbd(self):
182 path = os.environ['SELFTEST_PREFIX']
183 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)"
184 simple_acl_from_posix = "O:S-1-5-21-2212615479-2695158682-2101375467-512G:S-1-5-21-2212615479-2695158682-2101375467-513D:(A;;0x001f019f;;;S-1-5-21-2212615479-2695158682-2101375467-512)(A;;0x00120089;;;S-1-5-21-2212615479-2695158682-2101375467-513)(A;;WO;;;WD)"
185 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
186 open(tempf, 'w').write("empty")
187 setntacl(lp,tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467", use_ntvfs=False)
188 # This invalidates the hash of the NT acl just set because there is a hook in the posix ACL set code
189 smbd.set_simple_acl(tempf, 0640)
190 facl = getntacl(lp,tempf, direct_db_access=False)
191 anysid = security.dom_sid(security.SID_NT_SELF)
192 self.assertEquals(simple_acl_from_posix, facl.as_sddl(anysid))
195 def test_setntacl_smbd_setposixacl_group_getntacl_smbd(self):
199 path = os.environ['SELFTEST_PREFIX']
200 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)"
201 BA_sid = security.dom_sid(security.SID_BUILTIN_ADMINISTRATORS)
202 simple_acl_from_posix = "O:S-1-5-21-2212615479-2695158682-2101375467-512G:S-1-5-21-2212615479-2695158682-2101375467-513D:(A;;0x001f019f;;;S-1-5-21-2212615479-2695158682-2101375467-512)(A;;0x00120089;;;BA)(A;;0x00120089;;;S-1-5-21-2212615479-2695158682-2101375467-513)(A;;WO;;;WD)"
203 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
204 open(tempf, 'w').write("empty")
205 setntacl(lp,tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467", use_ntvfs=False)
206 # This invalidates the hash of the NT acl just set because there is a hook in the posix ACL set code
207 s3conf = s3param.get_context()
208 s4_passdb = passdb.PDB(s3conf.get("passdb backend"))
209 (BA_gid,BA_type) = s4_passdb.sid_to_id(BA_sid)
210 smbd.set_simple_acl(tempf, 0640, BA_gid)
212 # This should re-calculate an ACL based on the posix details
213 facl = getntacl(lp,tempf, direct_db_access=False)
214 anysid = security.dom_sid(security.SID_NT_SELF)
215 self.assertEquals(simple_acl_from_posix, facl.as_sddl(anysid))
218 def test_setntacl_smbd_getntacl_smbd_gpo(self):
222 path = os.environ['SELFTEST_PREFIX']
223 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)"
224 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
225 open(tempf, 'w').write("empty")
226 setntacl(lp,tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467", use_ntvfs=False)
227 facl = getntacl(lp,tempf, direct_db_access=False)
228 domsid = security.dom_sid("S-1-5-21-2212615479-2695158682-2101375467")
229 self.assertEquals(facl.as_sddl(domsid),acl)
232 def test_setntacl_getposixacl(self):
236 path = os.environ['SELFTEST_PREFIX']
237 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)"
238 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
239 open(tempf, 'w').write("empty")
240 setntacl(lp,tempf,acl,"S-1-5-21-2212615479-2695158682-2101375467", use_ntvfs=False)
241 facl = getntacl(lp,tempf)
242 anysid = security.dom_sid(security.SID_NT_SELF)
243 self.assertEquals(facl.as_sddl(anysid),acl)
244 posix_acl = smbd.get_sys_acl(tempf, smb_acl.SMB_ACL_TYPE_ACCESS)
247 def test_setposixacl_getposixacl(self):
251 path = os.environ['SELFTEST_PREFIX']
252 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
253 open(tempf, 'w').write("empty")
254 smbd.set_simple_acl(tempf, 0640)
255 posix_acl = smbd.get_sys_acl(tempf, smb_acl.SMB_ACL_TYPE_ACCESS)
256 self.assertEquals(posix_acl.count, 4)
258 self.assertEquals(posix_acl.acl[0].a_type, smb_acl.SMB_ACL_USER_OBJ)
259 self.assertEquals(posix_acl.acl[0].a_perm, 6)
261 self.assertEquals(posix_acl.acl[1].a_type, smb_acl.SMB_ACL_GROUP_OBJ)
262 self.assertEquals(posix_acl.acl[1].a_perm, 4)
264 self.assertEquals(posix_acl.acl[2].a_type, smb_acl.SMB_ACL_OTHER)
265 self.assertEquals(posix_acl.acl[2].a_perm, 0)
267 self.assertEquals(posix_acl.acl[3].a_type, smb_acl.SMB_ACL_MASK)
268 self.assertEquals(posix_acl.acl[3].a_perm, 6)
271 def test_setposixacl_getntacl(self):
275 path = os.environ['SELFTEST_PREFIX']
276 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
277 open(tempf, 'w').write("empty")
278 smbd.set_simple_acl(tempf, 0750)
280 facl = getntacl(lp,tempf)
281 self.assertTrue(False)
283 # We don't expect the xattr to be filled in in this case
287 def test_setposixacl_getntacl_smbd(self):
290 path = os.environ['SELFTEST_PREFIX']
291 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
292 open(tempf, 'w').write("empty")
293 s3conf = s3param.get_context()
294 s4_passdb = passdb.PDB(s3conf.get("passdb backend"))
295 group_SID = s4_passdb.gid_to_sid(os.stat(tempf).st_gid)
296 user_SID = s4_passdb.uid_to_sid(os.stat(tempf).st_uid)
297 smbd.set_simple_acl(tempf, 0640)
298 facl = getntacl(lp, tempf, direct_db_access=False)
299 acl = "O:%sG:%sD:(A;;0x001f019f;;;%s)(A;;0x00120089;;;%s)(A;;WO;;;WD)" % (user_SID, group_SID, user_SID, group_SID)
300 anysid = security.dom_sid(security.SID_NT_SELF)
301 self.assertEquals(acl, facl.as_sddl(anysid))
304 def test_setposixacl_group_getntacl_smbd(self):
307 path = os.environ['SELFTEST_PREFIX']
308 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
309 open(tempf, 'w').write("empty")
310 BA_sid = security.dom_sid(security.SID_BUILTIN_ADMINISTRATORS)
311 s3conf = s3param.get_context()
312 s4_passdb = passdb.PDB(s3conf.get("passdb backend"))
313 (BA_gid,BA_type) = s4_passdb.sid_to_id(BA_sid)
314 group_SID = s4_passdb.gid_to_sid(os.stat(tempf).st_gid)
315 user_SID = s4_passdb.uid_to_sid(os.stat(tempf).st_uid)
316 self.assertEquals(BA_type, idmap.ID_TYPE_BOTH)
317 smbd.set_simple_acl(tempf, 0640, BA_gid)
318 facl = getntacl(lp, tempf, direct_db_access=False)
319 domsid = passdb.get_global_sam_sid()
320 acl = "O:%sG:%sD:(A;;0x001f019f;;;%s)(A;;0x00120089;;;BA)(A;;0x00120089;;;%s)(A;;WO;;;WD)" % (user_SID, group_SID, user_SID, group_SID)
321 anysid = security.dom_sid(security.SID_NT_SELF)
322 self.assertEquals(acl, facl.as_sddl(anysid))
325 def test_setposixacl_getposixacl(self):
328 path = os.environ['SELFTEST_PREFIX']
329 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
330 open(tempf, 'w').write("empty")
331 smbd.set_simple_acl(tempf, 0640)
332 posix_acl = smbd.get_sys_acl(tempf, smb_acl.SMB_ACL_TYPE_ACCESS)
333 self.assertEquals(posix_acl.count, 4)
335 self.assertEquals(posix_acl.acl[0].a_type, smb_acl.SMB_ACL_USER_OBJ)
336 self.assertEquals(posix_acl.acl[0].a_perm, 6)
338 self.assertEquals(posix_acl.acl[1].a_type, smb_acl.SMB_ACL_GROUP_OBJ)
339 self.assertEquals(posix_acl.acl[1].a_perm, 4)
341 self.assertEquals(posix_acl.acl[2].a_type, smb_acl.SMB_ACL_OTHER)
342 self.assertEquals(posix_acl.acl[2].a_perm, 0)
344 self.assertEquals(posix_acl.acl[3].a_type, smb_acl.SMB_ACL_MASK)
345 self.assertEquals(posix_acl.acl[3].a_perm, 6)
348 def test_setposixacl_group_getposixacl(self):
351 path = os.environ['SELFTEST_PREFIX']
352 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
353 open(tempf, 'w').write("empty")
354 BA_sid = security.dom_sid(security.SID_BUILTIN_ADMINISTRATORS)
355 s3conf = s3param.get_context()
356 s4_passdb = passdb.PDB(s3conf.get("passdb backend"))
357 (BA_gid,BA_type) = s4_passdb.sid_to_id(BA_sid)
358 self.assertEquals(BA_type, idmap.ID_TYPE_BOTH)
359 smbd.set_simple_acl(tempf, 0670, BA_gid)
360 posix_acl = smbd.get_sys_acl(tempf, smb_acl.SMB_ACL_TYPE_ACCESS)
362 self.assertEquals(posix_acl.count, 5)
364 self.assertEquals(posix_acl.acl[0].a_type, smb_acl.SMB_ACL_USER_OBJ)
365 self.assertEquals(posix_acl.acl[0].a_perm, 6)
367 self.assertEquals(posix_acl.acl[1].a_type, smb_acl.SMB_ACL_GROUP_OBJ)
368 self.assertEquals(posix_acl.acl[1].a_perm, 7)
370 self.assertEquals(posix_acl.acl[2].a_type, smb_acl.SMB_ACL_OTHER)
371 self.assertEquals(posix_acl.acl[2].a_perm, 0)
373 self.assertEquals(posix_acl.acl[3].a_type, smb_acl.SMB_ACL_GROUP)
374 self.assertEquals(posix_acl.acl[3].a_perm, 7)
375 self.assertEquals(posix_acl.acl[3].info.gid, BA_gid)
377 self.assertEquals(posix_acl.acl[4].a_type, smb_acl.SMB_ACL_MASK)
378 self.assertEquals(posix_acl.acl[4].a_perm, 6)
381 def test_setntacl_sysvol_check_getposixacl(self):
384 s3conf = s3param.get_context()
386 path = os.environ['SELFTEST_PREFIX']
387 acl = provision.SYSVOL_ACL
388 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
389 open(tempf, 'w').write("empty")
390 domsid = passdb.get_global_sam_sid()
391 setntacl(lp,tempf,acl,str(domsid), use_ntvfs=False)
392 facl = getntacl(lp,tempf)
393 self.assertEquals(facl.as_sddl(domsid),acl)
394 posix_acl = smbd.get_sys_acl(tempf, smb_acl.SMB_ACL_TYPE_ACCESS)
396 LA_sid = security.dom_sid(str(domsid)+"-"+str(security.DOMAIN_RID_ADMINISTRATOR))
397 BA_sid = security.dom_sid(security.SID_BUILTIN_ADMINISTRATORS)
398 SO_sid = security.dom_sid(security.SID_BUILTIN_SERVER_OPERATORS)
399 SY_sid = security.dom_sid(security.SID_NT_SYSTEM)
400 AU_sid = security.dom_sid(security.SID_NT_AUTHENTICATED_USERS)
402 s4_passdb = passdb.PDB(s3conf.get("passdb backend"))
404 # These assertions correct for current plugin_s4_dc selftest
405 # configuration. When other environments have a broad range of
406 # groups mapped via passdb, we can relax some of these checks
407 (LA_uid,LA_type) = s4_passdb.sid_to_id(LA_sid)
408 self.assertEquals(LA_type, idmap.ID_TYPE_UID)
409 (BA_gid,BA_type) = s4_passdb.sid_to_id(BA_sid)
410 self.assertEquals(BA_type, idmap.ID_TYPE_BOTH)
411 (SO_gid,SO_type) = s4_passdb.sid_to_id(SO_sid)
412 self.assertEquals(SO_type, idmap.ID_TYPE_BOTH)
413 (SY_gid,SY_type) = s4_passdb.sid_to_id(SY_sid)
414 self.assertEquals(SO_type, idmap.ID_TYPE_BOTH)
415 (AU_gid,AU_type) = s4_passdb.sid_to_id(AU_sid)
416 self.assertEquals(AU_type, idmap.ID_TYPE_BOTH)
418 self.assertEquals(posix_acl.count, 9)
420 self.assertEquals(posix_acl.acl[0].a_type, smb_acl.SMB_ACL_GROUP)
421 self.assertEquals(posix_acl.acl[0].a_perm, 7)
422 self.assertEquals(posix_acl.acl[0].info.gid, BA_gid)
424 self.assertEquals(posix_acl.acl[1].a_type, smb_acl.SMB_ACL_USER)
425 self.assertEquals(posix_acl.acl[1].a_perm, 6)
426 self.assertEquals(posix_acl.acl[1].info.uid, LA_uid)
428 self.assertEquals(posix_acl.acl[2].a_type, smb_acl.SMB_ACL_OTHER)
429 self.assertEquals(posix_acl.acl[2].a_perm, 0)
431 self.assertEquals(posix_acl.acl[3].a_type, smb_acl.SMB_ACL_USER_OBJ)
432 self.assertEquals(posix_acl.acl[3].a_perm, 6)
434 self.assertEquals(posix_acl.acl[4].a_type, smb_acl.SMB_ACL_GROUP_OBJ)
435 self.assertEquals(posix_acl.acl[4].a_perm, 7)
437 self.assertEquals(posix_acl.acl[5].a_type, smb_acl.SMB_ACL_GROUP)
438 self.assertEquals(posix_acl.acl[5].a_perm, 5)
439 self.assertEquals(posix_acl.acl[5].info.gid, SO_gid)
441 self.assertEquals(posix_acl.acl[6].a_type, smb_acl.SMB_ACL_GROUP)
442 self.assertEquals(posix_acl.acl[6].a_perm, 7)
443 self.assertEquals(posix_acl.acl[6].info.gid, SY_gid)
445 self.assertEquals(posix_acl.acl[7].a_type, smb_acl.SMB_ACL_GROUP)
446 self.assertEquals(posix_acl.acl[7].a_perm, 5)
447 self.assertEquals(posix_acl.acl[7].info.gid, AU_gid)
449 self.assertEquals(posix_acl.acl[8].a_type, smb_acl.SMB_ACL_MASK)
450 self.assertEquals(posix_acl.acl[8].a_perm, 7)
453 # check that it matches:
455 # user:root:rwx (selftest user actually)
457 # group:Local Admins:rwx
465 # This is in this order in the NDR smb_acl (not re-orderded for display)
472 # uid: 0 (selftest user actually)
507 def test_setntacl_policies_check_getposixacl(self):
510 s3conf = s3param.get_context()
512 path = os.environ['SELFTEST_PREFIX']
513 acl = provision.POLICIES_ACL
514 tempf = os.path.join(path,"pytests"+str(int(100000*random.random())))
515 open(tempf, 'w').write("empty")
516 domsid = passdb.get_global_sam_sid()
517 setntacl(lp,tempf,acl,str(domsid), use_ntvfs=False)
518 facl = getntacl(lp,tempf)
519 self.assertEquals(facl.as_sddl(domsid),acl)
520 posix_acl = smbd.get_sys_acl(tempf, smb_acl.SMB_ACL_TYPE_ACCESS)
522 LA_sid = security.dom_sid(str(domsid)+"-"+str(security.DOMAIN_RID_ADMINISTRATOR))
523 BA_sid = security.dom_sid(security.SID_BUILTIN_ADMINISTRATORS)
524 SO_sid = security.dom_sid(security.SID_BUILTIN_SERVER_OPERATORS)
525 SY_sid = security.dom_sid(security.SID_NT_SYSTEM)
526 AU_sid = security.dom_sid(security.SID_NT_AUTHENTICATED_USERS)
527 PA_sid = security.dom_sid(str(domsid)+"-"+str(security.DOMAIN_RID_POLICY_ADMINS))
529 s4_passdb = passdb.PDB(s3conf.get("passdb backend"))
531 # These assertions correct for current plugin_s4_dc selftest
532 # configuration. When other environments have a broad range of
533 # groups mapped via passdb, we can relax some of these checks
534 (LA_uid,LA_type) = s4_passdb.sid_to_id(LA_sid)
535 self.assertEquals(LA_type, idmap.ID_TYPE_UID)
536 (BA_gid,BA_type) = s4_passdb.sid_to_id(BA_sid)
537 self.assertEquals(BA_type, idmap.ID_TYPE_BOTH)
538 (SO_gid,SO_type) = s4_passdb.sid_to_id(SO_sid)
539 self.assertEquals(SO_type, idmap.ID_TYPE_BOTH)
540 (SY_gid,SY_type) = s4_passdb.sid_to_id(SY_sid)
541 self.assertEquals(SO_type, idmap.ID_TYPE_BOTH)
542 (AU_gid,AU_type) = s4_passdb.sid_to_id(AU_sid)
543 self.assertEquals(AU_type, idmap.ID_TYPE_BOTH)
544 (PA_gid,PA_type) = s4_passdb.sid_to_id(PA_sid)
545 self.assertEquals(PA_type, idmap.ID_TYPE_BOTH)
547 self.assertEquals(posix_acl.count, 10)
549 self.assertEquals(posix_acl.acl[0].a_type, smb_acl.SMB_ACL_GROUP)
550 self.assertEquals(posix_acl.acl[0].a_perm, 7)
551 self.assertEquals(posix_acl.acl[0].info.gid, BA_gid)
553 self.assertEquals(posix_acl.acl[1].a_type, smb_acl.SMB_ACL_USER)
554 self.assertEquals(posix_acl.acl[1].a_perm, 6)
555 self.assertEquals(posix_acl.acl[1].info.uid, LA_uid)
557 self.assertEquals(posix_acl.acl[2].a_type, smb_acl.SMB_ACL_OTHER)
558 self.assertEquals(posix_acl.acl[2].a_perm, 0)
560 self.assertEquals(posix_acl.acl[3].a_type, smb_acl.SMB_ACL_USER_OBJ)
561 self.assertEquals(posix_acl.acl[3].a_perm, 6)
563 self.assertEquals(posix_acl.acl[4].a_type, smb_acl.SMB_ACL_GROUP_OBJ)
564 self.assertEquals(posix_acl.acl[4].a_perm, 7)
566 self.assertEquals(posix_acl.acl[5].a_type, smb_acl.SMB_ACL_GROUP)
567 self.assertEquals(posix_acl.acl[5].a_perm, 5)
568 self.assertEquals(posix_acl.acl[5].info.gid, SO_gid)
570 self.assertEquals(posix_acl.acl[6].a_type, smb_acl.SMB_ACL_GROUP)
571 self.assertEquals(posix_acl.acl[6].a_perm, 7)
572 self.assertEquals(posix_acl.acl[6].info.gid, SY_gid)
574 self.assertEquals(posix_acl.acl[7].a_type, smb_acl.SMB_ACL_GROUP)
575 self.assertEquals(posix_acl.acl[7].a_perm, 5)
576 self.assertEquals(posix_acl.acl[7].info.gid, AU_gid)
578 self.assertEquals(posix_acl.acl[8].a_type, smb_acl.SMB_ACL_GROUP)
579 self.assertEquals(posix_acl.acl[8].a_perm, 7)
580 self.assertEquals(posix_acl.acl[8].info.gid, PA_gid)
582 self.assertEquals(posix_acl.acl[9].a_type, smb_acl.SMB_ACL_MASK)
583 self.assertEquals(posix_acl.acl[9].a_perm, 7)
586 # check that it matches:
588 # user:root:rwx (selftest user actually)
590 # group:Local Admins:rwx
599 # This is in this order in the NDR smb_acl (not re-orderded for display)
606 # uid: 0 (selftest user actually)
646 super(PosixAclMappingTests, self).setUp()
647 s3conf = s3param.get_context()
648 s3conf.load(self.get_loadparm().configfile)