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;
133 check_valid = lp_parm_bool(SNUM(handle->conn),
134 "streams_depot", "check_valid", true);
136 tmp = talloc_asprintf(talloc_tos(), "%s/.streams",
137 handle->conn->connectpath);
144 rootdir = lp_parm_talloc_string(talloc_tos(),
145 SNUM(handle->conn), "streams_depot", "directory",
147 if (rootdir == NULL) {
152 rootdir_fname = synthetic_smb_fname(talloc_tos(),
157 if (rootdir_fname == NULL) {
162 /* Stat the base file if it hasn't already been done. */
163 if (base_sbuf == NULL) {
164 struct smb_filename *smb_fname_base;
166 smb_fname_base = synthetic_smb_fname(
168 smb_fname->base_name,
172 if (smb_fname_base == NULL) {
176 if (SMB_VFS_NEXT_STAT(handle, smb_fname_base) == -1) {
177 TALLOC_FREE(smb_fname_base);
180 base_sbuf_tmp = smb_fname_base->st;
181 TALLOC_FREE(smb_fname_base);
183 base_sbuf_tmp = *base_sbuf;
186 id = SMB_VFS_FILE_ID_CREATE(handle->conn, &base_sbuf_tmp);
188 push_file_id_16((char *)id_buf, &id);
190 hash = hash_fn(data_blob_const(id_buf, sizeof(id_buf)));
193 second = (hash >> 8) & 0xff;
195 id_hex = hex_encode_talloc(talloc_tos(), id_buf, sizeof(id_buf));
197 if (id_hex == NULL) {
202 result = talloc_asprintf(talloc_tos(), "%s/%2.2X/%2.2X/%s", rootdir,
203 first, second, id_hex);
207 if (result == NULL) {
212 smb_fname_hash = synthetic_smb_fname(talloc_tos(),
217 if (smb_fname_hash == NULL) {
222 if (SMB_VFS_NEXT_STAT(handle, smb_fname_hash) == 0) {
223 struct smb_filename *smb_fname_new = NULL;
227 if (!S_ISDIR(smb_fname_hash->st.st_ex_mode)) {
233 file_is_valid(handle, smb_fname)) {
238 * Someone has recreated a file under an existing inode
239 * without deleting the streams directory.
240 * Move it away or remove if streams_depot:delete_lost is set.
244 delete_lost = lp_parm_bool(SNUM(handle->conn), "streams_depot",
245 "delete_lost", false);
248 DEBUG(3, ("Someone has recreated a file under an "
249 "existing inode. Removing: %s\n",
250 smb_fname_hash->base_name));
251 recursive_rmdir(talloc_tos(), handle->conn,
253 SMB_VFS_NEXT_RMDIR(handle, smb_fname_hash);
255 newname = talloc_asprintf(talloc_tos(), "lost-%lu",
257 DEBUG(3, ("Someone has recreated a file under an "
258 "existing inode. Renaming: %s to: %s\n",
259 smb_fname_hash->base_name,
261 if (newname == NULL) {
266 smb_fname_new = synthetic_smb_fname(
272 TALLOC_FREE(newname);
273 if (smb_fname_new == NULL) {
278 if (SMB_VFS_NEXT_RENAMEAT(handle,
279 handle->conn->cwd_fsp,
281 handle->conn->cwd_fsp,
282 smb_fname_new) == -1) {
283 TALLOC_FREE(smb_fname_new);
284 if ((errno == EEXIST) || (errno == ENOTEMPTY)) {
290 TALLOC_FREE(smb_fname_new);
299 ret = SMB_VFS_NEXT_MKDIRAT(handle,
300 handle->conn->cwd_fsp,
303 if ((ret != 0) && (errno != EEXIST)) {
307 tmp = talloc_asprintf(result, "%s/%2.2X", rootdir, first);
313 tmp_fname = synthetic_smb_fname(talloc_tos(),
318 if (tmp_fname == NULL) {
323 ret = SMB_VFS_NEXT_MKDIRAT(handle,
324 handle->conn->cwd_fsp,
327 if ((ret != 0) && (errno != EEXIST)) {
332 TALLOC_FREE(tmp_fname);
334 tmp = talloc_asprintf(result, "%s/%2.2X/%2.2X", rootdir, first,
341 tmp_fname = synthetic_smb_fname(talloc_tos(),
346 if (tmp_fname == NULL) {
351 ret = SMB_VFS_NEXT_MKDIRAT(handle,
352 handle->conn->cwd_fsp,
355 if ((ret != 0) && (errno != EEXIST)) {
360 TALLOC_FREE(tmp_fname);
362 /* smb_fname_hash is the struct smb_filename version of 'result' */
363 ret = SMB_VFS_NEXT_MKDIRAT(handle,
364 handle->conn->cwd_fsp,
367 if ((ret != 0) && (errno != EEXIST)) {
371 if (check_valid && !mark_file_valid(handle, smb_fname)) {
375 TALLOC_FREE(rootdir_fname);
376 TALLOC_FREE(rootdir);
377 TALLOC_FREE(tmp_fname);
378 TALLOC_FREE(smb_fname_hash);
382 TALLOC_FREE(rootdir_fname);
383 TALLOC_FREE(rootdir);
384 TALLOC_FREE(tmp_fname);
385 TALLOC_FREE(smb_fname_hash);
390 * Given a stream name, populate smb_fname_out with the actual location of the
393 static NTSTATUS stream_smb_fname(vfs_handle_struct *handle,
394 const struct smb_filename *smb_fname,
395 struct smb_filename **smb_fname_out,
398 char *dirname, *stream_fname;
402 *smb_fname_out = NULL;
404 stype = strchr_m(smb_fname->stream_name + 1, ':');
407 if (strcasecmp_m(stype, ":$DATA") != 0) {
408 return NT_STATUS_INVALID_PARAMETER;
412 dirname = stream_dir(handle, smb_fname, NULL, create_dir);
414 if (dirname == NULL) {
415 status = map_nt_error_from_unix(errno);
419 stream_fname = talloc_asprintf(talloc_tos(), "%s/%s", dirname,
420 smb_fname->stream_name);
422 if (stream_fname == NULL) {
423 status = NT_STATUS_NO_MEMORY;
428 /* Append an explicit stream type if one wasn't specified. */
429 stream_fname = talloc_asprintf(talloc_tos(), "%s:$DATA",
431 if (stream_fname == NULL) {
432 status = NT_STATUS_NO_MEMORY;
436 /* Normalize the stream type to upercase. */
437 if (!strupper_m(strrchr_m(stream_fname, ':') + 1)) {
438 status = NT_STATUS_INVALID_PARAMETER;
443 DEBUG(10, ("stream filename = %s\n", stream_fname));
445 /* Create an smb_filename with stream_name == NULL. */
446 *smb_fname_out = synthetic_smb_fname(talloc_tos(),
451 if (*smb_fname_out == NULL) {
452 return NT_STATUS_NO_MEMORY;
458 DEBUG(5, ("stream_name failed: %s\n", strerror(errno)));
459 TALLOC_FREE(*smb_fname_out);
463 static NTSTATUS walk_streams(vfs_handle_struct *handle,
464 struct smb_filename *smb_fname_base,
466 bool (*fn)(const char *dirname,
472 struct smb_filename *dir_smb_fname = NULL;
473 DIR *dirhandle = NULL;
474 const char *dirent = NULL;
475 char *talloced = NULL;
477 dirname = stream_dir(handle, smb_fname_base, &smb_fname_base->st,
480 if (dirname == NULL) {
481 if (errno == ENOENT) {
487 return map_nt_error_from_unix(errno);
490 DEBUG(10, ("walk_streams: dirname=%s\n", dirname));
492 dir_smb_fname = synthetic_smb_fname(talloc_tos(),
496 smb_fname_base->flags);
497 if (dir_smb_fname == NULL) {
498 TALLOC_FREE(dirname);
499 return NT_STATUS_NO_MEMORY;
502 dirhandle = SMB_VFS_NEXT_OPENDIR(handle, dir_smb_fname, NULL, 0);
504 TALLOC_FREE(dir_smb_fname);
506 if (dirhandle == NULL) {
507 TALLOC_FREE(dirname);
508 return map_nt_error_from_unix(errno);
511 while ((dirent = vfs_readdirname(handle->conn, dirhandle, NULL,
512 &talloced)) != NULL) {
514 if (ISDOT(dirent) || ISDOTDOT(dirent)) {
515 TALLOC_FREE(talloced);
519 DEBUG(10, ("walk_streams: dirent=%s\n", dirent));
521 if (!fn(dirname, dirent, private_data)) {
522 TALLOC_FREE(talloced);
525 TALLOC_FREE(talloced);
528 SMB_VFS_NEXT_CLOSEDIR(handle, dirhandle);
530 if (pdirname != NULL) {
534 TALLOC_FREE(dirname);
541 * Helper to stat/lstat the base file of an smb_fname. This will actually
542 * fills in the stat struct in smb_filename.
544 static int streams_depot_stat_base(vfs_handle_struct *handle,
545 struct smb_filename *smb_fname,
548 char *tmp_stream_name;
551 tmp_stream_name = smb_fname->stream_name;
552 smb_fname->stream_name = NULL;
554 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
556 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
558 smb_fname->stream_name = tmp_stream_name;
562 static int streams_depot_stat(vfs_handle_struct *handle,
563 struct smb_filename *smb_fname)
565 struct smb_filename *smb_fname_stream = NULL;
569 DEBUG(10, ("streams_depot_stat called for [%s]\n",
570 smb_fname_str_dbg(smb_fname)));
572 if (!is_ntfs_stream_smb_fname(smb_fname)) {
573 return SMB_VFS_NEXT_STAT(handle, smb_fname);
576 /* If the default stream is requested, just stat the base file. */
577 if (is_ntfs_default_stream_smb_fname(smb_fname)) {
578 return streams_depot_stat_base(handle, smb_fname, true);
581 /* Stat the actual stream now. */
582 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
584 if (!NT_STATUS_IS_OK(status)) {
586 errno = map_errno_from_nt_status(status);
590 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_stream);
592 /* Update the original smb_fname with the stat info. */
593 smb_fname->st = smb_fname_stream->st;
595 TALLOC_FREE(smb_fname_stream);
601 static int streams_depot_lstat(vfs_handle_struct *handle,
602 struct smb_filename *smb_fname)
604 struct smb_filename *smb_fname_stream = NULL;
608 DEBUG(10, ("streams_depot_lstat called for [%s]\n",
609 smb_fname_str_dbg(smb_fname)));
611 if (!is_ntfs_stream_smb_fname(smb_fname)) {
612 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
615 /* If the default stream is requested, just stat the base file. */
616 if (is_ntfs_default_stream_smb_fname(smb_fname)) {
617 return streams_depot_stat_base(handle, smb_fname, false);
620 /* Stat the actual stream now. */
621 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
623 if (!NT_STATUS_IS_OK(status)) {
625 errno = map_errno_from_nt_status(status);
629 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_stream);
632 TALLOC_FREE(smb_fname_stream);
636 static int streams_depot_open(vfs_handle_struct *handle,
637 struct smb_filename *smb_fname,
638 files_struct *fsp, int flags, mode_t mode)
640 struct smb_filename *smb_fname_stream = NULL;
641 struct smb_filename *smb_fname_base = NULL;
645 if (!is_ntfs_stream_smb_fname(smb_fname)) {
646 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
649 /* If the default stream is requested, just open the base file. */
650 if (is_ntfs_default_stream_smb_fname(smb_fname)) {
651 char *tmp_stream_name;
653 tmp_stream_name = smb_fname->stream_name;
654 smb_fname->stream_name = NULL;
655 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
656 smb_fname->stream_name = tmp_stream_name;
661 /* Ensure the base file still exists. */
662 smb_fname_base = synthetic_smb_fname(talloc_tos(),
663 smb_fname->base_name,
667 if (smb_fname_base == NULL) {
673 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
678 /* Determine the stream name, and then open it. */
679 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream, true);
680 if (!NT_STATUS_IS_OK(status)) {
682 errno = map_errno_from_nt_status(status);
686 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname_stream, fsp, flags, mode);
689 TALLOC_FREE(smb_fname_stream);
690 TALLOC_FREE(smb_fname_base);
694 static int streams_depot_unlink_internal(vfs_handle_struct *handle,
695 struct files_struct *dirfsp,
696 const struct smb_filename *smb_fname,
699 struct smb_filename *smb_fname_base = NULL;
702 DEBUG(10, ("streams_depot_unlink called for %s\n",
703 smb_fname_str_dbg(smb_fname)));
705 /* If there is a valid stream, just unlink the stream and return. */
706 if (is_ntfs_stream_smb_fname(smb_fname) &&
707 !is_ntfs_default_stream_smb_fname(smb_fname)) {
708 struct smb_filename *smb_fname_stream = NULL;
711 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
713 if (!NT_STATUS_IS_OK(status)) {
714 errno = map_errno_from_nt_status(status);
718 ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_stream);
720 TALLOC_FREE(smb_fname_stream);
725 * We potentially need to delete the per-inode streams directory
728 smb_fname_base = synthetic_smb_fname(talloc_tos(),
729 smb_fname->base_name,
733 if (smb_fname_base == NULL) {
738 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
739 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
741 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
745 TALLOC_FREE(smb_fname_base);
750 * We know the unlink should succeed as the ACL
751 * check is already done in the caller. Remove the
752 * file *after* the streams.
755 char *dirname = stream_dir(handle, smb_fname_base,
756 &smb_fname_base->st, false);
758 if (dirname != NULL) {
759 struct smb_filename *smb_fname_dir =
760 synthetic_smb_fname(talloc_tos(),
765 if (smb_fname_dir == NULL) {
766 TALLOC_FREE(smb_fname_base);
767 TALLOC_FREE(dirname);
771 SMB_VFS_NEXT_RMDIR(handle, smb_fname_dir);
772 TALLOC_FREE(smb_fname_dir);
774 TALLOC_FREE(dirname);
777 ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
778 TALLOC_FREE(smb_fname_base);
782 static int streams_depot_unlink(vfs_handle_struct *handle,
783 const struct smb_filename *smb_fname)
785 return streams_depot_unlink_internal(handle,
786 handle->conn->cwd_fsp,
791 static int streams_depot_rmdir(vfs_handle_struct *handle,
792 const struct smb_filename *smb_fname)
794 struct smb_filename *smb_fname_base = NULL;
797 DEBUG(10, ("streams_depot_rmdir called for %s\n",
798 smb_fname->base_name));
801 * We potentially need to delete the per-inode streams directory
804 smb_fname_base = synthetic_smb_fname(talloc_tos(),
805 smb_fname->base_name,
809 if (smb_fname_base == NULL) {
814 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
815 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
817 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
821 TALLOC_FREE(smb_fname_base);
826 * We know the rmdir should succeed as the ACL
827 * check is already done in the caller. Remove the
828 * directory *after* the streams.
831 char *dirname = stream_dir(handle, smb_fname_base,
832 &smb_fname_base->st, false);
834 if (dirname != NULL) {
835 struct smb_filename *smb_fname_dir =
836 synthetic_smb_fname(talloc_tos(),
841 if (smb_fname_dir == NULL) {
842 TALLOC_FREE(smb_fname_base);
843 TALLOC_FREE(dirname);
847 SMB_VFS_NEXT_RMDIR(handle, smb_fname_dir);
848 TALLOC_FREE(smb_fname_dir);
850 TALLOC_FREE(dirname);
853 ret = SMB_VFS_NEXT_RMDIR(handle, smb_fname_base);
854 TALLOC_FREE(smb_fname_base);
858 static int streams_depot_unlinkat(vfs_handle_struct *handle,
859 struct files_struct *dirfsp,
860 const struct smb_filename *smb_fname,
864 SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
865 if (flags & AT_REMOVEDIR) {
866 ret = streams_depot_rmdir(handle, smb_fname);
868 ret = streams_depot_unlink_internal(handle,
876 static int streams_depot_renameat(vfs_handle_struct *handle,
877 files_struct *srcfsp,
878 const struct smb_filename *smb_fname_src,
879 files_struct *dstfsp,
880 const struct smb_filename *smb_fname_dst)
882 struct smb_filename *smb_fname_src_stream = NULL;
883 struct smb_filename *smb_fname_dst_stream = NULL;
884 bool src_is_stream, dst_is_stream;
888 DEBUG(10, ("streams_depot_renameat called for %s => %s\n",
889 smb_fname_str_dbg(smb_fname_src),
890 smb_fname_str_dbg(smb_fname_dst)));
892 src_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
893 dst_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
895 if (!src_is_stream && !dst_is_stream) {
896 return SMB_VFS_NEXT_RENAMEAT(handle,
903 /* for now don't allow renames from or to the default stream */
904 if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
905 is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
910 status = stream_smb_fname(handle, smb_fname_src, &smb_fname_src_stream,
912 if (!NT_STATUS_IS_OK(status)) {
913 errno = map_errno_from_nt_status(status);
917 status = stream_smb_fname(handle, smb_fname_dst,
918 &smb_fname_dst_stream, false);
919 if (!NT_STATUS_IS_OK(status)) {
920 errno = map_errno_from_nt_status(status);
924 ret = SMB_VFS_NEXT_RENAMEAT(handle,
926 smb_fname_src_stream,
928 smb_fname_dst_stream);
931 TALLOC_FREE(smb_fname_src_stream);
932 TALLOC_FREE(smb_fname_dst_stream);
936 static bool add_one_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
937 struct stream_struct **streams,
938 const char *name, off_t size,
941 struct stream_struct *tmp;
943 tmp = talloc_realloc(mem_ctx, *streams, struct stream_struct,
949 tmp[*num_streams].name = talloc_strdup(tmp, name);
950 if (tmp[*num_streams].name == NULL) {
954 tmp[*num_streams].size = size;
955 tmp[*num_streams].alloc_size = alloc_size;
962 struct streaminfo_state {
964 vfs_handle_struct *handle;
965 unsigned int num_streams;
966 struct stream_struct *streams;
970 static bool collect_one_stream(const char *dirname,
974 struct streaminfo_state *state =
975 (struct streaminfo_state *)private_data;
976 struct smb_filename *smb_fname = NULL;
980 sname = talloc_asprintf(talloc_tos(), "%s/%s", dirname, dirent);
982 state->status = NT_STATUS_NO_MEMORY;
987 smb_fname = synthetic_smb_fname(talloc_tos(), sname, NULL, NULL, 0);
988 if (smb_fname == NULL) {
989 state->status = NT_STATUS_NO_MEMORY;
994 if (SMB_VFS_NEXT_STAT(state->handle, smb_fname) == -1) {
995 DEBUG(10, ("Could not stat %s: %s\n", sname,
1001 if (!add_one_stream(state->mem_ctx,
1002 &state->num_streams, &state->streams,
1003 dirent, smb_fname->st.st_ex_size,
1004 SMB_VFS_GET_ALLOC_SIZE(state->handle->conn, NULL,
1006 state->status = NT_STATUS_NO_MEMORY;
1014 TALLOC_FREE(smb_fname);
1018 static NTSTATUS streams_depot_streaminfo(vfs_handle_struct *handle,
1019 struct files_struct *fsp,
1020 const struct smb_filename *smb_fname,
1021 TALLOC_CTX *mem_ctx,
1022 unsigned int *pnum_streams,
1023 struct stream_struct **pstreams)
1025 struct smb_filename *smb_fname_base = NULL;
1028 struct streaminfo_state state;
1030 smb_fname_base = synthetic_smb_fname(talloc_tos(),
1031 smb_fname->base_name,
1035 if (smb_fname_base == NULL) {
1036 return NT_STATUS_NO_MEMORY;
1039 if ((fsp != NULL) && (fsp->fh->fd != -1)) {
1040 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, &smb_fname_base->st);
1043 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
1044 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
1046 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
1051 status = map_nt_error_from_unix(errno);
1055 state.streams = *pstreams;
1056 state.num_streams = *pnum_streams;
1057 state.mem_ctx = mem_ctx;
1058 state.handle = handle;
1059 state.status = NT_STATUS_OK;
1061 if (S_ISLNK(smb_fname_base->st.st_ex_mode)) {
1063 * Currently we do't have SMB_VFS_LLISTXATTR
1064 * inside the VFS which means there's no way
1065 * to cope with a symlink when lp_posix_pathnames().
1066 * returns true. For now ignore links.
1067 * FIXME - by adding SMB_VFS_LLISTXATTR. JRA.
1069 status = NT_STATUS_OK;
1071 status = walk_streams(handle, smb_fname_base, NULL, collect_one_stream,
1075 if (!NT_STATUS_IS_OK(status)) {
1076 TALLOC_FREE(state.streams);
1080 if (!NT_STATUS_IS_OK(state.status)) {
1081 TALLOC_FREE(state.streams);
1082 status = state.status;
1086 *pnum_streams = state.num_streams;
1087 *pstreams = state.streams;
1088 status = SMB_VFS_NEXT_STREAMINFO(handle,
1096 TALLOC_FREE(smb_fname_base);
1100 static uint32_t streams_depot_fs_capabilities(struct vfs_handle_struct *handle,
1101 enum timestamp_set_resolution *p_ts_res)
1103 return SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res) | FILE_NAMED_STREAMS;
1106 static struct vfs_fn_pointers vfs_streams_depot_fns = {
1107 .fs_capabilities_fn = streams_depot_fs_capabilities,
1108 .open_fn = streams_depot_open,
1109 .stat_fn = streams_depot_stat,
1110 .lstat_fn = streams_depot_lstat,
1111 .unlink_fn = streams_depot_unlink,
1112 .unlinkat_fn = streams_depot_unlinkat,
1113 .rmdir_fn = streams_depot_rmdir,
1114 .renameat_fn = streams_depot_renameat,
1115 .streaminfo_fn = streams_depot_streaminfo,
1119 NTSTATUS vfs_streams_depot_init(TALLOC_CTX *ctx)
1121 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "streams_depot",
1122 &vfs_streams_depot_fns);