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 upercase. */
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, NULL, &talloced))
569 if (ISDOT(dname) || ISDOTDOT(dname)) {
570 TALLOC_FREE(talloced);
574 DBG_DEBUG("dirent=%s\n", dname);
576 if (!fn(dir_smb_fname, dname, private_data)) {
577 TALLOC_FREE(talloced);
580 TALLOC_FREE(talloced);
583 /* Restore the original connectpath. */
584 handle->conn->connectpath = orig_connectpath;
585 TALLOC_FREE(rootdir);
586 TALLOC_FREE(dir_smb_fname);
587 TALLOC_FREE(dir_hnd);
589 if (pdirname != NULL) {
593 TALLOC_FREE(dirname);
599 static int streams_depot_stat(vfs_handle_struct *handle,
600 struct smb_filename *smb_fname)
602 struct smb_filename *smb_fname_stream = NULL;
606 DEBUG(10, ("streams_depot_stat called for [%s]\n",
607 smb_fname_str_dbg(smb_fname)));
609 if (!is_named_stream(smb_fname)) {
610 return SMB_VFS_NEXT_STAT(handle, smb_fname);
613 /* Stat the actual stream now. */
614 status = stream_smb_fname(
615 handle, NULL, smb_fname, &smb_fname_stream, false);
616 if (!NT_STATUS_IS_OK(status)) {
618 errno = map_errno_from_nt_status(status);
622 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_stream);
624 /* Update the original smb_fname with the stat info. */
625 smb_fname->st = smb_fname_stream->st;
627 TALLOC_FREE(smb_fname_stream);
633 static int streams_depot_lstat(vfs_handle_struct *handle,
634 struct smb_filename *smb_fname)
636 struct smb_filename *smb_fname_stream = NULL;
640 DEBUG(10, ("streams_depot_lstat called for [%s]\n",
641 smb_fname_str_dbg(smb_fname)));
643 if (!is_named_stream(smb_fname)) {
644 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
647 /* Stat the actual stream now. */
648 status = stream_smb_fname(
649 handle, NULL, smb_fname, &smb_fname_stream, false);
650 if (!NT_STATUS_IS_OK(status)) {
652 errno = map_errno_from_nt_status(status);
656 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_stream);
659 TALLOC_FREE(smb_fname_stream);
663 static int streams_depot_openat(struct vfs_handle_struct *handle,
664 const struct files_struct *dirfsp,
665 const struct smb_filename *smb_fname,
666 struct files_struct *fsp,
667 const struct vfs_open_how *how)
669 struct smb_filename *smb_fname_stream = NULL;
670 struct files_struct *fspcwd = NULL;
675 if (!is_named_stream(smb_fname)) {
676 return SMB_VFS_NEXT_OPENAT(handle,
683 if (how->resolve != 0) {
688 SMB_ASSERT(fsp_is_alternate_stream(fsp));
689 SMB_ASSERT(dirfsp == NULL);
690 SMB_ASSERT(VALID_STAT(fsp->base_fsp->fsp_name->st));
692 create_it = (how->flags & O_CREAT);
694 /* Determine the stream name, and then open it. */
695 status = stream_smb_fname(
697 &fsp->base_fsp->fsp_name->st,
701 if (!NT_STATUS_IS_OK(status)) {
703 errno = map_errno_from_nt_status(status);
708 bool check_valid = lp_parm_bool(
717 DBG_DEBUG("marking file %s as valid\n",
718 fsp->base_fsp->fsp_name->base_name);
720 ret = SMB_VFS_FSETXATTR(
728 DBG_DEBUG("FSETXATTR failed: %s\n",
735 status = vfs_at_fspcwd(talloc_tos(), handle->conn, &fspcwd);
736 if (!NT_STATUS_IS_OK(status)) {
738 errno = map_errno_from_nt_status(status);
742 ret = SMB_VFS_NEXT_OPENAT(handle,
749 TALLOC_FREE(smb_fname_stream);
754 static int streams_depot_unlink_internal(vfs_handle_struct *handle,
755 struct files_struct *dirfsp,
756 const struct smb_filename *smb_fname,
759 struct smb_filename *full_fname = NULL;
760 char *dirname = NULL;
763 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
766 if (full_fname == NULL) {
770 DEBUG(10, ("streams_depot_unlink called for %s\n",
771 smb_fname_str_dbg(full_fname)));
773 /* If there is a valid stream, just unlink the stream and return. */
774 if (is_named_stream(full_fname)) {
775 struct smb_filename *smb_fname_stream = NULL;
778 status = stream_smb_fname(
779 handle, NULL, full_fname, &smb_fname_stream, false);
780 TALLOC_FREE(full_fname);
781 if (!NT_STATUS_IS_OK(status)) {
782 errno = map_errno_from_nt_status(status);
786 ret = SMB_VFS_NEXT_UNLINKAT(handle,
787 dirfsp->conn->cwd_fsp,
791 TALLOC_FREE(smb_fname_stream);
796 * We potentially need to delete the per-inode streams directory
799 if (full_fname->flags & SMB_FILENAME_POSIX_PATH) {
800 ret = SMB_VFS_NEXT_LSTAT(handle, full_fname);
802 ret = SMB_VFS_NEXT_STAT(handle, full_fname);
803 if (ret == -1 && (errno == ENOENT || errno == ELOOP)) {
804 if (VALID_STAT(smb_fname->st) &&
805 S_ISLNK(smb_fname->st.st_ex_mode)) {
807 * Original name was a link - Could be
808 * trying to remove a dangling symlink.
810 ret = SMB_VFS_NEXT_LSTAT(handle, full_fname);
815 TALLOC_FREE(full_fname);
820 * We know the unlink should succeed as the ACL
821 * check is already done in the caller. Remove the
822 * file *after* the streams.
824 dirname = stream_dir(handle,
828 TALLOC_FREE(full_fname);
829 if (dirname != NULL) {
830 struct smb_filename *smb_fname_dir = NULL;
832 smb_fname_dir = synthetic_smb_fname(talloc_tos(),
838 if (smb_fname_dir == NULL) {
839 TALLOC_FREE(dirname);
844 SMB_VFS_NEXT_UNLINKAT(handle,
845 dirfsp->conn->cwd_fsp,
848 TALLOC_FREE(smb_fname_dir);
849 TALLOC_FREE(dirname);
852 ret = SMB_VFS_NEXT_UNLINKAT(handle,
859 static int streams_depot_rmdir_internal(vfs_handle_struct *handle,
860 struct files_struct *dirfsp,
861 const struct smb_filename *smb_fname)
863 struct smb_filename *full_fname = NULL;
864 struct smb_filename *smb_fname_base = NULL;
867 full_fname = full_path_from_dirfsp_atname(talloc_tos(),
870 if (full_fname == NULL) {
874 DBG_DEBUG("called for %s\n", full_fname->base_name);
877 * We potentially need to delete the per-inode streams directory
880 smb_fname_base = synthetic_smb_fname(talloc_tos(),
881 full_fname->base_name,
886 TALLOC_FREE(full_fname);
887 if (smb_fname_base == NULL) {
892 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
893 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
895 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
899 TALLOC_FREE(smb_fname_base);
904 * We know the rmdir should succeed as the ACL
905 * check is already done in the caller. Remove the
906 * directory *after* the streams.
909 char *dirname = stream_dir(handle, smb_fname_base,
910 &smb_fname_base->st, false);
912 if (dirname != NULL) {
913 struct smb_filename *smb_fname_dir =
914 synthetic_smb_fname(talloc_tos(),
920 if (smb_fname_dir == NULL) {
921 TALLOC_FREE(smb_fname_base);
922 TALLOC_FREE(dirname);
926 SMB_VFS_NEXT_UNLINKAT(handle,
927 dirfsp->conn->cwd_fsp,
930 TALLOC_FREE(smb_fname_dir);
932 TALLOC_FREE(dirname);
935 ret = SMB_VFS_NEXT_UNLINKAT(handle,
939 TALLOC_FREE(smb_fname_base);
943 static int streams_depot_unlinkat(vfs_handle_struct *handle,
944 struct files_struct *dirfsp,
945 const struct smb_filename *smb_fname,
949 if (flags & AT_REMOVEDIR) {
950 ret = streams_depot_rmdir_internal(handle,
954 ret = streams_depot_unlink_internal(handle,
962 static int streams_depot_renameat(vfs_handle_struct *handle,
963 files_struct *srcfsp,
964 const struct smb_filename *smb_fname_src,
965 files_struct *dstfsp,
966 const struct smb_filename *smb_fname_dst)
968 struct smb_filename *smb_fname_src_stream = NULL;
969 struct smb_filename *smb_fname_dst_stream = NULL;
970 struct smb_filename *full_src = NULL;
971 struct smb_filename *full_dst = NULL;
972 bool src_is_stream, dst_is_stream;
976 DEBUG(10, ("streams_depot_renameat called for %s => %s\n",
977 smb_fname_str_dbg(smb_fname_src),
978 smb_fname_str_dbg(smb_fname_dst)));
980 src_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
981 dst_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
983 if (!src_is_stream && !dst_is_stream) {
984 return SMB_VFS_NEXT_RENAMEAT(handle,
991 /* for now don't allow renames from or to the default stream */
992 if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
993 is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
998 full_src = full_path_from_dirfsp_atname(talloc_tos(),
1001 if (full_src == NULL) {
1006 full_dst = full_path_from_dirfsp_atname(talloc_tos(),
1009 if (full_dst == NULL) {
1014 status = stream_smb_fname(
1015 handle, NULL, full_src, &smb_fname_src_stream, false);
1016 if (!NT_STATUS_IS_OK(status)) {
1017 errno = map_errno_from_nt_status(status);
1021 status = stream_smb_fname(
1022 handle, NULL, full_dst, &smb_fname_dst_stream, false);
1023 if (!NT_STATUS_IS_OK(status)) {
1024 errno = map_errno_from_nt_status(status);
1029 * We must use handle->conn->cwd_fsp as
1030 * srcfsp and dstfsp directory handles here
1031 * as we used the full pathname from the cwd dir
1032 * to calculate the streams directory and filename
1035 ret = SMB_VFS_NEXT_RENAMEAT(handle,
1036 handle->conn->cwd_fsp,
1037 smb_fname_src_stream,
1038 handle->conn->cwd_fsp,
1039 smb_fname_dst_stream);
1042 TALLOC_FREE(smb_fname_src_stream);
1043 TALLOC_FREE(smb_fname_dst_stream);
1047 static bool add_one_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
1048 struct stream_struct **streams,
1049 const char *name, off_t size,
1052 struct stream_struct *tmp;
1054 tmp = talloc_realloc(mem_ctx, *streams, struct stream_struct,
1060 tmp[*num_streams].name = talloc_strdup(tmp, name);
1061 if (tmp[*num_streams].name == NULL) {
1065 tmp[*num_streams].size = size;
1066 tmp[*num_streams].alloc_size = alloc_size;
1073 struct streaminfo_state {
1074 TALLOC_CTX *mem_ctx;
1075 vfs_handle_struct *handle;
1076 unsigned int num_streams;
1077 struct stream_struct *streams;
1081 static bool collect_one_stream(const struct smb_filename *dirfname,
1085 const char *dirname = dirfname->base_name;
1086 struct streaminfo_state *state =
1087 (struct streaminfo_state *)private_data;
1088 struct smb_filename *smb_fname = NULL;
1092 sname = talloc_asprintf(talloc_tos(), "%s/%s", dirname, dirent);
1093 if (sname == NULL) {
1094 state->status = NT_STATUS_NO_MEMORY;
1099 smb_fname = synthetic_smb_fname(talloc_tos(),
1105 if (smb_fname == NULL) {
1106 state->status = NT_STATUS_NO_MEMORY;
1111 if (SMB_VFS_NEXT_STAT(state->handle, smb_fname) == -1) {
1112 DEBUG(10, ("Could not stat %s: %s\n", sname,
1118 if (!add_one_stream(state->mem_ctx,
1119 &state->num_streams, &state->streams,
1120 dirent, smb_fname->st.st_ex_size,
1121 SMB_VFS_GET_ALLOC_SIZE(state->handle->conn, NULL,
1123 state->status = NT_STATUS_NO_MEMORY;
1131 TALLOC_FREE(smb_fname);
1135 static NTSTATUS streams_depot_fstreaminfo(vfs_handle_struct *handle,
1136 struct files_struct *fsp,
1137 TALLOC_CTX *mem_ctx,
1138 unsigned int *pnum_streams,
1139 struct stream_struct **pstreams)
1141 struct smb_filename *smb_fname_base = NULL;
1144 struct streaminfo_state state;
1146 smb_fname_base = synthetic_smb_fname(talloc_tos(),
1147 fsp->fsp_name->base_name,
1150 fsp->fsp_name->twrp,
1151 fsp->fsp_name->flags);
1152 if (smb_fname_base == NULL) {
1153 return NT_STATUS_NO_MEMORY;
1156 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, &smb_fname_base->st);
1158 status = map_nt_error_from_unix(errno);
1162 state.streams = *pstreams;
1163 state.num_streams = *pnum_streams;
1164 state.mem_ctx = mem_ctx;
1165 state.handle = handle;
1166 state.status = NT_STATUS_OK;
1168 status = walk_streams(handle,
1174 if (!NT_STATUS_IS_OK(status)) {
1175 TALLOC_FREE(state.streams);
1179 if (!NT_STATUS_IS_OK(state.status)) {
1180 TALLOC_FREE(state.streams);
1181 status = state.status;
1185 *pnum_streams = state.num_streams;
1186 *pstreams = state.streams;
1187 status = SMB_VFS_NEXT_FSTREAMINFO(handle,
1188 fsp->base_fsp ? fsp->base_fsp : fsp,
1194 TALLOC_FREE(smb_fname_base);
1198 static uint32_t streams_depot_fs_capabilities(struct vfs_handle_struct *handle,
1199 enum timestamp_set_resolution *p_ts_res)
1201 return SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res) | FILE_NAMED_STREAMS;
1204 static struct vfs_fn_pointers vfs_streams_depot_fns = {
1205 .fs_capabilities_fn = streams_depot_fs_capabilities,
1206 .openat_fn = streams_depot_openat,
1207 .stat_fn = streams_depot_stat,
1208 .lstat_fn = streams_depot_lstat,
1209 .unlinkat_fn = streams_depot_unlinkat,
1210 .renameat_fn = streams_depot_renameat,
1211 .fstreaminfo_fn = streams_depot_fstreaminfo,
1215 NTSTATUS vfs_streams_depot_init(TALLOC_CTX *ctx)
1217 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "streams_depot",
1218 &vfs_streams_depot_fns);