*/
#include "includes.h"
+#include "smbd/smbd.h"
+#include "system/filesys.h"
+#include "../lib/crypto/md5.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_VFS
SMB_ASSERT(upper_sname != NULL);
MD5Init(&ctx);
- MD5Update(&ctx, (unsigned char *)&(sbuf->st_ex_dev),
+ MD5Update(&ctx, (const unsigned char *)&(sbuf->st_ex_dev),
sizeof(sbuf->st_ex_dev));
- MD5Update(&ctx, (unsigned char *)&(sbuf->st_ex_ino),
+ MD5Update(&ctx, (const unsigned char *)&(sbuf->st_ex_ino),
sizeof(sbuf->st_ex_ino));
MD5Update(&ctx, (unsigned char *)upper_sname,
talloc_get_size(upper_sname)-1);
static bool streams_xattr_recheck(struct stream_io *sio)
{
NTSTATUS status;
- struct smb_filename *smb_fname = NULL;
char *xattr_name = NULL;
if (sio->fsp->fsp_name == sio->fsp_name_ptr) {
return true;
}
- status = create_synthetic_smb_fname_split(talloc_tos(),
- sio->fsp->fsp_name, NULL,
- &smb_fname);
- if (!NT_STATUS_IS_OK(status)) {
- return false;
- }
-
- if (smb_fname->stream_name == NULL) {
+ if (sio->fsp->fsp_name->stream_name == NULL) {
/* how can this happen */
errno = EINVAL;
return false;
}
- status = streams_xattr_get_name(talloc_tos(), smb_fname->stream_name,
+ status = streams_xattr_get_name(talloc_tos(),
+ sio->fsp->fsp_name->stream_name,
&xattr_name);
if (!NT_STATUS_IS_OK(status)) {
return false;
sio->xattr_name = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(sio->handle, sio->fsp),
xattr_name);
sio->base = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(sio->handle, sio->fsp),
- smb_fname->base_name);
+ sio->fsp->fsp_name->base_name);
sio->fsp_name_ptr = sio->fsp->fsp_name;
- TALLOC_FREE(smb_fname);
TALLOC_FREE(xattr_name);
if ((sio->xattr_name == NULL) || (sio->base == NULL)) {
sbuf->st_ex_ino = stream_inode(sbuf, io->xattr_name);
sbuf->st_ex_mode &= ~S_IFMT;
sbuf->st_ex_mode |= S_IFREG;
- sbuf->st_ex_blocks = sbuf->st_ex_size % STAT_ST_BLOCKSIZE + 1;
+ sbuf->st_ex_blocks = sbuf->st_ex_size / STAT_ST_BLOCKSIZE + 1;
return 0;
}
return SMB_VFS_NEXT_STAT(handle, smb_fname);
}
+ /* Note if lp_posix_paths() is true, we can never
+ * get here as is_ntfs_stream_smb_fname() is
+ * always false. So we never need worry about
+ * not following links here. */
+
/* If the default stream is requested, just stat the base file. */
if (is_ntfs_default_stream_smb_fname(smb_fname)) {
return streams_xattr_stat_base(handle, smb_fname, true);
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;
+ smb_fname->st.st_ex_size / STAT_ST_BLOCKSIZE + 1;
result = 0;
fail:
return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
}
- /* If the default stream is requested, just stat the base file. */
+ /* If the default stream is requested, just stat the base file. */
if (is_ntfs_default_stream_smb_fname(smb_fname)) {
return streams_xattr_stat_base(handle, smb_fname, false);
}
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;
+ smb_fname->st.st_ex_size / STAT_ST_BLOCKSIZE + 1;
result = 0;
}
/* Don't rename if the streams are identical. */
- if (StrCaseCmp(smb_fname_src->stream_name,
+ if (strcasecmp_m(smb_fname_src->stream_name,
smb_fname_dst->stream_name) == 0) {
goto done;
}
{
struct stream_struct *tmp;
- tmp = TALLOC_REALLOC_ARRAY(mem_ctx, *streams, struct stream_struct,
+ tmp = talloc_realloc(mem_ctx, *streams, struct stream_struct,
(*num_streams)+1);
if (tmp == NULL) {
return false;
return NT_STATUS_OK;
}
-static uint32_t streams_xattr_fs_capabilities(struct vfs_handle_struct *handle)
+static uint32_t streams_xattr_fs_capabilities(struct vfs_handle_struct *handle,
+ enum timestamp_set_resolution *p_ts_res)
{
- return SMB_VFS_NEXT_FS_CAPABILITIES(handle) | FILE_NAMED_STREAMS;
+ return SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res) | FILE_NAMED_STREAMS;
}
static ssize_t streams_xattr_pwrite(vfs_handle_struct *handle,
if ((offset + n) > ea.value.length-1) {
uint8 *tmp;
- tmp = TALLOC_REALLOC_ARRAY(talloc_tos(), ea.value.data, uint8,
+ tmp = talloc_realloc(talloc_tos(), ea.value.data, uint8,
offset + n + 1);
if (tmp == NULL) {
sio->xattr_name,
ea.value.data, ea.value.length, 0);
} else {
- ret = SMB_VFS_SETXATTR(fsp->conn, fsp->base_fsp->fsp_name,
+ ret = SMB_VFS_SETXATTR(fsp->conn,
+ fsp->base_fsp->fsp_name->base_name,
sio->xattr_name,
ea.value.data, ea.value.length, 0);
}
NTSTATUS status;
size_t length, overlap;
+ DEBUG(10, ("streams_xattr_pread: offset=%d, size=%d\n",
+ (int)offset, (int)n));
+
if (sio == NULL) {
return SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
}
length = ea.value.length-1;
+ DEBUG(10, ("streams_xattr_pread: get_ea_value returned %d bytes\n",
+ (int)length));
+
/* Attempt to read past EOF. */
if (length <= offset) {
- errno = EINVAL;
- return -1;
+ return 0;
}
overlap = (offset + n) > length ? (length - offset) : n;
(struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
DEBUG(10, ("streams_xattr_ftruncate called for file %s offset %.0f\n",
- fsp->fsp_name,
- (double)offset ));
+ fsp_str_dbg(fsp), (double)offset));
if (sio == NULL) {
return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
return -1;
}
- tmp = TALLOC_REALLOC_ARRAY(talloc_tos(), ea.value.data, uint8,
+ tmp = talloc_realloc(talloc_tos(), ea.value.data, uint8,
offset + 1);
if (tmp == NULL) {
sio->xattr_name,
ea.value.data, ea.value.length, 0);
} else {
- ret = SMB_VFS_SETXATTR(fsp->conn, fsp->base_fsp->fsp_name,
+ ret = SMB_VFS_SETXATTR(fsp->conn,
+ fsp->base_fsp->fsp_name->base_name,
sio->xattr_name,
ea.value.data, ea.value.length, 0);
}
return 0;
}
-/* VFS operations structure */
-
-static vfs_op_tuple streams_xattr_ops[] = {
- {SMB_VFS_OP(streams_xattr_fs_capabilities), SMB_VFS_OP_FS_CAPABILITIES,
- SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(streams_xattr_open), SMB_VFS_OP_OPEN,
- SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(streams_xattr_stat), SMB_VFS_OP_STAT,
- SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(streams_xattr_fstat), SMB_VFS_OP_FSTAT,
- SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(streams_xattr_lstat), SMB_VFS_OP_LSTAT,
- SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(streams_xattr_pread), SMB_VFS_OP_PREAD,
- SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(streams_xattr_pwrite), SMB_VFS_OP_PWRITE,
- SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(streams_xattr_unlink), SMB_VFS_OP_UNLINK,
- SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(streams_xattr_rename), SMB_VFS_OP_RENAME,
- SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(streams_xattr_ftruncate), SMB_VFS_OP_FTRUNCATE,
- SMB_VFS_LAYER_TRANSPARENT},
- {SMB_VFS_OP(streams_xattr_streaminfo), SMB_VFS_OP_STREAMINFO,
- SMB_VFS_LAYER_OPAQUE},
- {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
+static int streams_xattr_fallocate(struct vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ enum vfs_fallocate_mode mode,
+ SMB_OFF_T offset,
+ SMB_OFF_T len)
+{
+ struct stream_io *sio =
+ (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
+
+ DEBUG(10, ("streams_xattr_fallocate called for file %s offset %.0f"
+ "len = %.0f\n",
+ fsp_str_dbg(fsp), (double)offset, (double)len));
+
+ if (sio == NULL) {
+ return SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
+ }
+
+ if (!streams_xattr_recheck(sio)) {
+ return errno;
+ }
+
+ /* Let the pwrite code path handle it. */
+ return ENOSYS;
+}
+
+
+static struct vfs_fn_pointers vfs_streams_xattr_fns = {
+ .fs_capabilities = streams_xattr_fs_capabilities,
+ .open_fn = streams_xattr_open,
+ .stat = streams_xattr_stat,
+ .fstat = streams_xattr_fstat,
+ .lstat = streams_xattr_lstat,
+ .pread = streams_xattr_pread,
+ .pwrite = streams_xattr_pwrite,
+ .unlink = streams_xattr_unlink,
+ .rename = streams_xattr_rename,
+ .ftruncate = streams_xattr_ftruncate,
+ .fallocate = streams_xattr_fallocate,
+ .streaminfo = streams_xattr_streaminfo,
};
NTSTATUS vfs_streams_xattr_init(void);
NTSTATUS vfs_streams_xattr_init(void)
{
return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "streams_xattr",
- streams_xattr_ops);
+ &vfs_streams_xattr_fns);
}