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, const char *path)
74 DEBUG(10, ("file_is_valid (%s) called\n", path));
76 if (SMB_VFS_GETXATTR(handle->conn, path, SAMBA_XATTR_MARKER,
77 &buf, sizeof(buf)) != sizeof(buf)) {
78 DEBUG(10, ("GETXATTR failed: %s\n", strerror(errno)));
83 DEBUG(10, ("got wrong buffer content: '%c'\n", buf));
90 static bool mark_file_valid(vfs_handle_struct *handle,
91 const struct smb_filename *smb_fname)
96 DEBUG(10, ("marking file %s as valid\n", smb_fname->base_name));
98 ret = SMB_VFS_SETXATTR(handle->conn, smb_fname, SAMBA_XATTR_MARKER,
99 &buf, sizeof(buf), 0);
102 DEBUG(10, ("SETXATTR failed: %s\n", strerror(errno)));
110 * Given an smb_filename, determine the stream directory using the file's
113 static char *stream_dir(vfs_handle_struct *handle,
114 const struct smb_filename *smb_fname,
115 const SMB_STRUCT_STAT *base_sbuf, bool create_it)
118 struct smb_filename *smb_fname_hash = NULL;
120 SMB_STRUCT_STAT base_sbuf_tmp;
121 uint8_t first, second;
127 char *rootdir = NULL;
128 struct smb_filename *rootdir_fname = NULL;
129 struct smb_filename *tmp_fname = NULL;
131 check_valid = lp_parm_bool(SNUM(handle->conn),
132 "streams_depot", "check_valid", true);
134 tmp = talloc_asprintf(talloc_tos(), "%s/.streams",
135 handle->conn->connectpath);
142 rootdir = lp_parm_talloc_string(talloc_tos(),
143 SNUM(handle->conn), "streams_depot", "directory",
145 if (rootdir == NULL) {
150 rootdir_fname = synthetic_smb_fname(talloc_tos(),
155 if (rootdir_fname == NULL) {
160 /* Stat the base file if it hasn't already been done. */
161 if (base_sbuf == NULL) {
162 struct smb_filename *smb_fname_base;
164 smb_fname_base = synthetic_smb_fname(
166 smb_fname->base_name,
170 if (smb_fname_base == NULL) {
174 if (SMB_VFS_NEXT_STAT(handle, smb_fname_base) == -1) {
175 TALLOC_FREE(smb_fname_base);
178 base_sbuf_tmp = smb_fname_base->st;
179 TALLOC_FREE(smb_fname_base);
181 base_sbuf_tmp = *base_sbuf;
184 id = SMB_VFS_FILE_ID_CREATE(handle->conn, &base_sbuf_tmp);
186 push_file_id_16((char *)id_buf, &id);
188 hash = hash_fn(data_blob_const(id_buf, sizeof(id_buf)));
191 second = (hash >> 8) & 0xff;
193 id_hex = hex_encode_talloc(talloc_tos(), id_buf, sizeof(id_buf));
195 if (id_hex == NULL) {
200 result = talloc_asprintf(talloc_tos(), "%s/%2.2X/%2.2X/%s", rootdir,
201 first, second, id_hex);
205 if (result == NULL) {
210 smb_fname_hash = synthetic_smb_fname(talloc_tos(),
215 if (smb_fname_hash == NULL) {
220 if (SMB_VFS_NEXT_STAT(handle, smb_fname_hash) == 0) {
221 struct smb_filename *smb_fname_new = NULL;
225 if (!S_ISDIR(smb_fname_hash->st.st_ex_mode)) {
231 file_is_valid(handle, smb_fname->base_name)) {
236 * Someone has recreated a file under an existing inode
237 * without deleting the streams directory.
238 * Move it away or remove if streams_depot:delete_lost is set.
242 delete_lost = lp_parm_bool(SNUM(handle->conn), "streams_depot",
243 "delete_lost", false);
246 DEBUG(3, ("Someone has recreated a file under an "
247 "existing inode. Removing: %s\n",
248 smb_fname_hash->base_name));
249 recursive_rmdir(talloc_tos(), handle->conn,
251 SMB_VFS_NEXT_RMDIR(handle, smb_fname_hash);
253 newname = talloc_asprintf(talloc_tos(), "lost-%lu",
255 DEBUG(3, ("Someone has recreated a file under an "
256 "existing inode. Renaming: %s to: %s\n",
257 smb_fname_hash->base_name,
259 if (newname == NULL) {
264 smb_fname_new = synthetic_smb_fname(
270 TALLOC_FREE(newname);
271 if (smb_fname_new == NULL) {
276 if (SMB_VFS_NEXT_RENAME(handle, smb_fname_hash,
277 smb_fname_new) == -1) {
278 TALLOC_FREE(smb_fname_new);
279 if ((errno == EEXIST) || (errno == ENOTEMPTY)) {
285 TALLOC_FREE(smb_fname_new);
294 if ((SMB_VFS_NEXT_MKDIR(handle, rootdir_fname, 0755) != 0)
295 && (errno != EEXIST)) {
299 tmp = talloc_asprintf(result, "%s/%2.2X", rootdir, first);
305 tmp_fname = synthetic_smb_fname(talloc_tos(),
310 if (tmp_fname == NULL) {
315 if ((SMB_VFS_NEXT_MKDIR(handle, tmp_fname, 0755) != 0)
316 && (errno != EEXIST)) {
321 TALLOC_FREE(tmp_fname);
323 tmp = talloc_asprintf(result, "%s/%2.2X/%2.2X", rootdir, first,
330 tmp_fname = synthetic_smb_fname(talloc_tos(),
335 if (tmp_fname == NULL) {
340 if ((SMB_VFS_NEXT_MKDIR(handle, tmp_fname, 0755) != 0)
341 && (errno != EEXIST)) {
346 TALLOC_FREE(tmp_fname);
348 /* smb_fname_hash is the struct smb_filename version of 'result' */
349 if ((SMB_VFS_NEXT_MKDIR(handle, smb_fname_hash, 0755) != 0)
350 && (errno != EEXIST)) {
354 if (check_valid && !mark_file_valid(handle, smb_fname)) {
358 TALLOC_FREE(rootdir_fname);
359 TALLOC_FREE(rootdir);
360 TALLOC_FREE(tmp_fname);
361 TALLOC_FREE(smb_fname_hash);
365 TALLOC_FREE(rootdir_fname);
366 TALLOC_FREE(rootdir);
367 TALLOC_FREE(tmp_fname);
368 TALLOC_FREE(smb_fname_hash);
373 * Given a stream name, populate smb_fname_out with the actual location of the
376 static NTSTATUS stream_smb_fname(vfs_handle_struct *handle,
377 const struct smb_filename *smb_fname,
378 struct smb_filename **smb_fname_out,
381 char *dirname, *stream_fname;
385 *smb_fname_out = NULL;
387 stype = strchr_m(smb_fname->stream_name + 1, ':');
390 if (strcasecmp_m(stype, ":$DATA") != 0) {
391 return NT_STATUS_INVALID_PARAMETER;
395 dirname = stream_dir(handle, smb_fname, NULL, create_dir);
397 if (dirname == NULL) {
398 status = map_nt_error_from_unix(errno);
402 stream_fname = talloc_asprintf(talloc_tos(), "%s/%s", dirname,
403 smb_fname->stream_name);
405 if (stream_fname == NULL) {
406 status = NT_STATUS_NO_MEMORY;
411 /* Append an explicit stream type if one wasn't specified. */
412 stream_fname = talloc_asprintf(talloc_tos(), "%s:$DATA",
414 if (stream_fname == NULL) {
415 status = NT_STATUS_NO_MEMORY;
419 /* Normalize the stream type to upercase. */
420 if (!strupper_m(strrchr_m(stream_fname, ':') + 1)) {
421 status = NT_STATUS_INVALID_PARAMETER;
426 DEBUG(10, ("stream filename = %s\n", stream_fname));
428 /* Create an smb_filename with stream_name == NULL. */
429 *smb_fname_out = synthetic_smb_fname(talloc_tos(),
434 if (*smb_fname_out == NULL) {
435 return NT_STATUS_NO_MEMORY;
441 DEBUG(5, ("stream_name failed: %s\n", strerror(errno)));
442 TALLOC_FREE(*smb_fname_out);
446 static NTSTATUS walk_streams(vfs_handle_struct *handle,
447 struct smb_filename *smb_fname_base,
449 bool (*fn)(const char *dirname,
455 struct smb_filename *dir_smb_fname = NULL;
456 DIR *dirhandle = NULL;
457 const char *dirent = NULL;
458 char *talloced = NULL;
460 dirname = stream_dir(handle, smb_fname_base, &smb_fname_base->st,
463 if (dirname == NULL) {
464 if (errno == ENOENT) {
470 return map_nt_error_from_unix(errno);
473 DEBUG(10, ("walk_streams: dirname=%s\n", dirname));
475 dir_smb_fname = synthetic_smb_fname(talloc_tos(),
479 smb_fname_base->flags);
480 if (dir_smb_fname == NULL) {
481 TALLOC_FREE(dirname);
482 return NT_STATUS_NO_MEMORY;
485 dirhandle = SMB_VFS_NEXT_OPENDIR(handle, dir_smb_fname, NULL, 0);
487 TALLOC_FREE(dir_smb_fname);
489 if (dirhandle == NULL) {
490 TALLOC_FREE(dirname);
491 return map_nt_error_from_unix(errno);
494 while ((dirent = vfs_readdirname(handle->conn, dirhandle, NULL,
495 &talloced)) != NULL) {
497 if (ISDOT(dirent) || ISDOTDOT(dirent)) {
498 TALLOC_FREE(talloced);
502 DEBUG(10, ("walk_streams: dirent=%s\n", dirent));
504 if (!fn(dirname, dirent, private_data)) {
505 TALLOC_FREE(talloced);
508 TALLOC_FREE(talloced);
511 SMB_VFS_NEXT_CLOSEDIR(handle, dirhandle);
513 if (pdirname != NULL) {
517 TALLOC_FREE(dirname);
524 * Helper to stat/lstat the base file of an smb_fname. This will actually
525 * fills in the stat struct in smb_filename.
527 static int streams_depot_stat_base(vfs_handle_struct *handle,
528 struct smb_filename *smb_fname,
531 char *tmp_stream_name;
534 tmp_stream_name = smb_fname->stream_name;
535 smb_fname->stream_name = NULL;
537 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
539 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
541 smb_fname->stream_name = tmp_stream_name;
545 static int streams_depot_stat(vfs_handle_struct *handle,
546 struct smb_filename *smb_fname)
548 struct smb_filename *smb_fname_stream = NULL;
552 DEBUG(10, ("streams_depot_stat called for [%s]\n",
553 smb_fname_str_dbg(smb_fname)));
555 if (!is_ntfs_stream_smb_fname(smb_fname)) {
556 return SMB_VFS_NEXT_STAT(handle, smb_fname);
559 /* If the default stream is requested, just stat the base file. */
560 if (is_ntfs_default_stream_smb_fname(smb_fname)) {
561 return streams_depot_stat_base(handle, smb_fname, true);
564 /* Stat the actual stream now. */
565 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
567 if (!NT_STATUS_IS_OK(status)) {
569 errno = map_errno_from_nt_status(status);
573 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_stream);
575 /* Update the original smb_fname with the stat info. */
576 smb_fname->st = smb_fname_stream->st;
578 TALLOC_FREE(smb_fname_stream);
584 static int streams_depot_lstat(vfs_handle_struct *handle,
585 struct smb_filename *smb_fname)
587 struct smb_filename *smb_fname_stream = NULL;
591 DEBUG(10, ("streams_depot_lstat called for [%s]\n",
592 smb_fname_str_dbg(smb_fname)));
594 if (!is_ntfs_stream_smb_fname(smb_fname)) {
595 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
598 /* If the default stream is requested, just stat the base file. */
599 if (is_ntfs_default_stream_smb_fname(smb_fname)) {
600 return streams_depot_stat_base(handle, smb_fname, false);
603 /* Stat the actual stream now. */
604 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
606 if (!NT_STATUS_IS_OK(status)) {
608 errno = map_errno_from_nt_status(status);
612 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_stream);
615 TALLOC_FREE(smb_fname_stream);
619 static int streams_depot_open(vfs_handle_struct *handle,
620 struct smb_filename *smb_fname,
621 files_struct *fsp, int flags, mode_t mode)
623 struct smb_filename *smb_fname_stream = NULL;
624 struct smb_filename *smb_fname_base = NULL;
628 if (!is_ntfs_stream_smb_fname(smb_fname)) {
629 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
632 /* If the default stream is requested, just open the base file. */
633 if (is_ntfs_default_stream_smb_fname(smb_fname)) {
634 char *tmp_stream_name;
636 tmp_stream_name = smb_fname->stream_name;
637 smb_fname->stream_name = NULL;
638 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
639 smb_fname->stream_name = tmp_stream_name;
644 /* Ensure the base file still exists. */
645 smb_fname_base = synthetic_smb_fname(talloc_tos(),
646 smb_fname->base_name,
650 if (smb_fname_base == NULL) {
656 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
661 /* Determine the stream name, and then open it. */
662 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream, true);
663 if (!NT_STATUS_IS_OK(status)) {
665 errno = map_errno_from_nt_status(status);
669 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname_stream, fsp, flags, mode);
672 TALLOC_FREE(smb_fname_stream);
673 TALLOC_FREE(smb_fname_base);
677 static int streams_depot_unlink(vfs_handle_struct *handle,
678 const struct smb_filename *smb_fname)
680 struct smb_filename *smb_fname_base = NULL;
683 DEBUG(10, ("streams_depot_unlink called for %s\n",
684 smb_fname_str_dbg(smb_fname)));
686 /* If there is a valid stream, just unlink the stream and return. */
687 if (is_ntfs_stream_smb_fname(smb_fname) &&
688 !is_ntfs_default_stream_smb_fname(smb_fname)) {
689 struct smb_filename *smb_fname_stream = NULL;
692 status = stream_smb_fname(handle, smb_fname, &smb_fname_stream,
694 if (!NT_STATUS_IS_OK(status)) {
695 errno = map_errno_from_nt_status(status);
699 ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_stream);
701 TALLOC_FREE(smb_fname_stream);
706 * We potentially need to delete the per-inode streams directory
709 smb_fname_base = synthetic_smb_fname(talloc_tos(),
710 smb_fname->base_name,
714 if (smb_fname_base == NULL) {
719 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
720 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
722 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
726 TALLOC_FREE(smb_fname_base);
731 * We know the unlink should succeed as the ACL
732 * check is already done in the caller. Remove the
733 * file *after* the streams.
736 char *dirname = stream_dir(handle, smb_fname_base,
737 &smb_fname_base->st, false);
739 if (dirname != NULL) {
740 struct smb_filename *smb_fname_dir =
741 synthetic_smb_fname(talloc_tos(),
746 if (smb_fname_dir == NULL) {
747 TALLOC_FREE(smb_fname_base);
748 TALLOC_FREE(dirname);
752 SMB_VFS_NEXT_RMDIR(handle, smb_fname_dir);
753 TALLOC_FREE(smb_fname_dir);
755 TALLOC_FREE(dirname);
758 ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
759 TALLOC_FREE(smb_fname_base);
763 static int streams_depot_rmdir(vfs_handle_struct *handle,
764 const struct smb_filename *smb_fname)
766 struct smb_filename *smb_fname_base = NULL;
769 DEBUG(10, ("streams_depot_rmdir called for %s\n",
770 smb_fname->base_name));
773 * We potentially need to delete the per-inode streams directory
776 smb_fname_base = synthetic_smb_fname(talloc_tos(),
777 smb_fname->base_name,
781 if (smb_fname_base == NULL) {
786 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
787 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
789 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
793 TALLOC_FREE(smb_fname_base);
798 * We know the rmdir should succeed as the ACL
799 * check is already done in the caller. Remove the
800 * directory *after* the streams.
803 char *dirname = stream_dir(handle, smb_fname_base,
804 &smb_fname_base->st, false);
806 if (dirname != NULL) {
807 struct smb_filename *smb_fname_dir =
808 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_RMDIR(handle, smb_fname_dir);
820 TALLOC_FREE(smb_fname_dir);
822 TALLOC_FREE(dirname);
825 ret = SMB_VFS_NEXT_RMDIR(handle, smb_fname_base);
826 TALLOC_FREE(smb_fname_base);
830 static int streams_depot_rename(vfs_handle_struct *handle,
831 const struct smb_filename *smb_fname_src,
832 const struct smb_filename *smb_fname_dst)
834 struct smb_filename *smb_fname_src_stream = NULL;
835 struct smb_filename *smb_fname_dst_stream = NULL;
836 bool src_is_stream, dst_is_stream;
840 DEBUG(10, ("streams_depot_rename called for %s => %s\n",
841 smb_fname_str_dbg(smb_fname_src),
842 smb_fname_str_dbg(smb_fname_dst)));
844 src_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
845 dst_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
847 if (!src_is_stream && !dst_is_stream) {
848 return SMB_VFS_NEXT_RENAME(handle, smb_fname_src,
852 /* for now don't allow renames from or to the default stream */
853 if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
854 is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
859 status = stream_smb_fname(handle, smb_fname_src, &smb_fname_src_stream,
861 if (!NT_STATUS_IS_OK(status)) {
862 errno = map_errno_from_nt_status(status);
866 status = stream_smb_fname(handle, smb_fname_dst,
867 &smb_fname_dst_stream, false);
868 if (!NT_STATUS_IS_OK(status)) {
869 errno = map_errno_from_nt_status(status);
873 ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src_stream,
874 smb_fname_dst_stream);
877 TALLOC_FREE(smb_fname_src_stream);
878 TALLOC_FREE(smb_fname_dst_stream);
882 static bool add_one_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
883 struct stream_struct **streams,
884 const char *name, off_t size,
887 struct stream_struct *tmp;
889 tmp = talloc_realloc(mem_ctx, *streams, struct stream_struct,
895 tmp[*num_streams].name = talloc_strdup(tmp, name);
896 if (tmp[*num_streams].name == NULL) {
900 tmp[*num_streams].size = size;
901 tmp[*num_streams].alloc_size = alloc_size;
908 struct streaminfo_state {
910 vfs_handle_struct *handle;
911 unsigned int num_streams;
912 struct stream_struct *streams;
916 static bool collect_one_stream(const char *dirname,
920 struct streaminfo_state *state =
921 (struct streaminfo_state *)private_data;
922 struct smb_filename *smb_fname = NULL;
926 sname = talloc_asprintf(talloc_tos(), "%s/%s", dirname, dirent);
928 state->status = NT_STATUS_NO_MEMORY;
933 smb_fname = synthetic_smb_fname(talloc_tos(), sname, NULL, NULL, 0);
934 if (smb_fname == NULL) {
935 state->status = NT_STATUS_NO_MEMORY;
940 if (SMB_VFS_NEXT_STAT(state->handle, smb_fname) == -1) {
941 DEBUG(10, ("Could not stat %s: %s\n", sname,
947 if (!add_one_stream(state->mem_ctx,
948 &state->num_streams, &state->streams,
949 dirent, smb_fname->st.st_ex_size,
950 SMB_VFS_GET_ALLOC_SIZE(state->handle->conn, NULL,
952 state->status = NT_STATUS_NO_MEMORY;
960 TALLOC_FREE(smb_fname);
964 static NTSTATUS streams_depot_streaminfo(vfs_handle_struct *handle,
965 struct files_struct *fsp,
966 const struct smb_filename *smb_fname,
968 unsigned int *pnum_streams,
969 struct stream_struct **pstreams)
971 struct smb_filename *smb_fname_base = NULL;
974 struct streaminfo_state state;
976 smb_fname_base = synthetic_smb_fname(talloc_tos(),
977 smb_fname->base_name,
981 if (smb_fname_base == NULL) {
982 return NT_STATUS_NO_MEMORY;
985 if ((fsp != NULL) && (fsp->fh->fd != -1)) {
986 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, &smb_fname_base->st);
989 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
990 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname_base);
992 ret = SMB_VFS_NEXT_STAT(handle, smb_fname_base);
997 status = map_nt_error_from_unix(errno);
1001 state.streams = *pstreams;
1002 state.num_streams = *pnum_streams;
1003 state.mem_ctx = mem_ctx;
1004 state.handle = handle;
1005 state.status = NT_STATUS_OK;
1007 if (S_ISLNK(smb_fname_base->st.st_ex_mode)) {
1009 * Currently we do't have SMB_VFS_LLISTXATTR
1010 * inside the VFS which means there's no way
1011 * to cope with a symlink when lp_posix_pathnames().
1012 * returns true. For now ignore links.
1013 * FIXME - by adding SMB_VFS_LLISTXATTR. JRA.
1015 status = NT_STATUS_OK;
1017 status = walk_streams(handle, smb_fname_base, NULL, collect_one_stream,
1021 if (!NT_STATUS_IS_OK(status)) {
1022 TALLOC_FREE(state.streams);
1026 if (!NT_STATUS_IS_OK(state.status)) {
1027 TALLOC_FREE(state.streams);
1028 status = state.status;
1032 *pnum_streams = state.num_streams;
1033 *pstreams = state.streams;
1034 status = SMB_VFS_NEXT_STREAMINFO(handle,
1042 TALLOC_FREE(smb_fname_base);
1046 static uint32_t streams_depot_fs_capabilities(struct vfs_handle_struct *handle,
1047 enum timestamp_set_resolution *p_ts_res)
1049 return SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res) | FILE_NAMED_STREAMS;
1052 static struct vfs_fn_pointers vfs_streams_depot_fns = {
1053 .fs_capabilities_fn = streams_depot_fs_capabilities,
1054 .open_fn = streams_depot_open,
1055 .stat_fn = streams_depot_stat,
1056 .lstat_fn = streams_depot_lstat,
1057 .unlink_fn = streams_depot_unlink,
1058 .rmdir_fn = streams_depot_rmdir,
1059 .rename_fn = streams_depot_rename,
1060 .streaminfo_fn = streams_depot_streaminfo,
1063 NTSTATUS vfs_streams_depot_init(TALLOC_CTX *);
1064 NTSTATUS vfs_streams_depot_init(TALLOC_CTX *ctx)
1066 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "streams_depot",
1067 &vfs_streams_depot_fns);