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)
119 struct smb_filename *smb_fname_hash = NULL;
121 SMB_STRUCT_STAT base_sbuf_tmp;
122 uint8_t first, second;
128 char *rootdir = NULL;
129 struct smb_filename *rootdir_fname = NULL;
130 struct smb_filename *tmp_fname = NULL;
132 check_valid = lp_parm_bool(SNUM(handle->conn),
133 "streams_depot", "check_valid", true);
135 tmp = talloc_asprintf(talloc_tos(), "%s/.streams",
136 handle->conn->connectpath);
143 rootdir = lp_parm_talloc_string(talloc_tos(),
144 SNUM(handle->conn), "streams_depot", "directory",
146 if (rootdir == NULL) {
151 rootdir_fname = synthetic_smb_fname(talloc_tos(),
156 if (rootdir_fname == NULL) {
161 /* Stat the base file if it hasn't already been done. */
162 if (base_sbuf == NULL) {
163 struct smb_filename *smb_fname_base;
165 smb_fname_base = synthetic_smb_fname(
167 smb_fname->base_name,
171 if (smb_fname_base == NULL) {
175 if (SMB_VFS_NEXT_STAT(handle, smb_fname_base) == -1) {
176 TALLOC_FREE(smb_fname_base);
179 base_sbuf_tmp = smb_fname_base->st;
180 TALLOC_FREE(smb_fname_base);
182 base_sbuf_tmp = *base_sbuf;
185 id = SMB_VFS_FILE_ID_CREATE(handle->conn, &base_sbuf_tmp);
187 push_file_id_16((char *)id_buf, &id);
189 hash = hash_fn(data_blob_const(id_buf, sizeof(id_buf)));
192 second = (hash >> 8) & 0xff;
194 id_hex = hex_encode_talloc(talloc_tos(), id_buf, sizeof(id_buf));
196 if (id_hex == NULL) {
201 result = talloc_asprintf(talloc_tos(), "%s/%2.2X/%2.2X/%s", rootdir,
202 first, second, id_hex);
206 if (result == NULL) {
211 smb_fname_hash = synthetic_smb_fname(talloc_tos(),
216 if (smb_fname_hash == NULL) {
221 if (SMB_VFS_NEXT_STAT(handle, smb_fname_hash) == 0) {
222 struct smb_filename *smb_fname_new = NULL;
226 if (!S_ISDIR(smb_fname_hash->st.st_ex_mode)) {
232 file_is_valid(handle, smb_fname)) {
237 * Someone has recreated a file under an existing inode
238 * without deleting the streams directory.
239 * Move it away or remove if streams_depot:delete_lost is set.
243 delete_lost = lp_parm_bool(SNUM(handle->conn), "streams_depot",
244 "delete_lost", false);
247 DEBUG(3, ("Someone has recreated a file under an "
248 "existing inode. Removing: %s\n",
249 smb_fname_hash->base_name));
250 recursive_rmdir(talloc_tos(), handle->conn,
252 SMB_VFS_NEXT_RMDIR(handle, smb_fname_hash);
254 newname = talloc_asprintf(talloc_tos(), "lost-%lu",
256 DEBUG(3, ("Someone has recreated a file under an "
257 "existing inode. Renaming: %s to: %s\n",
258 smb_fname_hash->base_name,
260 if (newname == NULL) {
265 smb_fname_new = synthetic_smb_fname(
271 TALLOC_FREE(newname);
272 if (smb_fname_new == NULL) {
277 if (SMB_VFS_NEXT_RENAMEAT(handle,
278 handle->conn->cwd_fsp,
280 handle->conn->cwd_fsp,
281 smb_fname_new) == -1) {
282 TALLOC_FREE(smb_fname_new);
283 if ((errno == EEXIST) || (errno == ENOTEMPTY)) {
289 TALLOC_FREE(smb_fname_new);
298 if ((SMB_VFS_NEXT_MKDIR(handle, rootdir_fname, 0755) != 0)
299 && (errno != EEXIST)) {
303 tmp = talloc_asprintf(result, "%s/%2.2X", rootdir, first);
309 tmp_fname = synthetic_smb_fname(talloc_tos(),
314 if (tmp_fname == NULL) {
319 if ((SMB_VFS_NEXT_MKDIR(handle, tmp_fname, 0755) != 0)
320 && (errno != EEXIST)) {
325 TALLOC_FREE(tmp_fname);
327 tmp = talloc_asprintf(result, "%s/%2.2X/%2.2X", rootdir, first,
334 tmp_fname = synthetic_smb_fname(talloc_tos(),
339 if (tmp_fname == NULL) {
344 if ((SMB_VFS_NEXT_MKDIR(handle, tmp_fname, 0755) != 0)
345 && (errno != EEXIST)) {
350 TALLOC_FREE(tmp_fname);
352 /* smb_fname_hash is the struct smb_filename version of 'result' */
353 if ((SMB_VFS_NEXT_MKDIR(handle, smb_fname_hash, 0755) != 0)
354 && (errno != EEXIST)) {
358 if (check_valid && !mark_file_valid(handle, smb_fname)) {
362 TALLOC_FREE(rootdir_fname);
363 TALLOC_FREE(rootdir);
364 TALLOC_FREE(tmp_fname);
365 TALLOC_FREE(smb_fname_hash);
369 TALLOC_FREE(rootdir_fname);
370 TALLOC_FREE(rootdir);
371 TALLOC_FREE(tmp_fname);
372 TALLOC_FREE(smb_fname_hash);
377 * Given a stream name, populate smb_fname_out with the actual location of the
380 static NTSTATUS stream_smb_fname(vfs_handle_struct *handle,
381 const struct smb_filename *smb_fname,
382 struct smb_filename **smb_fname_out,
385 char *dirname, *stream_fname;
389 *smb_fname_out = NULL;
391 stype = strchr_m(smb_fname->stream_name + 1, ':');
394 if (strcasecmp_m(stype, ":$DATA") != 0) {
395 return NT_STATUS_INVALID_PARAMETER;
399 dirname = stream_dir(handle, smb_fname, NULL, create_dir);
401 if (dirname == NULL) {
402 status = map_nt_error_from_unix(errno);
406 stream_fname = talloc_asprintf(talloc_tos(), "%s/%s", dirname,
407 smb_fname->stream_name);
409 if (stream_fname == NULL) {
410 status = NT_STATUS_NO_MEMORY;
415 /* Append an explicit stream type if one wasn't specified. */
416 stream_fname = talloc_asprintf(talloc_tos(), "%s:$DATA",
418 if (stream_fname == NULL) {
419 status = NT_STATUS_NO_MEMORY;
423 /* Normalize the stream type to upercase. */
424 if (!strupper_m(strrchr_m(stream_fname, ':') + 1)) {
425 status = NT_STATUS_INVALID_PARAMETER;
430 DEBUG(10, ("stream filename = %s\n", stream_fname));
432 /* Create an smb_filename with stream_name == NULL. */
433 *smb_fname_out = synthetic_smb_fname(talloc_tos(),
438 if (*smb_fname_out == NULL) {
439 return NT_STATUS_NO_MEMORY;
445 DEBUG(5, ("stream_name failed: %s\n", strerror(errno)));
446 TALLOC_FREE(*smb_fname_out);
450 static NTSTATUS walk_streams(vfs_handle_struct *handle,
451 struct smb_filename *smb_fname_base,
453 bool (*fn)(const char *dirname,
459 struct smb_filename *dir_smb_fname = NULL;
460 DIR *dirhandle = NULL;
461 const char *dirent = NULL;
462 char *talloced = NULL;
464 dirname = stream_dir(handle, smb_fname_base, &smb_fname_base->st,
467 if (dirname == NULL) {
468 if (errno == ENOENT) {
474 return map_nt_error_from_unix(errno);
477 DEBUG(10, ("walk_streams: dirname=%s\n", dirname));
479 dir_smb_fname = synthetic_smb_fname(talloc_tos(),
483 smb_fname_base->flags);
484 if (dir_smb_fname == NULL) {
485 TALLOC_FREE(dirname);
486 return NT_STATUS_NO_MEMORY;
489 dirhandle = SMB_VFS_NEXT_OPENDIR(handle, dir_smb_fname, NULL, 0);
491 TALLOC_FREE(dir_smb_fname);
493 if (dirhandle == NULL) {
494 TALLOC_FREE(dirname);
495 return map_nt_error_from_unix(errno);
498 while ((dirent = vfs_readdirname(handle->conn, dirhandle, NULL,
499 &talloced)) != NULL) {
501 if (ISDOT(dirent) || ISDOTDOT(dirent)) {
502 TALLOC_FREE(talloced);
506 DEBUG(10, ("walk_streams: dirent=%s\n", dirent));
508 if (!fn(dirname, dirent, private_data)) {
509 TALLOC_FREE(talloced);
512 TALLOC_FREE(talloced);
515 SMB_VFS_NEXT_CLOSEDIR(handle, dirhandle);
517 if (pdirname != NULL) {
521 TALLOC_FREE(dirname);
528 * Helper to stat/lstat the base file of an smb_fname. This will actually
529 * fills in the stat struct in smb_filename.
531 static int streams_depot_stat_base(vfs_handle_struct *handle,
532 struct smb_filename *smb_fname,
535 char *tmp_stream_name;
538 tmp_stream_name = smb_fname->stream_name;
539 smb_fname->stream_name = NULL;
541 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
543 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
545 smb_fname->stream_name = tmp_stream_name;
549 static int streams_depot_stat(vfs_handle_struct *handle,
550 struct smb_filename *smb_fname)
552 struct smb_filename *smb_fname_stream = NULL;
556 DEBUG(10, ("streams_depot_stat called for [%s]\n",
557 smb_fname_str_dbg(smb_fname)));
559 if (!is_ntfs_stream_smb_fname(smb_fname)) {
560 return SMB_VFS_NEXT_STAT(handle, smb_fname);
563 /* If the default stream is requested, just stat the base file. */
564 if (is_ntfs_default_stream_smb_fname(smb_fname)) {
565 return streams_depot_stat_base(handle, smb_fname, true);
568 /* Stat the actual stream now. */
569 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
571 if (!NT_STATUS_IS_OK(status)) {
573 errno = map_errno_from_nt_status(status);
577 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_stream);
579 /* Update the original smb_fname with the stat info. */
580 smb_fname->st = smb_fname_stream->st;
582 TALLOC_FREE(smb_fname_stream);
588 static int streams_depot_lstat(vfs_handle_struct *handle,
589 struct smb_filename *smb_fname)
591 struct smb_filename *smb_fname_stream = NULL;
595 DEBUG(10, ("streams_depot_lstat called for [%s]\n",
596 smb_fname_str_dbg(smb_fname)));
598 if (!is_ntfs_stream_smb_fname(smb_fname)) {
599 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
602 /* If the default stream is requested, just stat the base file. */
603 if (is_ntfs_default_stream_smb_fname(smb_fname)) {
604 return streams_depot_stat_base(handle, smb_fname, false);
607 /* Stat the actual stream now. */
608 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
610 if (!NT_STATUS_IS_OK(status)) {
612 errno = map_errno_from_nt_status(status);
616 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_stream);
619 TALLOC_FREE(smb_fname_stream);
623 static int streams_depot_open(vfs_handle_struct *handle,
624 struct smb_filename *smb_fname,
625 files_struct *fsp, int flags, mode_t mode)
627 struct smb_filename *smb_fname_stream = NULL;
628 struct smb_filename *smb_fname_base = NULL;
632 if (!is_ntfs_stream_smb_fname(smb_fname)) {
633 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
636 /* If the default stream is requested, just open the base file. */
637 if (is_ntfs_default_stream_smb_fname(smb_fname)) {
638 char *tmp_stream_name;
640 tmp_stream_name = smb_fname->stream_name;
641 smb_fname->stream_name = NULL;
642 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
643 smb_fname->stream_name = tmp_stream_name;
648 /* Ensure the base file still exists. */
649 smb_fname_base = synthetic_smb_fname(talloc_tos(),
650 smb_fname->base_name,
654 if (smb_fname_base == NULL) {
660 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
665 /* Determine the stream name, and then open it. */
666 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream, true);
667 if (!NT_STATUS_IS_OK(status)) {
669 errno = map_errno_from_nt_status(status);
673 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname_stream, fsp, flags, mode);
676 TALLOC_FREE(smb_fname_stream);
677 TALLOC_FREE(smb_fname_base);
681 static int streams_depot_unlink(vfs_handle_struct *handle,
682 const struct smb_filename *smb_fname)
684 struct smb_filename *smb_fname_base = NULL;
687 DEBUG(10, ("streams_depot_unlink called for %s\n",
688 smb_fname_str_dbg(smb_fname)));
690 /* If there is a valid stream, just unlink the stream and return. */
691 if (is_ntfs_stream_smb_fname(smb_fname) &&
692 !is_ntfs_default_stream_smb_fname(smb_fname)) {
693 struct smb_filename *smb_fname_stream = NULL;
696 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
698 if (!NT_STATUS_IS_OK(status)) {
699 errno = map_errno_from_nt_status(status);
703 ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_stream);
705 TALLOC_FREE(smb_fname_stream);
710 * We potentially need to delete the per-inode streams directory
713 smb_fname_base = synthetic_smb_fname(talloc_tos(),
714 smb_fname->base_name,
718 if (smb_fname_base == NULL) {
723 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
724 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
726 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
730 TALLOC_FREE(smb_fname_base);
735 * We know the unlink should succeed as the ACL
736 * check is already done in the caller. Remove the
737 * file *after* the streams.
740 char *dirname = stream_dir(handle, smb_fname_base,
741 &smb_fname_base->st, false);
743 if (dirname != NULL) {
744 struct smb_filename *smb_fname_dir =
745 synthetic_smb_fname(talloc_tos(),
750 if (smb_fname_dir == NULL) {
751 TALLOC_FREE(smb_fname_base);
752 TALLOC_FREE(dirname);
756 SMB_VFS_NEXT_RMDIR(handle, smb_fname_dir);
757 TALLOC_FREE(smb_fname_dir);
759 TALLOC_FREE(dirname);
762 ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
763 TALLOC_FREE(smb_fname_base);
767 static int streams_depot_rmdir(vfs_handle_struct *handle,
768 const struct smb_filename *smb_fname)
770 struct smb_filename *smb_fname_base = NULL;
773 DEBUG(10, ("streams_depot_rmdir called for %s\n",
774 smb_fname->base_name));
777 * We potentially need to delete the per-inode streams directory
780 smb_fname_base = synthetic_smb_fname(talloc_tos(),
781 smb_fname->base_name,
785 if (smb_fname_base == NULL) {
790 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
791 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
793 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
797 TALLOC_FREE(smb_fname_base);
802 * We know the rmdir should succeed as the ACL
803 * check is already done in the caller. Remove the
804 * directory *after* the streams.
807 char *dirname = stream_dir(handle, smb_fname_base,
808 &smb_fname_base->st, false);
810 if (dirname != NULL) {
811 struct smb_filename *smb_fname_dir =
812 synthetic_smb_fname(talloc_tos(),
817 if (smb_fname_dir == NULL) {
818 TALLOC_FREE(smb_fname_base);
819 TALLOC_FREE(dirname);
823 SMB_VFS_NEXT_RMDIR(handle, smb_fname_dir);
824 TALLOC_FREE(smb_fname_dir);
826 TALLOC_FREE(dirname);
829 ret = SMB_VFS_NEXT_RMDIR(handle, smb_fname_base);
830 TALLOC_FREE(smb_fname_base);
834 static int streams_depot_renameat(vfs_handle_struct *handle,
835 files_struct *srcfsp,
836 const struct smb_filename *smb_fname_src,
837 files_struct *dstfsp,
838 const struct smb_filename *smb_fname_dst)
840 struct smb_filename *smb_fname_src_stream = NULL;
841 struct smb_filename *smb_fname_dst_stream = NULL;
842 bool src_is_stream, dst_is_stream;
846 DEBUG(10, ("streams_depot_renameat called for %s => %s\n",
847 smb_fname_str_dbg(smb_fname_src),
848 smb_fname_str_dbg(smb_fname_dst)));
850 src_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
851 dst_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
853 if (!src_is_stream && !dst_is_stream) {
854 return SMB_VFS_NEXT_RENAMEAT(handle,
861 /* for now don't allow renames from or to the default stream */
862 if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
863 is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
868 status = stream_smb_fname(handle, smb_fname_src, &smb_fname_src_stream,
870 if (!NT_STATUS_IS_OK(status)) {
871 errno = map_errno_from_nt_status(status);
875 status = stream_smb_fname(handle, smb_fname_dst,
876 &smb_fname_dst_stream, false);
877 if (!NT_STATUS_IS_OK(status)) {
878 errno = map_errno_from_nt_status(status);
882 ret = SMB_VFS_NEXT_RENAMEAT(handle,
884 smb_fname_src_stream,
886 smb_fname_dst_stream);
889 TALLOC_FREE(smb_fname_src_stream);
890 TALLOC_FREE(smb_fname_dst_stream);
894 static bool add_one_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
895 struct stream_struct **streams,
896 const char *name, off_t size,
899 struct stream_struct *tmp;
901 tmp = talloc_realloc(mem_ctx, *streams, struct stream_struct,
907 tmp[*num_streams].name = talloc_strdup(tmp, name);
908 if (tmp[*num_streams].name == NULL) {
912 tmp[*num_streams].size = size;
913 tmp[*num_streams].alloc_size = alloc_size;
920 struct streaminfo_state {
922 vfs_handle_struct *handle;
923 unsigned int num_streams;
924 struct stream_struct *streams;
928 static bool collect_one_stream(const char *dirname,
932 struct streaminfo_state *state =
933 (struct streaminfo_state *)private_data;
934 struct smb_filename *smb_fname = NULL;
938 sname = talloc_asprintf(talloc_tos(), "%s/%s", dirname, dirent);
940 state->status = NT_STATUS_NO_MEMORY;
945 smb_fname = synthetic_smb_fname(talloc_tos(), sname, NULL, NULL, 0);
946 if (smb_fname == NULL) {
947 state->status = NT_STATUS_NO_MEMORY;
952 if (SMB_VFS_NEXT_STAT(state->handle, smb_fname) == -1) {
953 DEBUG(10, ("Could not stat %s: %s\n", sname,
959 if (!add_one_stream(state->mem_ctx,
960 &state->num_streams, &state->streams,
961 dirent, smb_fname->st.st_ex_size,
962 SMB_VFS_GET_ALLOC_SIZE(state->handle->conn, NULL,
964 state->status = NT_STATUS_NO_MEMORY;
972 TALLOC_FREE(smb_fname);
976 static NTSTATUS streams_depot_streaminfo(vfs_handle_struct *handle,
977 struct files_struct *fsp,
978 const struct smb_filename *smb_fname,
980 unsigned int *pnum_streams,
981 struct stream_struct **pstreams)
983 struct smb_filename *smb_fname_base = NULL;
986 struct streaminfo_state state;
988 smb_fname_base = synthetic_smb_fname(talloc_tos(),
989 smb_fname->base_name,
993 if (smb_fname_base == NULL) {
994 return NT_STATUS_NO_MEMORY;
997 if ((fsp != NULL) && (fsp->fh->fd != -1)) {
998 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, &smb_fname_base->st);
1001 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
1002 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
1004 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
1009 status = map_nt_error_from_unix(errno);
1013 state.streams = *pstreams;
1014 state.num_streams = *pnum_streams;
1015 state.mem_ctx = mem_ctx;
1016 state.handle = handle;
1017 state.status = NT_STATUS_OK;
1019 if (S_ISLNK(smb_fname_base->st.st_ex_mode)) {
1021 * Currently we do't have SMB_VFS_LLISTXATTR
1022 * inside the VFS which means there's no way
1023 * to cope with a symlink when lp_posix_pathnames().
1024 * returns true. For now ignore links.
1025 * FIXME - by adding SMB_VFS_LLISTXATTR. JRA.
1027 status = NT_STATUS_OK;
1029 status = walk_streams(handle, smb_fname_base, NULL, collect_one_stream,
1033 if (!NT_STATUS_IS_OK(status)) {
1034 TALLOC_FREE(state.streams);
1038 if (!NT_STATUS_IS_OK(state.status)) {
1039 TALLOC_FREE(state.streams);
1040 status = state.status;
1044 *pnum_streams = state.num_streams;
1045 *pstreams = state.streams;
1046 status = SMB_VFS_NEXT_STREAMINFO(handle,
1054 TALLOC_FREE(smb_fname_base);
1058 static uint32_t streams_depot_fs_capabilities(struct vfs_handle_struct *handle,
1059 enum timestamp_set_resolution *p_ts_res)
1061 return SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res) | FILE_NAMED_STREAMS;
1064 static struct vfs_fn_pointers vfs_streams_depot_fns = {
1065 .fs_capabilities_fn = streams_depot_fs_capabilities,
1066 .open_fn = streams_depot_open,
1067 .stat_fn = streams_depot_stat,
1068 .lstat_fn = streams_depot_lstat,
1069 .unlink_fn = streams_depot_unlink,
1070 .rmdir_fn = streams_depot_rmdir,
1071 .renameat_fn = streams_depot_renameat,
1072 .streaminfo_fn = streams_depot_streaminfo,
1076 NTSTATUS vfs_streams_depot_init(TALLOC_CTX *ctx)
1078 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "streams_depot",
1079 &vfs_streams_depot_fns);