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
, const char *path
)
95 DEBUG(10, ("marking file %s as valid\n", path
));
97 ret
= SMB_VFS_SETXATTR(handle
->conn
, path
, SAMBA_XATTR_MARKER
,
98 &buf
, sizeof(buf
), 0);
101 DEBUG(10, ("SETXATTR failed: %s\n", strerror(errno
)));
109 * Given an smb_filename, determine the stream directory using the file's
112 static char *stream_dir(vfs_handle_struct
*handle
,
113 const struct smb_filename
*smb_fname
,
114 const SMB_STRUCT_STAT
*base_sbuf
, bool create_it
)
117 struct smb_filename
*smb_fname_hash
= NULL
;
119 SMB_STRUCT_STAT base_sbuf_tmp
;
120 uint8_t first
, second
;
126 char *rootdir
= NULL
;
127 struct smb_filename
*rootdir_fname
= NULL
;
128 struct smb_filename
*tmp_fname
= NULL
;
130 check_valid
= lp_parm_bool(SNUM(handle
->conn
),
131 "streams_depot", "check_valid", true);
133 tmp
= talloc_asprintf(talloc_tos(), "%s/.streams", handle
->conn
->cwd
);
140 rootdir
= lp_parm_talloc_string(talloc_tos(),
141 SNUM(handle
->conn
), "streams_depot", "directory",
143 if (rootdir
== NULL
) {
148 rootdir_fname
= synthetic_smb_fname(talloc_tos(),
153 if (rootdir_fname
== NULL
) {
158 /* Stat the base file if it hasn't already been done. */
159 if (base_sbuf
== NULL
) {
160 struct smb_filename
*smb_fname_base
;
162 smb_fname_base
= synthetic_smb_fname(
164 smb_fname
->base_name
,
168 if (smb_fname_base
== NULL
) {
172 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_base
) == -1) {
173 TALLOC_FREE(smb_fname_base
);
176 base_sbuf_tmp
= smb_fname_base
->st
;
177 TALLOC_FREE(smb_fname_base
);
179 base_sbuf_tmp
= *base_sbuf
;
182 id
= SMB_VFS_FILE_ID_CREATE(handle
->conn
, &base_sbuf_tmp
);
184 push_file_id_16((char *)id_buf
, &id
);
186 hash
= hash_fn(data_blob_const(id_buf
, sizeof(id_buf
)));
189 second
= (hash
>> 8) & 0xff;
191 id_hex
= hex_encode_talloc(talloc_tos(), id_buf
, sizeof(id_buf
));
193 if (id_hex
== NULL
) {
198 result
= talloc_asprintf(talloc_tos(), "%s/%2.2X/%2.2X/%s", rootdir
,
199 first
, second
, id_hex
);
203 if (result
== NULL
) {
208 smb_fname_hash
= synthetic_smb_fname(talloc_tos(),
213 if (smb_fname_hash
== NULL
) {
218 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_hash
) == 0) {
219 struct smb_filename
*smb_fname_new
= NULL
;
223 if (!S_ISDIR(smb_fname_hash
->st
.st_ex_mode
)) {
229 file_is_valid(handle
, smb_fname
->base_name
)) {
234 * Someone has recreated a file under an existing inode
235 * without deleting the streams directory.
236 * Move it away or remove if streams_depot:delete_lost is set.
240 delete_lost
= lp_parm_bool(SNUM(handle
->conn
), "streams_depot",
241 "delete_lost", false);
244 DEBUG(3, ("Someone has recreated a file under an "
245 "existing inode. Removing: %s\n",
246 smb_fname_hash
->base_name
));
247 recursive_rmdir(talloc_tos(), handle
->conn
,
249 SMB_VFS_NEXT_RMDIR(handle
, smb_fname_hash
);
251 newname
= talloc_asprintf(talloc_tos(), "lost-%lu",
253 DEBUG(3, ("Someone has recreated a file under an "
254 "existing inode. Renaming: %s to: %s\n",
255 smb_fname_hash
->base_name
,
257 if (newname
== NULL
) {
262 smb_fname_new
= synthetic_smb_fname(
268 TALLOC_FREE(newname
);
269 if (smb_fname_new
== NULL
) {
274 if (SMB_VFS_NEXT_RENAME(handle
, smb_fname_hash
,
275 smb_fname_new
) == -1) {
276 TALLOC_FREE(smb_fname_new
);
277 if ((errno
== EEXIST
) || (errno
== ENOTEMPTY
)) {
283 TALLOC_FREE(smb_fname_new
);
292 if ((SMB_VFS_NEXT_MKDIR(handle
, rootdir_fname
, 0755) != 0)
293 && (errno
!= EEXIST
)) {
297 tmp
= talloc_asprintf(result
, "%s/%2.2X", rootdir
, first
);
303 tmp_fname
= synthetic_smb_fname(talloc_tos(),
308 if (tmp_fname
== NULL
) {
313 if ((SMB_VFS_NEXT_MKDIR(handle
, tmp_fname
, 0755) != 0)
314 && (errno
!= EEXIST
)) {
319 TALLOC_FREE(tmp_fname
);
321 tmp
= talloc_asprintf(result
, "%s/%2.2X/%2.2X", rootdir
, first
,
328 tmp_fname
= synthetic_smb_fname(talloc_tos(),
333 if (tmp_fname
== NULL
) {
338 if ((SMB_VFS_NEXT_MKDIR(handle
, tmp_fname
, 0755) != 0)
339 && (errno
!= EEXIST
)) {
344 TALLOC_FREE(tmp_fname
);
346 /* smb_fname_hash is the struct smb_filename version of 'result' */
347 if ((SMB_VFS_NEXT_MKDIR(handle
, smb_fname_hash
, 0755) != 0)
348 && (errno
!= EEXIST
)) {
352 if (check_valid
&& !mark_file_valid(handle
, smb_fname
->base_name
)) {
356 TALLOC_FREE(rootdir_fname
);
357 TALLOC_FREE(rootdir
);
358 TALLOC_FREE(tmp_fname
);
359 TALLOC_FREE(smb_fname_hash
);
363 TALLOC_FREE(rootdir_fname
);
364 TALLOC_FREE(rootdir
);
365 TALLOC_FREE(tmp_fname
);
366 TALLOC_FREE(smb_fname_hash
);
371 * Given a stream name, populate smb_fname_out with the actual location of the
374 static NTSTATUS
stream_smb_fname(vfs_handle_struct
*handle
,
375 const struct smb_filename
*smb_fname
,
376 struct smb_filename
**smb_fname_out
,
379 char *dirname
, *stream_fname
;
383 *smb_fname_out
= NULL
;
385 stype
= strchr_m(smb_fname
->stream_name
+ 1, ':');
388 if (strcasecmp_m(stype
, ":$DATA") != 0) {
389 return NT_STATUS_INVALID_PARAMETER
;
393 dirname
= stream_dir(handle
, smb_fname
, NULL
, create_dir
);
395 if (dirname
== NULL
) {
396 status
= map_nt_error_from_unix(errno
);
400 stream_fname
= talloc_asprintf(talloc_tos(), "%s/%s", dirname
,
401 smb_fname
->stream_name
);
403 if (stream_fname
== NULL
) {
404 status
= NT_STATUS_NO_MEMORY
;
409 /* Append an explicit stream type if one wasn't specified. */
410 stream_fname
= talloc_asprintf(talloc_tos(), "%s:$DATA",
412 if (stream_fname
== NULL
) {
413 status
= NT_STATUS_NO_MEMORY
;
417 /* Normalize the stream type to upercase. */
418 if (!strupper_m(strrchr_m(stream_fname
, ':') + 1)) {
419 status
= NT_STATUS_INVALID_PARAMETER
;
424 DEBUG(10, ("stream filename = %s\n", stream_fname
));
426 /* Create an smb_filename with stream_name == NULL. */
427 *smb_fname_out
= synthetic_smb_fname(talloc_tos(),
432 if (*smb_fname_out
== NULL
) {
433 return NT_STATUS_NO_MEMORY
;
439 DEBUG(5, ("stream_name failed: %s\n", strerror(errno
)));
440 TALLOC_FREE(*smb_fname_out
);
444 static NTSTATUS
walk_streams(vfs_handle_struct
*handle
,
445 struct smb_filename
*smb_fname_base
,
447 bool (*fn
)(const char *dirname
,
453 struct smb_filename
*dir_smb_fname
= NULL
;
454 DIR *dirhandle
= NULL
;
455 const char *dirent
= NULL
;
456 char *talloced
= NULL
;
458 dirname
= stream_dir(handle
, smb_fname_base
, &smb_fname_base
->st
,
461 if (dirname
== NULL
) {
462 if (errno
== ENOENT
) {
468 return map_nt_error_from_unix(errno
);
471 DEBUG(10, ("walk_streams: dirname=%s\n", dirname
));
473 dir_smb_fname
= synthetic_smb_fname(talloc_tos(),
477 smb_fname_base
->flags
);
478 if (dir_smb_fname
== NULL
) {
479 TALLOC_FREE(dirname
);
480 return NT_STATUS_NO_MEMORY
;
483 dirhandle
= SMB_VFS_NEXT_OPENDIR(handle
, dir_smb_fname
, NULL
, 0);
485 TALLOC_FREE(dir_smb_fname
);
487 if (dirhandle
== NULL
) {
488 TALLOC_FREE(dirname
);
489 return map_nt_error_from_unix(errno
);
492 while ((dirent
= vfs_readdirname(handle
->conn
, dirhandle
, NULL
,
493 &talloced
)) != NULL
) {
495 if (ISDOT(dirent
) || ISDOTDOT(dirent
)) {
496 TALLOC_FREE(talloced
);
500 DEBUG(10, ("walk_streams: dirent=%s\n", dirent
));
502 if (!fn(dirname
, dirent
, private_data
)) {
503 TALLOC_FREE(talloced
);
506 TALLOC_FREE(talloced
);
509 SMB_VFS_NEXT_CLOSEDIR(handle
, dirhandle
);
511 if (pdirname
!= NULL
) {
515 TALLOC_FREE(dirname
);
522 * Helper to stat/lstat the base file of an smb_fname. This will actually
523 * fills in the stat struct in smb_filename.
525 static int streams_depot_stat_base(vfs_handle_struct
*handle
,
526 struct smb_filename
*smb_fname
,
529 char *tmp_stream_name
;
532 tmp_stream_name
= smb_fname
->stream_name
;
533 smb_fname
->stream_name
= NULL
;
535 result
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
537 result
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
539 smb_fname
->stream_name
= tmp_stream_name
;
543 static int streams_depot_stat(vfs_handle_struct
*handle
,
544 struct smb_filename
*smb_fname
)
546 struct smb_filename
*smb_fname_stream
= NULL
;
550 DEBUG(10, ("streams_depot_stat called for [%s]\n",
551 smb_fname_str_dbg(smb_fname
)));
553 if (!is_ntfs_stream_smb_fname(smb_fname
)) {
554 return SMB_VFS_NEXT_STAT(handle
, smb_fname
);
557 /* If the default stream is requested, just stat the base file. */
558 if (is_ntfs_default_stream_smb_fname(smb_fname
)) {
559 return streams_depot_stat_base(handle
, smb_fname
, true);
562 /* Stat the actual stream now. */
563 status
= stream_smb_fname(handle
, smb_fname
, &smb_fname_stream
,
565 if (!NT_STATUS_IS_OK(status
)) {
567 errno
= map_errno_from_nt_status(status
);
571 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname_stream
);
573 /* Update the original smb_fname with the stat info. */
574 smb_fname
->st
= smb_fname_stream
->st
;
576 TALLOC_FREE(smb_fname_stream
);
582 static int streams_depot_lstat(vfs_handle_struct
*handle
,
583 struct smb_filename
*smb_fname
)
585 struct smb_filename
*smb_fname_stream
= NULL
;
589 DEBUG(10, ("streams_depot_lstat called for [%s]\n",
590 smb_fname_str_dbg(smb_fname
)));
592 if (!is_ntfs_stream_smb_fname(smb_fname
)) {
593 return SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
596 /* If the default stream is requested, just stat the base file. */
597 if (is_ntfs_default_stream_smb_fname(smb_fname
)) {
598 return streams_depot_stat_base(handle
, smb_fname
, false);
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_ntfs_stream_smb_fname(smb_fname
)) {
627 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
630 /* If the default stream is requested, just open the base file. */
631 if (is_ntfs_default_stream_smb_fname(smb_fname
)) {
632 char *tmp_stream_name
;
634 tmp_stream_name
= smb_fname
->stream_name
;
635 smb_fname
->stream_name
= NULL
;
636 ret
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
637 smb_fname
->stream_name
= tmp_stream_name
;
642 /* Ensure the base file still exists. */
643 smb_fname_base
= synthetic_smb_fname(talloc_tos(),
644 smb_fname
->base_name
,
648 if (smb_fname_base
== NULL
) {
654 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname_base
);
659 /* Determine the stream name, and then open it. */
660 status
= stream_smb_fname(handle
, smb_fname
, &smb_fname_stream
, true);
661 if (!NT_STATUS_IS_OK(status
)) {
663 errno
= map_errno_from_nt_status(status
);
667 ret
= SMB_VFS_NEXT_OPEN(handle
, smb_fname_stream
, fsp
, flags
, mode
);
670 TALLOC_FREE(smb_fname_stream
);
671 TALLOC_FREE(smb_fname_base
);
675 static int streams_depot_unlink(vfs_handle_struct
*handle
,
676 const struct smb_filename
*smb_fname
)
678 struct smb_filename
*smb_fname_base
= NULL
;
681 DEBUG(10, ("streams_depot_unlink called for %s\n",
682 smb_fname_str_dbg(smb_fname
)));
684 /* If there is a valid stream, just unlink the stream and return. */
685 if (is_ntfs_stream_smb_fname(smb_fname
) &&
686 !is_ntfs_default_stream_smb_fname(smb_fname
)) {
687 struct smb_filename
*smb_fname_stream
= NULL
;
690 status
= stream_smb_fname(handle
, smb_fname
, &smb_fname_stream
,
692 if (!NT_STATUS_IS_OK(status
)) {
693 errno
= map_errno_from_nt_status(status
);
697 ret
= SMB_VFS_NEXT_UNLINK(handle
, smb_fname_stream
);
699 TALLOC_FREE(smb_fname_stream
);
704 * We potentially need to delete the per-inode streams directory
707 smb_fname_base
= synthetic_smb_fname(talloc_tos(),
708 smb_fname
->base_name
,
712 if (smb_fname_base
== NULL
) {
717 if (smb_fname_base
->flags
& SMB_FILENAME_POSIX_PATH
) {
718 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname_base
);
720 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname_base
);
724 TALLOC_FREE(smb_fname_base
);
728 ret
= SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
730 char *dirname
= stream_dir(handle
, smb_fname_base
,
731 &smb_fname_base
->st
, false);
733 if (dirname
!= NULL
) {
734 struct smb_filename
*smb_fname_dir
=
735 synthetic_smb_fname(talloc_tos(),
740 if (smb_fname_dir
== NULL
) {
741 TALLOC_FREE(smb_fname_base
);
742 TALLOC_FREE(dirname
);
746 SMB_VFS_NEXT_RMDIR(handle
, smb_fname_dir
);
747 TALLOC_FREE(smb_fname_dir
);
749 TALLOC_FREE(dirname
);
752 TALLOC_FREE(smb_fname_base
);
756 static int streams_depot_rmdir(vfs_handle_struct
*handle
,
757 const struct smb_filename
*smb_fname
)
759 struct smb_filename
*smb_fname_base
= NULL
;
762 DEBUG(10, ("streams_depot_rmdir called for %s\n",
763 smb_fname
->base_name
));
766 * We potentially need to delete the per-inode streams directory
769 smb_fname_base
= synthetic_smb_fname(talloc_tos(),
770 smb_fname
->base_name
,
774 if (smb_fname_base
== NULL
) {
779 if (smb_fname_base
->flags
& SMB_FILENAME_POSIX_PATH
) {
780 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname_base
);
782 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname_base
);
786 TALLOC_FREE(smb_fname_base
);
790 ret
= SMB_VFS_NEXT_RMDIR(handle
, smb_fname_base
);
792 char *dirname
= stream_dir(handle
, smb_fname_base
,
793 &smb_fname_base
->st
, false);
795 if (dirname
!= NULL
) {
796 struct smb_filename
*smb_fname_dir
=
797 synthetic_smb_fname(talloc_tos(),
802 if (smb_fname_dir
== NULL
) {
803 TALLOC_FREE(smb_fname_base
);
804 TALLOC_FREE(dirname
);
808 SMB_VFS_NEXT_RMDIR(handle
, smb_fname_dir
);
809 TALLOC_FREE(smb_fname_dir
);
811 TALLOC_FREE(dirname
);
814 TALLOC_FREE(smb_fname_base
);
818 static int streams_depot_rename(vfs_handle_struct
*handle
,
819 const struct smb_filename
*smb_fname_src
,
820 const struct smb_filename
*smb_fname_dst
)
822 struct smb_filename
*smb_fname_src_stream
= NULL
;
823 struct smb_filename
*smb_fname_dst_stream
= NULL
;
824 bool src_is_stream
, dst_is_stream
;
828 DEBUG(10, ("streams_depot_rename called for %s => %s\n",
829 smb_fname_str_dbg(smb_fname_src
),
830 smb_fname_str_dbg(smb_fname_dst
)));
832 src_is_stream
= is_ntfs_stream_smb_fname(smb_fname_src
);
833 dst_is_stream
= is_ntfs_stream_smb_fname(smb_fname_dst
);
835 if (!src_is_stream
&& !dst_is_stream
) {
836 return SMB_VFS_NEXT_RENAME(handle
, smb_fname_src
,
840 /* for now don't allow renames from or to the default stream */
841 if (is_ntfs_default_stream_smb_fname(smb_fname_src
) ||
842 is_ntfs_default_stream_smb_fname(smb_fname_dst
)) {
847 status
= stream_smb_fname(handle
, smb_fname_src
, &smb_fname_src_stream
,
849 if (!NT_STATUS_IS_OK(status
)) {
850 errno
= map_errno_from_nt_status(status
);
854 status
= stream_smb_fname(handle
, smb_fname_dst
,
855 &smb_fname_dst_stream
, false);
856 if (!NT_STATUS_IS_OK(status
)) {
857 errno
= map_errno_from_nt_status(status
);
861 ret
= SMB_VFS_NEXT_RENAME(handle
, smb_fname_src_stream
,
862 smb_fname_dst_stream
);
865 TALLOC_FREE(smb_fname_src_stream
);
866 TALLOC_FREE(smb_fname_dst_stream
);
870 static bool add_one_stream(TALLOC_CTX
*mem_ctx
, unsigned int *num_streams
,
871 struct stream_struct
**streams
,
872 const char *name
, off_t size
,
875 struct stream_struct
*tmp
;
877 tmp
= talloc_realloc(mem_ctx
, *streams
, struct stream_struct
,
883 tmp
[*num_streams
].name
= talloc_strdup(tmp
, name
);
884 if (tmp
[*num_streams
].name
== NULL
) {
888 tmp
[*num_streams
].size
= size
;
889 tmp
[*num_streams
].alloc_size
= alloc_size
;
896 struct streaminfo_state
{
898 vfs_handle_struct
*handle
;
899 unsigned int num_streams
;
900 struct stream_struct
*streams
;
904 static bool collect_one_stream(const char *dirname
,
908 struct streaminfo_state
*state
=
909 (struct streaminfo_state
*)private_data
;
910 struct smb_filename
*smb_fname
= NULL
;
914 sname
= talloc_asprintf(talloc_tos(), "%s/%s", dirname
, dirent
);
916 state
->status
= NT_STATUS_NO_MEMORY
;
921 smb_fname
= synthetic_smb_fname(talloc_tos(), sname
, NULL
, NULL
, 0);
922 if (smb_fname
== NULL
) {
923 state
->status
= NT_STATUS_NO_MEMORY
;
928 if (SMB_VFS_NEXT_STAT(state
->handle
, smb_fname
) == -1) {
929 DEBUG(10, ("Could not stat %s: %s\n", sname
,
935 if (!add_one_stream(state
->mem_ctx
,
936 &state
->num_streams
, &state
->streams
,
937 dirent
, smb_fname
->st
.st_ex_size
,
938 SMB_VFS_GET_ALLOC_SIZE(state
->handle
->conn
, NULL
,
940 state
->status
= NT_STATUS_NO_MEMORY
;
948 TALLOC_FREE(smb_fname
);
952 static NTSTATUS
streams_depot_streaminfo(vfs_handle_struct
*handle
,
953 struct files_struct
*fsp
,
954 const struct smb_filename
*smb_fname
,
956 unsigned int *pnum_streams
,
957 struct stream_struct
**pstreams
)
959 struct smb_filename
*smb_fname_base
= NULL
;
962 struct streaminfo_state state
;
964 smb_fname_base
= synthetic_smb_fname(talloc_tos(),
965 smb_fname
->base_name
,
969 if (smb_fname_base
== NULL
) {
970 return NT_STATUS_NO_MEMORY
;
973 if ((fsp
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
974 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, &smb_fname_base
->st
);
977 if (smb_fname_base
->flags
& SMB_FILENAME_POSIX_PATH
) {
978 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname_base
);
980 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname_base
);
985 status
= map_nt_error_from_unix(errno
);
989 state
.streams
= *pstreams
;
990 state
.num_streams
= *pnum_streams
;
991 state
.mem_ctx
= mem_ctx
;
992 state
.handle
= handle
;
993 state
.status
= NT_STATUS_OK
;
995 if (S_ISLNK(smb_fname_base
->st
.st_ex_mode
)) {
997 * Currently we do't have SMB_VFS_LLISTXATTR
998 * inside the VFS which means there's no way
999 * to cope with a symlink when lp_posix_pathnames().
1000 * returns true. For now ignore links.
1001 * FIXME - by adding SMB_VFS_LLISTXATTR. JRA.
1003 status
= NT_STATUS_OK
;
1005 status
= walk_streams(handle
, smb_fname_base
, NULL
, collect_one_stream
,
1009 if (!NT_STATUS_IS_OK(status
)) {
1010 TALLOC_FREE(state
.streams
);
1014 if (!NT_STATUS_IS_OK(state
.status
)) {
1015 TALLOC_FREE(state
.streams
);
1016 status
= state
.status
;
1020 *pnum_streams
= state
.num_streams
;
1021 *pstreams
= state
.streams
;
1022 status
= SMB_VFS_NEXT_STREAMINFO(handle
,
1030 TALLOC_FREE(smb_fname_base
);
1034 static uint32_t streams_depot_fs_capabilities(struct vfs_handle_struct
*handle
,
1035 enum timestamp_set_resolution
*p_ts_res
)
1037 return SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
) | FILE_NAMED_STREAMS
;
1040 static struct vfs_fn_pointers vfs_streams_depot_fns
= {
1041 .fs_capabilities_fn
= streams_depot_fs_capabilities
,
1042 .open_fn
= streams_depot_open
,
1043 .stat_fn
= streams_depot_stat
,
1044 .lstat_fn
= streams_depot_lstat
,
1045 .unlink_fn
= streams_depot_unlink
,
1046 .rmdir_fn
= streams_depot_rmdir
,
1047 .rename_fn
= streams_depot_rename
,
1048 .streaminfo_fn
= streams_depot_streaminfo
,
1051 NTSTATUS
vfs_streams_depot_init(void);
1052 NTSTATUS
vfs_streams_depot_init(void)
1054 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "streams_depot",
1055 &vfs_streams_depot_fns
);