}
if(!backends) {
- static_init_vfs;
+ static_init_vfs(NULL);
}
DEBUG(3, ("Initialising custom vfs hooks from [%s]\n", vfs_object));
len -= fsp->fsp_name->st.st_ex_size;
len /= 1024; /* Len is now number of 1k blocks needed. */
- space_avail = get_dfree_info(conn, fsp->fsp_name->base_name,
- &bsize, &dfree, &dsize);
+ space_avail =
+ get_dfree_info(conn, fsp->fsp_name, &bsize, &dfree, &dsize);
if (space_avail == (uint64_t)-1) {
return -1;
}
A wrapper for vfs_chdir().
********************************************************************/
-int vfs_ChDir(connection_struct *conn, const char *path)
+int vfs_ChDir(connection_struct *conn, const struct smb_filename *smb_fname)
{
int ret;
LastDir = SMB_STRDUP("");
}
- if (ISDOT(path)) {
+ if (ISDOT(smb_fname->base_name)) {
return 0;
}
- if (*path == '/' && strcsequal(LastDir,path)) {
+ if (*smb_fname->base_name == '/' &&
+ strcsequal(LastDir,smb_fname->base_name)) {
return 0;
}
- DEBUG(4,("vfs_ChDir to %s\n",path));
+ DEBUG(4,("vfs_ChDir to %s\n", smb_fname->base_name));
- ret = SMB_VFS_CHDIR(conn,path);
+ ret = SMB_VFS_CHDIR(conn, smb_fname);
if (ret == 0) {
/* Global cache. */
SAFE_FREE(LastDir);
- LastDir = SMB_STRDUP(path);
+ LastDir = SMB_STRDUP(smb_fname->base_name);
/* conn cache. */
TALLOC_FREE(conn->cwd);
const char *last_component = NULL;
char *resolved_name = NULL;
char *saved_dir = NULL;
+ struct smb_filename *saved_dir_fname = NULL;
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
goto err;
}
+ saved_dir_fname = synthetic_smb_fname(ctx,
+ saved_dir,
+ NULL,
+ NULL,
+ 0);
+ if (saved_dir_fname == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto err;
+ }
+
/* Go to the parent directory to lock in memory. */
- if (vfs_ChDir(conn, priv_paths->parent_name.base_name) == -1) {
+ if (vfs_ChDir(conn, &priv_paths->parent_name) == -1) {
status = map_nt_error_from_unix(errno);
goto err;
}
err:
- if (saved_dir) {
- vfs_ChDir(conn, saved_dir);
+ if (saved_dir_fname) {
+ vfs_ChDir(conn, saved_dir_fname);
+ TALLOC_FREE(saved_dir);
+ TALLOC_FREE(saved_dir_fname);
}
SAFE_FREE(resolved_name);
if (!NT_STATUS_IS_OK(status)) {
/*******************************************************************
Reduce a file name, removing .. elements and checking that
it is below dir in the heirachy. This uses realpath.
+
+ If cwd_name == NULL then fname is a client given path relative
+ to the root path of the share.
+
+ If cwd_name != NULL then fname is a client given path relative
+ to cwd_name. cwd_name is relative to the root path of the share.
********************************************************************/
-NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
+NTSTATUS check_reduced_name(connection_struct *conn,
+ const char *cwd_name,
+ const char *fname)
{
char *resolved_name = NULL;
+ char *new_fname = NULL;
bool allow_symlinks = true;
bool allow_widelinks = false;
/* fname can't have changed in resolved_path. */
const char *p = &resolved_name[rootdir_len];
- /* *p can be '\0' if fname was "." */
- if (*p == '\0' && ISDOT(fname)) {
+ /*
+ * UNIX filesystem semantics, names consisting
+ * only of "." or ".." CANNOT be symlinks.
+ */
+ if (ISDOT(fname) || ISDOTDOT(fname)) {
goto out;
}
}
p++;
+
+ /*
+ * If cwd_name is present and not ".",
+ * then fname is relative to that, not
+ * the root of the share. Make sure the
+ * path we check is the one the client
+ * sent (cwd_name+fname).
+ */
+ if (cwd_name != NULL && !ISDOT(cwd_name)) {
+ new_fname = talloc_asprintf(talloc_tos(),
+ "%s/%s",
+ cwd_name,
+ fname);
+ if (new_fname == NULL) {
+ SAFE_FREE(resolved_name);
+ return NT_STATUS_NO_MEMORY;
+ }
+ fname = new_fname;
+ }
+
if (strcmp(fname, p)!=0) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink to %s\n",
fname, p));
SAFE_FREE(resolved_name);
+ TALLOC_FREE(new_fname);
return NT_STATUS_ACCESS_DENIED;
}
}
DBG_INFO("%s reduced to %s\n", fname, resolved_name);
SAFE_FREE(resolved_name);
+ TALLOC_FREE(new_fname);
return NT_STATUS_OK;
}
}
uint64_t smb_vfs_call_disk_free(struct vfs_handle_struct *handle,
- const char *path, uint64_t *bsize,
- uint64_t *dfree, uint64_t *dsize)
+ const struct smb_filename *smb_fname,
+ uint64_t *bsize,
+ uint64_t *dfree,
+ uint64_t *dsize)
{
VFS_FIND(disk_free);
- return handle->fns->disk_free_fn(handle, path, bsize, dfree, dsize);
+ return handle->fns->disk_free_fn(handle, smb_fname,
+ bsize, dfree, dsize);
}
-int smb_vfs_call_get_quota(struct vfs_handle_struct *handle, const char *path,
- enum SMB_QUOTA_TYPE qtype, unid_t id,
- SMB_DISK_QUOTA *qt)
+int smb_vfs_call_get_quota(struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ enum SMB_QUOTA_TYPE qtype,
+ unid_t id,
+ SMB_DISK_QUOTA *qt)
{
VFS_FIND(get_quota);
- return handle->fns->get_quota_fn(handle, path, qtype, id, qt);
+ return handle->fns->get_quota_fn(handle, smb_fname, qtype, id, qt);
}
int smb_vfs_call_set_quota(struct vfs_handle_struct *handle,
shadow_copy_data,
labels);
}
-int smb_vfs_call_statvfs(struct vfs_handle_struct *handle, const char *path,
- struct vfs_statvfs_struct *statbuf)
+int smb_vfs_call_statvfs(struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ struct vfs_statvfs_struct *statbuf)
{
VFS_FIND(statvfs);
- return handle->fns->statvfs_fn(handle, path, statbuf);
+ return handle->fns->statvfs_fn(handle, smb_fname, statbuf);
}
uint32_t smb_vfs_call_fs_capabilities(struct vfs_handle_struct *handle,
char *parent_dir = NULL;
const char *final_component = NULL;
struct smb_filename *local_smb_fname = NULL;
+ struct smb_filename parent_dir_fname = {0};
+ struct smb_filename saved_dir_fname = {0};
saved_dir = vfs_GetWd(talloc_tos(),fsp->conn);
if (!saved_dir) {
return status;
}
+ saved_dir_fname = (struct smb_filename) {
+ .base_name = saved_dir
+ };
+
if (!parent_dirname(talloc_tos(),
fsp->fsp_name->base_name,
&parent_dir,
return NT_STATUS_NO_MEMORY;
}
+ parent_dir_fname = (struct smb_filename) {
+ .base_name = parent_dir,
+ .flags = fsp->fsp_name->flags
+ };
+
/* cd into the parent dir to pin it. */
- ret = vfs_ChDir(fsp->conn, parent_dir);
+ ret = vfs_ChDir(fsp->conn, &parent_dir_fname);
if (ret == -1) {
return map_nt_error_from_unix(errno);
}
out:
- vfs_ChDir(fsp->conn,saved_dir);
+ vfs_ChDir(fsp->conn, &saved_dir_fname);
TALLOC_FREE(local_smb_fname);
TALLOC_FREE(saved_dir);
TALLOC_FREE(parent_dir);
return status;
}
-int smb_vfs_call_chdir(struct vfs_handle_struct *handle, const char *path)
+int smb_vfs_call_chdir(struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname)
{
VFS_FIND(chdir);
- return handle->fns->chdir_fn(handle, path);
+ return handle->fns->chdir_fn(handle, smb_fname);
}
char *smb_vfs_call_getwd(struct vfs_handle_struct *handle)
return handle->fns->linux_setlease_fn(handle, fsp, leasetype);
}
-int smb_vfs_call_symlink(struct vfs_handle_struct *handle, const char *oldpath,
- const char *newpath)
+int smb_vfs_call_symlink(struct vfs_handle_struct *handle,
+ const char *link_target,
+ const struct smb_filename *new_smb_fname)
{
VFS_FIND(symlink);
- return handle->fns->symlink_fn(handle, oldpath, newpath);
+ return handle->fns->symlink_fn(handle, link_target, new_smb_fname);
}
int smb_vfs_call_readlink(struct vfs_handle_struct *handle,
- const char *path, char *buf, size_t bufsiz)
+ const struct smb_filename *smb_fname,
+ char *buf,
+ size_t bufsiz)
{
VFS_FIND(readlink);
- return handle->fns->readlink_fn(handle, path, buf, bufsiz);
+ return handle->fns->readlink_fn(handle, smb_fname, buf, bufsiz);
}
-int smb_vfs_call_link(struct vfs_handle_struct *handle, const char *oldpath,
- const char *newpath)
+int smb_vfs_call_link(struct vfs_handle_struct *handle,
+ const struct smb_filename *old_smb_fname,
+ const struct smb_filename *new_smb_fname)
{
VFS_FIND(link);
- return handle->fns->link_fn(handle, oldpath, newpath);
+ return handle->fns->link_fn(handle, old_smb_fname, new_smb_fname);
}
-int smb_vfs_call_mknod(struct vfs_handle_struct *handle, const char *path,
- mode_t mode, SMB_DEV_T dev)
+int smb_vfs_call_mknod(struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ mode_t mode,
+ SMB_DEV_T dev)
{
VFS_FIND(mknod);
- return handle->fns->mknod_fn(handle, path, mode, dev);
+ return handle->fns->mknod_fn(handle, smb_fname, mode, dev);
}
char *smb_vfs_call_realpath(struct vfs_handle_struct *handle, const char *path)
return handle->fns->realpath_fn(handle, path);
}
-int smb_vfs_call_chflags(struct vfs_handle_struct *handle, const char *path,
- unsigned int flags)
+int smb_vfs_call_chflags(struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ unsigned int flags)
{
VFS_FIND(chflags);
- return handle->fns->chflags_fn(handle, path, flags);
+ return handle->fns->chflags_fn(handle, smb_fname, flags);
}
struct file_id smb_vfs_call_file_id_create(struct vfs_handle_struct *handle,
off_t src_off,
struct files_struct *dest_fsp,
off_t dest_off,
- off_t num)
+ off_t num,
+ uint32_t flags)
{
VFS_FIND(copy_chunk_send);
return handle->fns->copy_chunk_send_fn(handle, mem_ctx, ev, src_fsp,
- src_off, dest_fsp, dest_off, num);
+ src_off, dest_fsp, dest_off, num,
+ flags);
}
NTSTATUS smb_vfs_call_copy_chunk_recv(struct vfs_handle_struct *handle,
}
SMB_ACL_T smb_vfs_call_sys_acl_get_file(struct vfs_handle_struct *handle,
- const char *path_p,
+ const struct smb_filename *smb_fname,
SMB_ACL_TYPE_T type,
TALLOC_CTX *mem_ctx)
{
VFS_FIND(sys_acl_get_file);
- return handle->fns->sys_acl_get_file_fn(handle, path_p, type, mem_ctx);
+ return handle->fns->sys_acl_get_file_fn(handle, smb_fname, type, mem_ctx);
}
SMB_ACL_T smb_vfs_call_sys_acl_get_fd(struct vfs_handle_struct *handle,
}
int smb_vfs_call_sys_acl_blob_get_file(struct vfs_handle_struct *handle,
- const char *path_p,
- TALLOC_CTX *mem_ctx,
- char **blob_description,
- DATA_BLOB *blob)
+ const struct smb_filename *smb_fname,
+ TALLOC_CTX *mem_ctx,
+ char **blob_description,
+ DATA_BLOB *blob)
{
VFS_FIND(sys_acl_blob_get_file);
- return handle->fns->sys_acl_blob_get_file_fn(handle, path_p, mem_ctx, blob_description, blob);
+ return handle->fns->sys_acl_blob_get_file_fn(handle, smb_fname,
+ mem_ctx, blob_description, blob);
}
int smb_vfs_call_sys_acl_blob_get_fd(struct vfs_handle_struct *handle,
}
int smb_vfs_call_sys_acl_set_file(struct vfs_handle_struct *handle,
- const char *name, SMB_ACL_TYPE_T acltype,
- SMB_ACL_T theacl)
+ const struct smb_filename *smb_fname,
+ SMB_ACL_TYPE_T acltype,
+ SMB_ACL_T theacl)
{
VFS_FIND(sys_acl_set_file);
- return handle->fns->sys_acl_set_file_fn(handle, name, acltype, theacl);
+ return handle->fns->sys_acl_set_file_fn(handle, smb_fname,
+ acltype, theacl);
}
int smb_vfs_call_sys_acl_set_fd(struct vfs_handle_struct *handle,
}
int smb_vfs_call_sys_acl_delete_def_file(struct vfs_handle_struct *handle,
- const char *path)
+ const struct smb_filename *smb_fname)
{
VFS_FIND(sys_acl_delete_def_file);
- return handle->fns->sys_acl_delete_def_file_fn(handle, path);
+ return handle->fns->sys_acl_delete_def_file_fn(handle, smb_fname);
}
ssize_t smb_vfs_call_getxattr(struct vfs_handle_struct *handle,
- const char *path, const char *name, void *value,
- size_t size)
+ const struct smb_filename *smb_fname,
+ const char *name,
+ void *value,
+ size_t size)
{
VFS_FIND(getxattr);
- return handle->fns->getxattr_fn(handle, path, name, value, size);
+ return handle->fns->getxattr_fn(handle, smb_fname, name, value, size);
}
ssize_t smb_vfs_call_fgetxattr(struct vfs_handle_struct *handle,
}
ssize_t smb_vfs_call_listxattr(struct vfs_handle_struct *handle,
- const char *path, char *list, size_t size)
+ const struct smb_filename *smb_fname,
+ char *list,
+ size_t size)
{
VFS_FIND(listxattr);
- return handle->fns->listxattr_fn(handle, path, list, size);
+ return handle->fns->listxattr_fn(handle, smb_fname, list, size);
}
ssize_t smb_vfs_call_flistxattr(struct vfs_handle_struct *handle,
}
int smb_vfs_call_removexattr(struct vfs_handle_struct *handle,
- const char *path, const char *name)
+ const struct smb_filename *smb_fname,
+ const char *name)
{
VFS_FIND(removexattr);
- return handle->fns->removexattr_fn(handle, path, name);
+ return handle->fns->removexattr_fn(handle, smb_fname, name);
}
int smb_vfs_call_fremovexattr(struct vfs_handle_struct *handle,
return handle->fns->fremovexattr_fn(handle, fsp, name);
}
-int smb_vfs_call_setxattr(struct vfs_handle_struct *handle, const char *path,
- const char *name, const void *value, size_t size,
- int flags)
+int smb_vfs_call_setxattr(struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ const char *name,
+ const void *value,
+ size_t size,
+ int flags)
{
VFS_FIND(setxattr);
- return handle->fns->setxattr_fn(handle, path, name, value, size, flags);
+ return handle->fns->setxattr_fn(handle, smb_fname,
+ name, value, size, flags);
}
int smb_vfs_call_fsetxattr(struct vfs_handle_struct *handle,
return handle->fns->aio_force_fn(handle, fsp);
}
-bool smb_vfs_call_is_offline(struct vfs_handle_struct *handle,
- const struct smb_filename *fname,
- SMB_STRUCT_STAT *sbuf)
-{
- VFS_FIND(is_offline);
- return handle->fns->is_offline_fn(handle, fname, sbuf);
-}
-
-int smb_vfs_call_set_offline(struct vfs_handle_struct *handle,
- const struct smb_filename *fname)
-{
- VFS_FIND(set_offline);
- return handle->fns->set_offline_fn(handle, fname);
-}
-
NTSTATUS smb_vfs_call_durable_cookie(struct vfs_handle_struct *handle,
struct files_struct *fsp,
TALLOC_CTX *mem_ctx,