From: Volker Lendecke Date: Thu, 23 Oct 2025 17:14:48 +0000 (+0200) Subject: vfs_default: Implement SMB_VFS_OPEN_SHARE_ROOT() X-Git-Tag: talloc-2.5.0~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1c8ec69900d1aedfbae915e0c0393bb0597fb60;p=thirdparty%2Fsamba.git vfs_default: Implement SMB_VFS_OPEN_SHARE_ROOT() Signed-off-by: Volker Lendecke Reviewed-by: Anoop C S Reviewed-by: Ralph Boehme --- diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 6ad8e3b4ed8..0a8ea79249f 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -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 */ diff --git a/source3/smbd/smb2_service.c b/source3/smbd/smb2_service.c index 4be8f6bfceb..24c7bd4148a 100644 --- a/source3/smbd/smb2_service.c +++ b/source3/smbd/smb2_service.c @@ -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();