The branch, master has been updated via dcd4fed talloc: Add tests for talloc destructor behaviour after talloc_realloc() via eee2367 selftest: Print the POSIX ACL we got when the posixacl test fails from d43d0a1 smb.conf: add identity mapping section
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit dcd4fed82d25c40ac61fe3aa42083b47eca94389 Author: Andrew Bartlett <abart...@samba.org> Date: Thu Nov 24 13:57:54 2016 +1300 talloc: Add tests for talloc destructor behaviour after talloc_realloc() That this behaved correctly was not clear, so I added tests to prove it to myself. Signed-off-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Garming Sam <garm...@catalyst.net.nz> Autobuild-User(master): Andrew Bartlett <abart...@samba.org> Autobuild-Date(master): Tue Dec 13 06:47:58 CET 2016 on sn-devel-144 commit eee23677eaf19f8e5015e4febdc7fec62507c5b0 Author: Andrew Bartlett <abart...@samba.org> Date: Tue Dec 13 14:21:29 2016 +1300 selftest: Print the POSIX ACL we got when the posixacl test fails Knowing we have 11 of 15 ACEs is not very helpful Signed-off-by: Andrew Bartlett <abart...@samba.org> Reviewed-by: Garming Sam <garm...@catalyst.net.nz> ----------------------------------------------------------------------- Summary of changes: lib/talloc/testsuite.c | 67 +++++++++++++++++++++++++++++++++++++++++- python/samba/tests/posixacl.py | 27 ++++++++++++----- 2 files changed, 85 insertions(+), 9 deletions(-) Changeset truncated at 500 lines: diff --git a/lib/talloc/testsuite.c b/lib/talloc/testsuite.c index 835d38b..dfaeec1 100644 --- a/lib/talloc/testsuite.c +++ b/lib/talloc/testsuite.c @@ -610,7 +610,7 @@ static bool test_realloc_child(void) void *root; struct el2 { const char *name; - } *el2, *el2_2, *el2_3; + } *el2, *el2_2, *el2_3, **el_list_save; struct el1 { int count; struct el2 **list, **list2, **list3; @@ -640,7 +640,13 @@ static bool test_realloc_child(void) el2_3 = talloc(el1->list3, struct el2); CHECK_PARENT("el2", el2_3, el1->list3); + el_list_save = el1->list; el1->list = talloc_realloc(el1, el1->list, struct el2 *, 100); + if (el1->list == el_list_save) { + printf("failure: talloc_realloc didn't move pointer"); + return false; + } + CHECK_PARENT("el1_after_realloc", el1->list, el1); el1->list2 = talloc_realloc(el1, el1->list2, struct el2 *, 200); CHECK_PARENT("el1_after_realloc", el1->list2, el1); @@ -651,6 +657,12 @@ static bool test_realloc_child(void) CHECK_PARENT("el2", el2_2, el1->list2); CHECK_PARENT("el2", el2_3, el1->list3); + /* Finally check realloc with multiple children */ + el1 = talloc_realloc(root, el1, struct el1, 100); + CHECK_PARENT("el1->list", el1->list, el1); + CHECK_PARENT("el1->list2", el1->list2, el1); + CHECK_PARENT("el1->list3", el1->list3, el1); + talloc_free(root); printf("success: REALLOC WITH CHILD\n"); @@ -973,6 +985,57 @@ static bool test_loop(void) return true; } +static int realloc_parent_destructor_count; + +static int test_realloc_parent_destructor(char *ptr) +{ + realloc_parent_destructor_count++; + return 0; +} + +static bool test_realloc_on_destructor_parent(void) +{ + void *top = talloc_new(NULL); + char *parent; + char *a, *b, *C, *D; + realloc_parent_destructor_count = 0; + + printf("test: free_for_exit\n# TALLOC FREE FOR EXIT\n"); + + parent = talloc_strdup(top, "parent"); + a = talloc_strdup(parent, "a"); + b = talloc_strdup(a, "b"); + C = talloc_strdup(a, "C"); + D = talloc_strdup(b, "D"); + talloc_set_destructor(D, test_realloc_parent_destructor); + /* Capitalised ones have destructors. + * + * parent --> a -> b -> D + * -> c + */ + + a = talloc_realloc(parent, a, char, 2048); + + torture_assert("check talloc_realloc", a != NULL, "talloc_realloc failed"); + + talloc_set_destructor(C, test_realloc_parent_destructor); + /* + * parent --> a[2048] -> b -> D + * -> C + * + */ + + talloc_free(parent); + + torture_assert("check destructor realloc_parent_destructor", + realloc_parent_destructor_count == 2, + "FAILED TO FIRE free_for_exit_destructor\n"); + + + printf("success: free_for_exit\n"); + return true; +} + static int fail_destructor_str(char *ptr) { return -1; @@ -1994,6 +2057,8 @@ bool torture_local_talloc(struct torture_context *tctx) test_reset(); ret &= test_free_parent_deny_child(); test_reset(); + ret &= test_realloc_on_destructor_parent(); + test_reset(); ret &= test_free_parent_reparent_child(); test_reset(); ret &= test_free_parent_reparent_child_in_pool(); diff --git a/python/samba/tests/posixacl.py b/python/samba/tests/posixacl.py index 40632f4..8dc2098 100644 --- a/python/samba/tests/posixacl.py +++ b/python/samba/tests/posixacl.py @@ -39,6 +39,17 @@ from samba.samba3 import param as s3param class PosixAclMappingTests(TestCaseInTempDir): + def print_posix_acl(self, posix_acl): + aclstr = "" + for entry in posix_acl.acl: + aclstr += "a_type: %d\n" % entry.a_type + aclstr += "a_perm: %o\n" % entry.a_perm + if entry.a_type == smb_acl.SMB_ACL_USER: + aclstr += "uid: %d\n" % entry.info.uid + if entry.a_type == smb_acl.SMB_ACL_GROUP: + aclstr += "gid: %d\n" % entry.info.gid + return aclstr + def test_setntacl(self): 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)" setntacl(self.lp, self.tempf, acl, "S-1-5-21-2212615479-2695158682-2101375467", use_ntvfs=False) @@ -182,7 +193,7 @@ class PosixAclMappingTests(TestCaseInTempDir): def test_setposixacl_getposixacl(self): smbd.set_simple_acl(self.tempf, 0640) posix_acl = smbd.get_sys_acl(self.tempf, smb_acl.SMB_ACL_TYPE_ACCESS) - self.assertEquals(posix_acl.count, 4) + self.assertEquals(posix_acl.count, 4, self.print_posix_acl(posix_acl)) self.assertEquals(posix_acl.acl[0].a_type, smb_acl.SMB_ACL_USER_OBJ) self.assertEquals(posix_acl.acl[0].a_perm, 6) @@ -251,7 +262,7 @@ class PosixAclMappingTests(TestCaseInTempDir): def test_setposixacl_getposixacl(self): smbd.set_simple_acl(self.tempf, 0640) posix_acl = smbd.get_sys_acl(self.tempf, smb_acl.SMB_ACL_TYPE_ACCESS) - self.assertEquals(posix_acl.count, 4) + self.assertEquals(posix_acl.count, 4, self.print_posix_acl(posix_acl)) self.assertEquals(posix_acl.acl[0].a_type, smb_acl.SMB_ACL_USER_OBJ) self.assertEquals(posix_acl.acl[0].a_perm, 6) @@ -268,7 +279,7 @@ class PosixAclMappingTests(TestCaseInTempDir): def test_setposixacl_dir_getposixacl(self): smbd.set_simple_acl(self.tempdir, 0750) posix_acl = smbd.get_sys_acl(self.tempdir, smb_acl.SMB_ACL_TYPE_ACCESS) - self.assertEquals(posix_acl.count, 4) + self.assertEquals(posix_acl.count, 4, self.print_posix_acl(posix_acl)) self.assertEquals(posix_acl.acl[0].a_type, smb_acl.SMB_ACL_USER_OBJ) self.assertEquals(posix_acl.acl[0].a_perm, 7) @@ -290,7 +301,7 @@ class PosixAclMappingTests(TestCaseInTempDir): smbd.set_simple_acl(self.tempf, 0670, BA_gid) posix_acl = smbd.get_sys_acl(self.tempf, smb_acl.SMB_ACL_TYPE_ACCESS) - self.assertEquals(posix_acl.count, 5) + self.assertEquals(posix_acl.count, 5, self.print_posix_acl(posix_acl)) self.assertEquals(posix_acl.acl[0].a_type, smb_acl.SMB_ACL_USER_OBJ) self.assertEquals(posix_acl.acl[0].a_perm, 6) @@ -344,7 +355,7 @@ class PosixAclMappingTests(TestCaseInTempDir): (AU_gid,AU_type) = s4_passdb.sid_to_id(AU_sid) self.assertEquals(AU_type, idmap.ID_TYPE_BOTH) - self.assertEquals(posix_acl.count, 13) + self.assertEquals(posix_acl.count, 13, self.print_posix_acl(posix_acl)) self.assertEquals(posix_acl.acl[0].a_type, smb_acl.SMB_ACL_GROUP) self.assertEquals(posix_acl.acl[0].a_perm, 7) @@ -484,7 +495,7 @@ class PosixAclMappingTests(TestCaseInTempDir): (AU_gid,AU_type) = s4_passdb.sid_to_id(AU_sid) self.assertEquals(AU_type, idmap.ID_TYPE_BOTH) - self.assertEquals(posix_acl.count, 13) + self.assertEquals(posix_acl.count, 13, self.print_posix_acl(posix_acl)) self.assertEquals(posix_acl.acl[0].a_type, smb_acl.SMB_ACL_GROUP) self.assertEquals(posix_acl.acl[0].a_perm, 7) @@ -580,7 +591,7 @@ class PosixAclMappingTests(TestCaseInTempDir): (PA_gid,PA_type) = s4_passdb.sid_to_id(PA_sid) self.assertEquals(PA_type, idmap.ID_TYPE_BOTH) - self.assertEquals(posix_acl.count, 15) + self.assertEquals(posix_acl.count, 15, self.print_posix_acl(posix_acl)) self.assertEquals(posix_acl.acl[0].a_type, smb_acl.SMB_ACL_GROUP) self.assertEquals(posix_acl.acl[0].a_perm, 7) @@ -693,7 +704,7 @@ class PosixAclMappingTests(TestCaseInTempDir): (PA_gid,PA_type) = s4_passdb.sid_to_id(PA_sid) self.assertEquals(PA_type, idmap.ID_TYPE_BOTH) - self.assertEquals(posix_acl.count, 15) + self.assertEquals(posix_acl.count, 15, self.print_posix_acl(posix_acl)) self.assertEquals(posix_acl.acl[0].a_type, smb_acl.SMB_ACL_GROUP) self.assertEquals(posix_acl.acl[0].a_perm, 7) -- Samba Shared Repository