The branch, master has been updated
via 3e1c19c2c3f pytests: test pysmbd with relative path names via
samba-tool ntacl
via 26705d047cb pysmbd: Fix interactive samba-tool use after
0bb35e246141
via 334f621e4b7 pytests: test pysmbd with non-existent file
via 0a9946258eb pysmbd: Init mangle_fns
from 7e4095b45c0 s4:kdc: pass the full samba_kdc_db_context to most
helper functions
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 3e1c19c2c3f8b0bdf21301431bc886757fd4b3ce
Author: Björn Baumbach <[email protected]>
Date: Thu Feb 13 18:05:44 2025 +0100
pytests: test pysmbd with relative path names via samba-tool ntacl
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15806
Signed-off-by: Björn Baumbach <[email protected]>
Reviewed-by: Douglas Bagnall <[email protected]>
Autobuild-User(master): Björn Baumbach <[email protected]>
Autobuild-Date(master): Fri Feb 14 16:18:19 UTC 2025 on atb-devel-224
commit 26705d047cb885957a49939370e03047429351b6
Author: Volker Lendecke <[email protected]>
Date: Wed Feb 12 13:45:42 2025 +0100
pysmbd: Fix interactive samba-tool use after 0bb35e246141
samba-tool ntacl also calls into pysmbd, and 0bb35e246141 broke
relative path names. Thanks to Björn Baumbach <[email protected]> for
testing interactively!!
Bug: https://bugzilla.samba.org/show_bug.cgi?id=15806
Signed-off-by: Volker Lendecke <[email protected]>
Reviewed-by: Douglas Bagnall <[email protected]>
commit 334f621e4b74e9cda735982e223aefc7eefb4631
Author: Björn Baumbach <[email protected]>
Date: Wed Feb 12 17:15:37 2025 +0100
pytests: test pysmbd with non-existent file
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15807
Signed-off-by: Björn Baumbach <[email protected]>
Reviewed-by: Douglas Bagnall <[email protected]>
commit 0a9946258eb4587f5c132805d7c44062c377f375
Author: Volker Lendecke <[email protected]>
Date: Mon Jan 13 11:45:06 2025 +0100
pysmbd: Init mangle_fns
openat_pathref_fsp() eventually calls mangling functions, so we have
to initialize them.
Bug: https://bugzilla.samba.org/show_bug.cgi?id=15807
Signed-off-by: Volker Lendecke <[email protected]>
Reviewed-by: Douglas Bagnall <[email protected]>
-----------------------------------------------------------------------
Summary of changes:
python/samba/tests/samba_tool/ntacl.py | 80 ++++++++++++++++++++++++++++++++++
source3/smbd/pysmbd.c | 44 ++++++++++++++++---
2 files changed, 118 insertions(+), 6 deletions(-)
Changeset truncated at 500 lines:
diff --git a/python/samba/tests/samba_tool/ntacl.py
b/python/samba/tests/samba_tool/ntacl.py
index 11731011e95..8dd3d236989 100644
--- a/python/samba/tests/samba_tool/ntacl.py
+++ b/python/samba/tests/samba_tool/ntacl.py
@@ -22,6 +22,7 @@ import os
from samba.tests.samba_tool.base import SambaToolCmdTest
from samba.tests import env_loadparm
import random
+import secrets
class NtACLCmdSysvolTestCase(SambaToolCmdTest):
@@ -123,6 +124,85 @@ class NtACLCmdGetSetTestCase(SambaToolCmdTest):
self.assertEqual(err, "", "Shouldn't be any error messages")
self.assertEqual(out, "", "Shouldn't be any output messages")
+ def test_set_expect_file_not_found(self):
+ path = os.environ['SELFTEST_PREFIX']
+ tempf_basename = f"{self.unique_name()}-{secrets.token_hex(10)}"
+ tempf = os.path.join(path, tempf_basename)
+
+ for fs_arg in ["--use-s3fs", "--use-ntvfs"]:
+ (result, out, err) = self.runsubcmd("ntacl",
+ "set",
+ self.acl,
+ tempf_basename,
+ fs_arg)
+
+ self.assertCmdFail(result, "succeeded with non-existent file")
+ self.assertIn("No such file or directory",
+ err,
+ "No such file or directory expected")
+ self.assertEqual(out, "", "Shouldn't be any output messages")
+
+ def test_set_with_relative_path(self):
+ path = os.environ['SELFTEST_PREFIX']
+ tempf_basename = f"{self.unique_name()}-{secrets.token_hex(10)}"
+ tempf = os.path.join(path, tempf_basename)
+ workdir = os.getcwd()
+
+ open(tempf, 'w').write("empty")
+
+ os.chdir(path)
+
+ for fs_arg in ["--use-s3fs", "--use-ntvfs"]:
+ (result, out, err) = self.runsubcmd("ntacl",
+ "set",
+ self.acl,
+ tempf_basename,
+ fs_arg)
+
+ self.assertCmdSuccess(result, out, err)
+ if fs_arg == "--use-s3fs":
+ self.assertEqual(err, "", "Shouldn't be any error messages")
+ elif fs_arg == "--use-ntvfs":
+ self.assertIn("only the stored NT ACL",
+ err,
+ "only the stored NT ACL warning expected")
+ self.assertEqual(out, "", "Shouldn't be any output messages")
+
+ os.chdir(workdir)
+
+ def test_set_with_relative_parent_path(self):
+ path = os.environ['SELFTEST_PREFIX']
+ tempf_basename = f"{self.unique_name()}-{secrets.token_hex(10)}"
+ tempf = os.path.join(path, tempf_basename)
+ subdir_basename =
f"{self.unique_name()}-subdir-{secrets.token_hex(10)}"
+ subdir_path = os.path.join(path, subdir_basename)
+ workdir = os.getcwd()
+
+ os.mkdir(subdir_path)
+ open(tempf, 'w').write("empty")
+
+ tempf_relative_path = os.path.join("../", tempf_basename)
+
+ os.chdir(subdir_path)
+
+ for fs_arg in ["--use-s3fs", "--use-ntvfs"]:
+ (result, out, err) = self.runsubcmd("ntacl",
+ "set",
+ self.acl,
+ tempf_relative_path,
+ fs_arg)
+
+ self.assertCmdSuccess(result, out, err)
+ if fs_arg == "--use-s3fs":
+ self.assertEqual(err, "", "Shouldn't be any error messages")
+ elif fs_arg == "--use-ntvfs":
+ self.assertIn("only the stored NT ACL",
+ err,
+ "only the stored NT ACL warning expected")
+ self.assertEqual(out, "", "Shouldn't be any output messages")
+
+ os.chdir(workdir)
+
def test_ntvfs_check(self):
path = os.environ['SELFTEST_PREFIX']
tempf = os.path.join(path, "pytests" + str(int(100000 *
random.random())))
diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c
index 9fe885a51b0..79e6d558c82 100644
--- a/source3/smbd/pysmbd.c
+++ b/source3/smbd/pysmbd.c
@@ -60,6 +60,8 @@ static connection_struct *get_conn_tos(
struct smb_filename cwd_fname = {0};
int ret;
+ mangle_reset_cache();
+
if (!posix_locking_init(false)) {
PyErr_NoMemory();
return NULL;
@@ -124,6 +126,36 @@ static connection_struct *get_conn_tos(
return c->conn;
}
+static const char *canonicalize_path(TALLOC_CTX *mem_ctx,
+ struct connection_struct *conn,
+ const char *fname)
+{
+ char *to_free = NULL;
+ char *result = NULL;
+
+ if (fname[0] != '/') {
+ struct smb_filename *cwd = SMB_VFS_GETWD(conn, mem_ctx);
+ if (cwd == NULL) {
+ return NULL;
+ }
+
+ to_free = talloc_asprintf(mem_ctx,
+ "%s/%s",
+ cwd->base_name,
+ fname);
+ TALLOC_FREE(cwd);
+
+ if (to_free == NULL) {
+ return NULL;
+ }
+ fname = to_free;
+ }
+
+ result = canonicalize_absolute_path(mem_ctx, fname);
+ TALLOC_FREE(to_free);
+ return result;
+}
+
static int set_sys_acl_conn(const char *fname,
SMB_ACL_TYPE_T acltype,
SMB_ACL_T theacl, connection_struct *conn)
@@ -135,7 +167,7 @@ static int set_sys_acl_conn(const char *fname,
smb_fname = synthetic_smb_fname_split(
frame,
- canonicalize_absolute_path(talloc_tos(), fname),
+ canonicalize_path(talloc_tos(), conn, fname),
lp_posix_pathnames());
if (smb_fname == NULL) {
TALLOC_FREE(frame);
@@ -189,7 +221,7 @@ static NTSTATUS init_files_struct(TALLOC_CTX *mem_ctx,
smb_fname = synthetic_smb_fname_split(
fsp,
- canonicalize_absolute_path(talloc_tos(), fname),
+ canonicalize_path(talloc_tos(), conn, fname),
lp_posix_pathnames());
if (smb_fname == NULL) {
return NT_STATUS_NO_MEMORY;
@@ -306,7 +338,7 @@ static NTSTATUS get_nt_acl_conn(TALLOC_CTX *mem_ctx,
smb_fname = synthetic_smb_fname_split(
frame,
- canonicalize_absolute_path(talloc_tos(), fname),
+ canonicalize_path(talloc_tos(), conn, fname),
lp_posix_pathnames());
if (smb_fname == NULL) {
@@ -702,7 +734,7 @@ static PyObject *py_smbd_unlink(PyObject *self, PyObject
*args, PyObject *kwargs
smb_fname = synthetic_smb_fname_split(
frame,
- canonicalize_absolute_path(talloc_tos(), fname),
+ canonicalize_path(talloc_tos(), conn, fname),
lp_posix_pathnames());
if (smb_fname == NULL) {
TALLOC_FREE(frame);
@@ -1044,7 +1076,7 @@ static PyObject *py_smbd_get_sys_acl(PyObject *self,
PyObject *args, PyObject *k
smb_fname = synthetic_smb_fname_split(
frame,
- canonicalize_absolute_path(talloc_tos(), fname),
+ canonicalize_path(talloc_tos(), conn, fname),
lp_posix_pathnames());
if (smb_fname == NULL) {
TALLOC_FREE(frame);
@@ -1134,7 +1166,7 @@ static PyObject *py_smbd_mkdir(PyObject *self, PyObject
*args, PyObject *kwargs)
smb_fname = synthetic_smb_fname(
talloc_tos(),
- canonicalize_absolute_path(talloc_tos(), fname),
+ canonicalize_path(talloc_tos(), conn, fname),
NULL,
NULL,
0,
--
Samba Shared Repository