From: Ralph Boehme Date: Mon, 2 Mar 2026 13:51:34 +0000 (+0100) Subject: python/tests: add Smb3UnixTests.test_delete_read_only_attr X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=71f1e50e1d9c2cd44cbf8b38077aa96cb67985e0;p=thirdparty%2Fsamba.git python/tests: add Smb3UnixTests.test_delete_read_only_attr Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/python/samba/tests/smb3unix.py b/python/samba/tests/smb3unix.py index 3039a68a1cd..f753e189f24 100644 --- a/python/samba/tests/smb3unix.py +++ b/python/samba/tests/smb3unix.py @@ -508,6 +508,58 @@ class Smb3UnixTests(samba.tests.libsmb.LibsmbTests): found_files = {get_string(f['name']): f for f in l} self.assertFalse('test_delete_on_close' in found_files) + def test_delete_read_only_attr(self): + """ + Test deleting a file with FILE_ATTRIBUTE_READONLY + """ + + testfile = 'test_delete_read_only_attr' + wc, c = self.connections() + + self.clean_file(c, testfile) + + wh,_,_ = wc.create_ex( + testfile, + DesiredAccess=security.SEC_STD_ALL, + ShareAccess=0x07, + CreateDisposition=libsmb.FILE_CREATE, + FileAttributes=libsmb.FILE_ATTRIBUTE_READONLY) + + # First try to delete on a Windows handle, should fail + try: + wc.delete_on_close(wh, 1) + except Exception as e: + if e.args[0] != ntstatus.NT_STATUS_CANNOT_DELETE: + wc.close(wh) + raise e + + wc.close(wh) + + wire_mode = libsmb.unix_mode_to_wire(0o666) + + h,_,_ = c.create_ex( + testfile, + DesiredAccess=security.SEC_STD_DELETE | + security.SEC_FILE_WRITE_ATTRIBUTE, + ShareAccess=0x07, + CreateDisposition=libsmb.FILE_OPEN, + FileAttributes=libsmb.FILE_ATTRIBUTE_READONLY, + CreateContexts=[posix_context(wire_mode)]) + + self.addCleanup(self.clean_file, c, testfile) + + try: + c.delete_on_close(h, 1) + except Exception as e: + c.close(h) + raise e + c.close(h) + + # The file should be deleted + l = c.list('', mask='*') + found_files = {get_string(f['name']): f for f in l} + self.assertFalse(testfile in found_files) + def test_posix_fs_info(self): """ Test the posix filesystem attributes list given by cli_get_posix_fs_info.