2 * Store streams in a separate subdirectory
4 * Copyright (C) Volker Lendecke, 2007
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "smbd/smbd.h"
22 #include "system/filesys.h"
23 #include "source3/smbd/dir.h"
26 #define DBGC_CLASS DBGC_VFS
29 * Excerpt from a mail from tridge:
31 * Volker, what I'm thinking of is this:
32 * /mount-point/.streams/XX/YY/aaaa.bbbb/namedstream1
33 * /mount-point/.streams/XX/YY/aaaa.bbbb/namedstream2
35 * where XX/YY is a 2 level hash based on the fsid/inode. "aaaa.bbbb"
36 * is the fsid/inode. "namedstreamX" is a file named after the stream
40 static uint32_t hash_fn(DATA_BLOB key)
42 uint32_t value; /* Used to compute the hash value. */
43 uint32_t i; /* Used to cycle through random values. */
45 /* Set the initial value from the key size. */
46 for (value = 0x238F13AF * key.length, i=0; i < key.length; i++)
47 value = (value + (key.data[i] << (i*5 % 24)));
49 return (1103515243 * value + 12345);
53 * With the hashing scheme based on the inode we need to protect against
54 * streams showing up on files with re-used inodes. This can happen if we
55 * create a stream directory from within Samba, and a local process or NFS
56 * client deletes the file without deleting the streams directory. When the
57 * inode is re-used and the stream directory is still around, the streams in
58 * there would be show up as belonging to the new file.
60 * There are several workarounds for this, probably the easiest one is on
61 * systems which have a true birthtime stat element: When the file has a later
62 * birthtime than the streams directory, then we have to recreate the
65 * The other workaround is to somehow mark the file as generated by Samba with
66 * something that a NFS client would not do. The closest one is a special
67 * xattr value being set. On systems which do not support xattrs, it might be
68 * an option to put in a special ACL entry for a non-existing group.
71 static bool file_is_valid(vfs_handle_struct *handle,
72 const struct smb_filename *smb_fname)
76 struct smb_filename *pathref = NULL;
79 DEBUG(10, ("file_is_valid (%s) called\n", smb_fname->base_name));
81 status = synthetic_pathref(talloc_tos(),
82 handle->conn->cwd_fsp,
89 if (!NT_STATUS_IS_OK(status)) {
92 ret = SMB_VFS_FGETXATTR(pathref->fsp,
96 if (ret != sizeof(buf)) {
97 int saved_errno = errno;
98 DBG_DEBUG("FGETXATTR failed: %s\n", strerror(saved_errno));
104 TALLOC_FREE(pathref);
107 DEBUG(10, ("got wrong buffer content: '%c'\n", buf));
115 * Return the root of the stream directory. Can be
116 * external to the share definition but by default
117 * is "handle->conn->connectpath/.streams".
119 * Note that this is an *absolute* path, starting
120 * with '/', so the dirfsp being used in the
121 * calls below isn't looked at.
124 static char *stream_rootdir(vfs_handle_struct *handle,
127 const struct loadparm_substitution *lp_sub =
128 loadparm_s3_global_substitution();
131 tmp = talloc_asprintf(ctx,
133 handle->conn->connectpath);
139 return lp_parm_substituted_string(ctx,
148 * Given an smb_filename, determine the stream directory using the file's
151 static char *stream_dir(vfs_handle_struct *handle,
152 const struct smb_filename *smb_fname,
153 const SMB_STRUCT_STAT *base_sbuf, bool create_it)
156 struct smb_filename *smb_fname_hash = NULL;
158 SMB_STRUCT_STAT base_sbuf_tmp;
160 uint8_t first, second;
165 char *rootdir = NULL;
166 struct smb_filename *rootdir_fname = NULL;
167 struct smb_filename *tmp_fname = NULL;
170 check_valid = lp_parm_bool(SNUM(handle->conn),
171 "streams_depot", "check_valid", true);
173 rootdir = stream_rootdir(handle,
175 if (rootdir == NULL) {
180 rootdir_fname = synthetic_smb_fname(talloc_tos(),
186 if (rootdir_fname == NULL) {
191 /* Stat the base file if it hasn't already been done. */
192 if (base_sbuf == NULL) {
193 struct smb_filename *smb_fname_base;
195 smb_fname_base = synthetic_smb_fname(
197 smb_fname->base_name,
202 if (smb_fname_base == NULL) {
206 if (SMB_VFS_NEXT_STAT(handle, smb_fname_base) == -1) {
207 TALLOC_FREE(smb_fname_base);
210 base_sbuf_tmp = smb_fname_base->st;
211 TALLOC_FREE(smb_fname_base);
213 base_sbuf_tmp = *base_sbuf;
216 id = SMB_VFS_FILE_ID_CREATE(handle->conn, &base_sbuf_tmp);
218 push_file_id_16((char *)id_buf, &id);
220 hash = hash_fn(data_blob_const(id_buf, sizeof(id_buf)));
223 second = (hash >> 8) & 0xff;
225 id_hex = hex_encode_talloc(talloc_tos(), id_buf, sizeof(id_buf));
227 if (id_hex == NULL) {
232 result = talloc_asprintf(talloc_tos(), "%s/%2.2X/%2.2X/%s", rootdir,
233 first, second, id_hex);
237 if (result == NULL) {
242 smb_fname_hash = synthetic_smb_fname(talloc_tos(),
248 if (smb_fname_hash == NULL) {
253 if (SMB_VFS_NEXT_STAT(handle, smb_fname_hash) == 0) {
254 struct smb_filename *smb_fname_new = NULL;
258 if (!S_ISDIR(smb_fname_hash->st.st_ex_mode)) {
264 file_is_valid(handle, smb_fname)) {
269 * Someone has recreated a file under an existing inode
270 * without deleting the streams directory.
271 * Move it away or remove if streams_depot:delete_lost is set.
275 delete_lost = lp_parm_bool(SNUM(handle->conn), "streams_depot",
276 "delete_lost", false);
279 DEBUG(3, ("Someone has recreated a file under an "
280 "existing inode. Removing: %s\n",
281 smb_fname_hash->base_name));
282 recursive_rmdir(talloc_tos(), handle->conn,
284 SMB_VFS_NEXT_UNLINKAT(handle,
285 handle->conn->cwd_fsp,
289 newname = talloc_asprintf(talloc_tos(), "lost-%lu",
291 DEBUG(3, ("Someone has recreated a file under an "
292 "existing inode. Renaming: %s to: %s\n",
293 smb_fname_hash->base_name,
295 if (newname == NULL) {
300 smb_fname_new = synthetic_smb_fname(
307 TALLOC_FREE(newname);
308 if (smb_fname_new == NULL) {
313 if (SMB_VFS_NEXT_RENAMEAT(handle,
314 handle->conn->cwd_fsp,
316 handle->conn->cwd_fsp,
317 smb_fname_new) == -1) {
318 TALLOC_FREE(smb_fname_new);
319 if ((errno == EEXIST) || (errno == ENOTEMPTY)) {
325 TALLOC_FREE(smb_fname_new);
334 ret = SMB_VFS_NEXT_MKDIRAT(handle,
335 handle->conn->cwd_fsp,
338 if ((ret != 0) && (errno != EEXIST)) {
342 tmp = talloc_asprintf(result, "%s/%2.2X", rootdir, first);
348 tmp_fname = synthetic_smb_fname(talloc_tos(),
354 if (tmp_fname == NULL) {
359 ret = SMB_VFS_NEXT_MKDIRAT(handle,
360 handle->conn->cwd_fsp,
363 if ((ret != 0) && (errno != EEXIST)) {
368 TALLOC_FREE(tmp_fname);
370 tmp = talloc_asprintf(result, "%s/%2.2X/%2.2X", rootdir, first,
377 tmp_fname = synthetic_smb_fname(talloc_tos(),
383 if (tmp_fname == NULL) {
388 ret = SMB_VFS_NEXT_MKDIRAT(handle,
389 handle->conn->cwd_fsp,
392 if ((ret != 0) && (errno != EEXIST)) {
397 TALLOC_FREE(tmp_fname);
399 /* smb_fname_hash is the struct smb_filename version of 'result' */
400 ret = SMB_VFS_NEXT_MKDIRAT(handle,
401 handle->conn->cwd_fsp,
404 if ((ret != 0) && (errno != EEXIST)) {
408 TALLOC_FREE(rootdir_fname);
409 TALLOC_FREE(rootdir);
410 TALLOC_FREE(tmp_fname);
411 TALLOC_FREE(smb_fname_hash);
415 TALLOC_FREE(rootdir_fname);
416 TALLOC_FREE(rootdir);
417 TALLOC_FREE(tmp_fname);
418 TALLOC_FREE(smb_fname_hash);
423 * Given a stream name, populate smb_fname_out with the actual location of the
426 static NTSTATUS stream_smb_fname(vfs_handle_struct *handle,
427 const struct stat_ex *base_sbuf,
428 const struct smb_filename *smb_fname,
429 struct smb_filename **smb_fname_out,
432 char *dirname, *stream_fname;
436 *smb_fname_out = NULL;
438 stype = strchr_m(smb_fname->stream_name + 1, ':');
441 if (strcasecmp_m(stype, ":$DATA") != 0) {
442 return NT_STATUS_INVALID_PARAMETER;
446 dirname = stream_dir(handle, smb_fname, base_sbuf, create_dir);
448 if (dirname == NULL) {
449 status = map_nt_error_from_unix(errno);
453 stream_fname = talloc_asprintf(talloc_tos(), "%s/%s", dirname,
454 smb_fname->stream_name);
456 if (stream_fname == NULL) {
457 status = NT_STATUS_NO_MEMORY;
462 /* Append an explicit stream type if one wasn't specified. */
463 stream_fname = talloc_asprintf(talloc_tos(), "%s:$DATA",
465 if (stream_fname == NULL) {
466 status = NT_STATUS_NO_MEMORY;
470 /* Normalize the stream type to uppercase. */
471 if (!strupper_m(strrchr_m(stream_fname, ':') + 1)) {
472 status = NT_STATUS_INVALID_PARAMETER;
477 DEBUG(10, ("stream filename = %s\n", stream_fname));
479 /* Create an smb_filename with stream_name == NULL. */
480 *smb_fname_out = synthetic_smb_fname(talloc_tos(),
486 if (*smb_fname_out == NULL) {
487 return NT_STATUS_NO_MEMORY;
493 DEBUG(5, ("stream_name failed: %s\n", strerror(errno)));
494 TALLOC_FREE(*smb_fname_out);
498 static NTSTATUS walk_streams(vfs_handle_struct *handle,
499 struct smb_filename *smb_fname_base,
501 bool (*fn)(const struct smb_filename *dirname,
507 char *rootdir = NULL;
508 char *orig_connectpath = NULL;
509 struct smb_filename *dir_smb_fname = NULL;
510 struct smb_Dir *dir_hnd = NULL;
511 const char *dname = NULL;
512 char *talloced = NULL;
515 dirname = stream_dir(handle, smb_fname_base, &smb_fname_base->st,
518 if (dirname == NULL) {
519 if (errno == ENOENT) {
525 return map_nt_error_from_unix(errno);
528 DEBUG(10, ("walk_streams: dirname=%s\n", dirname));
530 dir_smb_fname = synthetic_smb_fname(talloc_tos(),
534 smb_fname_base->twrp,
535 smb_fname_base->flags);
536 if (dir_smb_fname == NULL) {
537 TALLOC_FREE(dirname);
538 return NT_STATUS_NO_MEMORY;
542 * For OpenDir to succeed if the stream rootdir is outside
543 * the share path, we must temporarily swap out the connect
544 * path for this share. We're dealing with absolute paths
545 * here so we don't care about chdir calls.
547 rootdir = stream_rootdir(handle, talloc_tos());
548 if (rootdir == NULL) {
549 TALLOC_FREE(dir_smb_fname);
550 TALLOC_FREE(dirname);
551 return NT_STATUS_NO_MEMORY;
554 orig_connectpath = handle->conn->connectpath;
555 handle->conn->connectpath = rootdir;
558 talloc_tos(), handle->conn, dir_smb_fname, NULL, 0, &dir_hnd);
559 if (!NT_STATUS_IS_OK(status)) {
560 handle->conn->connectpath = orig_connectpath;
561 TALLOC_FREE(rootdir);
562 TALLOC_FREE(dir_smb_fname);
563 TALLOC_FREE(dirname);
567 while ((dname = ReadDirName(dir_hnd, &talloced)) != NULL) {
568 if (ISDOT(dname) || ISDOTDOT(dname)) {
569 TALLOC_FREE(talloced);
573 DBG_DEBUG("dirent=%s\n", dname);
575 if (!fn(dir_smb_fname, dname, private_data)) {
576 TALLOC_FREE(talloced);
579 TALLOC_FREE(talloced);
582 /* Restore the original connectpath. */
583 handle->conn->connectpath = orig_connectpath;
584 TALLOC_FREE(rootdir);
585 TALLOC_FREE(dir_smb_fname);
586 TALLOC_FREE(dir_hnd);
588 if (pdirname != NULL) {
592 TALLOC_FREE(dirname);
598 static int streams_depot_stat(vfs_handle_struct *handle,
599 struct smb_filename *smb_fname)
601 struct smb_filename *smb_fname_stream = NULL;
605 DEBUG(10, ("streams_depot_stat called for [%s]\n",
606 smb_fname_str_dbg(smb_fname)));
608 if (!is_named_stream(smb_fname)) {
609 return SMB_VFS_NEXT_STAT(handle, smb_fname);
612 /* Stat the actual stream now. */
613 status = stream_smb_fname(
614 handle, NULL, smb_fname, &smb_fname_stream, false);
615 if (!NT_STATUS_IS_OK(status)) {
617 errno = map_errno_from_nt_status(status);
621 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_stream);
623 /* Update the original smb_fname with the stat info. */
624 smb_fname->st = smb_fname_stream->st;
626 TALLOC_FREE(smb_fname_stream);
632 static int streams_depot_lstat(vfs_handle_struct *handle,
633 struct smb_filename *smb_fname)
635 struct smb_filename *smb_fname_stream = NULL;
639 DEBUG(10, ("streams_depot_lstat called for [%s]\n",
640 smb_fname_str_dbg(smb_fname)));
642 if (!is_named_stream(smb_fname)) {
643 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
646 /* Stat the actual stream now. */
647 status = stream_smb_fname(
648 handle, NULL, smb_fname, &smb_fname_stream, false);
649 if (!NT_STATUS_IS_OK(status)) {
651 errno = map_errno_from_nt_status(status);
655 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_stream);
658 TALLOC_FREE(smb_fname_stream);
662 static int streams_depot_openat(struct vfs_handle_struct *handle,
663 const struct files_struct *dirfsp,
664 const struct smb_filename *smb_fname,
665 struct files_struct *fsp,
666 const struct vfs_open_how *how)
668 struct smb_filename *smb_fname_stream = NULL;
669 struct files_struct *fspcwd = NULL;
674 if (!is_named_stream(smb_fname)) {
675 return SMB_VFS_NEXT_OPENAT(handle,
682 if (how->resolve != 0) {
687 SMB_ASSERT(fsp_is_alternate_stream(fsp));
688 SMB_ASSERT(dirfsp == NULL);
689 SMB_ASSERT(VALID_STAT(fsp->base_fsp->fsp_name->st));
691 create_it = (how->flags & O_CREAT);
693 /* Determine the stream name, and then open it. */
694 status = stream_smb_fname(
696 &fsp->base_fsp->fsp_name->st,
700 if (!NT_STATUS_IS_OK(status)) {
702 errno = map_errno_from_nt_status(status);
707 bool check_valid = lp_parm_bool(
716 DBG_DEBUG("marking file %s as valid\n",
717 fsp->base_fsp->fsp_name->base_name);
719 ret = SMB_VFS_FSETXATTR(
727 DBG_DEBUG("FSETXATTR failed: %s\n",
734 status = vfs_at_fspcwd(talloc_tos(), handle->conn, &fspcwd);
735 if (!NT_STATUS_IS_OK(status)) {
737 errno = map_errno_from_nt_status(status);
741 ret = SMB_VFS_NEXT_OPENAT(handle,
748 TALLOC_FREE(smb_fname_stream);
753 static int streams_depot_unlink_internal(vfs_handle_struct *handle,
754 struct files_struct *dirfsp,
755 const struct smb_filename *smb_fname,
758 struct smb_filename *full_fname = NULL;
759 char *dirname = NULL;
762 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
765 if (full_fname == NULL) {
769 DEBUG(10, ("streams_depot_unlink called for %s\n",
770 smb_fname_str_dbg(full_fname)));
772 /* If there is a valid stream, just unlink the stream and return. */
773 if (is_named_stream(full_fname)) {
774 struct smb_filename *smb_fname_stream = NULL;
777 status = stream_smb_fname(
778 handle, NULL, full_fname, &smb_fname_stream, false);
779 TALLOC_FREE(full_fname);
780 if (!NT_STATUS_IS_OK(status)) {
781 errno = map_errno_from_nt_status(status);
785 ret = SMB_VFS_NEXT_UNLINKAT(handle,
786 dirfsp->conn->cwd_fsp,
790 TALLOC_FREE(smb_fname_stream);
795 * We potentially need to delete the per-inode streams directory
798 if (full_fname->flags & SMB_FILENAME_POSIX_PATH) {
799 ret = SMB_VFS_NEXT_LSTAT(handle, full_fname);
801 ret = SMB_VFS_NEXT_STAT(handle, full_fname);
802 if (ret == -1 && (errno == ENOENT || errno == ELOOP)) {
803 if (VALID_STAT(smb_fname->st) &&
804 S_ISLNK(smb_fname->st.st_ex_mode)) {
806 * Original name was a link - Could be
807 * trying to remove a dangling symlink.
809 ret = SMB_VFS_NEXT_LSTAT(handle, full_fname);
814 TALLOC_FREE(full_fname);
819 * We know the unlink should succeed as the ACL
820 * check is already done in the caller. Remove the
821 * file *after* the streams.
823 dirname = stream_dir(handle,
827 TALLOC_FREE(full_fname);
828 if (dirname != NULL) {
829 struct smb_filename *smb_fname_dir = NULL;
831 smb_fname_dir = synthetic_smb_fname(talloc_tos(),
837 if (smb_fname_dir == NULL) {
838 TALLOC_FREE(dirname);
843 SMB_VFS_NEXT_UNLINKAT(handle,
844 dirfsp->conn->cwd_fsp,
847 TALLOC_FREE(smb_fname_dir);
848 TALLOC_FREE(dirname);
851 ret = SMB_VFS_NEXT_UNLINKAT(handle,
858 static int streams_depot_rmdir_internal(vfs_handle_struct *handle,
859 struct files_struct *dirfsp,
860 const struct smb_filename *smb_fname)
862 struct smb_filename *full_fname = NULL;
863 struct smb_filename *smb_fname_base = NULL;
866 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
869 if (full_fname == NULL) {
873 DBG_DEBUG("called for %s\n", full_fname->base_name);
876 * We potentially need to delete the per-inode streams directory
879 smb_fname_base = synthetic_smb_fname(talloc_tos(),
880 full_fname->base_name,
885 TALLOC_FREE(full_fname);
886 if (smb_fname_base == NULL) {
891 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
892 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
894 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
898 TALLOC_FREE(smb_fname_base);
903 * We know the rmdir should succeed as the ACL
904 * check is already done in the caller. Remove the
905 * directory *after* the streams.
908 char *dirname = stream_dir(handle, smb_fname_base,
909 &smb_fname_base->st, false);
911 if (dirname != NULL) {
912 struct smb_filename *smb_fname_dir =
913 synthetic_smb_fname(talloc_tos(),
919 if (smb_fname_dir == NULL) {
920 TALLOC_FREE(smb_fname_base);
921 TALLOC_FREE(dirname);
925 SMB_VFS_NEXT_UNLINKAT(handle,
926 dirfsp->conn->cwd_fsp,
929 TALLOC_FREE(smb_fname_dir);
931 TALLOC_FREE(dirname);
934 ret = SMB_VFS_NEXT_UNLINKAT(handle,
938 TALLOC_FREE(smb_fname_base);
942 static int streams_depot_unlinkat(vfs_handle_struct *handle,
943 struct files_struct *dirfsp,
944 const struct smb_filename *smb_fname,
948 if (flags & AT_REMOVEDIR) {
949 ret = streams_depot_rmdir_internal(handle,
953 ret = streams_depot_unlink_internal(handle,
961 static int streams_depot_renameat(vfs_handle_struct *handle,
962 files_struct *srcfsp,
963 const struct smb_filename *smb_fname_src,
964 files_struct *dstfsp,
965 const struct smb_filename *smb_fname_dst)
967 struct smb_filename *smb_fname_src_stream = NULL;
968 struct smb_filename *smb_fname_dst_stream = NULL;
969 struct smb_filename *full_src = NULL;
970 struct smb_filename *full_dst = NULL;
971 bool src_is_stream, dst_is_stream;
975 DEBUG(10, ("streams_depot_renameat called for %s => %s\n",
976 smb_fname_str_dbg(smb_fname_src),
977 smb_fname_str_dbg(smb_fname_dst)));
979 src_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
980 dst_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
982 if (!src_is_stream && !dst_is_stream) {
983 return SMB_VFS_NEXT_RENAMEAT(handle,
990 /* for now don't allow renames from or to the default stream */
991 if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
992 is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
997 full_src = full_path_from_dirfsp_atname(talloc_tos(),
1000 if (full_src == NULL) {
1005 full_dst = full_path_from_dirfsp_atname(talloc_tos(),
1008 if (full_dst == NULL) {
1013 status = stream_smb_fname(
1014 handle, NULL, full_src, &smb_fname_src_stream, false);
1015 if (!NT_STATUS_IS_OK(status)) {
1016 errno = map_errno_from_nt_status(status);
1020 status = stream_smb_fname(
1021 handle, NULL, full_dst, &smb_fname_dst_stream, false);
1022 if (!NT_STATUS_IS_OK(status)) {
1023 errno = map_errno_from_nt_status(status);
1028 * We must use handle->conn->cwd_fsp as
1029 * srcfsp and dstfsp directory handles here
1030 * as we used the full pathname from the cwd dir
1031 * to calculate the streams directory and filename
1034 ret = SMB_VFS_NEXT_RENAMEAT(handle,
1035 handle->conn->cwd_fsp,
1036 smb_fname_src_stream,
1037 handle->conn->cwd_fsp,
1038 smb_fname_dst_stream);
1041 TALLOC_FREE(smb_fname_src_stream);
1042 TALLOC_FREE(smb_fname_dst_stream);
1046 static bool add_one_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
1047 struct stream_struct **streams,
1048 const char *name, off_t size,
1051 struct stream_struct *tmp;
1053 tmp = talloc_realloc(mem_ctx, *streams, struct stream_struct,
1059 tmp[*num_streams].name = talloc_strdup(tmp, name);
1060 if (tmp[*num_streams].name == NULL) {
1064 tmp[*num_streams].size = size;
1065 tmp[*num_streams].alloc_size = alloc_size;
1072 struct streaminfo_state {
1073 TALLOC_CTX *mem_ctx;
1074 vfs_handle_struct *handle;
1075 unsigned int num_streams;
1076 struct stream_struct *streams;
1080 static bool collect_one_stream(const struct smb_filename *dirfname,
1084 const char *dirname = dirfname->base_name;
1085 struct streaminfo_state *state =
1086 (struct streaminfo_state *)private_data;
1087 struct smb_filename *smb_fname = NULL;
1091 sname = talloc_asprintf(talloc_tos(), "%s/%s", dirname, dirent);
1092 if (sname == NULL) {
1093 state->status = NT_STATUS_NO_MEMORY;
1098 smb_fname = synthetic_smb_fname(talloc_tos(),
1104 if (smb_fname == NULL) {
1105 state->status = NT_STATUS_NO_MEMORY;
1110 if (SMB_VFS_NEXT_STAT(state->handle, smb_fname) == -1) {
1111 DEBUG(10, ("Could not stat %s: %s\n", sname,
1117 if (!add_one_stream(state->mem_ctx,
1118 &state->num_streams, &state->streams,
1119 dirent, smb_fname->st.st_ex_size,
1120 SMB_VFS_GET_ALLOC_SIZE(state->handle->conn, NULL,
1122 state->status = NT_STATUS_NO_MEMORY;
1130 TALLOC_FREE(smb_fname);
1134 static NTSTATUS streams_depot_fstreaminfo(vfs_handle_struct *handle,
1135 struct files_struct *fsp,
1136 TALLOC_CTX *mem_ctx,
1137 unsigned int *pnum_streams,
1138 struct stream_struct **pstreams)
1140 struct smb_filename *smb_fname_base = NULL;
1143 struct streaminfo_state state;
1145 smb_fname_base = synthetic_smb_fname(talloc_tos(),
1146 fsp->fsp_name->base_name,
1149 fsp->fsp_name->twrp,
1150 fsp->fsp_name->flags);
1151 if (smb_fname_base == NULL) {
1152 return NT_STATUS_NO_MEMORY;
1155 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, &smb_fname_base->st);
1157 status = map_nt_error_from_unix(errno);
1161 state.streams = *pstreams;
1162 state.num_streams = *pnum_streams;
1163 state.mem_ctx = mem_ctx;
1164 state.handle = handle;
1165 state.status = NT_STATUS_OK;
1167 status = walk_streams(handle,
1173 if (!NT_STATUS_IS_OK(status)) {
1174 TALLOC_FREE(state.streams);
1178 if (!NT_STATUS_IS_OK(state.status)) {
1179 TALLOC_FREE(state.streams);
1180 status = state.status;
1184 *pnum_streams = state.num_streams;
1185 *pstreams = state.streams;
1186 status = SMB_VFS_NEXT_FSTREAMINFO(handle,
1187 fsp->base_fsp ? fsp->base_fsp : fsp,
1193 TALLOC_FREE(smb_fname_base);
1197 static uint32_t streams_depot_fs_capabilities(struct vfs_handle_struct *handle,
1198 enum timestamp_set_resolution *p_ts_res)
1200 return SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res) | FILE_NAMED_STREAMS;
1203 static struct vfs_fn_pointers vfs_streams_depot_fns = {
1204 .fs_capabilities_fn = streams_depot_fs_capabilities,
1205 .openat_fn = streams_depot_openat,
1206 .stat_fn = streams_depot_stat,
1207 .lstat_fn = streams_depot_lstat,
1208 .unlinkat_fn = streams_depot_unlinkat,
1209 .renameat_fn = streams_depot_renameat,
1210 .fstreaminfo_fn = streams_depot_fstreaminfo,
1214 NTSTATUS vfs_streams_depot_init(TALLOC_CTX *ctx)
1216 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "streams_depot",
1217 &vfs_streams_depot_fns);