[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Fri Nov 20 00:21:03 UTC 2020


The branch, master has been updated
       via  382a5c4e7ec smbd: Fix failure to check dstdir for delete on close
       via  0f67dd540fe tests: SMB2 rename fails to check del-on-close on dst dir
       via  d680d392685 pylibsmb: Add rename()
       via  fec5a569b6b tests: Factor out prep_creds()
       via  74576743969 libsmb: Make cli_nt_pipes_close() static
       via  47d93b02807 lib: g_lock.h references "struct server_id", add #include
       via  7aaefd6f467 lib: Remove unused security_descriptor_append()
       via  b948b99c6ca build: fcvt() and fcvtl() are not used
      from  c4d82a6b1f3 smbd: avoid a smb_fname copy in call_trans2setfilepathinfo()

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


- Log -----------------------------------------------------------------
commit 382a5c4e7ec08ec9291453ffad9541ab36aca274
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Nov 19 12:38:06 2020 +0100

    smbd: Fix failure to check dstdir for delete on close
    
    In smb2_setinfo.c the call to smbd_do_setfilepathinfo() to perform the
    rename takes place while holding a share mode lock. The function
    check_parent_access() called below tries to query the destination
    directory's locking.tdb entry to check whether the delete on close
    flag is set on the destination directory. This fails because the
    file to be renamed already has the share mode entry locked, we can't
    lock two share mode entries simultaneously.
    
    Convert the check to use fetch_share_mode_unlocked(). This might
    introduce races, but this whole check is racy anyway. It does not
    really matter whether we do the check for delete_on_close under a lock
    or not, fetch_share_mode_unlocked() retrieves a consistent status of
    the locking.tdb entry at some point in time as well.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Fri Nov 20 00:20:06 UTC 2020 on sn-devel-184

commit 0f67dd540fe11f6543ed759d3d947600c265e889
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Nov 17 15:24:43 2020 +0100

    tests: SMB2 rename fails to check del-on-close on dst dir
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d680d392685b2501111b1bb9e879f821a348628c
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Nov 16 12:41:35 2020 +0100

    pylibsmb: Add rename()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit fec5a569b6be94ee7fcc2608be9ce7dbd2976871
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Nov 17 16:11:11 2020 +0100

    tests: Factor out prep_creds()
    
    3 times the same code can be put together
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 74576743969e42ba5424f0989e4e707b4264564a
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Nov 9 19:32:57 2020 +0100

    libsmb: Make cli_nt_pipes_close() static
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 47d93b02807caea5e9c686d95281f800b473f188
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Nov 11 16:52:07 2020 +0100

    lib: g_lock.h references "struct server_id", add #include
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 7aaefd6f467569c4040592212c8fcf6fb6a1c399
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Nov 11 08:03:46 2020 +0100

    lib: Remove unused security_descriptor_append()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b948b99c6ca08b436f473781a559e9976c2a4896
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Nov 16 14:37:43 2020 +0100

    build: fcvt() and fcvtl() are not used
    
    No need to check for them in the configure phase
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

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

Summary of changes:
 libcli/security/security_descriptor.c | 12 -------
 libcli/security/security_descriptor.h |  2 --
 python/samba/tests/libsmb.py          | 59 +++++++++++++++++++++++++----------
 source3/include/g_lock.h              |  2 ++
 source3/libsmb/clientgen.c            |  2 +-
 source3/libsmb/proto.h                |  1 -
 source3/libsmb/pylibsmb.c             | 37 ++++++++++++++++++++++
 source3/smbd/open.c                   |  7 ++++-
 source3/wscript                       |  4 +--
 9 files changed, 89 insertions(+), 37 deletions(-)


Changeset truncated at 500 lines:

diff --git a/libcli/security/security_descriptor.c b/libcli/security/security_descriptor.c
index 28c68215b8a..ba142016389 100644
--- a/libcli/security/security_descriptor.c
+++ b/libcli/security/security_descriptor.c
@@ -547,18 +547,6 @@ static struct security_descriptor *security_descriptor_appendv(struct security_d
 	return sd;
 }
 
-struct security_descriptor *security_descriptor_append(struct security_descriptor *sd,
-						       ...)
-{
-	va_list ap;
-
-	va_start(ap, sd);
-	sd = security_descriptor_appendv(sd, false, ap);
-	va_end(ap);
-
-	return sd;
-}
-
 static struct security_descriptor *security_descriptor_createv(TALLOC_CTX *mem_ctx,
 							       uint16_t sd_type,
 							       const char *owner_sid,
diff --git a/libcli/security/security_descriptor.h b/libcli/security/security_descriptor.h
index dd5d5f38049..7e6df87fefa 100644
--- a/libcli/security/security_descriptor.h
+++ b/libcli/security/security_descriptor.h
@@ -48,8 +48,6 @@ bool security_descriptor_equal(const struct security_descriptor *sd1,
 bool security_descriptor_mask_equal(const struct security_descriptor *sd1, 
 				    const struct security_descriptor *sd2, 
 				    uint32_t mask);
-struct security_descriptor *security_descriptor_append(struct security_descriptor *sd,
-						       ...);
 struct security_descriptor *security_descriptor_dacl_create(TALLOC_CTX *mem_ctx,
 							    uint16_t sd_type,
 							    const char *owner_sid,
diff --git a/python/samba/tests/libsmb.py b/python/samba/tests/libsmb.py
index 81d4e482644..1acb5b12a16 100644
--- a/python/samba/tests/libsmb.py
+++ b/python/samba/tests/libsmb.py
@@ -20,7 +20,8 @@
 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 (credentials,NTSTATUSError)
+from samba.ntstatus import NT_STATUS_DELETE_PENDING
 from samba.credentials import SMB_ENCRYPTION_REQUIRED
 import samba.tests
 import threading
@@ -51,8 +52,7 @@ class LibsmbTestCase(samba.tests.TestCase):
             except Exception:
                 self.exc = sys.exc_info()
 
-    def test_OpenClose(self):
-
+    def prep_creds(self):
         lp = s3param.get_context()
         lp.load(os.getenv("SMB_CONF_PATH"))
 
@@ -61,6 +61,11 @@ class LibsmbTestCase(samba.tests.TestCase):
         creds.set_username(os.getenv("USERNAME"))
         creds.set_password(os.getenv("PASSWORD"))
 
+        return (lp,creds)
+
+    def test_OpenClose(self):
+        (lp,creds) = self.prep_creds()
+
         c = libsmb.Conn(os.getenv("SERVER_IP"), "tmp",
                         lp, creds, multi_threaded=True,
                         force_smb1=True)
@@ -82,13 +87,7 @@ class LibsmbTestCase(samba.tests.TestCase):
     def test_SMB3EncryptionRequired(self):
         test_dir = 'testing_%d' % random.randint(0, 0xFFFF)
 
-        lp = s3param.get_context()
-        lp.load(os.getenv("SMB_CONF_PATH"))
-
-        creds = credentials.Credentials()
-        creds.guess(lp)
-        creds.set_username(os.getenv("USERNAME"))
-        creds.set_password(os.getenv("PASSWORD"))
+        (lp,creds) = self.prep_creds()
         creds.set_smb_encryption(SMB_ENCRYPTION_REQUIRED)
 
         c = libsmb.Conn(os.getenv("SERVER_IP"), "tmp",
@@ -100,13 +99,7 @@ class LibsmbTestCase(samba.tests.TestCase):
     def test_SMB1EncryptionRequired(self):
         test_dir = 'testing_%d' % random.randint(0, 0xFFFF)
 
-        lp = s3param.get_context()
-        lp.load(os.getenv("SMB_CONF_PATH"))
-
-        creds = credentials.Credentials()
-        creds.guess(lp)
-        creds.set_username(os.getenv("USERNAME"))
-        creds.set_password(os.getenv("PASSWORD"))
+        (lp,creds) = self.prep_creds()
         creds.set_smb_encryption(SMB_ENCRYPTION_REQUIRED)
 
         c = libsmb.Conn(os.getenv("SERVER_IP"), "tmp",
@@ -115,6 +108,38 @@ class LibsmbTestCase(samba.tests.TestCase):
         c.mkdir(test_dir)
         c.rmdir(test_dir)
 
+    def test_RenameDstDelOnClose(self):
+        (lp,creds) = self.prep_creds()
+
+        dstdir = "\\dst-subdir"
+
+        c1 = libsmb.Conn(os.getenv("SERVER_IP"), "tmp", lp, creds)
+        c2 = libsmb.Conn(os.getenv("SERVER_IP"), "tmp", lp, creds)
+
+        try:
+            c1.deltree(dstdir)
+        except:
+            pass
+
+        c1.mkdir(dstdir)
+        dnum = c1.create(dstdir, DesiredAccess=security.SEC_STD_DELETE)
+        c1.delete_on_close(dnum,1)
+        c2.savefile("\\src.txt", b"Content")
+
+        with self.assertRaises(NTSTATUSError) as cm:
+            c2.rename("\\src.txt", dstdir + "\\dst.txt")
+        if (cm.exception.args[0] != NT_STATUS_DELETE_PENDING):
+            raise AssertionError("Rename must fail with DELETE_PENDING")
+
+        c1.delete_on_close(dnum,0)
+        c1.close(dnum)
+
+        try:
+            c1.deltree(dstdir)
+            c1.unlink("\\src.txt")
+        except:
+            pass
+
 if __name__ == "__main__":
     import unittest
     unittest.main()
diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h
index 5892f10fcd6..3a94879d209 100644
--- a/source3/include/g_lock.h
+++ b/source3/include/g_lock.h
@@ -20,6 +20,8 @@
 #ifndef _G_LOCK_H_
 #define _G_LOCK_H_
 
+#include "replace.h"
+#include "librpc/gen_ndr/server_id.h"
 #include "dbwrap/dbwrap.h"
 
 struct g_lock_ctx;
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c
index 7cb89e87a9d..d117885b8f7 100644
--- a/source3/libsmb/clientgen.c
+++ b/source3/libsmb/clientgen.c
@@ -206,7 +206,7 @@ struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx,
  Close all pipes open on this session.
 ****************************************************************************/
 
-void cli_nt_pipes_close(struct cli_state *cli)
+static void cli_nt_pipes_close(struct cli_state *cli)
 {
 	while (cli->pipe_list != NULL) {
 		/*
diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
index 64ba498e369..df5be718f17 100644
--- a/source3/libsmb/proto.h
+++ b/source3/libsmb/proto.h
@@ -172,7 +172,6 @@ struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx,
 				   const char *remote_name,
 				   enum smb_signing_setting signing_state,
 				   int flags);
-void cli_nt_pipes_close(struct cli_state *cli);
 void cli_shutdown(struct cli_state *cli);
 uint16_t cli_state_get_vc_num(struct cli_state *cli);
 uint32_t cli_setpid(struct cli_state *cli, uint32_t pid);
diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c
index 24551d2661d..b84685b55f9 100644
--- a/source3/libsmb/pylibsmb.c
+++ b/source3/libsmb/pylibsmb.c
@@ -743,6 +743,39 @@ static PyObject *py_cli_close(struct py_cli_state *self, PyObject *args)
 	Py_RETURN_NONE;
 }
 
+static PyObject *py_cli_rename(
+	struct py_cli_state *self, PyObject *args, PyObject *kwds)
+{
+	char *fname_src = NULL, *fname_dst = NULL;
+	int replace = false;
+	struct tevent_req *req = NULL;
+	NTSTATUS status;
+	bool ok;
+
+	static const char *kwlist[] = { "src", "dst", "replace", NULL };
+
+	ok = ParseTupleAndKeywords(
+		args, kwds, "ss|p", kwlist, &fname_src, &fname_dst, &replace);
+	if (!ok) {
+		return NULL;
+	}
+
+	req = cli_rename_send(
+		NULL, self->ev, self->cli, fname_src, fname_dst, replace);
+	if (!py_tevent_req_wait_exc(self, req)) {
+		return NULL;
+	}
+	status = cli_rename_recv(req);
+	TALLOC_FREE(req);
+
+	if (!NT_STATUS_IS_OK(status)) {
+		PyErr_SetNTSTATUS(status);
+		return NULL;
+	}
+	Py_RETURN_NONE;
+}
+
+
 struct push_state {
 	char *data;
 	off_t nread;
@@ -1439,6 +1472,10 @@ static PyMethodDef py_cli_state_methods[] = {
 	  "mkdir(path) -> None\n\n \t\tCreate a directory." },
 	{ "rmdir", (PyCFunction)py_smb_rmdir, METH_VARARGS,
 	  "rmdir(path) -> None\n\n \t\tDelete a directory." },
+	{ "rename",
+	  PY_DISCARD_FUNC_SIG(PyCFunction, py_cli_rename),
+	  METH_VARARGS|METH_KEYWORDS,
+	  "rename(src,dst) -> None\n\n \t\tRename a file." },
 	{ "chkpath", (PyCFunction)py_smb_chkpath, METH_VARARGS,
 	  "chkpath(dir_path) -> True or False\n\n"
 	  "\t\tReturn true if directory exists, false otherwise." },
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 95934e2e321..11ddfc6eb09 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -373,7 +373,12 @@ NTSTATUS check_parent_access(struct connection_struct *conn,
 		goto out;
 	}
 
-	lck = get_existing_share_mode_lock(frame, id);
+	/*
+	 * Don't take a lock here. We just need a snapshot
+	 * of the current state of delete on close and someone
+	 * else may already have a lock on this id.
+	 */
+	lck = fetch_share_mode_unlocked(frame, id);
 	if (lck == NULL) {
 		status = NT_STATUS_OK;
 		goto out;
diff --git a/source3/wscript b/source3/wscript
index bbd53358359..011594b3844 100644
--- a/source3/wscript
+++ b/source3/wscript
@@ -137,7 +137,7 @@ def configure(conf):
     conf.CHECK_FUNCS('getpwnam', headers='sys/types.h pwd.h')
     conf.CHECK_FUNCS('fdopendir')
     conf.CHECK_FUNCS('fstatat')
-    conf.CHECK_FUNCS('getpwent_r setenv clearenv strcasecmp fcvt fcvtl')
+    conf.CHECK_FUNCS('getpwent_r setenv clearenv strcasecmp')
     conf.CHECK_FUNCS('syslog vsyslog timegm setlocale')
     conf.CHECK_FUNCS('lutimes futimes utimensat futimens')
     conf.CHECK_FUNCS('mlock munlock mlockall munlockall')
@@ -415,8 +415,6 @@ endmntent
 execl
 fchmod
 fchown
-fcvt
-fcvtl
 fseeko
 fsync
 futimens


-- 
Samba Shared Repository



More information about the samba-cvs mailing list