Skip to content

Commit

Permalink
vfs: Add dirfsp to connectpath_fn()
Browse files Browse the repository at this point in the history
So far we only call CONNECTPATH on full paths. In the future, we'll
have a call that will not have converted a relative path to absolute
just for efficiency reasons. To give shadow_copy2 the chance to still
find the snapshot directory, pass the dirfsp down to it.

Signed-off-by: Volker Lendecke <[email protected]>
Reviewed-by: Jeremy Allison <[email protected]>
  • Loading branch information
vlendec authored and jrasamba committed Sep 17, 2022
1 parent 9ef2f73 commit e1ca4e2
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 31 deletions.
6 changes: 4 additions & 2 deletions examples/VFS/skel_opaque.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,10 @@ static NTSTATUS skel_get_real_filename_at(struct vfs_handle_struct *handle,
return NT_STATUS_NOT_IMPLEMENTED;
}

static const char *skel_connectpath(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname)
static const char *skel_connectpath(
struct vfs_handle_struct *handle,
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname)
{
errno = ENOSYS;
return NULL;
Expand Down
8 changes: 5 additions & 3 deletions examples/VFS/skel_transparent.c
Original file line number Diff line number Diff line change
Expand Up @@ -886,10 +886,12 @@ static NTSTATUS skel_get_real_filename_at(struct vfs_handle_struct *handle,
handle, dirfsp, name, mem_ctx, found_name);
}

static const char *skel_connectpath(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname)
static const char *skel_connectpath(
struct vfs_handle_struct *handle,
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname)
{
return SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
return SMB_VFS_NEXT_CONNECTPATH(handle, dirfsp, smb_fname);
}

static NTSTATUS skel_brl_lock_windows(struct vfs_handle_struct *handle,
Expand Down
11 changes: 8 additions & 3 deletions source3/include/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@
* Version 47 - Add VFS_OPEN_HOW_RESOLVE_NO_SYMLINKS for SMB_VFS_OPENAT()
* Change to Version 48 - will ship with 4.18
* Version 48 - Add cached_dos_attributes to struct stat_ex
* Version 48 - Add dirfsp to connectpath_fn()
*/

#define SMB_VFS_INTERFACE_VERSION 48
Expand Down Expand Up @@ -1172,6 +1173,7 @@ struct vfs_fn_pointers {
char **found_name);

const char *(*connectpath_fn)(struct vfs_handle_struct *handle,
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname);

NTSTATUS (*brl_lock_windows_fn)(struct vfs_handle_struct *handle,
Expand Down Expand Up @@ -1640,7 +1642,8 @@ NTSTATUS smb_vfs_call_get_real_filename_at(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
char **found_name);
const char *smb_vfs_call_connectpath(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname);
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname);
NTSTATUS smb_vfs_call_brl_lock_windows(struct vfs_handle_struct *handle,
struct byte_range_lock *br_lck,
struct lock_struct *plock);
Expand Down Expand Up @@ -2112,8 +2115,10 @@ NTSTATUS vfs_not_implemented_get_real_filename_at(
const char *name,
TALLOC_CTX *mem_ctx,
char **found_name);
const char *vfs_not_implemented_connectpath(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname);
const char *vfs_not_implemented_connectpath(
struct vfs_handle_struct *handle,
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname);
NTSTATUS vfs_not_implemented_brl_lock_windows(struct vfs_handle_struct *handle,
struct byte_range_lock *br_lck,
struct lock_struct *plock);
Expand Down
8 changes: 4 additions & 4 deletions source3/include/vfs_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@
(mem_ctx), \
(found_name))

#define SMB_VFS_CONNECTPATH(conn, smb_fname) \
smb_vfs_call_connectpath((conn)->vfs_handles, (smb_fname))
#define SMB_VFS_NEXT_CONNECTPATH(conn, smb_fname) \
smb_vfs_call_connectpath((conn)->next, (smb_fname))
#define SMB_VFS_CONNECTPATH(conn, dirfsp, smb_fname) \
smb_vfs_call_connectpath((conn)->vfs_handles, (dirfsp), (smb_fname))
#define SMB_VFS_NEXT_CONNECTPATH(conn, dirfsp, smb_fname) \
smb_vfs_call_connectpath((conn)->next, (dirfsp), (smb_fname))

#define SMB_VFS_BRL_LOCK_WINDOWS(conn, br_lck, plock) \
smb_vfs_call_brl_lock_windows((conn)->vfs_handles, (br_lck), (plock))
Expand Down
6 changes: 4 additions & 2 deletions source3/modules/vfs_ceph.c
Original file line number Diff line number Diff line change
Expand Up @@ -1292,8 +1292,10 @@ static NTSTATUS cephwrap_get_real_filename_at(
return NT_STATUS_NOT_SUPPORTED;
}

static const char *cephwrap_connectpath(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname)
static const char *cephwrap_connectpath(
struct vfs_handle_struct *handle,
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname)
{
return handle->conn->connectpath;
}
Expand Down
1 change: 1 addition & 0 deletions source3/modules/vfs_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -3453,6 +3453,7 @@ static NTSTATUS vfswrap_get_real_filename_at(
}

