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 DEBUG(10, ("file_is_valid (%s) called\n", smb_fname->base_name));
77 if (SMB_VFS_GETXATTR(handle->conn, smb_fname, SAMBA_XATTR_MARKER,
78 &buf, sizeof(buf)) != sizeof(buf)) {
79 DEBUG(10, ("GETXATTR failed: %s\n", strerror(errno)));
84 DEBUG(10, ("got wrong buffer content: '%c'\n", buf));
91 static bool mark_file_valid(vfs_handle_struct *handle,
92 const struct smb_filename *smb_fname)
97 DEBUG(10, ("marking file %s as valid\n", smb_fname->base_name));
99 ret = SMB_VFS_SETXATTR(handle->conn, smb_fname, SAMBA_XATTR_MARKER,
100 &buf, sizeof(buf), 0);
103 DEBUG(10, ("SETXATTR failed: %s\n", strerror(errno)));
111 * Given an smb_filename, determine the stream directory using the file's
114 static char *stream_dir(vfs_handle_struct *handle,
115 const struct smb_filename *smb_fname,
116 const SMB_STRUCT_STAT *base_sbuf, bool create_it)
118 const struct loadparm_substitution *lp_sub =
119 loadparm_s3_global_substitution();
121 struct smb_filename *smb_fname_hash = NULL;
123 SMB_STRUCT_STAT base_sbuf_tmp;
124 uint8_t first, second;
130 char *rootdir = NULL;
131 struct smb_filename *rootdir_fname = NULL;
132 struct smb_filename *tmp_fname = NULL;
135 check_valid = lp_parm_bool(SNUM(handle->conn),
136 "streams_depot", "check_valid", true);
138 tmp = talloc_asprintf(talloc_tos(), "%s/.streams",
139 handle->conn->connectpath);
146 rootdir = lp_parm_substituted_string(talloc_tos(), lp_sub,
147 SNUM(handle->conn), "streams_depot", "directory",
149 if (rootdir == NULL) {
154 rootdir_fname = synthetic_smb_fname(talloc_tos(),
160 if (rootdir_fname == NULL) {
165 /* Stat the base file if it hasn't already been done. */
166 if (base_sbuf == NULL) {
167 struct smb_filename *smb_fname_base;
169 smb_fname_base = synthetic_smb_fname(
171 smb_fname->base_name,
176 if (smb_fname_base == NULL) {
180 if (SMB_VFS_NEXT_STAT(handle, smb_fname_base) == -1) {
181 TALLOC_FREE(smb_fname_base);
184 base_sbuf_tmp = smb_fname_base->st;
185 TALLOC_FREE(smb_fname_base);
187 base_sbuf_tmp = *base_sbuf;
190 id = SMB_VFS_FILE_ID_CREATE(handle->conn, &base_sbuf_tmp);
192 push_file_id_16((char *)id_buf, &id);
194 hash = hash_fn(data_blob_const(id_buf, sizeof(id_buf)));
197 second = (hash >> 8) & 0xff;
199 id_hex = hex_encode_talloc(talloc_tos(), id_buf, sizeof(id_buf));
201 if (id_hex == NULL) {
206 result = talloc_asprintf(talloc_tos(), "%s/%2.2X/%2.2X/%s", rootdir,
207 first, second, id_hex);
211 if (result == NULL) {
216 smb_fname_hash = synthetic_smb_fname(talloc_tos(),
222 if (smb_fname_hash == NULL) {
227 if (SMB_VFS_NEXT_STAT(handle, smb_fname_hash) == 0) {
228 struct smb_filename *smb_fname_new = NULL;
232 if (!S_ISDIR(smb_fname_hash->st.st_ex_mode)) {
238 file_is_valid(handle, smb_fname)) {
243 * Someone has recreated a file under an existing inode
244 * without deleting the streams directory.
245 * Move it away or remove if streams_depot:delete_lost is set.
249 delete_lost = lp_parm_bool(SNUM(handle->conn), "streams_depot",
250 "delete_lost", false);
253 DEBUG(3, ("Someone has recreated a file under an "
254 "existing inode. Removing: %s\n",
255 smb_fname_hash->base_name));
256 recursive_rmdir(talloc_tos(), handle->conn,
258 SMB_VFS_NEXT_UNLINKAT(handle,
259 handle->conn->cwd_fsp,
263 newname = talloc_asprintf(talloc_tos(), "lost-%lu",
265 DEBUG(3, ("Someone has recreated a file under an "
266 "existing inode. Renaming: %s to: %s\n",
267 smb_fname_hash->base_name,
269 if (newname == NULL) {
274 smb_fname_new = synthetic_smb_fname(
281 TALLOC_FREE(newname);
282 if (smb_fname_new == NULL) {
287 if (SMB_VFS_NEXT_RENAMEAT(handle,
288 handle->conn->cwd_fsp,
290 handle->conn->cwd_fsp,
291 smb_fname_new) == -1) {
292 TALLOC_FREE(smb_fname_new);
293 if ((errno == EEXIST) || (errno == ENOTEMPTY)) {
299 TALLOC_FREE(smb_fname_new);
308 ret = SMB_VFS_NEXT_MKDIRAT(handle,
309 handle->conn->cwd_fsp,
312 if ((ret != 0) && (errno != EEXIST)) {
316 tmp = talloc_asprintf(result, "%s/%2.2X", rootdir, first);
322 tmp_fname = synthetic_smb_fname(talloc_tos(),
328 if (tmp_fname == NULL) {
333 ret = SMB_VFS_NEXT_MKDIRAT(handle,
334 handle->conn->cwd_fsp,
337 if ((ret != 0) && (errno != EEXIST)) {
342 TALLOC_FREE(tmp_fname);
344 tmp = talloc_asprintf(result, "%s/%2.2X/%2.2X", rootdir, first,
351 tmp_fname = synthetic_smb_fname(talloc_tos(),
357 if (tmp_fname == NULL) {
362 ret = SMB_VFS_NEXT_MKDIRAT(handle,
363 handle->conn->cwd_fsp,
366 if ((ret != 0) && (errno != EEXIST)) {
371 TALLOC_FREE(tmp_fname);
373 /* smb_fname_hash is the struct smb_filename version of 'result' */
374 ret = SMB_VFS_NEXT_MKDIRAT(handle,
375 handle->conn->cwd_fsp,
378 if ((ret != 0) && (errno != EEXIST)) {
382 if (check_valid && !mark_file_valid(handle, smb_fname)) {
386 TALLOC_FREE(rootdir_fname);
387 TALLOC_FREE(rootdir);
388 TALLOC_FREE(tmp_fname);
389 TALLOC_FREE(smb_fname_hash);
393 TALLOC_FREE(rootdir_fname);
394 TALLOC_FREE(rootdir);
395 TALLOC_FREE(tmp_fname);
396 TALLOC_FREE(smb_fname_hash);
401 * Given a stream name, populate smb_fname_out with the actual location of the
404 static NTSTATUS stream_smb_fname(vfs_handle_struct *handle,
405 const struct smb_filename *smb_fname,
406 struct smb_filename **smb_fname_out,
409 char *dirname, *stream_fname;
413 *smb_fname_out = NULL;
415 stype = strchr_m(smb_fname->stream_name + 1, ':');
418 if (strcasecmp_m(stype, ":$DATA") != 0) {
419 return NT_STATUS_INVALID_PARAMETER;
423 dirname = stream_dir(handle, smb_fname, NULL, create_dir);
425 if (dirname == NULL) {
426 status = map_nt_error_from_unix(errno);
430 stream_fname = talloc_asprintf(talloc_tos(), "%s/%s", dirname,
431 smb_fname->stream_name);
433 if (stream_fname == NULL) {
434 status = NT_STATUS_NO_MEMORY;
439 /* Append an explicit stream type if one wasn't specified. */
440 stream_fname = talloc_asprintf(talloc_tos(), "%s:$DATA",
442 if (stream_fname == NULL) {
443 status = NT_STATUS_NO_MEMORY;
447 /* Normalize the stream type to upercase. */
448 if (!strupper_m(strrchr_m(stream_fname, ':') + 1)) {
449 status = NT_STATUS_INVALID_PARAMETER;
454 DEBUG(10, ("stream filename = %s\n", stream_fname));
456 /* Create an smb_filename with stream_name == NULL. */
457 *smb_fname_out = synthetic_smb_fname(talloc_tos(),
463 if (*smb_fname_out == NULL) {
464 return NT_STATUS_NO_MEMORY;
470 DEBUG(5, ("stream_name failed: %s\n", strerror(errno)));
471 TALLOC_FREE(*smb_fname_out);
475 static NTSTATUS walk_streams(vfs_handle_struct *handle,
476 struct smb_filename *smb_fname_base,
478 bool (*fn)(const struct smb_filename *dirname,
484 struct smb_filename *dir_smb_fname = NULL;
485 struct smb_Dir *dir_hnd = NULL;
486 const char *dname = NULL;
488 char *talloced = NULL;
490 dirname = stream_dir(handle, smb_fname_base, &smb_fname_base->st,
493 if (dirname == NULL) {
494 if (errno == ENOENT) {
500 return map_nt_error_from_unix(errno);
503 DEBUG(10, ("walk_streams: dirname=%s\n", dirname));
505 dir_smb_fname = synthetic_smb_fname(talloc_tos(),
509 smb_fname_base->twrp,
510 smb_fname_base->flags);
511 if (dir_smb_fname == NULL) {
512 TALLOC_FREE(dirname);
513 return NT_STATUS_NO_MEMORY;
516 dir_hnd = OpenDir(talloc_tos(), handle->conn, dir_smb_fname, NULL, 0);
517 if (dir_hnd == NULL) {
518 TALLOC_FREE(dir_smb_fname);
519 TALLOC_FREE(dirname);
520 return map_nt_error_from_unix(errno);
523 while ((dname = ReadDirName(dir_hnd, &offset, NULL, &talloced))
526 if (ISDOT(dname) || ISDOTDOT(dname)) {
527 TALLOC_FREE(talloced);
531 DBG_DEBUG("dirent=%s\n", dname);
533 if (!fn(dir_smb_fname, dname, private_data)) {
534 TALLOC_FREE(talloced);
537 TALLOC_FREE(talloced);
540 TALLOC_FREE(dir_smb_fname);
541 TALLOC_FREE(dir_hnd);
543 if (pdirname != NULL) {
547 TALLOC_FREE(dirname);
553 static int streams_depot_stat(vfs_handle_struct *handle,
554 struct smb_filename *smb_fname)
556 struct smb_filename *smb_fname_stream = NULL;
560 DEBUG(10, ("streams_depot_stat called for [%s]\n",
561 smb_fname_str_dbg(smb_fname)));
563 if (!is_named_stream(smb_fname)) {
564 return SMB_VFS_NEXT_STAT(handle, smb_fname);
567 /* Stat the actual stream now. */
568 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
570 if (!NT_STATUS_IS_OK(status)) {
572 errno = map_errno_from_nt_status(status);
576 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_stream);
578 /* Update the original smb_fname with the stat info. */
579 smb_fname->st = smb_fname_stream->st;
581 TALLOC_FREE(smb_fname_stream);
587 static int streams_depot_lstat(vfs_handle_struct *handle,
588 struct smb_filename *smb_fname)
590 struct smb_filename *smb_fname_stream = NULL;
594 DEBUG(10, ("streams_depot_lstat called for [%s]\n",
595 smb_fname_str_dbg(smb_fname)));
597 if (!is_named_stream(smb_fname)) {
598 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
601 /* Stat the actual stream now. */
602 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
604 if (!NT_STATUS_IS_OK(status)) {
606 errno = map_errno_from_nt_status(status);
610 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_stream);
613 TALLOC_FREE(smb_fname_stream);
617 static int streams_depot_open(vfs_handle_struct *handle,
618 struct smb_filename *smb_fname,
619 files_struct *fsp, int flags, mode_t mode)
621 struct smb_filename *smb_fname_stream = NULL;
622 struct smb_filename *smb_fname_base = NULL;
626 if (!is_named_stream(smb_fname)) {
627 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
630 /* Ensure the base file still exists. */
631 smb_fname_base = synthetic_smb_fname(talloc_tos(),
632 smb_fname->base_name,
637 if (smb_fname_base == NULL) {
643 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
648 /* Determine the stream name, and then open it. */
649 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream, true);
650 if (!NT_STATUS_IS_OK(status)) {
652 errno = map_errno_from_nt_status(status);
656 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname_stream, fsp, flags, mode);
659 TALLOC_FREE(smb_fname_stream);
660 TALLOC_FREE(smb_fname_base);
664 static int streams_depot_openat(struct vfs_handle_struct *handle,
665 const struct files_struct *dirfsp,
666 const struct smb_filename *smb_fname,
667 struct files_struct *fsp,
671 struct smb_filename *smb_fname_stream = NULL;
672 struct smb_filename *smb_fname_base = NULL;
673 struct files_struct *fspcwd = NULL;
678 * For now assert this so the below SMB_VFS_STAT() is ok.
680 SMB_ASSERT(dirfsp->fh->fd == AT_FDCWD);
682 if (!is_named_stream(smb_fname)) {
683 return SMB_VFS_NEXT_OPENAT(handle,
691 /* Ensure the base file still exists. */
692 smb_fname_base = synthetic_smb_fname(talloc_tos(),
693 smb_fname->base_name,
698 if (smb_fname_base == NULL) {
704 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
709 /* Determine the stream name, and then open it. */
710 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream, true);
711 if (!NT_STATUS_IS_OK(status)) {
713 errno = map_errno_from_nt_status(status);
717 status = vfs_at_fspcwd(talloc_tos(), handle->conn, &fspcwd);
718 if (!NT_STATUS_IS_OK(status)) {
720 errno = map_errno_from_nt_status(status);
724 ret = SMB_VFS_NEXT_OPENAT(handle,
732 TALLOC_FREE(smb_fname_stream);
733 TALLOC_FREE(smb_fname_base);
738 static int streams_depot_unlink_internal(vfs_handle_struct *handle,
739 struct files_struct *dirfsp,
740 const struct smb_filename *smb_fname,
743 struct smb_filename *smb_fname_base = NULL;
746 DEBUG(10, ("streams_depot_unlink called for %s\n",
747 smb_fname_str_dbg(smb_fname)));
749 /* If there is a valid stream, just unlink the stream and return. */
750 if (is_named_stream(smb_fname)) {
751 struct smb_filename *smb_fname_stream = NULL;
754 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
756 if (!NT_STATUS_IS_OK(status)) {
757 errno = map_errno_from_nt_status(status);
761 ret = SMB_VFS_NEXT_UNLINKAT(handle,
766 TALLOC_FREE(smb_fname_stream);
771 * We potentially need to delete the per-inode streams directory
774 smb_fname_base = synthetic_smb_fname(talloc_tos(),
775 smb_fname->base_name,
780 if (smb_fname_base == NULL) {
785 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
786 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
788 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
792 TALLOC_FREE(smb_fname_base);
797 * We know the unlink should succeed as the ACL
798 * check is already done in the caller. Remove the
799 * file *after* the streams.
802 char *dirname = stream_dir(handle, smb_fname_base,
803 &smb_fname_base->st, false);
805 if (dirname != NULL) {
806 struct smb_filename *smb_fname_dir =
807 synthetic_smb_fname(talloc_tos(),
813 if (smb_fname_dir == NULL) {
814 TALLOC_FREE(smb_fname_base);
815 TALLOC_FREE(dirname);
819 SMB_VFS_NEXT_UNLINKAT(handle,
823 TALLOC_FREE(smb_fname_dir);
825 TALLOC_FREE(dirname);
828 ret = SMB_VFS_NEXT_UNLINKAT(handle,
832 TALLOC_FREE(smb_fname_base);
836 static int streams_depot_rmdir_internal(vfs_handle_struct *handle,
837 struct files_struct *dirfsp,
838 const struct smb_filename *smb_fname)
840 struct smb_filename *smb_fname_base = NULL;
843 DBG_DEBUG("called for %s\n", smb_fname->base_name);
846 * We potentially need to delete the per-inode streams directory
849 smb_fname_base = synthetic_smb_fname(talloc_tos(),
850 smb_fname->base_name,
855 if (smb_fname_base == NULL) {
860 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
861 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
863 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
867 TALLOC_FREE(smb_fname_base);
872 * We know the rmdir should succeed as the ACL
873 * check is already done in the caller. Remove the
874 * directory *after* the streams.
877 char *dirname = stream_dir(handle, smb_fname_base,
878 &smb_fname_base->st, false);
880 if (dirname != NULL) {
881 struct smb_filename *smb_fname_dir =
882 synthetic_smb_fname(talloc_tos(),
888 if (smb_fname_dir == NULL) {
889 TALLOC_FREE(smb_fname_base);
890 TALLOC_FREE(dirname);
894 SMB_VFS_NEXT_UNLINKAT(handle,
898 TALLOC_FREE(smb_fname_dir);
900 TALLOC_FREE(dirname);
903 ret = SMB_VFS_NEXT_UNLINKAT(handle,
907 TALLOC_FREE(smb_fname_base);
911 static int streams_depot_unlinkat(vfs_handle_struct *handle,
912 struct files_struct *dirfsp,
913 const struct smb_filename *smb_fname,
917 SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
918 if (flags & AT_REMOVEDIR) {
919 ret = streams_depot_rmdir_internal(handle,
923 ret = streams_depot_unlink_internal(handle,
931 static int streams_depot_renameat(vfs_handle_struct *handle,
932 files_struct *srcfsp,
933 const struct smb_filename *smb_fname_src,
934 files_struct *dstfsp,
935 const struct smb_filename *smb_fname_dst)
937 struct smb_filename *smb_fname_src_stream = NULL;
938 struct smb_filename *smb_fname_dst_stream = NULL;
939 bool src_is_stream, dst_is_stream;
943 DEBUG(10, ("streams_depot_renameat called for %s => %s\n",
944 smb_fname_str_dbg(smb_fname_src),
945 smb_fname_str_dbg(smb_fname_dst)));
947 src_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
948 dst_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
950 if (!src_is_stream && !dst_is_stream) {
951 return SMB_VFS_NEXT_RENAMEAT(handle,
958 /* for now don't allow renames from or to the default stream */
959 if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
960 is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
965 status = stream_smb_fname(handle, smb_fname_src, &smb_fname_src_stream,
967 if (!NT_STATUS_IS_OK(status)) {
968 errno = map_errno_from_nt_status(status);
972 status = stream_smb_fname(handle, smb_fname_dst,
973 &smb_fname_dst_stream, false);
974 if (!NT_STATUS_IS_OK(status)) {
975 errno = map_errno_from_nt_status(status);
979 ret = SMB_VFS_NEXT_RENAMEAT(handle,
981 smb_fname_src_stream,
983 smb_fname_dst_stream);
986 TALLOC_FREE(smb_fname_src_stream);
987 TALLOC_FREE(smb_fname_dst_stream);
991 static bool add_one_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
992 struct stream_struct **streams,
993 const char *name, off_t size,
996 struct stream_struct *tmp;
998 tmp = talloc_realloc(mem_ctx, *streams, struct stream_struct,
1004 tmp[*num_streams].name = talloc_strdup(tmp, name);
1005 if (tmp[*num_streams].name == NULL) {
1009 tmp[*num_streams].size = size;
1010 tmp[*num_streams].alloc_size = alloc_size;
1017 struct streaminfo_state {
1018 TALLOC_CTX *mem_ctx;
1019 vfs_handle_struct *handle;
1020 unsigned int num_streams;
1021 struct stream_struct *streams;
1025 static bool collect_one_stream(const struct smb_filename *dirfname,
1029 const char *dirname = dirfname->base_name;
1030 struct streaminfo_state *state =
1031 (struct streaminfo_state *)private_data;
1032 struct smb_filename *smb_fname = NULL;
1036 sname = talloc_asprintf(talloc_tos(), "%s/%s", dirname, dirent);
1037 if (sname == NULL) {
1038 state->status = NT_STATUS_NO_MEMORY;
1043 smb_fname = synthetic_smb_fname(talloc_tos(),
1049 if (smb_fname == NULL) {
1050 state->status = NT_STATUS_NO_MEMORY;
1055 if (SMB_VFS_NEXT_STAT(state->handle, smb_fname) == -1) {
1056 DEBUG(10, ("Could not stat %s: %s\n", sname,
1062 if (!add_one_stream(state->mem_ctx,
1063 &state->num_streams, &state->streams,
1064 dirent, smb_fname->st.st_ex_size,
1065 SMB_VFS_GET_ALLOC_SIZE(state->handle->conn, NULL,
1067 state->status = NT_STATUS_NO_MEMORY;
1075 TALLOC_FREE(smb_fname);
1079 static NTSTATUS streams_depot_streaminfo(vfs_handle_struct *handle,
1080 struct files_struct *fsp,
1081 const struct smb_filename *smb_fname,
1082 TALLOC_CTX *mem_ctx,
1083 unsigned int *pnum_streams,
1084 struct stream_struct **pstreams)
1086 struct smb_filename *smb_fname_base = NULL;
1089 struct streaminfo_state state;
1091 smb_fname_base = synthetic_smb_fname(talloc_tos(),
1092 smb_fname->base_name,
1097 if (smb_fname_base == NULL) {
1098 return NT_STATUS_NO_MEMORY;
1101 if ((fsp != NULL) && (fsp->fh->fd != -1)) {
1102 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, &smb_fname_base->st);
1105 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
1106 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
1108 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
1113 status = map_nt_error_from_unix(errno);
1117 state.streams = *pstreams;
1118 state.num_streams = *pnum_streams;
1119 state.mem_ctx = mem_ctx;
1120 state.handle = handle;
1121 state.status = NT_STATUS_OK;
1123 if (S_ISLNK(smb_fname_base->st.st_ex_mode)) {
1125 * Currently we do't have SMB_VFS_LLISTXATTR
1126 * inside the VFS which means there's no way
1127 * to cope with a symlink when lp_posix_pathnames().
1128 * returns true. For now ignore links.
1129 * FIXME - by adding SMB_VFS_LLISTXATTR. JRA.
1131 status = NT_STATUS_OK;
1133 status = walk_streams(handle, smb_fname_base, NULL, collect_one_stream,
1137 if (!NT_STATUS_IS_OK(status)) {
1138 TALLOC_FREE(state.streams);
1142 if (!NT_STATUS_IS_OK(state.status)) {
1143 TALLOC_FREE(state.streams);
1144 status = state.status;
1148 *pnum_streams = state.num_streams;
1149 *pstreams = state.streams;
1150 status = SMB_VFS_NEXT_STREAMINFO(handle,
1158 TALLOC_FREE(smb_fname_base);
1162 static uint32_t streams_depot_fs_capabilities(struct vfs_handle_struct *handle,
1163 enum timestamp_set_resolution *p_ts_res)
1165 return SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res) | FILE_NAMED_STREAMS;
1168 static struct vfs_fn_pointers vfs_streams_depot_fns = {
1169 .fs_capabilities_fn = streams_depot_fs_capabilities,
1170 .open_fn = streams_depot_open,
1171 .openat_fn = streams_depot_openat,
1172 .stat_fn = streams_depot_stat,
1173 .lstat_fn = streams_depot_lstat,
1174 .unlinkat_fn = streams_depot_unlinkat,
1175 .renameat_fn = streams_depot_renameat,
1176 .streaminfo_fn = streams_depot_streaminfo,
1180 NTSTATUS vfs_streams_depot_init(TALLOC_CTX *ctx)
1182 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "streams_depot",
1183 &vfs_streams_depot_fns);