]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_default: Implement SMB_VFS_OPEN_SHARE_ROOT()
authorVolker Lendecke <vl@samba.org>
Thu, 23 Oct 2025 17:14:48 +0000 (19:14 +0200)
committerAnoop C S <anoopcs@samba.org>
Wed, 22 Jul 2026 14:43:36 +0000 (14:43 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/modules/vfs_default.c
source3/smbd/smb2_service.c

index 6ad8e3b4ed81fa58a16df76d0b2c08e003531fb3..0a8ea79249f91309ff50d6d5794b6e6d1b2bcee8 100644 (file)
@@ -100,8 +100,28 @@ static int vfswrap_open_share_root(struct vfs_handle_struct *handle,
                                   struct files_struct *root_fsp,
                                   const char *connectpath)
 {
-       errno = ENOSYS;
-       return -1;
+       struct smb_filename fname = {
+               .base_name = discard_const_p(char, connectpath),
+       };
+       int ret;
+       bool ok;
+
+       ret = sys_stat(connectpath,
+                      &fname.st,
+                      lp_fake_directory_create_times(SNUM(handle->conn)));
+       if (ret == -1) {
+               return ret;
+       }
+
+       ok = fsp_set_smb_fname(root_fsp, &fname);
+       if (!ok) {
+               errno = ENOMEM;
+               return -1;
+       }
+
+       fsp_set_fd(root_fsp, AT_FDCWD);
+
+       return 0;
 }
 
 /* Disk operations */
index 4be8f6bfceb25162d74133e336bfa2c163040368..24c7bd4148a23529f7831ff3bd061ece5f70a9fe 100644 (file)
@@ -502,7 +502,6 @@ NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
        struct smbd_server_connection *sconn = xconn->client->sconn;
        const struct loadparm_substitution *lp_sub =
                loadparm_s3_global_substitution();
-       struct smb_filename *smb_fname_cpath = NULL;
        fstring dev;
        int ret;
        bool on_err_call_dis_hook = false;
@@ -791,16 +790,6 @@ NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
                        goto err_root_exit;
                }
        }
-       smb_fname_cpath = synthetic_smb_fname(talloc_tos(),
-                                       conn->connectpath,
-                                       NULL,
-                                       NULL,
-                                       0,
-                                       0);
-       if (smb_fname_cpath == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto err_root_exit;
-       }
 
        /* win2000 does not check the permissions on the directory
           during the tree connect, instead relying on permission
@@ -808,7 +797,7 @@ NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
           I have disabled this chdir check (tridge) */
        /* the alternative is just to check the directory exists */
 
-       ret = SMB_VFS_STAT(conn, smb_fname_cpath);
+       ret = SMB_VFS_OPEN_SHARE_ROOT(conn, conn->cwd_fsp, conn->connectpath);
        if (ret != 0) {
                DBG_ERR("'%s' does not exist or permission denied "
                        "when connecting to [%s] Error was %s\n",
@@ -819,7 +808,7 @@ NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
                goto err_root_exit;
        }
 
-       if (!S_ISDIR(smb_fname_cpath->st.st_ex_mode)) {
+       if (!S_ISDIR(conn->cwd_fsp->fsp_name->st.st_ex_mode)) {
                DBG_ERR("'%s' is not a directory, when connecting to "
                        "[%s]\n",
                        conn->connectpath,
@@ -828,7 +817,7 @@ NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
                goto err_root_exit;
        }
 
-       conn->base_share_dev = smb_fname_cpath->st.st_ex_dev;
+       conn->base_share_dev = conn->cwd_fsp->fsp_name->st.st_ex_dev;
 
        /* Figure out the characteristics of the underlying filesystem. This
         * assumes that all the filesystem mounted within a share path have
@@ -874,7 +863,6 @@ NTSTATUS make_connection_snum(struct smbXsrv_connection *xconn,
 
   err_root_exit:
 
-       TALLOC_FREE(smb_fname_cpath);
        /* We must exit this function as root. */
        if (geteuid() != 0) {
                change_to_root_user();