DEBUG(10, ("file_is_valid (%s) called\n", path));
- if (SMB_VFS_NEXT_GETXATTR(handle, path, SAMBA_XATTR_MARKER,
+ if (SMB_VFS_GETXATTR(handle->conn, path, SAMBA_XATTR_MARKER,
&buf, sizeof(buf)) != sizeof(buf)) {
DEBUG(10, ("GETXATTR failed: %s\n", strerror(errno)));
return false;
DEBUG(10, ("marking file %s as valid\n", path));
- ret = SMB_VFS_NEXT_SETXATTR(handle, path, SAMBA_XATTR_MARKER,
+ ret = SMB_VFS_SETXATTR(handle->conn, path, SAMBA_XATTR_MARKER,
&buf, sizeof(buf), 0);
if (ret == -1) {
return true;
}
-static char *stream_dir(vfs_handle_struct *handle, const char *base_path,
+/**
+ * Given an smb_filename, determine the stream directory using the file's
+ * base_name.
+ */
+static char *stream_dir(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
const SMB_STRUCT_STAT *base_sbuf, bool create_it)
{
uint32_t hash;
+ struct smb_filename *smb_fname_hash = NULL;
char *result = NULL;
- SMB_STRUCT_STAT sbuf;
+ SMB_STRUCT_STAT base_sbuf_tmp;
uint8_t first, second;
char *tmp;
char *id_hex;
uint8 id_buf[16];
bool check_valid;
const char *rootdir;
+ NTSTATUS status;
check_valid = lp_parm_bool(SNUM(handle->conn),
"streams_depot", "check_valid", true);
SNUM(handle->conn), "streams_depot", "directory",
tmp);
+ /* Stat the base file if it hasn't already been done. */
if (base_sbuf == NULL) {
- if (SMB_VFS_NEXT_STAT(handle, base_path, &sbuf) == -1) {
- /*
- * base file is not there
- */
+ struct smb_filename *smb_fname_base = NULL;
+
+ status = create_synthetic_smb_fname(talloc_tos(),
+ smb_fname->base_name,
+ NULL, NULL,
+ &smb_fname_base);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
goto fail;
}
- base_sbuf = &sbuf;
+ if (SMB_VFS_NEXT_STAT(handle, smb_fname_base) == -1) {
+ TALLOC_FREE(smb_fname_base);
+ goto fail;
+ }
+ base_sbuf_tmp = smb_fname_base->st;
+ TALLOC_FREE(smb_fname_base);
+ } else {
+ base_sbuf_tmp = *base_sbuf;
}
- id = SMB_VFS_FILE_ID_CREATE(handle->conn, base_sbuf);
+ id = SMB_VFS_FILE_ID_CREATE(handle->conn, &base_sbuf_tmp);
push_file_id_16((char *)id_buf, &id);
return NULL;
}
- if (SMB_VFS_NEXT_STAT(handle, result, &sbuf) == 0) {
+ status = create_synthetic_smb_fname(talloc_tos(), result, NULL, NULL,
+ &smb_fname_hash);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto fail;
+ }
+
+ if (SMB_VFS_NEXT_STAT(handle, smb_fname_hash) == 0) {
char *newname;
- if (!S_ISDIR(sbuf.st_mode)) {
+ if (!S_ISDIR(smb_fname_hash->st.st_ex_mode)) {
errno = EINVAL;
goto fail;
}
- if (file_is_valid(handle, base_path, check_valid)) {
+ if (file_is_valid(handle, smb_fname->base_name, check_valid)) {
return result;
}
goto fail;
}
- if (!mark_file_valid(handle, base_path, check_valid)) {
+ if (!mark_file_valid(handle, smb_fname->base_name, check_valid)) {
goto fail;
}
+ TALLOC_FREE(smb_fname_hash);
return result;
fail:
+ TALLOC_FREE(smb_fname_hash);
TALLOC_FREE(result);
return NULL;
}
-
-static char *stream_name(vfs_handle_struct *handle, const char *fname,
- bool create_dir)
+/**
+ * Given a stream name, populate smb_fname_out with the actual location of the
+ * stream.
+ */
+static NTSTATUS stream_smb_fname(vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ struct smb_filename **smb_fname_out,
+ bool create_dir)
{
- char *base = NULL;
- char *sname = NULL;
- char *id_hex = NULL;
char *dirname, *stream_fname;
+ const char *stype;
+ NTSTATUS status;
- if (!NT_STATUS_IS_OK(split_ntfs_stream_name(talloc_tos(), fname,
- &base, &sname))) {
- DEBUG(10, ("split_ntfs_stream_name failed\n"));
- errno = ENOMEM;
- goto fail;
- }
-
- /* if it's the ::$DATA stream just return the base file name */
- if (!sname) {
- return base;
- }
+ *smb_fname_out = NULL;
- dirname = stream_dir(handle, base, NULL, create_dir);
+ dirname = stream_dir(handle, smb_fname, NULL, create_dir);
if (dirname == NULL) {
+ status = map_nt_error_from_unix(errno);
goto fail;
}
- stream_fname = talloc_asprintf(talloc_tos(), "%s/:%s", dirname, sname);
+ stype = strchr_m(smb_fname->stream_name + 1, ':');
+
+ stream_fname = talloc_asprintf(talloc_tos(), "%s/%s", dirname,
+ smb_fname->stream_name);
if (stream_fname == NULL) {
- errno = ENOMEM;
+ status = NT_STATUS_NO_MEMORY;
goto fail;
}
+ if (stype == NULL) {
+ /* Append an explicit stream type if one wasn't specified. */
+ stream_fname = talloc_asprintf(talloc_tos(), "%s:$DATA",
+ stream_fname);
+ if (stream_fname == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto fail;
+ }
+ } else {
+ /* Normalize the stream type to upercase. */
+ strupper_m(strrchr_m(stream_fname, ':') + 1);
+ }
+
DEBUG(10, ("stream filename = %s\n", stream_fname));
- TALLOC_FREE(base);
- TALLOC_FREE(sname);
- TALLOC_FREE(id_hex);
+ /* Create an smb_filename with stream_name == NULL. */
+ status = create_synthetic_smb_fname(talloc_tos(), stream_fname, NULL,
+ NULL, smb_fname_out);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
- return stream_fname;
+ return NT_STATUS_OK;
fail:
DEBUG(5, ("stream_name failed: %s\n", strerror(errno)));
- TALLOC_FREE(base);
- TALLOC_FREE(sname);
- TALLOC_FREE(id_hex);
- return NULL;
+ TALLOC_FREE(*smb_fname_out);
+ return status;
+}
+
+/*
+ * XXX: This function should be removed after the other vfs ops take
+ * smb_filename structs
+ */
+static char *stream_name(vfs_handle_struct *handle, const char *fname,
+ bool create_dir)
+{
+ struct smb_filename *smb_fname = NULL;
+ struct smb_filename *smb_fname_stream = NULL;
+ char *sname = NULL;
+ NTSTATUS status;
+
+ status = create_synthetic_smb_fname_split(talloc_tos(), fname,
+ NULL, &smb_fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto out;
+ }
+
+ status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
+ create_dir);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto out;
+ }
+
+ status = get_full_smb_filename(talloc_tos(), smb_fname_stream,
+ &sname);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ goto out;
+ }
+ out:
+ TALLOC_FREE(smb_fname);
+ TALLOC_FREE(smb_fname_stream);
+
+ return sname;
}
static NTSTATUS walk_streams(vfs_handle_struct *handle,
- const char *fname,
- const SMB_STRUCT_STAT *sbuf,
+ struct smb_filename *smb_fname_base,
char **pdirname,
bool (*fn)(const char *dirname,
const char *dirent,
SMB_STRUCT_DIR *dirhandle = NULL;
char *dirent;
- dirname = stream_dir(handle, fname, sbuf, false);
+ dirname = stream_dir(handle, smb_fname_base, &smb_fname_base->st,
+ false);
if (dirname == NULL) {
if (errno == ENOENT) {
return NT_STATUS_OK;
}
-static int streams_depot_stat(vfs_handle_struct *handle, const char *fname,
- SMB_STRUCT_STAT *sbuf)
+/**
+ * Helper to stat/lstat the base file of an smb_fname. This will actually
+ * fills in the stat struct in smb_filename.
+ */
+static int streams_depot_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_depot_stat(vfs_handle_struct *handle,
+ struct smb_filename *smb_fname)
{
- char *stream_fname;
+ struct smb_filename *smb_fname_stream = NULL;
+ NTSTATUS status;
int ret = -1;
- DEBUG(10, ("streams_depot_stat called for [%s]\n", fname));
+ DEBUG(10, ("streams_depot_stat called for [%s]\n",
+ smb_fname_str_dbg(smb_fname)));
- if (!is_ntfs_stream_name(fname)) {
- return SMB_VFS_NEXT_STAT(handle, fname, sbuf);
+ if (!is_ntfs_stream_smb_fname(smb_fname)) {
+ return SMB_VFS_NEXT_STAT(handle, smb_fname);
}
- stream_fname = stream_name(handle, fname, false);
- if (stream_fname == NULL) {
+ /* If the default stream is requested, just stat the base file. */
+ if (is_ntfs_default_stream_smb_fname(smb_fname)) {
+ return streams_depot_stat_base(handle, smb_fname, true);
+ }
+
+ /* Stat the actual stream now. */
+ status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
+ false);
+ if (!NT_STATUS_IS_OK(status)) {
+ ret = -1;
+ errno = map_errno_from_nt_status(status);
goto done;
}
- ret = SMB_VFS_NEXT_STAT(handle, stream_fname, sbuf);
+ ret = SMB_VFS_NEXT_STAT(handle, smb_fname_stream);
+ /* Update the original smb_fname with the stat info. */
+ smb_fname->st = smb_fname_stream->st;
done:
- TALLOC_FREE(stream_fname);
+ TALLOC_FREE(smb_fname_stream);
return ret;
}
-static int streams_depot_lstat(vfs_handle_struct *handle, const char *fname,
- SMB_STRUCT_STAT *sbuf)
+
+
+static int streams_depot_lstat(vfs_handle_struct *handle,
+ struct smb_filename *smb_fname)
{
- char *stream_fname;
+ struct smb_filename *smb_fname_stream = NULL;
+ NTSTATUS status;
int ret = -1;
- if (!is_ntfs_stream_name(fname)) {
- return SMB_VFS_NEXT_LSTAT(handle, fname, sbuf);
+ DEBUG(10, ("streams_depot_lstat called for [%s]\n",
+ smb_fname_str_dbg(smb_fname)));
+
+ if (!is_ntfs_stream_smb_fname(smb_fname)) {
+ return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
}
- stream_fname = stream_name(handle, fname, false);
- if (stream_fname == NULL) {
+ /* If the default stream is requested, just stat the base file. */
+ if (is_ntfs_default_stream_smb_fname(smb_fname)) {
+ return streams_depot_stat_base(handle, smb_fname, false);
+ }
+
+ /* Stat the actual stream now. */
+ status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
+ false);
+ if (!NT_STATUS_IS_OK(status)) {
+ ret = -1;
+ errno = map_errno_from_nt_status(status);
goto done;
}
- ret = SMB_VFS_NEXT_LSTAT(handle, stream_fname, sbuf);
+ ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_stream);
done:
- TALLOC_FREE(stream_fname);
+ TALLOC_FREE(smb_fname_stream);
return ret;
}
-static int streams_depot_open(vfs_handle_struct *handle, const char *fname,
+static int streams_depot_open(vfs_handle_struct *handle,
+ struct smb_filename *smb_fname,
files_struct *fsp, int flags, mode_t mode)
{
- TALLOC_CTX *frame;
- char *base = NULL;
- char *sname = NULL;
- SMB_STRUCT_STAT base_sbuf;
- char *stream_fname;
+ struct smb_filename *smb_fname_stream = NULL;
+ struct smb_filename *smb_fname_base = NULL;
+ NTSTATUS status;
int ret = -1;
- if (!is_ntfs_stream_name(fname)) {
- return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
+ if (!is_ntfs_stream_smb_fname(smb_fname)) {
+ ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+ return ret;
}
- frame = talloc_stackframe();
+ /* If the default stream is requested, just open the base file. */
+ if (is_ntfs_default_stream_smb_fname(smb_fname)) {
+ char *tmp_stream_name;
- if (!NT_STATUS_IS_OK(split_ntfs_stream_name(talloc_tos(), fname,
- &base, &sname))) {
- errno = ENOMEM;
- goto done;
+ tmp_stream_name = smb_fname->stream_name;
+ smb_fname->stream_name = NULL;
+ ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
+ smb_fname->stream_name = tmp_stream_name;
+
+ return ret;
}
- if (!sname) {
- ret = SMB_VFS_NEXT_OPEN(handle, base, fsp, flags, mode);
+ /* Ensure the base file still exists. */
+ status = create_synthetic_smb_fname(talloc_tos(),
+ smb_fname->base_name,
+ NULL, NULL,
+ &smb_fname_base);
+ if (!NT_STATUS_IS_OK(status)) {
+ ret = -1;
+ errno = map_errno_from_nt_status(status);
goto done;
}
- ret = SMB_VFS_NEXT_STAT(handle, base, &base_sbuf);
-
+ ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
if (ret == -1) {
goto done;
}
- TALLOC_FREE(base);
-
- stream_fname = stream_name(handle, fname, true);
- if (stream_fname == NULL) {
+ /* Determine the stream name, and then open it. */
+ status = stream_smb_fname(handle, smb_fname, &smb_fname_stream, true);
+ if (!NT_STATUS_IS_OK(status)) {
+ ret = -1;
+ errno = map_errno_from_nt_status(status);
goto done;
}
- ret = SMB_VFS_NEXT_OPEN(handle, stream_fname, fsp, flags, mode);
+ ret = SMB_VFS_NEXT_OPEN(handle, smb_fname_stream, fsp, flags, mode);
done:
- TALLOC_FREE(frame);
+ TALLOC_FREE(smb_fname_stream);
+ TALLOC_FREE(smb_fname_base);
return ret;
}
static int streams_depot_unlink(vfs_handle_struct *handle, const char *fname)
{
+ struct smb_filename *smb_fname_base = NULL;
+ NTSTATUS status;
int ret = -1;
- SMB_STRUCT_STAT sbuf;
DEBUG(10, ("streams_depot_unlink called for %s\n", fname));
* We potentially need to delete the per-inode streams directory
*/
+ status = create_synthetic_smb_fname(talloc_tos(), fname, NULL, NULL,
+ &smb_fname_base);
+ if (!NT_STATUS_IS_OK(status)) {
+ errno = map_errno_from_nt_status(status);
+ return -1;
+ }
+
if (lp_posix_pathnames()) {
- ret = SMB_VFS_NEXT_LSTAT(handle, fname, &sbuf);
+ ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
} else {
- ret = SMB_VFS_NEXT_STAT(handle, fname, &sbuf);
+ ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
}
if (ret == -1) {
+ TALLOC_FREE(smb_fname_base);
return -1;
}
- if (sbuf.st_nlink == 1) {
- char *dirname = stream_dir(handle, fname, &sbuf, false);
+ if (smb_fname_base->st.st_ex_nlink == 1) {
+ char *dirname = stream_dir(handle, smb_fname_base,
+ &smb_fname_base->st, false);
if (dirname != NULL) {
SMB_VFS_NEXT_RMDIR(handle, dirname);
TALLOC_FREE(dirname);
}
+ TALLOC_FREE(smb_fname_base);
+
return SMB_VFS_NEXT_UNLINK(handle, fname);
}
{
struct streaminfo_state *state =
(struct streaminfo_state *)private_data;
- char *full_sname;
- SMB_STRUCT_STAT sbuf;
+ struct smb_filename *smb_fname = NULL;
+ char *sname = NULL;
+ NTSTATUS status;
+ bool ret;
- if (asprintf(&full_sname, "%s/%s", dirname, dirent) == -1) {
+ sname = talloc_asprintf(talloc_tos(), "%s/%s", dirname, dirent);
+ if (sname == NULL) {
state->status = NT_STATUS_NO_MEMORY;
- return false;
+ ret = false;
+ goto out;
}
- if (SMB_VFS_NEXT_STAT(state->handle, full_sname, &sbuf) == -1) {
- DEBUG(10, ("Could not stat %s: %s\n", full_sname,
- strerror(errno)));
- SAFE_FREE(full_sname);
- return true;
+
+ status = create_synthetic_smb_fname(talloc_tos(), sname, NULL,
+ NULL, &smb_fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ state->status = status;
+ ret = false;
+ goto out;
}
- SAFE_FREE(full_sname);
+ if (SMB_VFS_NEXT_STAT(state->handle, smb_fname) == -1) {
+ DEBUG(10, ("Could not stat %s: %s\n", sname,
+ strerror(errno)));
+ ret = true;
+ goto out;
+ }
if (!add_one_stream(state->mem_ctx,
&state->num_streams, &state->streams,
- dirent, sbuf.st_size,
+ dirent, smb_fname->st.st_ex_size,
SMB_VFS_GET_ALLOC_SIZE(state->handle->conn, NULL,
- &sbuf))) {
+ &smb_fname->st))) {
state->status = NT_STATUS_NO_MEMORY;
- return false;
+ ret = false;
+ goto out;
}
- return true;
+ ret = true;
+ out:
+ TALLOC_FREE(sname);
+ TALLOC_FREE(smb_fname);
+ return ret;
}
static NTSTATUS streams_depot_streaminfo(vfs_handle_struct *handle,
unsigned int *pnum_streams,
struct stream_struct **pstreams)
{
- SMB_STRUCT_STAT sbuf;
+ struct smb_filename *smb_fname_base = NULL;
int ret;
NTSTATUS status;
struct streaminfo_state state;
+ status = create_synthetic_smb_fname(talloc_tos(), fname, NULL, NULL,
+ &smb_fname_base);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
if ((fsp != NULL) && (fsp->fh->fd != -1)) {
if (is_ntfs_stream_name(fsp->fsp_name)) {
return NT_STATUS_INVALID_PARAMETER;
}
- ret = SMB_VFS_NEXT_FSTAT(handle, fsp, &sbuf);
+ ret = SMB_VFS_NEXT_FSTAT(handle, fsp, &smb_fname_base->st);
}
else {
if (is_ntfs_stream_name(fname)) {
return NT_STATUS_INVALID_PARAMETER;
}
if (lp_posix_pathnames()) {
- ret = SMB_VFS_NEXT_LSTAT(handle, fname, &sbuf);
+ ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
} else {
- ret = SMB_VFS_NEXT_STAT(handle, fname, &sbuf);
+ ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
}
}
if (ret == -1) {
- return map_nt_error_from_unix(errno);
+ status = map_nt_error_from_unix(errno);
+ goto out;
}
state.streams = NULL;
state.num_streams = 0;
- if (!S_ISDIR(sbuf.st_mode)) {
+ if (!S_ISDIR(smb_fname_base->st.st_ex_mode)) {
if (!add_one_stream(mem_ctx,
&state.num_streams, &state.streams,
- "::$DATA", sbuf.st_size,
+ "::$DATA", smb_fname_base->st.st_ex_size,
SMB_VFS_GET_ALLOC_SIZE(handle->conn, fsp,
- &sbuf))) {
- return NT_STATUS_NO_MEMORY;
+ &smb_fname_base->st))) {
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
}
}
state.handle = handle;
state.status = NT_STATUS_OK;
- status = walk_streams(handle, fname, &sbuf, NULL, collect_one_stream,
+ status = walk_streams(handle, smb_fname_base, NULL, collect_one_stream,
&state);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(state.streams);
- return status;
+ goto out;
}
if (!NT_STATUS_IS_OK(state.status)) {
TALLOC_FREE(state.streams);
- return state.status;
+ status = state.status;
+ goto out;
}
*pnum_streams = state.num_streams;
*pstreams = state.streams;
- return NT_STATUS_OK;
+ status = NT_STATUS_OK;
+
+ out:
+ TALLOC_FREE(smb_fname_base);
+ return status;
}
static uint32_t streams_depot_fs_capabilities(struct vfs_handle_struct *handle)