From aad39687b6f1facdba5a03319ee6bc45f5915547 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 12 Feb 2025 13:45:42 +0100 Subject: [PATCH] pysmbd: Fix interactive samba-tool use after 0bb35e246141 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit samba-tool ntacl also calls into pysmbd, and 0bb35e246141 broke relative path names. Thanks to Björn Baumbach for testing interactively!! Bug: https://bugzilla.samba.org/show_bug.cgi?id=15806 Signed-off-by: Volker Lendecke Reviewed-by: Douglas Bagnall (cherry picked from commit 26705d047cb885957a49939370e03047429351b6) --- source3/smbd/pysmbd.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c index 26286afe945..79e6d558c82 100644 --- a/source3/smbd/pysmbd.c +++ b/source3/smbd/pysmbd.c @@ -126,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) @@ -137,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); @@ -191,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; @@ -308,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) { @@ -704,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); @@ -1046,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); @@ -1136,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, -- 2.47.2