static const char *vfswrap_connectpath(struct vfs_handle_struct *handle,
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname)
{
return handle->conn->connectpath;
Expand Down
8 changes: 5 additions & 3 deletions source3/modules/vfs_full_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2115,12 +2115,14 @@ static NTSTATUS smb_full_audit_get_real_filename_at(
return result;
}

static const char *smb_full_audit_connectpath(vfs_handle_struct *handle,
const struct smb_filename *smb_fname)
static const char *smb_full_audit_connectpath(
vfs_handle_struct *handle,
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname)
{
const char *result;

result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
result = SMB_VFS_NEXT_CONNECTPATH(handle, dirfsp, smb_fname);

do_log(SMB_VFS_OP_CONNECTPATH,
result != NULL,
Expand Down
6 changes: 4 additions & 2 deletions source3/modules/vfs_glusterfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2348,8 +2348,10 @@ static NTSTATUS vfs_gluster_get_real_filename_at(
return NT_STATUS_OK;
}

static const char *vfs_gluster_connectpath(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname)
static const char *vfs_gluster_connectpath(
struct vfs_handle_struct *handle,
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname)
{
return handle->conn->connectpath;
}
Expand Down
6 changes: 4 additions & 2 deletions source3/modules/vfs_not_implemented.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,10 @@ NTSTATUS vfs_not_implemented_get_real_filename_at(
}

_PUBLIC_
const char *vfs_not_implemented_connectpath(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname)
const char *vfs_not_implemented_connectpath(
struct vfs_handle_struct *handle,
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname)
{
errno = ENOSYS;
return NULL;
Expand Down
8 changes: 5 additions & 3 deletions source3/modules/vfs_shadow_copy2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2625,8 +2625,10 @@ static NTSTATUS shadow_copy2_get_real_filename_at(
return NT_STATUS_OK;
}

static const char *shadow_copy2_connectpath(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname_in)
static const char *shadow_copy2_connectpath(
struct vfs_handle_struct *handle,
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname_in)
{
time_t timestamp = 0;
char *stripped = NULL;
Expand Down Expand Up @@ -2656,7 +2658,7 @@ static const char *shadow_copy2_connectpath(struct vfs_handle_struct *handle,
goto done;
}
if (timestamp == 0) {
return SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname_in);
return SMB_VFS_NEXT_CONNECTPATH(handle, dirfsp, smb_fname_in);
}

tmp = shadow_copy2_do_convert(talloc_tos(), handle, stripped, timestamp,
Expand Down
8 changes: 5 additions & 3 deletions source3/modules/vfs_time_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1743,15 +1743,17 @@ static NTSTATUS smb_time_audit_get_real_filename_at(
return result;
}

static const char *smb_time_audit_connectpath(vfs_handle_struct *handle,
const struct smb_filename *smb_fname)
static const char *smb_time_audit_connectpath(
vfs_handle_struct *handle,
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname)
{
const char *result;
struct timespec ts1,ts2;
double timediff;

clock_gettime_mono(&ts1);
result = SMB_VFS_NEXT_CONNECTPATH(handle, smb_fname);
result = SMB_VFS_NEXT_CONNECTPATH(handle, dirfsp, smb_fname);
clock_gettime_mono(&ts2);
timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;

Expand Down
5 changes: 3 additions & 2 deletions source3/smbd/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ static NTSTATUS process_symlink_open(const struct files_struct *dirfsp,
struct smb_filename *full_fname = NULL;
NTSTATUS status;

conn_rootdir = SMB_VFS_CONNECTPATH(conn, smb_fname);
conn_rootdir = SMB_VFS_CONNECTPATH(conn, NULL, smb_fname);
if (conn_rootdir == NULL) {
return NT_STATUS_NO_MEMORY;
}
Expand Down Expand Up @@ -705,7 +705,8 @@ static NTSTATUS non_widelink_open(const struct files_struct *dirfsp,
SMB_ASSERT(!fsp_is_alternate_stream(fsp));

if (smb_fname->base_name[0] == '/') {
const char *connpath = SMB_VFS_CONNECTPATH(conn, smb_fname);
const char *connpath = SMB_VFS_CONNECTPATH(
conn, NULL, smb_fname);
int cmp = strcmp(connpath, smb_fname->base_name);

if (cmp == 0) {
Expand Down
5 changes: 3 additions & 2 deletions source3/smbd/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ NTSTATUS check_reduced_name(connection_struct *conn,
}

/* Common widelinks and symlinks checks. */
conn_rootdir = SMB_VFS_CONNECTPATH(conn, smb_fname);
conn_rootdir = SMB_VFS_CONNECTPATH(conn, NULL, smb_fname);
if (conn_rootdir == NULL) {
DBG_NOTICE("Could not get conn_rootdir\n");
TALLOC_FREE(resolved_fname);
Expand Down Expand Up @@ -2312,10 +2312,11 @@ NTSTATUS smb_vfs_call_get_real_filename_at(struct vfs_handle_struct *handle,
}

const char *smb_vfs_call_connectpath(struct vfs_handle_struct *handle,
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname)
{
VFS_FIND(connectpath);
return handle->fns->connectpath_fn(handle, smb_fname);
return handle->fns->connectpath_fn(handle, dirfsp, smb_fname);
}

bool smb_vfs_call_strict_lock_check(struct vfs_handle_struct *handle,
Expand Down

0 comments on commit e1ca4e2

Please sign in to comment.