]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pysmbd: Fix interactive samba-tool use after 0bb35e246141
authorVolker Lendecke <vl@samba.org>
Wed, 12 Feb 2025 12:45:42 +0000 (13:45 +0100)
committerJule Anger <janger@samba.org>
Thu, 20 Feb 2025 10:19:35 +0000 (10:19 +0000)
samba-tool ntacl also calls into pysmbd, and 0bb35e246141 broke
relative path names. Thanks to Björn Baumbach <bb@sernet.de> for
testing interactively!!

Bug: https://bugzilla.samba.org/show_bug.cgi?id=15806
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
(cherry picked from commit 26705d047cb885957a49939370e03047429351b6)

source3/smbd/pysmbd.c

index 26286afe945ad3d6e404a16332482d2e1a36d7fd..79e6d558c82af465702ec676707de8c1dfdb930e 100644 (file)
@@ -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,