From: Ralph Boehme Date: Thu, 9 Nov 2023 18:53:46 +0000 (+0100) Subject: CI/smb3unix: add test_delete_on_close X-Git-Tag: talloc-2.4.2~777 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8ccc809f931f5ea8c8893042c1552f7352f0805b;p=thirdparty%2Fsamba.git CI/smb3unix: add test_delete_on_close BUG:https://bugzilla.samba.org/show_bug.cgi?id=15517 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/python/samba/tests/smb3unix.py b/python/samba/tests/smb3unix.py index 33a3d546f75..5a88640e1cd 100644 --- a/python/samba/tests/smb3unix.py +++ b/python/samba/tests/smb3unix.py @@ -35,6 +35,35 @@ class Smb3UnixTests(samba.tests.libsmb.LibsmbTests): self.samsid = os.environ["SAMSID"] + def connections(self, share1=None, posix1=False, share2=None, posix2=True): + if not share1: + share1 = samba.tests.env_get_var_value( + "SHARE1", allow_missing=True) + if not share1: + share1 = "tmp" + + if not share2: + share2 = samba.tests.env_get_var_value( + "SHARE2", allow_missing=True) + if not share2: + share2 = "tmp" + + conn1 = libsmb.Conn( + self.server_ip, + share1, + self.lp, + self.creds, + posix=posix1) + + conn2 = libsmb.Conn( + self.server_ip, + share2, + self.lp, + self.creds, + posix=posix2) + + return (conn1, conn2) + def test_negotiate_context_posix(self): c = libsmb.Conn( self.server_ip, @@ -351,3 +380,39 @@ class Smb3UnixTests(samba.tests.libsmb.LibsmbTests): finally: self.delete_test_file(c, '\\test_create_context_basic1_file') self.delete_test_file(c, '\\test_create_context_basic1_dir') + + def test_delete_on_close(self): + """ + Test two opens with delete-on-close: + 1. Windows open + 2. POSIX open + Closing handle 1 should unlink the file, a subsequent directory + listing shouldn't list the deleted file. + """ + (winconn,posixconn) = self.connections() + + self.clean_file(winconn, 'test_delete_on_close') + + fdw = winconn.create( + 'test_delete_on_close', + DesiredAccess=security.SEC_FILE_WRITE_ATTRIBUTE | security.SEC_STD_DELETE, + ShareAccess=0x07, + CreateDisposition=libsmb.FILE_CREATE) + self.addCleanup(self.clean_file, winconn, 'test_delete_on_close') + + fdp,_,_ = posixconn.create_ex( + 'test_delete_on_close', + DesiredAccess=security.SEC_FILE_WRITE_ATTRIBUTE | security.SEC_STD_DELETE, + ShareAccess=0x07, + CreateDisposition=libsmb.FILE_OPEN, + CreateContexts=[posix_context(0o600)]) + + winconn.delete_on_close(fdw, 1) + posixconn.delete_on_close(fdp, 1) + + winconn.close(fdw) + + # The file should now already be deleted + l = winconn.list('', mask='test_delete_on_close') + found_files = {get_string(f['name']): f for f in l} + self.assertFalse('test_delete_on_close' in found_files) diff --git a/selftest/knownfail.d/samba.tests.smb3unix.samba.tests.smb3unix.Smb3UnixTests b/selftest/knownfail.d/samba.tests.smb3unix.samba.tests.smb3unix.Smb3UnixTests new file mode 100644 index 00000000000..e893a357571 --- /dev/null +++ b/selftest/knownfail.d/samba.tests.smb3unix.samba.tests.smb3unix.Smb3UnixTests @@ -0,0 +1 @@ +^samba.tests.smb3unix.samba.tests.smb3unix.Smb3UnixTests.test_delete_on_close\(fileserver_smb1\)