vfs_handle_struct *handle;
};
-static ssize_t get_xattr_size(connection_struct *conn,
- const struct smb_filename *smb_fname,
- const char *xattr_name)
+static ssize_t get_xattr_size_fsp(struct files_struct *fsp,
+ const char *xattr_name)
{
NTSTATUS status;
struct ea_struct ea;
ssize_t result;
- status = get_ea_value(talloc_tos(), conn, NULL, smb_fname,
- xattr_name, &ea);
-
+ status = get_ea_value_fsp(talloc_tos(),
+ fsp,
+ xattr_name,
+ &ea);
if (!NT_STATUS_IS_OK(status)) {
return -1;
}
const char *stream_name,
char **xattr_name)
{
- char *sname;
+ size_t stream_name_len = strlen(stream_name);
char *stype;
struct streams_xattr_config *config;
SMB_VFS_HANDLE_GET_DATA(handle, config, struct streams_xattr_config,
return NT_STATUS_UNSUCCESSFUL);
- sname = talloc_strdup(ctx, stream_name + 1);
- if (sname == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
+ SMB_ASSERT(stream_name[0] == ':');
+ stream_name += 1;
/*
* With vfs_fruit option "fruit:encoding = native" we're
* In check_path_syntax() we've already ensured the streamname
* we got from the client is valid.
*/
- stype = strrchr_m(sname, ':');
+ stype = strrchr_m(stream_name, ':');
if (stype) {
/*
* We only support one stream type: "$DATA"
*/
if (strcasecmp_m(stype, ":$DATA") != 0) {
- talloc_free(sname);
return NT_STATUS_INVALID_PARAMETER;
}
/* Split name and type */
- stype[0] = '\0';
+ stream_name_len = (stype - stream_name);
}
- *xattr_name = talloc_asprintf(ctx, "%s%s%s",
+ *xattr_name = talloc_asprintf(ctx, "%s%.*s%s",
config->prefix,
- sname,
+ (int)stream_name_len,
+ stream_name,
config->store_stream_type ? ":$DATA" : "");
if (*xattr_name == NULL) {
- talloc_free(sname);
return NT_STATUS_NO_MEMORY;
}
DEBUG(10, ("xattr_name: %s, stream_name: %s\n", *xattr_name,
stream_name));
- talloc_free(sname);
return NT_STATUS_OK;
}
return true;
}
-/**
- * Helper to stat/lstat the base file of an smb_fname.
- */
-static int streams_xattr_stat_base(vfs_handle_struct *handle,
- struct smb_filename *smb_fname,
- bool follow_links)
-{
- char *tmp_stream_name;
- int result;
-
- tmp_stream_name = smb_fname->stream_name;
- smb_fname->stream_name = NULL;
- if (follow_links) {
- result = SMB_VFS_NEXT_STAT(handle, smb_fname);
- } else {
- result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
- }
- smb_fname->stream_name = tmp_stream_name;
- return result;
-}
-
static int streams_xattr_fstat(vfs_handle_struct *handle, files_struct *fsp,
SMB_STRUCT_STAT *sbuf)
{
- struct smb_filename *smb_fname_base = NULL;
int ret = -1;
struct stream_io *io = (struct stream_io *)
VFS_FETCH_FSP_EXTENSION(handle, fsp);
- if (io == NULL || fsp->base_fsp == NULL) {
+ if (io == NULL || !fsp_is_alternate_stream(fsp)) {
return SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
}
return -1;
}
- /* Create an smb_filename with stream_name == NULL. */
- smb_fname_base = synthetic_smb_fname(talloc_tos(),
- io->base,
- NULL,
- NULL,
- fsp->fsp_name->twrp,
- fsp->fsp_name->flags);
- if (smb_fname_base == NULL) {
- errno = ENOMEM;
- return -1;
- }
-
- ret = vfs_stat(handle->conn, smb_fname_base);
- *sbuf = smb_fname_base->st;
-
+ ret = SMB_VFS_NEXT_FSTAT(handle, fsp->base_fsp, sbuf);
if (ret == -1) {
- TALLOC_FREE(smb_fname_base);
return -1;
}
- sbuf->st_ex_size = get_xattr_size(handle->conn,
- smb_fname_base, io->xattr_name);
+ sbuf->st_ex_size = get_xattr_size_fsp(fsp->base_fsp,
+ io->xattr_name);
if (sbuf->st_ex_size == -1) {
- TALLOC_FREE(smb_fname_base);
SET_STAT_INVALID(*sbuf);
return -1;
}
sbuf->st_ex_mode |= S_IFREG;
sbuf->st_ex_blocks = sbuf->st_ex_size / STAT_ST_BLOCKSIZE + 1;
- TALLOC_FREE(smb_fname_base);
return 0;
}
NTSTATUS status;
int result = -1;
char *xattr_name = NULL;
+ char *tmp_stream_name = NULL;
+ struct smb_filename *pathref = NULL;
+ struct files_struct *fsp = smb_fname->fsp;
if (!is_named_stream(smb_fname)) {
return SMB_VFS_NEXT_STAT(handle, smb_fname);
* not following links here. */
/* Populate the stat struct with info from the base file. */
- if (streams_xattr_stat_base(handle, smb_fname, true) == -1) {
+ tmp_stream_name = smb_fname->stream_name;
+ smb_fname->stream_name = NULL;
+ result = SMB_VFS_NEXT_STAT(handle, smb_fname);
+ smb_fname->stream_name = tmp_stream_name;
+
+ if (result == -1) {
return -1;
}
}
/* Augment the base file's stat information before returning. */
- smb_fname->st.st_ex_size = get_xattr_size(handle->conn,
- smb_fname,
- xattr_name);
+ if (fsp == NULL) {
+ status = synthetic_pathref(talloc_tos(),
+ handle->conn->cwd_fsp,
+ smb_fname->base_name,
+ NULL,
+ NULL,
+ smb_fname->twrp,
+ smb_fname->flags,
+ &pathref);
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(xattr_name);
+ SET_STAT_INVALID(smb_fname->st);
+ errno = ENOENT;
+ return -1;
+ }
+ fsp = pathref->fsp;
+ } else {
+ fsp = fsp->base_fsp;
+ }
+
+ smb_fname->st.st_ex_size = get_xattr_size_fsp(fsp,
+ xattr_name);
if (smb_fname->st.st_ex_size == -1) {
+ TALLOC_FREE(xattr_name);
+ TALLOC_FREE(pathref);
SET_STAT_INVALID(smb_fname->st);
errno = ENOENT;
- result = -1;
- goto fail;
+ return -1;
}
smb_fname->st.st_ex_ino = hash_inode(&smb_fname->st, xattr_name);
smb_fname->st.st_ex_mode &= ~S_IFMT;
- smb_fname->st.st_ex_mode &= ~S_IFDIR;
smb_fname->st.st_ex_mode |= S_IFREG;
smb_fname->st.st_ex_blocks =
smb_fname->st.st_ex_size / STAT_ST_BLOCKSIZE + 1;
- result = 0;
- fail:
TALLOC_FREE(xattr_name);
- return result;
+ TALLOC_FREE(pathref);
+ return 0;
}
static int streams_xattr_lstat(vfs_handle_struct *handle,
struct smb_filename *smb_fname)
{
- NTSTATUS status;
- int result = -1;
- char *xattr_name = NULL;
-
- if (!is_named_stream(smb_fname)) {
- return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
- }
-
- /* Populate the stat struct with info from the base file. */
- if (streams_xattr_stat_base(handle, smb_fname, false) == -1) {
- return -1;
- }
-
- /* Derive the xattr name to lookup. */
- status = streams_xattr_get_name(handle, talloc_tos(),
- smb_fname->stream_name, &xattr_name);
- if (!NT_STATUS_IS_OK(status)) {
- errno = map_errno_from_nt_status(status);
- return -1;
- }
-
- /* Augment the base file's stat information before returning. */
- smb_fname->st.st_ex_size = get_xattr_size(handle->conn,
- smb_fname,
- xattr_name);
- if (smb_fname->st.st_ex_size == -1) {
+ if (is_named_stream(smb_fname)) {
+ /*
+ * There can never be EA's on a symlink.
+ * Windows will never see a symlink, and
+ * in SMB_FILENAME_POSIX_PATH mode we don't
+ * allow EA's on a symlink.
+ */
SET_STAT_INVALID(smb_fname->st);
errno = ENOENT;
- result = -1;
- goto fail;
+ return -1;
}
-
- smb_fname->st.st_ex_ino = hash_inode(&smb_fname->st, xattr_name);
- smb_fname->st.st_ex_mode &= ~S_IFMT;
- smb_fname->st.st_ex_mode |= S_IFREG;
- smb_fname->st.st_ex_blocks =
- smb_fname->st.st_ex_size / STAT_ST_BLOCKSIZE + 1;
-
- result = 0;
-
- fail:
- TALLOC_FREE(xattr_name);
- return result;
+ return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
}
static int streams_xattr_openat(struct vfs_handle_struct *handle,
const struct files_struct *dirfsp,
const struct smb_filename *smb_fname,
files_struct *fsp,
- int flags,
- mode_t mode)
+ const struct vfs_open_how *how)
{
NTSTATUS status;
struct streams_xattr_config *config = NULL;
SMB_VFS_HANDLE_GET_DATA(handle, config, struct streams_xattr_config,
return -1);
- DEBUG(10, ("streams_xattr_open called for %s with flags 0x%x\n",
- smb_fname_str_dbg(smb_fname), flags));
+ DBG_DEBUG("called for %s with flags 0x%x\n",
+ smb_fname_str_dbg(smb_fname),
+ how->flags);
if (!is_named_stream(smb_fname)) {
return SMB_VFS_NEXT_OPENAT(handle,
dirfsp,
smb_fname,
fsp,
- flags,
- mode);
+ how);
}
- /*
- * For now assert this, so the below SMB_VFS_SETXATTR() works.
- */
- SMB_ASSERT(fsp_get_pathref_fd(dirfsp) == AT_FDCWD);
+ if (how->resolve != 0) {
+ errno = ENOSYS;
+ return -1;
+ }
+
+ SMB_ASSERT(fsp_is_alternate_stream(fsp));
+ SMB_ASSERT(dirfsp == NULL);
status = streams_xattr_get_name(handle, talloc_tos(),
smb_fname->stream_name, &xattr_name);
goto fail;
}
- status = get_ea_value(talloc_tos(), handle->conn, NULL,
- smb_fname, xattr_name, &ea);
+ status = get_ea_value_fsp(talloc_tos(),
+ fsp->base_fsp,
+ xattr_name,
+ &ea);
- DEBUG(10, ("get_ea_value returned %s\n", nt_errstr(status)));
+ DBG_DEBUG("get_ea_value_fsp returned %s\n", nt_errstr(status));
if (!NT_STATUS_IS_OK(status)) {
if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
goto fail;
}
- if (!(flags & O_CREAT)) {
+ if (!(how->flags & O_CREAT)) {
errno = ENOATTR;
goto fail;
}
set_empty_xattr = true;
}
- if (flags & O_TRUNC) {
+ if (how->flags & O_TRUNC) {
set_empty_xattr = true;
}
DEBUG(10, ("creating or truncating attribute %s on file %s\n",
xattr_name, smb_fname->base_name));
- ret = SMB_VFS_FSETXATTR(fsp->base_fsp ? fsp->base_fsp : fsp,
+ ret = SMB_VFS_FSETXATTR(fsp->base_fsp,
xattr_name,
&null, sizeof(null),
- flags & O_EXCL ? XATTR_CREATE : 0);
+ how->flags & O_EXCL ? XATTR_CREATE : 0);
if (ret != 0) {
goto fail;
}
DBG_DEBUG("streams_xattr_close called [%s] fd [%d]\n",
smb_fname_str_dbg(fsp->fsp_name), fd);
- if (!is_named_stream(fsp->fsp_name)) {
+ if (!fsp_is_alternate_stream(fsp)) {
return SMB_VFS_NEXT_CLOSE(handle, fsp);
}
return ret;
}
-static int streams_xattr_unlink_internal(vfs_handle_struct *handle,
+static int streams_xattr_unlinkat(vfs_handle_struct *handle,
struct files_struct *dirfsp,
const struct smb_filename *smb_fname,
int flags)
NTSTATUS status;
int ret = -1;
char *xattr_name = NULL;
+ struct smb_filename *pathref = NULL;
+ struct files_struct *fsp = smb_fname->fsp;
if (!is_named_stream(smb_fname)) {
return SMB_VFS_NEXT_UNLINKAT(handle,
flags);
}
+ /* A stream can never be rmdir'ed */
+ SMB_ASSERT((flags & AT_REMOVEDIR) == 0);
+
status = streams_xattr_get_name(handle, talloc_tos(),
smb_fname->stream_name, &xattr_name);
if (!NT_STATUS_IS_OK(status)) {
goto fail;
}
- SMB_ASSERT(smb_fname->fsp != NULL);
- SMB_ASSERT(smb_fname->fsp->base_fsp != NULL);
+ if (fsp == NULL) {
+ status = synthetic_pathref(talloc_tos(),
+ handle->conn->cwd_fsp,
+ smb_fname->base_name,
+ NULL,
+ NULL,
+ smb_fname->twrp,
+ smb_fname->flags,
+ &pathref);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = ENOENT;
+ goto fail;
+ }
+ fsp = pathref->fsp;
+ } else {
+ SMB_ASSERT(fsp_is_alternate_stream(smb_fname->fsp));
+ fsp = fsp->base_fsp;
+ }
- ret = SMB_VFS_FREMOVEXATTR(smb_fname->fsp->base_fsp, xattr_name);
+ ret = SMB_VFS_FREMOVEXATTR(fsp, xattr_name);
if ((ret == -1) && (errno == ENOATTR)) {
errno = ENOENT;
fail:
TALLOC_FREE(xattr_name);
- return ret;
-}
-
-static int streams_xattr_unlinkat(vfs_handle_struct *handle,
- struct files_struct *dirfsp,
- const struct smb_filename *smb_fname,
- int flags)
-{
- int ret;
- if (flags & AT_REMOVEDIR) {
- ret = SMB_VFS_NEXT_UNLINKAT(handle,
- dirfsp,
- smb_fname,
- flags);
- } else {
- ret = streams_xattr_unlink_internal(handle,
- dirfsp,
- smb_fname,
- flags);
- }
+ TALLOC_FREE(pathref);
return ret;
}
}
/* Read the old stream from the base file fsp. */
- status = get_ea_value(talloc_tos(),
- handle->conn,
- pathref_src->fsp,
- NULL,
- src_xattr_name,
- &ea);
+ status = get_ea_value_fsp(talloc_tos(),
+ pathref_src->fsp,
+ src_xattr_name,
+ &ea);
if (!NT_STATUS_IS_OK(status)) {
errno = map_errno_from_nt_status(status);
goto fail;
SMB_VFS_HANDLE_GET_DATA(handle, config, struct streams_xattr_config,
return NT_STATUS_UNSUCCESSFUL);
- status = get_ea_names_from_file(talloc_tos(),
+ status = get_ea_names_from_fsp(talloc_tos(),
smb_fname->fsp,
&names,
&num_names);
continue;
}
- status = get_ea_value(names,
- handle->conn,
- NULL,
- smb_fname,
- names[i],
- &ea);
+ status = get_ea_value_fsp(names,
+ smb_fname->fsp,
+ names[i],
+ &ea);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10, ("Could not get ea %s for file %s: %s\n",
names[i],
(struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
struct ea_struct ea;
NTSTATUS status;
- struct smb_filename *smb_fname_base = NULL;
int ret;
DEBUG(10, ("streams_xattr_pwrite called for %d bytes\n", (int)n));
return -1;
}
- /* Create an smb_filename with stream_name == NULL. */
- smb_fname_base = synthetic_smb_fname(talloc_tos(),
- sio->base,
- NULL,
- NULL,
- fsp->fsp_name->twrp,
- fsp->fsp_name->flags);
- if (smb_fname_base == NULL) {
- errno = ENOMEM;
- return -1;
- }
-
- status = get_ea_value(talloc_tos(), handle->conn, NULL,
- smb_fname_base, sio->xattr_name, &ea);
+ status = get_ea_value_fsp(talloc_tos(),
+ fsp->base_fsp,
+ sio->xattr_name,
+ &ea);
if (!NT_STATUS_IS_OK(status)) {
return -1;
}
struct ea_struct ea;
NTSTATUS status;
size_t length, overlap;
- struct smb_filename *smb_fname_base = NULL;
DEBUG(10, ("streams_xattr_pread: offset=%d, size=%d\n",
(int)offset, (int)n));
return -1;
}
- /* Create an smb_filename with stream_name == NULL. */
- smb_fname_base = synthetic_smb_fname(talloc_tos(),
- sio->base,
- NULL,
- NULL,
- fsp->fsp_name->twrp,
- fsp->fsp_name->flags);
- if (smb_fname_base == NULL) {
- errno = ENOMEM;
- return -1;
- }
-
- status = get_ea_value(talloc_tos(), handle->conn, NULL,
- smb_fname_base, sio->xattr_name, &ea);
+ status = get_ea_value_fsp(talloc_tos(),
+ fsp->base_fsp,
+ sio->xattr_name,
+ &ea);
if (!NT_STATUS_IS_OK(status)) {
return -1;
}
length = ea.value.length-1;
- DEBUG(10, ("streams_xattr_pread: get_ea_value returned %d bytes\n",
- (int)length));
+ DBG_DEBUG("get_ea_value_fsp returned %d bytes\n",
+ (int)length);
/* Attempt to read past EOF. */
if (length <= offset) {
NTSTATUS status;
struct stream_io *sio =
(struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
- struct smb_filename *smb_fname_base = NULL;
DEBUG(10, ("streams_xattr_ftruncate called for file %s offset %.0f\n",
fsp_str_dbg(fsp), (double)offset));
return -1;
}
- /* Create an smb_filename with stream_name == NULL. */
- smb_fname_base = synthetic_smb_fname(talloc_tos(),
- sio->base,
- NULL,
- NULL,
- fsp->fsp_name->twrp,
- fsp->fsp_name->flags);
- if (smb_fname_base == NULL) {
- errno = ENOMEM;
- return -1;
- }
-
- status = get_ea_value(talloc_tos(), handle->conn, NULL,
- smb_fname_base, sio->xattr_name, &ea);
+ status = get_ea_value_fsp(talloc_tos(),
+ fsp->base_fsp,
+ sio->xattr_name,
+ &ea);
if (!NT_STATUS_IS_OK(status)) {
return -1;
}
ea.value.length = offset + 1;
ea.value.data[offset] = 0;
- ret = SMB_VFS_FSETXATTR(fsp->base_fsp ? fsp->base_fsp : fsp,
- sio->xattr_name,
- ea.value.data, ea.value.length, 0);
+ ret = SMB_VFS_FSETXATTR(fsp->base_fsp,
+ sio->xattr_name,
+ ea.value.data,
+ ea.value.length,
+ 0);
TALLOC_FREE(ea.value.data);
return false;
}
-static int streams_xattr_kernel_flock(vfs_handle_struct *handle,
- files_struct *fsp,
- uint32_t share_access,
- uint32_t access_mask)
+static int streams_xattr_filesystem_sharemode(vfs_handle_struct *handle,
+ files_struct *fsp,
+ uint32_t share_access,
+ uint32_t access_mask)
{
struct stream_io *sio =
(struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
if (sio == NULL) {
- return SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp,
- share_access, access_mask);
+ return SMB_VFS_NEXT_FILESYSTEM_SHAREMODE(handle,
+ fsp,
+ share_access,
+ access_mask);
}
return 0;
return true;
}
+static int streams_xattr_fcntl(vfs_handle_struct *handle,
+ files_struct *fsp,
+ int cmd,
+ va_list cmd_arg)
+{
+ va_list dup_cmd_arg;
+ void *arg;
+ int ret;
+
+ if (fsp_is_alternate_stream(fsp)) {
+ switch (cmd) {
+ case F_GETFL:
+ case F_SETFL:
+ break;
+ default:
+ DBG_ERR("Unsupported fcntl() cmd [%d] on [%s]\n",
+ cmd, fsp_str_dbg(fsp));
+ errno = EINVAL;
+ return -1;
+ }
+ }
+
+ va_copy(dup_cmd_arg, cmd_arg);
+ arg = va_arg(dup_cmd_arg, void *);
+
+ ret = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
+
+ va_end(dup_cmd_arg);
+
+ return ret;
+}
+
static struct vfs_fn_pointers vfs_streams_xattr_fns = {
.fs_capabilities_fn = streams_xattr_fs_capabilities,
.connect_fn = streams_xattr_connect,
.lock_fn = streams_xattr_lock,
.getlock_fn = streams_xattr_getlock,
- .kernel_flock_fn = streams_xattr_kernel_flock,
+ .filesystem_sharemode_fn = streams_xattr_filesystem_sharemode,
.linux_setlease_fn = streams_xattr_linux_setlease,
.strict_lock_check_fn = streams_xattr_strict_lock_check,
+ .fcntl_fn = streams_xattr_fcntl,
.fchown_fn = streams_xattr_fchown,
.fchmod_fn = streams_xattr_fchmod,