The branch, master has been updated
       via  95443320847 smbd: fix has_other_nonposix_opens_fn()
       via  8ccc809f931 CI/smb3unix: add test_delete_on_close
       via  f09c5a3dcbb python: move clean_file() to samba/tests/libsmb.py
      from  29bb93d03a4 libcli/security: conditional aces: don't allow U+0000 
in unicode

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 95443320847967ea6412e59b5b7d3853fffe588a
Author: Ralph Boehme <s...@samba.org>
Date:   Fri Oct 13 10:54:44 2023 +0200

    smbd: fix has_other_nonposix_opens_fn()
    
    Given two opens on a file:
    
    1. Windows open with delete-on-close
    2. POSIX open with delete-on-close set
    
    When handle 1 is closed processing in has_other_nonposix_opens_fn() will not
    delete the file as (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) is false, so
    has_other_nonposix_opens() will return true which is wrong.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15517
    
    Signed-off-by: Ralph Boehme <s...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>
    
    Autobuild-User(master): Jeremy Allison <j...@samba.org>
    Autobuild-Date(master): Mon Nov 13 19:34:29 UTC 2023 on atb-devel-224

commit 8ccc809f931f5ea8c8893042c1552f7352f0805b
Author: Ralph Boehme <s...@samba.org>
Date:   Thu Nov 9 19:53:46 2023 +0100

    CI/smb3unix: add test_delete_on_close
    
    BUG:https://bugzilla.samba.org/show_bug.cgi?id=15517
    
    Signed-off-by: Ralph Boehme <s...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>

commit f09c5a3dcbb15bb138b6a11eadc04f1bd1d9e3fa
Author: Ralph Boehme <s...@samba.org>
Date:   Thu Nov 9 19:52:55 2023 +0100

    python: move clean_file() to samba/tests/libsmb.py
    
    BUG:https://bugzilla.samba.org/show_bug.cgi?id=15517
    
    Signed-off-by: Ralph Boehme <s...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>

-----------------------------------------------------------------------

Summary of changes:
 python/samba/tests/libsmb.py      | 11 +++++++
 python/samba/tests/smb2symlink.py | 10 ------
 python/samba/tests/smb3unix.py    | 65 +++++++++++++++++++++++++++++++++++++++
 source3/smbd/close.c              |  3 +-
 4 files changed, 77 insertions(+), 12 deletions(-)


Changeset truncated at 500 lines:

diff --git a/python/samba/tests/libsmb.py b/python/samba/tests/libsmb.py
index 85068b1caec..cb632d0e3a7 100644
--- a/python/samba/tests/libsmb.py
+++ b/python/samba/tests/libsmb.py
@@ -21,6 +21,7 @@ from samba.samba3 import libsmb_samba_internal as libsmb
 from samba.dcerpc import security
 from samba.samba3 import param as s3param
 from samba import credentials
+from samba import (ntstatus,NTSTATUSError)
 import samba.tests
 import os
 
@@ -42,3 +43,13 @@ class LibsmbTests(samba.tests.TestCase):
         self.global_inject = os.path.join(server_conf_dir, 
"global_inject.conf")
 
         self.server_ip = samba.tests.env_get_var_value("SERVER_IP")
+
+    def clean_file(self, conn, filename):
+        try:
+            conn.unlink(filename)
+        except NTSTATUSError as e:
+            if e.args[0] == ntstatus.NT_STATUS_FILE_IS_A_DIRECTORY:
+                conn.rmdir(filename)
+            elif not (e.args[0] == ntstatus.NT_STATUS_OBJECT_NAME_NOT_FOUND or
+                      e.args[0] == ntstatus.NT_STATUS_OBJECT_PATH_NOT_FOUND):
+                raise
diff --git a/python/samba/tests/smb2symlink.py 
b/python/samba/tests/smb2symlink.py
index 5fca138e82a..83df78e8bb6 100644
--- a/python/samba/tests/smb2symlink.py
+++ b/python/samba/tests/smb2symlink.py
@@ -55,16 +55,6 @@ class Smb2SymlinkTests(samba.tests.libsmb.LibsmbTests):
             self.creds)
         return (smb1, smb2)
 
-    def clean_file(self, conn, filename):
-        try:
-            conn.unlink(filename)
-        except NTSTATUSError as e:
-            if e.args[0] == ntstatus.NT_STATUS_FILE_IS_A_DIRECTORY:
-                conn.rmdir(filename)
-            elif not (e.args[0] == ntstatus.NT_STATUS_OBJECT_NAME_NOT_FOUND or
-                      e.args[0] == ntstatus.NT_STATUS_OBJECT_PATH_NOT_FOUND):
-                raise
-
     def create_symlink(self, conn, target, symlink):
         self.clean_file(conn, symlink)
         if (conn.protocol() < libsmb.PROTOCOL_SMB2_02 and conn.have_posix()):
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/source3/smbd/close.c b/source3/smbd/close.c
index ad451ecd1e6..f1f5e41a43f 100644
--- a/source3/smbd/close.c
+++ b/source3/smbd/close.c
@@ -241,8 +241,7 @@ static bool has_other_nonposix_opens_fn(
        if (e->name_hash != fsp->name_hash) {
                return false;
        }
-       if ((fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) &&
-           (e->flags & SHARE_MODE_FLAG_POSIX_OPEN)) {
+       if (e->flags & SHARE_MODE_FLAG_POSIX_OPEN) {
                return false;
        }
        if (e->share_file_id == fh_get_gen_id(fsp->fh)) {


-- 
Samba Shared Repository

Reply via email to