s3: pysmbd: Ensure conn->cwd_fsp member of created connections is initialized.
authorJeremy Allison <jra@samba.org>
Fri, 6 Sep 2019 21:51:29 +0000 (14:51 -0700)
committerRalph Boehme <slow@samba.org>
Wed, 11 Sep 2019 18:24:28 +0000 (18:24 +0000)
This is needed to correctly call the XXXAT() vfs calls.

We should probably just use create_conn_struct_tos_cwd() here
and pass $cwd instead of using create_conn_struct_tos() and
passing "/" as the share root. We wouldn't change the current
working directory and the created share root would be set to $cwd
but I'm not sure what effects this may have on users of pysmbd
in case any of them pass paths above the $cwd to these functions.

Less changes to just call vfs_ChDir(conn, &cwd) which doesn't
change the current directory and leaves the share root as "/".

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/pysmbd.c

index 082c2b44f94629b3ef9a774ccbe8cdb6e51768f3..c0905b4b485ee715f33c2b73453cfd4c9197ece0 100644 (file)
@@ -56,6 +56,9 @@ static connection_struct *get_conn_tos(
        struct conn_struct_tos *c = NULL;
        int snum = -1;
        NTSTATUS status;
+       char *cwd = NULL;
+       struct smb_filename cwd_fname = {0};
+       int ret;
 
        if (!posix_locking_init(false)) {
                PyErr_NoMemory();
@@ -80,6 +83,29 @@ static connection_struct *get_conn_tos(
        /* Ignore read-only and share restrictions */
        c->conn->read_only = false;
        c->conn->share_access = SEC_RIGHTS_FILE_ALL;
+
+       /* Provided by libreplace if not present. Always mallocs. */
+       cwd = get_current_dir_name();
+       if (cwd == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
+       cwd_fname.base_name = cwd;
+       /*
+        * We need to call vfs_ChDir() to initialize
+        * conn->cwd_fsp correctly. Change directory
+        * to current directory (so no change for process).
+        */
+       ret = vfs_ChDir(c->conn, &cwd_fname);
+       if (ret != 0) {
+               status = map_nt_error_from_unix(errno);
+               SAFE_FREE(cwd);
+               PyErr_NTSTATUS_IS_ERR_RAISE(status);
+       }
+
+       SAFE_FREE(cwd);
+
        return c->conn;
 }