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"
25 #define DBGC_CLASS DBGC_VFS
28 * Excerpt from a mail from tridge:
30 * Volker, what I'm thinking of is this:
31 * /mount-point/.streams/XX/YY/aaaa.bbbb/namedstream1
32 * /mount-point/.streams/XX/YY/aaaa.bbbb/namedstream2
34 * where XX/YY is a 2 level hash based on the fsid/inode. "aaaa.bbbb"
35 * is the fsid/inode. "namedstreamX" is a file named after the stream
39 static uint32_t hash_fn(DATA_BLOB key)
41 uint32_t value; /* Used to compute the hash value. */
42 uint32_t i; /* Used to cycle through random values. */
44 /* Set the initial value from the key size. */
45 for (value = 0x238F13AF * key.length, i=0; i < key.length; i++)
46 value = (value + (key.data[i] << (i*5 % 24)));
48 return (1103515243 * value + 12345);
52 * With the hashing scheme based on the inode we need to protect against
53 * streams showing up on files with re-used inodes. This can happen if we
54 * create a stream directory from within Samba, and a local process or NFS
55 * client deletes the file without deleting the streams directory. When the
56 * inode is re-used and the stream directory is still around, the streams in
57 * there would be show up as belonging to the new file.
59 * There are several workarounds for this, probably the easiest one is on
60 * systems which have a true birthtime stat element: When the file has a later
61 * birthtime than the streams directory, then we have to recreate the
64 * The other workaround is to somehow mark the file as generated by Samba with
65 * something that a NFS client would not do. The closest one is a special
66 * xattr value being set. On systems which do not support xattrs, it might be
67 * an option to put in a special ACL entry for a non-existing group.
70 static bool file_is_valid(vfs_handle_struct *handle,
71 const struct smb_filename *smb_fname)
75 struct smb_filename *pathref = NULL;
78 DEBUG(10, ("file_is_valid (%s) called\n", smb_fname->base_name));
80 status = synthetic_pathref(talloc_tos(),
81 handle->conn->cwd_fsp,
88 if (!NT_STATUS_IS_OK(status)) {
91 ret = SMB_VFS_FGETXATTR(pathref->fsp,
95 if (ret != sizeof(buf)) {
96 int saved_errno = errno;
97 DBG_DEBUG("FGETXATTR failed: %s\n", strerror(saved_errno));
103 TALLOC_FREE(pathref);
106 DEBUG(10, ("got wrong buffer content: '%c'\n", buf));
114 * Return the root of the stream directory. Can be
115 * external to the share definition but by default
116 * is "handle->conn->connectpath/.streams".
118 * Note that this is an *absolute* path, starting
119 * with '/', so the dirfsp being used in the
120 * calls below isn't looked at.
123 static char *stream_rootdir(vfs_handle_struct *handle,
126 const struct loadparm_substitution *lp_sub =
127 loadparm_s3_global_substitution();
130 tmp = talloc_asprintf(ctx,
132 handle->conn->connectpath);
138 return lp_parm_substituted_string(ctx,
147 * Given an smb_filename, determine the stream directory using the file's
150 static char *stream_dir(vfs_handle_struct *handle,
151 const struct smb_filename *smb_fname,
152 const SMB_STRUCT_STAT *base_sbuf, bool create_it)
155 struct smb_filename *smb_fname_hash = NULL;
157 SMB_STRUCT_STAT base_sbuf_tmp;
159 uint8_t first, second;
164 char *rootdir = NULL;
165 struct smb_filename *rootdir_fname = NULL;
166 struct smb_filename *tmp_fname = NULL;
169 check_valid = lp_parm_bool(SNUM(handle->conn),
170 "streams_depot", "check_valid", true);
172 rootdir = stream_rootdir(handle,
174 if (rootdir == NULL) {
179 rootdir_fname = synthetic_smb_fname(talloc_tos(),
185 if (rootdir_fname == NULL) {
190 /* Stat the base file if it hasn't already been done. */
191 if (base_sbuf == NULL) {
192 struct smb_filename *smb_fname_base;
194 smb_fname_base = synthetic_smb_fname(
196 smb_fname->base_name,
201 if (smb_fname_base == NULL) {
205 if (SMB_VFS_NEXT_STAT(handle, smb_fname_base) == -1) {
206 TALLOC_FREE(smb_fname_base);
209 base_sbuf_tmp = smb_fname_base->st;
210 TALLOC_FREE(smb_fname_base);
212 base_sbuf_tmp = *base_sbuf;
215 id = SMB_VFS_FILE_ID_CREATE(handle->conn, &base_sbuf_tmp);
217 push_file_id_16((char *)id_buf, &id);
219 hash = hash_fn(data_blob_const(id_buf, sizeof(id_buf)));
222 second = (hash >> 8) & 0xff;
224 id_hex = hex_encode_talloc(talloc_tos(), id_buf, sizeof(id_buf));
226 if (id_hex == NULL) {
231 result = talloc_asprintf(talloc_tos(), "%s/%2.2X/%2.2X/%s", rootdir,
232 first, second, id_hex);
236 if (result == NULL) {
241 smb_fname_hash = synthetic_smb_fname(talloc_tos(),
247 if (smb_fname_hash == NULL) {
252 if (SMB_VFS_NEXT_STAT(handle, smb_fname_hash) == 0) {
253 struct smb_filename *smb_fname_new = NULL;
257 if (!S_ISDIR(smb_fname_hash->st.st_ex_mode)) {
263 file_is_valid(handle, smb_fname)) {
268 * Someone has recreated a file under an existing inode
269 * without deleting the streams directory.
270 * Move it away or remove if streams_depot:delete_lost is set.
274 delete_lost = lp_parm_bool(SNUM(handle->conn), "streams_depot",
275 "delete_lost", false);
278 DEBUG(3, ("Someone has recreated a file under an "
279 "existing inode. Removing: %s\n",
280 smb_fname_hash->base_name));
281 recursive_rmdir(talloc_tos(), handle->conn,
283 SMB_VFS_NEXT_UNLINKAT(handle,
284 handle->conn->cwd_fsp,
288 newname = talloc_asprintf(talloc_tos(), "lost-%lu",
290 DEBUG(3, ("Someone has recreated a file under an "
291 "existing inode. Renaming: %s to: %s\n",
292 smb_fname_hash->base_name,
294 if (newname == NULL) {
299 smb_fname_new = synthetic_smb_fname(
306 TALLOC_FREE(newname);
307 if (smb_fname_new == NULL) {
312 if (SMB_VFS_NEXT_RENAMEAT(handle,
313 handle->conn->cwd_fsp,
315 handle->conn->cwd_fsp,
316 smb_fname_new) == -1) {
317 TALLOC_FREE(smb_fname_new);
318 if ((errno == EEXIST) || (errno == ENOTEMPTY)) {
324 TALLOC_FREE(smb_fname_new);
333 ret = SMB_VFS_NEXT_MKDIRAT(handle,
334 handle->conn->cwd_fsp,
337 if ((ret != 0) && (errno != EEXIST)) {
341 tmp = talloc_asprintf(result, "%s/%2.2X", rootdir, first);
347 tmp_fname = synthetic_smb_fname(talloc_tos(),
353 if (tmp_fname == NULL) {
358 ret = SMB_VFS_NEXT_MKDIRAT(handle,
359 handle->conn->cwd_fsp,
362 if ((ret != 0) && (errno != EEXIST)) {
367 TALLOC_FREE(tmp_fname);
369 tmp = talloc_asprintf(result, "%s/%2.2X/%2.2X", rootdir, first,
376 tmp_fname = synthetic_smb_fname(talloc_tos(),
382 if (tmp_fname == NULL) {
387 ret = SMB_VFS_NEXT_MKDIRAT(handle,
388 handle->conn->cwd_fsp,
391 if ((ret != 0) && (errno != EEXIST)) {
396 TALLOC_FREE(tmp_fname);
398 /* smb_fname_hash is the struct smb_filename version of 'result' */
399 ret = SMB_VFS_NEXT_MKDIRAT(handle,
400 handle->conn->cwd_fsp,
403 if ((ret != 0) && (errno != EEXIST)) {
407 TALLOC_FREE(rootdir_fname);
408 TALLOC_FREE(rootdir);
409 TALLOC_FREE(tmp_fname);
410 TALLOC_FREE(smb_fname_hash);
414 TALLOC_FREE(rootdir_fname);
415 TALLOC_FREE(rootdir);
416 TALLOC_FREE(tmp_fname);
417 TALLOC_FREE(smb_fname_hash);
422 * Given a stream name, populate smb_fname_out with the actual location of the
425 static NTSTATUS stream_smb_fname(vfs_handle_struct *handle,
426 const struct stat_ex *base_sbuf,
427 const struct smb_filename *smb_fname,
428 struct smb_filename **smb_fname_out,
431 char *dirname, *stream_fname;
435 *smb_fname_out = NULL;
437 stype = strchr_m(smb_fname->stream_name + 1, ':');
440 if (strcasecmp_m(stype, ":$DATA") != 0) {
441 return NT_STATUS_INVALID_PARAMETER;
445 dirname = stream_dir(handle, smb_fname, base_sbuf, create_dir);
447 if (dirname == NULL) {
448 status = map_nt_error_from_unix(errno);
452 stream_fname = talloc_asprintf(talloc_tos(), "%s/%s", dirname,
453 smb_fname->stream_name);
455 if (stream_fname == NULL) {
456 status = NT_STATUS_NO_MEMORY;
461 /* Append an explicit stream type if one wasn't specified. */
462 stream_fname = talloc_asprintf(talloc_tos(), "%s:$DATA",
464 if (stream_fname == NULL) {
465 status = NT_STATUS_NO_MEMORY;
469 /* Normalize the stream type to uppercase. */
470 if (!strupper_m(strrchr_m(stream_fname, ':') + 1)) {
471 status = NT_STATUS_INVALID_PARAMETER;
476 DEBUG(10, ("stream filename = %s\n", stream_fname));
478 /* Create an smb_filename with stream_name == NULL. */
479 *smb_fname_out = synthetic_smb_fname(talloc_tos(),
485 if (*smb_fname_out == NULL) {
486 return NT_STATUS_NO_MEMORY;
492 DEBUG(5, ("stream_name failed: %s\n", strerror(errno)));
493 TALLOC_FREE(*smb_fname_out);
497 static NTSTATUS walk_streams(vfs_handle_struct *handle,
498 struct smb_filename *smb_fname_base,
500 bool (*fn)(const struct smb_filename *dirname,
506 char *rootdir = NULL;
507 char *orig_connectpath = NULL;
508 struct smb_filename *dir_smb_fname = NULL;
509 struct smb_Dir *dir_hnd = NULL;
510 const char *dname = NULL;
511 char *talloced = NULL;
514 dirname = stream_dir(handle, smb_fname_base, &smb_fname_base->st,
517 if (dirname == NULL) {
518 if (errno == ENOENT) {
524 return map_nt_error_from_unix(errno);
527 DEBUG(10, ("walk_streams: dirname=%s\n", dirname));
529 dir_smb_fname = synthetic_smb_fname(talloc_tos(),
533 smb_fname_base->twrp,
534 smb_fname_base->flags);
535 if (dir_smb_fname == NULL) {
536 TALLOC_FREE(dirname);
537 return NT_STATUS_NO_MEMORY;
541 * For OpenDir to succeed if the stream rootdir is outside
542 * the share path, we must temporarily swap out the connect
543 * path for this share. We're dealing with absolute paths
544 * here so we don't care about chdir calls.
546 rootdir = stream_rootdir(handle, talloc_tos());
547 if (rootdir == NULL) {
548 TALLOC_FREE(dir_smb_fname);
549 TALLOC_FREE(dirname);
550 return NT_STATUS_NO_MEMORY;
553 orig_connectpath = handle->conn->connectpath;
554 handle->conn->connectpath = rootdir;
557 talloc_tos(), handle->conn, dir_smb_fname, NULL, 0, &dir_hnd);
558 if (!NT_STATUS_IS_OK(status)) {
559 handle->conn->connectpath = orig_connectpath;
560 TALLOC_FREE(rootdir);
561 TALLOC_FREE(dir_smb_fname);
562 TALLOC_FREE(dirname);
566 while ((dname = ReadDirName(dir_hnd, &talloced)) != NULL) {
567 if (ISDOT(dname) || ISDOTDOT(dname)) {
568 TALLOC_FREE(talloced);
572 DBG_DEBUG("dirent=%s\n", dname);
574 if (!fn(dir_smb_fname, dname, private_data)) {
575 TALLOC_FREE(talloced);
578 TALLOC_FREE(talloced);
581 /* Restore the original connectpath. */
582 handle->conn->connectpath = orig_connectpath;
583 TALLOC_FREE(rootdir);
584 TALLOC_FREE(dir_smb_fname);
585 TALLOC_FREE(dir_hnd);
587 if (pdirname != NULL) {
591 TALLOC_FREE(dirname);
597 static int streams_depot_stat(vfs_handle_struct *handle,
598 struct smb_filename *smb_fname)
600 struct smb_filename *smb_fname_stream = NULL;
604 DEBUG(10, ("streams_depot_stat called for [%s]\n",
605 smb_fname_str_dbg(smb_fname)));
607 if (!is_named_stream(smb_fname)) {
608 return SMB_VFS_NEXT_STAT(handle, smb_fname);
611 /* Stat the actual stream now. */
612 status = stream_smb_fname(
613 handle, NULL, smb_fname, &smb_fname_stream, false);
614 if (!NT_STATUS_IS_OK(status)) {
616 errno = map_errno_from_nt_status(status);
620 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_stream);
622 /* Update the original smb_fname with the stat info. */
623 smb_fname->st = smb_fname_stream->st;
625 TALLOC_FREE(smb_fname_stream);
631 static int streams_depot_lstat(vfs_handle_struct *handle,
632 struct smb_filename *smb_fname)
634 struct smb_filename *smb_fname_stream = NULL;
638 DEBUG(10, ("streams_depot_lstat called for [%s]\n",
639 smb_fname_str_dbg(smb_fname)));
641 if (!is_named_stream(smb_fname)) {
642 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
645 /* Stat the actual stream now. */
646 status = stream_smb_fname(
647 handle, NULL, smb_fname, &smb_fname_stream, false);
648 if (!NT_STATUS_IS_OK(status)) {
650 errno = map_errno_from_nt_status(status);
654 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_stream);
657 TALLOC_FREE(smb_fname_stream);
661 static int streams_depot_openat(struct vfs_handle_struct *handle,
662 const struct files_struct *dirfsp,
663 const struct smb_filename *smb_fname,
664 struct files_struct *fsp,
665 const struct vfs_open_how *how)
667 struct smb_filename *smb_fname_stream = NULL;
668 struct files_struct *fspcwd = NULL;
673 if (!is_named_stream(smb_fname)) {
674 return SMB_VFS_NEXT_OPENAT(handle,
681 if (how->resolve != 0) {
686 SMB_ASSERT(fsp_is_alternate_stream(fsp));
687 SMB_ASSERT(dirfsp == NULL);
688 SMB_ASSERT(VALID_STAT(fsp->base_fsp->fsp_name->st));
690 create_it = (how->flags & O_CREAT);
692 /* Determine the stream name, and then open it. */
693 status = stream_smb_fname(
695 &fsp->base_fsp->fsp_name->st,
699 if (!NT_STATUS_IS_OK(status)) {
701 errno = map_errno_from_nt_status(status);
706 bool check_valid = lp_parm_bool(
715 DBG_DEBUG("marking file %s as valid\n",
716 fsp->base_fsp->fsp_name->base_name);
718 ret = SMB_VFS_FSETXATTR(
726 DBG_DEBUG("FSETXATTR failed: %s\n",
733 status = vfs_at_fspcwd(talloc_tos(), handle->conn, &fspcwd);
734 if (!NT_STATUS_IS_OK(status)) {
736 errno = map_errno_from_nt_status(status);
740 ret = SMB_VFS_NEXT_OPENAT(handle,
747 TALLOC_FREE(smb_fname_stream);
752 static int streams_depot_unlink_internal(vfs_handle_struct *handle,
753 struct files_struct *dirfsp,
754 const struct smb_filename *smb_fname,
757 struct smb_filename *full_fname = NULL;
758 char *dirname = NULL;
761 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
764 if (full_fname == NULL) {
768 DEBUG(10, ("streams_depot_unlink called for %s\n",
769 smb_fname_str_dbg(full_fname)));
771 /* If there is a valid stream, just unlink the stream and return. */
772 if (is_named_stream(full_fname)) {
773 struct smb_filename *smb_fname_stream = NULL;
776 status = stream_smb_fname(
777 handle, NULL, full_fname, &smb_fname_stream, false);
778 TALLOC_FREE(full_fname);
779 if (!NT_STATUS_IS_OK(status)) {
780 errno = map_errno_from_nt_status(status);
784 ret = SMB_VFS_NEXT_UNLINKAT(handle,
785 dirfsp->conn->cwd_fsp,
789 TALLOC_FREE(smb_fname_stream);
794 * We potentially need to delete the per-inode streams directory
797 if (full_fname->flags & SMB_FILENAME_POSIX_PATH) {
798 ret = SMB_VFS_NEXT_LSTAT(handle, full_fname);
800 ret = SMB_VFS_NEXT_STAT(handle, full_fname);
801 if (ret == -1 && (errno == ENOENT || errno == ELOOP)) {
802 if (VALID_STAT(smb_fname->st) &&
803 S_ISLNK(smb_fname->st.st_ex_mode)) {
805 * Original name was a link - Could be
806 * trying to remove a dangling symlink.
808 ret = SMB_VFS_NEXT_LSTAT(handle, full_fname);
813 TALLOC_FREE(full_fname);
818 * We know the unlink should succeed as the ACL
819 * check is already done in the caller. Remove the
820 * file *after* the streams.
822 dirname = stream_dir(handle,
826 TALLOC_FREE(full_fname);
827 if (dirname != NULL) {
828 struct smb_filename *smb_fname_dir = NULL;
830 smb_fname_dir = synthetic_smb_fname(talloc_tos(),
836 if (smb_fname_dir == NULL) {
837 TALLOC_FREE(dirname);
842 SMB_VFS_NEXT_UNLINKAT(handle,
843 dirfsp->conn->cwd_fsp,
846 TALLOC_FREE(smb_fname_dir);
847 TALLOC_FREE(dirname);
850 ret = SMB_VFS_NEXT_UNLINKAT(handle,
857 static int streams_depot_rmdir_internal(vfs_handle_struct *handle,
858 struct files_struct *dirfsp,
859 const struct smb_filename *smb_fname)
861 struct smb_filename *full_fname = NULL;
862 struct smb_filename *smb_fname_base = NULL;
865 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
868 if (full_fname == NULL) {
872 DBG_DEBUG("called for %s\n", full_fname->base_name);
875 * We potentially need to delete the per-inode streams directory
878 smb_fname_base = synthetic_smb_fname(talloc_tos(),
879 full_fname->base_name,
884 TALLOC_FREE(full_fname);
885 if (smb_fname_base == NULL) {
890 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
891 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
893 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
897 TALLOC_FREE(smb_fname_base);
902 * We know the rmdir should succeed as the ACL
903 * check is already done in the caller. Remove the
904 * directory *after* the streams.
907 char *dirname = stream_dir(handle, smb_fname_base,
908 &smb_fname_base->st, false);
910 if (dirname != NULL) {
911 struct smb_filename *smb_fname_dir =
912 synthetic_smb_fname(talloc_tos(),
918 if (smb_fname_dir == NULL) {
919 TALLOC_FREE(smb_fname_base);
920 TALLOC_FREE(dirname);
924 SMB_VFS_NEXT_UNLINKAT(handle,
925 dirfsp->conn->cwd_fsp,
928 TALLOC_FREE(smb_fname_dir);
930 TALLOC_FREE(dirname);
933 ret = SMB_VFS_NEXT_UNLINKAT(handle,
937 TALLOC_FREE(smb_fname_base);
941 static int streams_depot_unlinkat(vfs_handle_struct *handle,
942 struct files_struct *dirfsp,
943 const struct smb_filename *smb_fname,
947 if (flags & AT_REMOVEDIR) {
948 ret = streams_depot_rmdir_internal(handle,
952 ret = streams_depot_unlink_internal(handle,
960 static int streams_depot_renameat(vfs_handle_struct *handle,
961 files_struct *srcfsp,
962 const struct smb_filename *smb_fname_src,
963 files_struct *dstfsp,
964 const struct smb_filename *smb_fname_dst)
966 struct smb_filename *smb_fname_src_stream = NULL;
967 struct smb_filename *smb_fname_dst_stream = NULL;
968 struct smb_filename *full_src = NULL;
969 struct smb_filename *full_dst = NULL;
970 bool src_is_stream, dst_is_stream;
974 DEBUG(10, ("streams_depot_renameat called for %s => %s\n",
975 smb_fname_str_dbg(smb_fname_src),
976 smb_fname_str_dbg(smb_fname_dst)));
978 src_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
979 dst_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
981 if (!src_is_stream && !dst_is_stream) {
982 return SMB_VFS_NEXT_RENAMEAT(handle,
989 /* for now don't allow renames from or to the default stream */
990 if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
991 is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
996 full_src = full_path_from_dirfsp_atname(talloc_tos(),
999 if (full_src == NULL) {
1004 full_dst = full_path_from_dirfsp_atname(talloc_tos(),
1007 if (full_dst == NULL) {
1012 status = stream_smb_fname(
1013 handle, NULL, full_src, &smb_fname_src_stream, false);
1014 if (!NT_STATUS_IS_OK(status)) {
1015 errno = map_errno_from_nt_status(status);
1019 status = stream_smb_fname(
1020 handle, NULL, full_dst, &smb_fname_dst_stream, false);
1021 if (!NT_STATUS_IS_OK(status)) {
1022 errno = map_errno_from_nt_status(status);
1027 * We must use handle->conn->cwd_fsp as
1028 * srcfsp and dstfsp directory handles here
1029 * as we used the full pathname from the cwd dir
1030 * to calculate the streams directory and filename
1033 ret = SMB_VFS_NEXT_RENAMEAT(handle,
1034 handle->conn->cwd_fsp,
1035 smb_fname_src_stream,
1036 handle->conn->cwd_fsp,
1037 smb_fname_dst_stream);
1040 TALLOC_FREE(smb_fname_src_stream);
1041 TALLOC_FREE(smb_fname_dst_stream);
1045 static bool add_one_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
1046 struct stream_struct **streams,
1047 const char *name, off_t size,
1050 struct stream_struct *tmp;
1052 tmp = talloc_realloc(mem_ctx, *streams, struct stream_struct,
1058 tmp[*num_streams].name = talloc_strdup(tmp, name);
1059 if (tmp[*num_streams].name == NULL) {
1063 tmp[*num_streams].size = size;
1064 tmp[*num_streams].alloc_size = alloc_size;
1071 struct streaminfo_state {
1072 TALLOC_CTX *mem_ctx;
1073 vfs_handle_struct *handle;
1074 unsigned int num_streams;
1075 struct stream_struct *streams;
1079 static bool collect_one_stream(const struct smb_filename *dirfname,
1083 const char *dirname = dirfname->base_name;
1084 struct streaminfo_state *state =
1085 (struct streaminfo_state *)private_data;
1086 struct smb_filename *smb_fname = NULL;
1090 sname = talloc_asprintf(talloc_tos(), "%s/%s", dirname, dirent);
1091 if (sname == NULL) {
1092 state->status = NT_STATUS_NO_MEMORY;
1097 smb_fname = synthetic_smb_fname(talloc_tos(),
1103 if (smb_fname == NULL) {
1104 state->status = NT_STATUS_NO_MEMORY;
1109 if (SMB_VFS_NEXT_STAT(state->handle, smb_fname) == -1) {
1110 DEBUG(10, ("Could not stat %s: %s\n", sname,
1116 if (!add_one_stream(state->mem_ctx,
1117 &state->num_streams, &state->streams,
1118 dirent, smb_fname->st.st_ex_size,
1119 SMB_VFS_GET_ALLOC_SIZE(state->handle->conn, NULL,
1121 state->status = NT_STATUS_NO_MEMORY;
1129 TALLOC_FREE(smb_fname);
1133 static NTSTATUS streams_depot_fstreaminfo(vfs_handle_struct *handle,
1134 struct files_struct *fsp,
1135 TALLOC_CTX *mem_ctx,
1136 unsigned int *pnum_streams,
1137 struct stream_struct **pstreams)
1139 struct smb_filename *smb_fname_base = NULL;
1142 struct streaminfo_state state;
1144 smb_fname_base = synthetic_smb_fname(talloc_tos(),
1145 fsp->fsp_name->base_name,
1148 fsp->fsp_name->twrp,
1149 fsp->fsp_name->flags);
1150 if (smb_fname_base == NULL) {
1151 return NT_STATUS_NO_MEMORY;
1154 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, &smb_fname_base->st);
1156 status = map_nt_error_from_unix(errno);
1160 state.streams = *pstreams;
1161 state.num_streams = *pnum_streams;
1162 state.mem_ctx = mem_ctx;
1163 state.handle = handle;
1164 state.status = NT_STATUS_OK;
1166 status = walk_streams(handle,
1172 if (!NT_STATUS_IS_OK(status)) {
1173 TALLOC_FREE(state.streams);
1177 if (!NT_STATUS_IS_OK(state.status)) {
1178 TALLOC_FREE(state.streams);
1179 status = state.status;
1183 *pnum_streams = state.num_streams;
1184 *pstreams = state.streams;
1185 status = SMB_VFS_NEXT_FSTREAMINFO(handle,
1186 fsp->base_fsp ? fsp->base_fsp : fsp,
1192 TALLOC_FREE(smb_fname_base);
1196 static uint32_t streams_depot_fs_capabilities(struct vfs_handle_struct *handle,
1197 enum timestamp_set_resolution *p_ts_res)
1199 return SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res) | FILE_NAMED_STREAMS;
1202 static struct vfs_fn_pointers vfs_streams_depot_fns = {
1203 .fs_capabilities_fn = streams_depot_fs_capabilities,
1204 .openat_fn = streams_depot_openat,
1205 .stat_fn = streams_depot_stat,
1206 .lstat_fn = streams_depot_lstat,
1207 .unlinkat_fn = streams_depot_unlinkat,
1208 .renameat_fn = streams_depot_renameat,
1209 .fstreaminfo_fn = streams_depot_fstreaminfo,
1213 NTSTATUS vfs_streams_depot_init(TALLOC_CTX *ctx)
1215 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "streams_depot",
1216 &vfs_streams_depot_fns);