ctdb-tcp: Do not stop outbound connection in ctdb_tcp_node_connect()
[Samba.git] / source3 / modules / vfs_streams_xattr.c
blob85efe2bcc376192f0e9e34f76831b82b7602fa3d
1 /*
2 * Store streams in xattrs
4 * Copyright (C) Volker Lendecke, 2008
6 * Partly based on James Peach's Darwin module, which is
8 * Copyright (C) James Peach 2006-2007
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "smbd/smbd.h"
26 #include "system/filesys.h"
27 #include "lib/util/tevent_unix.h"
28 #include "librpc/gen_ndr/ioctl.h"
29 #include "hash_inode.h"
31 #undef DBGC_CLASS
32 #define DBGC_CLASS DBGC_VFS
34 struct streams_xattr_config {
35 const char *prefix;
36 size_t prefix_len;
37 bool store_stream_type;
40 struct stream_io {
41 char *base;
42 char *xattr_name;
43 void *fsp_name_ptr;
44 files_struct *fsp;
45 vfs_handle_struct *handle;
48 static ssize_t get_xattr_size(connection_struct *conn,
49 const struct smb_filename *smb_fname,
50 const char *xattr_name)
52 NTSTATUS status;
53 struct ea_struct ea;
54 ssize_t result;
56 status = get_ea_value(talloc_tos(), conn, NULL, smb_fname,
57 xattr_name, &ea);
59 if (!NT_STATUS_IS_OK(status)) {
60 return -1;
63 result = ea.value.length-1;
64 TALLOC_FREE(ea.value.data);
65 return result;
68 /**
69 * Given a stream name, populate xattr_name with the xattr name to use for
70 * accessing the stream.
72 static NTSTATUS streams_xattr_get_name(vfs_handle_struct *handle,
73 TALLOC_CTX *ctx,
74 const char *stream_name,
75 char **xattr_name)
77 char *sname;
78 char *stype;
79 struct streams_xattr_config *config;
81 SMB_VFS_HANDLE_GET_DATA(handle, config, struct streams_xattr_config,
82 return NT_STATUS_UNSUCCESSFUL);
84 sname = talloc_strdup(ctx, stream_name + 1);
85 if (sname == NULL) {
86 return NT_STATUS_NO_MEMORY;
90 * With vfs_fruit option "fruit:encoding = native" we're
91 * already converting stream names that contain illegal NTFS
92 * characters from their on-the-wire Unicode Private Range
93 * encoding to their native ASCII representation.
95 * As as result the name of xattrs storing the streams (via
96 * vfs_streams_xattr) may contain a colon, so we have to use
97 * strrchr_m() instead of strchr_m() for matching the stream
98 * type suffix.
100 * In check_path_syntax() we've already ensured the streamname
101 * we got from the client is valid.
103 stype = strrchr_m(sname, ':');
105 if (stype) {
107 * We only support one stream type: "$DATA"
109 if (strcasecmp_m(stype, ":$DATA") != 0) {
110 talloc_free(sname);
111 return NT_STATUS_INVALID_PARAMETER;
114 /* Split name and type */
115 stype[0] = '\0';
118 *xattr_name = talloc_asprintf(ctx, "%s%s%s",
119 config->prefix,
120 sname,
121 config->store_stream_type ? ":$DATA" : "");
122 if (*xattr_name == NULL) {
123 talloc_free(sname);
124 return NT_STATUS_NO_MEMORY;
127 DEBUG(10, ("xattr_name: %s, stream_name: %s\n", *xattr_name,
128 stream_name));
130 talloc_free(sname);
131 return NT_STATUS_OK;
134 static bool streams_xattr_recheck(struct stream_io *sio)
136 NTSTATUS status;
137 char *xattr_name = NULL;
139 if (sio->fsp->fsp_name == sio->fsp_name_ptr) {
140 return true;
143 if (sio->fsp->fsp_name->stream_name == NULL) {
144 /* how can this happen */
145 errno = EINVAL;
146 return false;
149 status = streams_xattr_get_name(sio->handle, talloc_tos(),
150 sio->fsp->fsp_name->stream_name,
151 &xattr_name);
152 if (!NT_STATUS_IS_OK(status)) {
153 return false;
156 TALLOC_FREE(sio->xattr_name);
157 TALLOC_FREE(sio->base);
158 sio->xattr_name = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(sio->handle, sio->fsp),
159 xattr_name);
160 if (sio->xattr_name == NULL) {
161 DBG_DEBUG("sio->xattr_name==NULL\n");
162 return false;
164 TALLOC_FREE(xattr_name);
166 sio->base = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(sio->handle, sio->fsp),
167 sio->fsp->fsp_name->base_name);
168 if (sio->base == NULL) {
169 DBG_DEBUG("sio->base==NULL\n");
170 return false;
173 sio->fsp_name_ptr = sio->fsp->fsp_name;
175 return true;
179 * Helper to stat/lstat the base file of an smb_fname.
181 static int streams_xattr_stat_base(vfs_handle_struct *handle,
182 struct smb_filename *smb_fname,
183 bool follow_links)
185 char *tmp_stream_name;
186 int result;
188 tmp_stream_name = smb_fname->stream_name;
189 smb_fname->stream_name = NULL;
190 if (follow_links) {
191 result = SMB_VFS_NEXT_STAT(handle, smb_fname);
192 } else {
193 result = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
195 smb_fname->stream_name = tmp_stream_name;
196 return result;
199 static int streams_xattr_fstat(vfs_handle_struct *handle, files_struct *fsp,
200 SMB_STRUCT_STAT *sbuf)
202 struct smb_filename *smb_fname_base = NULL;
203 int ret = -1;
204 struct stream_io *io = (struct stream_io *)
205 VFS_FETCH_FSP_EXTENSION(handle, fsp);
207 if (io == NULL || fsp->base_fsp == NULL) {
208 return SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
211 DBG_DEBUG("streams_xattr_fstat called for %s\n", fsp_str_dbg(io->fsp));
213 if (!streams_xattr_recheck(io)) {
214 return -1;
217 /* Create an smb_filename with stream_name == NULL. */
218 smb_fname_base = synthetic_smb_fname(talloc_tos(),
219 io->base,
220 NULL,
221 NULL,
222 fsp->fsp_name->flags);
223 if (smb_fname_base == NULL) {
224 errno = ENOMEM;
225 return -1;
228 if (smb_fname_base->flags & SMB_FILENAME_POSIX_PATH) {
229 ret = SMB_VFS_LSTAT(handle->conn, smb_fname_base);
230 } else {
231 ret = SMB_VFS_STAT(handle->conn, smb_fname_base);
233 *sbuf = smb_fname_base->st;
235 if (ret == -1) {
236 TALLOC_FREE(smb_fname_base);
237 return -1;
240 sbuf->st_ex_size = get_xattr_size(handle->conn,
241 smb_fname_base, io->xattr_name);
242 if (sbuf->st_ex_size == -1) {
243 TALLOC_FREE(smb_fname_base);
244 SET_STAT_INVALID(*sbuf);
245 return -1;
248 DEBUG(10, ("sbuf->st_ex_size = %d\n", (int)sbuf->st_ex_size));
250 sbuf->st_ex_ino = hash_inode(sbuf, io->xattr_name);
251 sbuf->st_ex_mode &= ~S_IFMT;
252 sbuf->st_ex_mode &= ~S_IFDIR;
253 sbuf->st_ex_mode |= S_IFREG;
254 sbuf->st_ex_blocks = sbuf->st_ex_size / STAT_ST_BLOCKSIZE + 1;
256 TALLOC_FREE(smb_fname_base);
257 return 0;
260 static int streams_xattr_stat(vfs_handle_struct *handle,
261 struct smb_filename *smb_fname)
263 NTSTATUS status;
264 int result = -1;
265 char *xattr_name = NULL;
267 if (!is_named_stream(smb_fname)) {
268 return SMB_VFS_NEXT_STAT(handle, smb_fname);
271 /* Note if lp_posix_paths() is true, we can never
272 * get here as is_named_stream() is
273 * always false. So we never need worry about
274 * not following links here. */
276 /* Populate the stat struct with info from the base file. */
277 if (streams_xattr_stat_base(handle, smb_fname, true) == -1) {
278 return -1;
281 /* Derive the xattr name to lookup. */
282 status = streams_xattr_get_name(handle, talloc_tos(),
283 smb_fname->stream_name, &xattr_name);
284 if (!NT_STATUS_IS_OK(status)) {
285 errno = map_errno_from_nt_status(status);
286 return -1;
289 /* Augment the base file's stat information before returning. */
290 smb_fname->st.st_ex_size = get_xattr_size(handle->conn,
291 smb_fname,
292 xattr_name);
293 if (smb_fname->st.st_ex_size == -1) {
294 SET_STAT_INVALID(smb_fname->st);
295 errno = ENOENT;
296 result = -1;
297 goto fail;
300 smb_fname->st.st_ex_ino = hash_inode(&smb_fname->st, xattr_name);
301 smb_fname->st.st_ex_mode &= ~S_IFMT;
302 smb_fname->st.st_ex_mode &= ~S_IFDIR;
303 smb_fname->st.st_ex_mode |= S_IFREG;
304 smb_fname->st.st_ex_blocks =
305 smb_fname->st.st_ex_size / STAT_ST_BLOCKSIZE + 1;
307 result = 0;
308 fail:
309 TALLOC_FREE(xattr_name);
310 return result;
313 static int streams_xattr_lstat(vfs_handle_struct *handle,
314 struct smb_filename *smb_fname)
316 NTSTATUS status;
317 int result = -1;
318 char *xattr_name = NULL;
320 if (!is_named_stream(smb_fname)) {
321 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
324 /* Populate the stat struct with info from the base file. */
325 if (streams_xattr_stat_base(handle, smb_fname, false) == -1) {
326 return -1;
329 /* Derive the xattr name to lookup. */
330 status = streams_xattr_get_name(handle, talloc_tos(),
331 smb_fname->stream_name, &xattr_name);
332 if (!NT_STATUS_IS_OK(status)) {
333 errno = map_errno_from_nt_status(status);
334 return -1;
337 /* Augment the base file's stat information before returning. */
338 smb_fname->st.st_ex_size = get_xattr_size(handle->conn,
339 smb_fname,
340 xattr_name);
341 if (smb_fname->st.st_ex_size == -1) {
342 SET_STAT_INVALID(smb_fname->st);
343 errno = ENOENT;
344 result = -1;
345 goto fail;
348 smb_fname->st.st_ex_ino = hash_inode(&smb_fname->st, xattr_name);
349 smb_fname->st.st_ex_mode &= ~S_IFMT;
350 smb_fname->st.st_ex_mode |= S_IFREG;
351 smb_fname->st.st_ex_blocks =
352 smb_fname->st.st_ex_size / STAT_ST_BLOCKSIZE + 1;
354 result = 0;
356 fail:
357 TALLOC_FREE(xattr_name);
358 return result;
361 static int streams_xattr_open(vfs_handle_struct *handle,
362 struct smb_filename *smb_fname,
363 files_struct *fsp, int flags, mode_t mode)
365 NTSTATUS status;
366 struct streams_xattr_config *config = NULL;
367 struct stream_io *sio = NULL;
368 struct ea_struct ea;
369 char *xattr_name = NULL;
370 int pipe_fds[2];
371 int fakefd = -1;
372 bool set_empty_xattr = false;
373 int ret;
375 SMB_VFS_HANDLE_GET_DATA(handle, config, struct streams_xattr_config,
376 return -1);
378 DEBUG(10, ("streams_xattr_open called for %s with flags 0x%x\n",
379 smb_fname_str_dbg(smb_fname), flags));
381 if (!is_named_stream(smb_fname)) {
382 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
385 status = streams_xattr_get_name(handle, talloc_tos(),
386 smb_fname->stream_name, &xattr_name);
387 if (!NT_STATUS_IS_OK(status)) {
388 errno = map_errno_from_nt_status(status);
389 goto fail;
392 status = get_ea_value(talloc_tos(), handle->conn, NULL,
393 smb_fname, xattr_name, &ea);
395 DEBUG(10, ("get_ea_value returned %s\n", nt_errstr(status)));
397 if (!NT_STATUS_IS_OK(status)) {
398 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
400 * The base file is not there. This is an error even if
401 * we got O_CREAT, the higher levels should have created
402 * the base file for us.
404 DBG_DEBUG("streams_xattr_open: base file %s not around, "
405 "returning ENOENT\n", smb_fname->base_name);
406 errno = ENOENT;
407 goto fail;
410 if (!(flags & O_CREAT)) {
411 errno = ENOATTR;
412 goto fail;
415 set_empty_xattr = true;
418 if (flags & O_TRUNC) {
419 set_empty_xattr = true;
422 if (set_empty_xattr) {
424 * The attribute does not exist or needs to be truncated
428 * Darn, xattrs need at least 1 byte
430 char null = '\0';
432 DEBUG(10, ("creating or truncating attribute %s on file %s\n",
433 xattr_name, smb_fname->base_name));
435 ret = SMB_VFS_SETXATTR(fsp->conn,
436 smb_fname,
437 xattr_name,
438 &null, sizeof(null),
439 flags & O_EXCL ? XATTR_CREATE : 0);
440 if (ret != 0) {
441 goto fail;
446 * Return a valid fd, but ensure any attempt to use it returns an error
447 * (EPIPE).
449 ret = pipe(pipe_fds);
450 if (ret != 0) {
451 goto fail;
454 close(pipe_fds[1]);
455 pipe_fds[1] = -1;
456 fakefd = pipe_fds[0];
458 sio = VFS_ADD_FSP_EXTENSION(handle, fsp, struct stream_io, NULL);
459 if (sio == NULL) {
460 errno = ENOMEM;
461 goto fail;
464 sio->xattr_name = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
465 xattr_name);
466 if (sio->xattr_name == NULL) {
467 errno = ENOMEM;
468 goto fail;
472 * so->base needs to be a copy of fsp->fsp_name->base_name,
473 * making it identical to streams_xattr_recheck(). If the
474 * open is changing directories, fsp->fsp_name->base_name
475 * will be the full path from the share root, whilst
476 * smb_fname will be relative to the $cwd.
478 sio->base = talloc_strdup(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
479 fsp->fsp_name->base_name);
480 if (sio->base == NULL) {
481 errno = ENOMEM;
482 goto fail;
485 sio->fsp_name_ptr = fsp->fsp_name;
486 sio->handle = handle;
487 sio->fsp = fsp;
489 return fakefd;
491 fail:
492 if (fakefd >= 0) {
493 close(fakefd);
494 fakefd = -1;
497 return -1;
500 static int streams_xattr_close(vfs_handle_struct *handle,
501 files_struct *fsp)
503 int ret;
504 int fd;
506 fd = fsp->fh->fd;
508 DBG_DEBUG("streams_xattr_close called [%s] fd [%d]\n",
509 smb_fname_str_dbg(fsp->fsp_name), fd);
511 if (!is_named_stream(fsp->fsp_name)) {
512 return SMB_VFS_NEXT_CLOSE(handle, fsp);
515 ret = close(fd);
516 fsp->fh->fd = -1;
518 return ret;
521 static int streams_xattr_unlink_internal(vfs_handle_struct *handle,
522 struct files_struct *dirfsp,
523 const struct smb_filename *smb_fname,
524 int flags)
526 NTSTATUS status;
527 int ret = -1;
528 char *xattr_name = NULL;
530 if (!is_named_stream(smb_fname)) {
531 return SMB_VFS_NEXT_UNLINKAT(handle,
532 dirfsp,
533 smb_fname,
534 flags);
537 status = streams_xattr_get_name(handle, talloc_tos(),
538 smb_fname->stream_name, &xattr_name);
539 if (!NT_STATUS_IS_OK(status)) {
540 errno = map_errno_from_nt_status(status);
541 goto fail;
544 ret = SMB_VFS_REMOVEXATTR(handle->conn, smb_fname, xattr_name);
546 if ((ret == -1) && (errno == ENOATTR)) {
547 errno = ENOENT;
548 goto fail;
551 ret = 0;
553 fail:
554 TALLOC_FREE(xattr_name);
555 return ret;
558 static int streams_xattr_unlinkat(vfs_handle_struct *handle,
559 struct files_struct *dirfsp,
560 const struct smb_filename *smb_fname,
561 int flags)
563 int ret;
564 if (flags & AT_REMOVEDIR) {
565 ret = SMB_VFS_NEXT_UNLINKAT(handle,
566 dirfsp,
567 smb_fname,
568 flags);
569 } else {
570 ret = streams_xattr_unlink_internal(handle,
571 dirfsp,
572 smb_fname,
573 flags);
575 return ret;
578 static int streams_xattr_renameat(vfs_handle_struct *handle,
579 files_struct *srcfsp,
580 const struct smb_filename *smb_fname_src,
581 files_struct *dstfsp,
582 const struct smb_filename *smb_fname_dst)
584 NTSTATUS status;
585 int ret = -1;
586 char *src_xattr_name = NULL;
587 char *dst_xattr_name = NULL;
588 bool src_is_stream, dst_is_stream;
589 ssize_t oret;
590 ssize_t nret;
591 struct ea_struct ea;
593 src_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
594 dst_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);
596 if (!src_is_stream && !dst_is_stream) {
597 return SMB_VFS_NEXT_RENAMEAT(handle,
598 srcfsp,
599 smb_fname_src,
600 dstfsp,
601 smb_fname_dst);
604 /* For now don't allow renames from or to the default stream. */
605 if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
606 is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
607 errno = ENOSYS;
608 goto done;
611 /* Don't rename if the streams are identical. */
612 if (strcasecmp_m(smb_fname_src->stream_name,
613 smb_fname_dst->stream_name) == 0) {
614 goto done;
617 /* Get the xattr names. */
618 status = streams_xattr_get_name(handle, talloc_tos(),
619 smb_fname_src->stream_name,
620 &src_xattr_name);
621 if (!NT_STATUS_IS_OK(status)) {
622 errno = map_errno_from_nt_status(status);
623 goto fail;
625 status = streams_xattr_get_name(handle, talloc_tos(),
626 smb_fname_dst->stream_name,
627 &dst_xattr_name);
628 if (!NT_STATUS_IS_OK(status)) {
629 errno = map_errno_from_nt_status(status);
630 goto fail;
633 /* read the old stream */
634 status = get_ea_value(talloc_tos(), handle->conn, NULL,
635 smb_fname_src, src_xattr_name, &ea);
636 if (!NT_STATUS_IS_OK(status)) {
637 errno = ENOENT;
638 goto fail;
641 /* (over)write the new stream */
642 nret = SMB_VFS_SETXATTR(handle->conn, smb_fname_src,
643 dst_xattr_name, ea.value.data, ea.value.length,
645 if (nret < 0) {
646 if (errno == ENOATTR) {
647 errno = ENOENT;
649 goto fail;
652 /* remove the old stream */
653 oret = SMB_VFS_REMOVEXATTR(handle->conn, smb_fname_src,
654 src_xattr_name);
655 if (oret < 0) {
656 if (errno == ENOATTR) {
657 errno = ENOENT;
659 goto fail;
662 done:
663 errno = 0;
664 ret = 0;
665 fail:
666 TALLOC_FREE(src_xattr_name);
667 TALLOC_FREE(dst_xattr_name);
668 return ret;
671 static NTSTATUS walk_xattr_streams(vfs_handle_struct *handle,
672 files_struct *fsp,
673 const struct smb_filename *smb_fname,
674 bool (*fn)(struct ea_struct *ea,
675 void *private_data),
676 void *private_data)
678 NTSTATUS status;
679 char **names;
680 size_t i, num_names;
681 struct streams_xattr_config *config;
683 SMB_VFS_HANDLE_GET_DATA(handle, config, struct streams_xattr_config,
684 return NT_STATUS_UNSUCCESSFUL);
686 status = get_ea_names_from_file(talloc_tos(),
687 handle->conn,
688 fsp,
689 smb_fname,
690 &names,
691 &num_names);
692 if (!NT_STATUS_IS_OK(status)) {
693 return status;
696 for (i=0; i<num_names; i++) {
697 struct ea_struct ea;
700 * We want to check with samba_private_attr_name()
701 * whether the xattr name is a private one,
702 * unfortunately it flags xattrs that begin with the
703 * default streams prefix as private.
705 * By only calling samba_private_attr_name() in case
706 * the xattr does NOT begin with the default prefix,
707 * we know that if it returns 'true' it definitely one
708 * of our internal xattr like "user.DOSATTRIB".
710 if (strncasecmp_m(names[i], SAMBA_XATTR_DOSSTREAM_PREFIX,
711 strlen(SAMBA_XATTR_DOSSTREAM_PREFIX)) != 0) {
712 if (samba_private_attr_name(names[i])) {
713 continue;
717 if (strncmp(names[i], config->prefix,
718 config->prefix_len) != 0) {
719 continue;
722 status = get_ea_value(names,
723 handle->conn,
724 NULL,
725 smb_fname,
726 names[i],
727 &ea);
728 if (!NT_STATUS_IS_OK(status)) {
729 DEBUG(10, ("Could not get ea %s for file %s: %s\n",
730 names[i],
731 smb_fname->base_name,
732 nt_errstr(status)));
733 continue;
736 ea.name = talloc_asprintf(
737 ea.value.data, ":%s%s",
738 names[i] + config->prefix_len,
739 config->store_stream_type ? "" : ":$DATA");
740 if (ea.name == NULL) {
741 DEBUG(0, ("talloc failed\n"));
742 continue;
745 if (!fn(&ea, private_data)) {
746 TALLOC_FREE(ea.value.data);
747 return NT_STATUS_OK;
750 TALLOC_FREE(ea.value.data);
753 TALLOC_FREE(names);
754 return NT_STATUS_OK;
757 static bool add_one_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
758 struct stream_struct **streams,
759 const char *name, off_t size,
760 off_t alloc_size)
762 struct stream_struct *tmp;
764 tmp = talloc_realloc(mem_ctx, *streams, struct stream_struct,
765 (*num_streams)+1);
766 if (tmp == NULL) {
767 return false;
770 tmp[*num_streams].name = talloc_strdup(tmp, name);
771 if (tmp[*num_streams].name == NULL) {
772 return false;
775 tmp[*num_streams].size = size;
776 tmp[*num_streams].alloc_size = alloc_size;
778 *streams = tmp;
779 *num_streams += 1;
780 return true;
783 struct streaminfo_state {
784 TALLOC_CTX *mem_ctx;
785 vfs_handle_struct *handle;
786 unsigned int num_streams;
787 struct stream_struct *streams;
788 NTSTATUS status;
791 static bool collect_one_stream(struct ea_struct *ea, void *private_data)
793 struct streaminfo_state *state =
794 (struct streaminfo_state *)private_data;
796 if (!add_one_stream(state->mem_ctx,
797 &state->num_streams, &state->streams,
798 ea->name, ea->value.length-1,
799 smb_roundup(state->handle->conn,
800 ea->value.length-1))) {
801 state->status = NT_STATUS_NO_MEMORY;
802 return false;
805 return true;
808 static NTSTATUS streams_xattr_streaminfo(vfs_handle_struct *handle,
809 struct files_struct *fsp,
810 const struct smb_filename *smb_fname,
811 TALLOC_CTX *mem_ctx,
812 unsigned int *pnum_streams,
813 struct stream_struct **pstreams)
815 SMB_STRUCT_STAT sbuf;
816 int ret;
817 NTSTATUS status;
818 struct streaminfo_state state;
820 ret = vfs_stat_smb_basename(handle->conn, smb_fname, &sbuf);
821 if (ret == -1) {
822 return map_nt_error_from_unix(errno);
825 state.streams = *pstreams;
826 state.num_streams = *pnum_streams;
827 state.mem_ctx = mem_ctx;
828 state.handle = handle;
829 state.status = NT_STATUS_OK;
831 if (S_ISLNK(sbuf.st_ex_mode)) {
833 * Currently we do't have SMB_VFS_LLISTXATTR
834 * inside the VFS which means there's no way
835 * to cope with a symlink when lp_posix_pathnames().
836 * returns true. For now ignore links.
837 * FIXME - by adding SMB_VFS_LLISTXATTR. JRA.
839 status = NT_STATUS_OK;
840 } else {
841 status = walk_xattr_streams(handle, fsp, smb_fname,
842 collect_one_stream, &state);
845 if (!NT_STATUS_IS_OK(status)) {
846 TALLOC_FREE(state.streams);
847 return status;
850 if (!NT_STATUS_IS_OK(state.status)) {
851 TALLOC_FREE(state.streams);
852 return state.status;
855 *pnum_streams = state.num_streams;
856 *pstreams = state.streams;
858 return SMB_VFS_NEXT_STREAMINFO(handle,
859 fsp,
860 smb_fname,
861 mem_ctx,
862 pnum_streams,
863 pstreams);
866 static uint32_t streams_xattr_fs_capabilities(struct vfs_handle_struct *handle,
867 enum timestamp_set_resolution *p_ts_res)
869 return SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res) | FILE_NAMED_STREAMS;
872 static int streams_xattr_connect(vfs_handle_struct *handle,
873 const char *service, const char *user)
875 struct streams_xattr_config *config;
876 const char *default_prefix = SAMBA_XATTR_DOSSTREAM_PREFIX;
877 const char *prefix;
878 int rc;
880 rc = SMB_VFS_NEXT_CONNECT(handle, service, user);
881 if (rc != 0) {
882 return rc;
885 config = talloc_zero(handle->conn, struct streams_xattr_config);
886 if (config == NULL) {
887 DEBUG(1, ("talloc_zero() failed\n"));
888 errno = ENOMEM;
889 return -1;
892 prefix = lp_parm_const_string(SNUM(handle->conn),
893 "streams_xattr", "prefix",
894 default_prefix);
895 config->prefix = talloc_strdup(config, prefix);
896 if (config->prefix == NULL) {
897 DEBUG(1, ("talloc_strdup() failed\n"));
898 errno = ENOMEM;
899 return -1;
901 config->prefix_len = strlen(config->prefix);
902 DEBUG(10, ("streams_xattr using stream prefix: %s\n", config->prefix));
904 config->store_stream_type = lp_parm_bool(SNUM(handle->conn),
905 "streams_xattr",
906 "store_stream_type",
907 true);
909 SMB_VFS_HANDLE_SET_DATA(handle, config,
910 NULL, struct stream_xattr_config,
911 return -1);
913 return 0;
916 static ssize_t streams_xattr_pwrite(vfs_handle_struct *handle,
917 files_struct *fsp, const void *data,
918 size_t n, off_t offset)
920 struct stream_io *sio =
921 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
922 struct ea_struct ea;
923 NTSTATUS status;
924 struct smb_filename *smb_fname_base = NULL;
925 int ret;
927 DEBUG(10, ("streams_xattr_pwrite called for %d bytes\n", (int)n));
929 if (sio == NULL) {
930 return SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
933 if (!streams_xattr_recheck(sio)) {
934 return -1;
937 /* Create an smb_filename with stream_name == NULL. */
938 smb_fname_base = synthetic_smb_fname(talloc_tos(),
939 sio->base,
940 NULL,
941 NULL,
942 fsp->fsp_name->flags);
943 if (smb_fname_base == NULL) {
944 errno = ENOMEM;
945 return -1;
948 status = get_ea_value(talloc_tos(), handle->conn, NULL,
949 smb_fname_base, sio->xattr_name, &ea);
950 if (!NT_STATUS_IS_OK(status)) {
951 return -1;
954 if ((offset + n) > ea.value.length-1) {
955 uint8_t *tmp;
957 tmp = talloc_realloc(talloc_tos(), ea.value.data, uint8_t,
958 offset + n + 1);
960 if (tmp == NULL) {
961 TALLOC_FREE(ea.value.data);
962 errno = ENOMEM;
963 return -1;
965 ea.value.data = tmp;
966 ea.value.length = offset + n + 1;
967 ea.value.data[offset+n] = 0;
970 memcpy(ea.value.data + offset, data, n);
972 ret = SMB_VFS_SETXATTR(fsp->conn,
973 fsp->fsp_name,
974 sio->xattr_name,
975 ea.value.data, ea.value.length, 0);
976 TALLOC_FREE(ea.value.data);
978 if (ret == -1) {
979 return -1;
982 return n;
985 static ssize_t streams_xattr_pread(vfs_handle_struct *handle,
986 files_struct *fsp, void *data,
987 size_t n, off_t offset)
989 struct stream_io *sio =
990 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
991 struct ea_struct ea;
992 NTSTATUS status;
993 size_t length, overlap;
994 struct smb_filename *smb_fname_base = NULL;
996 DEBUG(10, ("streams_xattr_pread: offset=%d, size=%d\n",
997 (int)offset, (int)n));
999 if (sio == NULL) {
1000 return SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1003 if (!streams_xattr_recheck(sio)) {
1004 return -1;
1007 /* Create an smb_filename with stream_name == NULL. */
1008 smb_fname_base = synthetic_smb_fname(talloc_tos(),
1009 sio->base,
1010 NULL,
1011 NULL,
1012 fsp->fsp_name->flags);
1013 if (smb_fname_base == NULL) {
1014 errno = ENOMEM;
1015 return -1;
1018 status = get_ea_value(talloc_tos(), handle->conn, NULL,
1019 smb_fname_base, sio->xattr_name, &ea);
1020 if (!NT_STATUS_IS_OK(status)) {
1021 return -1;
1024 length = ea.value.length-1;
1026 DEBUG(10, ("streams_xattr_pread: get_ea_value returned %d bytes\n",
1027 (int)length));
1029 /* Attempt to read past EOF. */
1030 if (length <= offset) {
1031 return 0;
1034 overlap = (offset + n) > length ? (length - offset) : n;
1035 memcpy(data, ea.value.data + offset, overlap);
1037 TALLOC_FREE(ea.value.data);
1038 return overlap;
1041 struct streams_xattr_pread_state {
1042 ssize_t nread;
1043 struct vfs_aio_state vfs_aio_state;
1046 static void streams_xattr_pread_done(struct tevent_req *subreq);
1048 static struct tevent_req *streams_xattr_pread_send(
1049 struct vfs_handle_struct *handle,
1050 TALLOC_CTX *mem_ctx,
1051 struct tevent_context *ev,
1052 struct files_struct *fsp,
1053 void *data,
1054 size_t n, off_t offset)
1056 struct tevent_req *req = NULL;
1057 struct tevent_req *subreq = NULL;
1058 struct streams_xattr_pread_state *state = NULL;
1059 struct stream_io *sio =
1060 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1062 req = tevent_req_create(mem_ctx, &state,
1063 struct streams_xattr_pread_state);
1064 if (req == NULL) {
1065 return NULL;
1068 if (sio == NULL) {
1069 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp,
1070 data, n, offset);
1071 if (tevent_req_nomem(req, subreq)) {
1072 return tevent_req_post(req, ev);
1074 tevent_req_set_callback(subreq, streams_xattr_pread_done, req);
1075 return req;
1078 state->nread = SMB_VFS_PREAD(fsp, data, n, offset);
1079 if (state->nread != n) {
1080 if (state->nread != -1) {
1081 errno = EIO;
1083 tevent_req_error(req, errno);
1084 return tevent_req_post(req, ev);
1087 tevent_req_done(req);
1088 return tevent_req_post(req, ev);
1091 static void streams_xattr_pread_done(struct tevent_req *subreq)
1093 struct tevent_req *req = tevent_req_callback_data(
1094 subreq, struct tevent_req);
1095 struct streams_xattr_pread_state *state = tevent_req_data(
1096 req, struct streams_xattr_pread_state);
1098 state->nread = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1099 TALLOC_FREE(subreq);
1101 if (tevent_req_error(req, state->vfs_aio_state.error)) {
1102 return;
1104 tevent_req_done(req);
1107 static ssize_t streams_xattr_pread_recv(struct tevent_req *req,
1108 struct vfs_aio_state *vfs_aio_state)
1110 struct streams_xattr_pread_state *state = tevent_req_data(
1111 req, struct streams_xattr_pread_state);
1113 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1114 return -1;
1117 *vfs_aio_state = state->vfs_aio_state;
1118 return state->nread;
1121 struct streams_xattr_pwrite_state {
1122 ssize_t nwritten;
1123 struct vfs_aio_state vfs_aio_state;
1126 static void streams_xattr_pwrite_done(struct tevent_req *subreq);
1128 static struct tevent_req *streams_xattr_pwrite_send(
1129 struct vfs_handle_struct *handle,
1130 TALLOC_CTX *mem_ctx,
1131 struct tevent_context *ev,
1132 struct files_struct *fsp,
1133 const void *data,
1134 size_t n, off_t offset)
1136 struct tevent_req *req = NULL;
1137 struct tevent_req *subreq = NULL;
1138 struct streams_xattr_pwrite_state *state = NULL;
1139 struct stream_io *sio =
1140 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1142 req = tevent_req_create(mem_ctx, &state,
1143 struct streams_xattr_pwrite_state);
1144 if (req == NULL) {
1145 return NULL;
1148 if (sio == NULL) {
1149 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp,
1150 data, n, offset);
1151 if (tevent_req_nomem(req, subreq)) {
1152 return tevent_req_post(req, ev);
1154 tevent_req_set_callback(subreq, streams_xattr_pwrite_done, req);
1155 return req;
1158 state->nwritten = SMB_VFS_PWRITE(fsp, data, n, offset);
1159 if (state->nwritten != n) {
1160 if (state->nwritten != -1) {
1161 errno = EIO;
1163 tevent_req_error(req, errno);
1164 return tevent_req_post(req, ev);
1167 tevent_req_done(req);
1168 return tevent_req_post(req, ev);
1171 static void streams_xattr_pwrite_done(struct tevent_req *subreq)
1173 struct tevent_req *req = tevent_req_callback_data(
1174 subreq, struct tevent_req);
1175 struct streams_xattr_pwrite_state *state = tevent_req_data(
1176 req, struct streams_xattr_pwrite_state);
1178 state->nwritten = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1179 TALLOC_FREE(subreq);
1181 if (tevent_req_error(req, state->vfs_aio_state.error)) {
1182 return;
1184 tevent_req_done(req);
1187 static ssize_t streams_xattr_pwrite_recv(struct tevent_req *req,
1188 struct vfs_aio_state *vfs_aio_state)
1190 struct streams_xattr_pwrite_state *state = tevent_req_data(
1191 req, struct streams_xattr_pwrite_state);
1193 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1194 return -1;
1197 *vfs_aio_state = state->vfs_aio_state;
1198 return state->nwritten;
1201 static int streams_xattr_ftruncate(struct vfs_handle_struct *handle,
1202 struct files_struct *fsp,
1203 off_t offset)
1205 int ret;
1206 uint8_t *tmp;
1207 struct ea_struct ea;
1208 NTSTATUS status;
1209 struct stream_io *sio =
1210 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1211 struct smb_filename *smb_fname_base = NULL;
1213 DEBUG(10, ("streams_xattr_ftruncate called for file %s offset %.0f\n",
1214 fsp_str_dbg(fsp), (double)offset));
1216 if (sio == NULL) {
1217 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
1220 if (!streams_xattr_recheck(sio)) {
1221 return -1;
1224 /* Create an smb_filename with stream_name == NULL. */
1225 smb_fname_base = synthetic_smb_fname(talloc_tos(),
1226 sio->base,
1227 NULL,
1228 NULL,
1229 fsp->fsp_name->flags);
1230 if (smb_fname_base == NULL) {
1231 errno = ENOMEM;
1232 return -1;
1235 status = get_ea_value(talloc_tos(), handle->conn, NULL,
1236 smb_fname_base, sio->xattr_name, &ea);
1237 if (!NT_STATUS_IS_OK(status)) {
1238 return -1;
1241 tmp = talloc_realloc(talloc_tos(), ea.value.data, uint8_t,
1242 offset + 1);
1244 if (tmp == NULL) {
1245 TALLOC_FREE(ea.value.data);
1246 errno = ENOMEM;
1247 return -1;
1250 /* Did we expand ? */
1251 if (ea.value.length < offset + 1) {
1252 memset(&tmp[ea.value.length], '\0',
1253 offset + 1 - ea.value.length);
1256 ea.value.data = tmp;
1257 ea.value.length = offset + 1;
1258 ea.value.data[offset] = 0;
1260 ret = SMB_VFS_SETXATTR(fsp->conn,
1261 fsp->fsp_name,
1262 sio->xattr_name,
1263 ea.value.data, ea.value.length, 0);
1264 TALLOC_FREE(ea.value.data);
1266 if (ret == -1) {
1267 return -1;
1270 return 0;
1273 static int streams_xattr_fallocate(struct vfs_handle_struct *handle,
1274 struct files_struct *fsp,
1275 uint32_t mode,
1276 off_t offset,
1277 off_t len)
1279 struct stream_io *sio =
1280 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1282 DEBUG(10, ("streams_xattr_fallocate called for file %s offset %.0f"
1283 "len = %.0f\n",
1284 fsp_str_dbg(fsp), (double)offset, (double)len));
1286 if (sio == NULL) {
1287 return SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1290 if (!streams_xattr_recheck(sio)) {
1291 return -1;
1294 /* Let the pwrite code path handle it. */
1295 errno = ENOSYS;
1296 return -1;
1299 static int streams_xattr_fchown(vfs_handle_struct *handle, files_struct *fsp,
1300 uid_t uid, gid_t gid)
1302 struct stream_io *sio =
1303 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1305 if (sio == NULL) {
1306 return SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1309 return 0;
1312 static int streams_xattr_fchmod(vfs_handle_struct *handle,
1313 files_struct *fsp,
1314 mode_t mode)
1316 struct stream_io *sio =
1317 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1319 if (sio == NULL) {
1320 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1323 return 0;
1326 static ssize_t streams_xattr_fgetxattr(struct vfs_handle_struct *handle,
1327 struct files_struct *fsp,
1328 const char *name,
1329 void *value,
1330 size_t size)
1332 struct stream_io *sio =
1333 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1335 if (sio == NULL) {
1336 return SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
1339 errno = ENOTSUP;
1340 return -1;
1343 static ssize_t streams_xattr_flistxattr(struct vfs_handle_struct *handle,
1344 struct files_struct *fsp,
1345 char *list,
1346 size_t size)
1348 struct stream_io *sio =
1349 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1351 if (sio == NULL) {
1352 return SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
1355 errno = ENOTSUP;
1356 return -1;
1359 static int streams_xattr_fremovexattr(struct vfs_handle_struct *handle,
1360 struct files_struct *fsp,
1361 const char *name)
1363 struct stream_io *sio =
1364 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1366 if (sio == NULL) {
1367 return SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
1370 errno = ENOTSUP;
1371 return -1;
1374 static int streams_xattr_fsetxattr(struct vfs_handle_struct *handle,
1375 struct files_struct *fsp,
1376 const char *name,
1377 const void *value,
1378 size_t size,
1379 int flags)
1381 struct stream_io *sio =
1382 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1384 if (sio == NULL) {
1385 return SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value,
1386 size, flags);
1389 errno = ENOTSUP;
1390 return -1;
1393 static SMB_ACL_T streams_xattr_sys_acl_get_fd(vfs_handle_struct *handle,
1394 files_struct *fsp,
1395 TALLOC_CTX *mem_ctx)
1397 struct stream_io *sio =
1398 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1400 if (sio == NULL) {
1401 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1404 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(
1405 handle, fsp->base_fsp->fsp_name,
1406 SMB_ACL_TYPE_ACCESS, mem_ctx);
1409 static int streams_xattr_sys_acl_set_fd(vfs_handle_struct *handle,
1410 files_struct *fsp,
1411 SMB_ACL_T theacl)
1413 struct stream_io *sio =
1414 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1416 if (sio == NULL) {
1417 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1420 return 0;
1423 static int streams_xattr_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1424 files_struct *fsp,
1425 TALLOC_CTX *mem_ctx,
1426 char **blob_description,
1427 DATA_BLOB *blob)
1429 struct stream_io *sio =
1430 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1432 if (sio == NULL) {
1433 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1434 blob_description, blob);
1437 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(
1438 handle, fsp->base_fsp->fsp_name, mem_ctx,
1439 blob_description, blob);
1442 static NTSTATUS streams_xattr_fget_nt_acl(vfs_handle_struct *handle,
1443 files_struct *fsp,
1444 uint32_t security_info,
1445 TALLOC_CTX *mem_ctx,
1446 struct security_descriptor **ppdesc)
1448 struct stream_io *sio =
1449 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1451 if (sio == NULL) {
1452 return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1453 mem_ctx, ppdesc);
1456 return SMB_VFS_NEXT_GET_NT_ACL(handle, fsp->base_fsp->fsp_name,
1457 security_info, mem_ctx, ppdesc);
1460 static NTSTATUS streams_xattr_fset_nt_acl(vfs_handle_struct *handle,
1461 files_struct *fsp,
1462 uint32_t security_info_sent,
1463 const struct security_descriptor *psd)
1465 struct stream_io *sio =
1466 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1468 if (sio == NULL) {
1469 return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp,
1470 security_info_sent, psd);
1473 return NT_STATUS_OK;
1476 struct streams_xattr_fsync_state {
1477 int ret;
1478 struct vfs_aio_state vfs_aio_state;
1481 static void streams_xattr_fsync_done(struct tevent_req *subreq);
1483 static struct tevent_req *streams_xattr_fsync_send(
1484 struct vfs_handle_struct *handle,
1485 TALLOC_CTX *mem_ctx,
1486 struct tevent_context *ev,
1487 struct files_struct *fsp)
1489 struct tevent_req *req = NULL;
1490 struct tevent_req *subreq = NULL;
1491 struct streams_xattr_fsync_state *state = NULL;
1492 struct stream_io *sio =
1493 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1495 req = tevent_req_create(mem_ctx, &state,
1496 struct streams_xattr_fsync_state);
1497 if (req == NULL) {
1498 return NULL;
1501 if (sio == NULL) {
1502 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1503 if (tevent_req_nomem(req, subreq)) {
1504 return tevent_req_post(req, ev);
1506 tevent_req_set_callback(subreq, streams_xattr_fsync_done, req);
1507 return req;
1511 * There's no pathname based sync variant and we don't have access to
1512 * the basefile handle, so we can't do anything here.
1515 tevent_req_done(req);
1516 return tevent_req_post(req, ev);
1519 static void streams_xattr_fsync_done(struct tevent_req *subreq)
1521 struct tevent_req *req = tevent_req_callback_data(
1522 subreq, struct tevent_req);
1523 struct streams_xattr_fsync_state *state = tevent_req_data(
1524 req, struct streams_xattr_fsync_state);
1526 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1527 TALLOC_FREE(subreq);
1528 if (state->ret != 0) {
1529 tevent_req_error(req, errno);
1530 return;
1533 tevent_req_done(req);
1536 static int streams_xattr_fsync_recv(struct tevent_req *req,
1537 struct vfs_aio_state *vfs_aio_state)
1539 struct streams_xattr_fsync_state *state = tevent_req_data(
1540 req, struct streams_xattr_fsync_state);
1542 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1543 return -1;
1546 *vfs_aio_state = state->vfs_aio_state;
1547 return state->ret;
1550 static bool streams_xattr_lock(vfs_handle_struct *handle,
1551 files_struct *fsp,
1552 int op,
1553 off_t offset,
1554 off_t count,
1555 int type)
1557 struct stream_io *sio =
1558 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1560 if (sio == NULL) {
1561 return SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1564 return true;
1567 static bool streams_xattr_getlock(vfs_handle_struct *handle,
1568 files_struct *fsp,
1569 off_t *poffset,
1570 off_t *pcount,
1571 int *ptype,
1572 pid_t *ppid)
1574 struct stream_io *sio =
1575 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1577 if (sio == NULL) {
1578 return SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset,
1579 pcount, ptype, ppid);
1582 errno = ENOTSUP;
1583 return false;
1586 static int streams_xattr_kernel_flock(vfs_handle_struct *handle,
1587 files_struct *fsp,
1588 uint32_t share_access,
1589 uint32_t access_mask)
1591 struct stream_io *sio =
1592 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1594 if (sio == NULL) {
1595 return SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp,
1596 share_access, access_mask);
1599 return 0;
1602 static int streams_xattr_linux_setlease(vfs_handle_struct *handle,
1603 files_struct *fsp,
1604 int leasetype)
1606 struct stream_io *sio =
1607 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1609 if (sio == NULL) {
1610 return SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1613 return 0;
1616 static bool streams_xattr_strict_lock_check(struct vfs_handle_struct *handle,
1617 files_struct *fsp,
1618 struct lock_struct *plock)
1620 struct stream_io *sio =
1621 (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
1623 if (sio == NULL) {
1624 return SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
1627 return true;
1630 static struct vfs_fn_pointers vfs_streams_xattr_fns = {
1631 .fs_capabilities_fn = streams_xattr_fs_capabilities,
1632 .connect_fn = streams_xattr_connect,
1633 .open_fn = streams_xattr_open,
1634 .close_fn = streams_xattr_close,
1635 .stat_fn = streams_xattr_stat,
1636 .fstat_fn = streams_xattr_fstat,
1637 .lstat_fn = streams_xattr_lstat,
1638 .pread_fn = streams_xattr_pread,
1639 .pwrite_fn = streams_xattr_pwrite,
1640 .pread_send_fn = streams_xattr_pread_send,
1641 .pread_recv_fn = streams_xattr_pread_recv,
1642 .pwrite_send_fn = streams_xattr_pwrite_send,
1643 .pwrite_recv_fn = streams_xattr_pwrite_recv,
1644 .unlinkat_fn = streams_xattr_unlinkat,
1645 .renameat_fn = streams_xattr_renameat,
1646 .ftruncate_fn = streams_xattr_ftruncate,
1647 .fallocate_fn = streams_xattr_fallocate,
1648 .streaminfo_fn = streams_xattr_streaminfo,
1650 .fsync_send_fn = streams_xattr_fsync_send,
1651 .fsync_recv_fn = streams_xattr_fsync_recv,
1653 .lock_fn = streams_xattr_lock,
1654 .getlock_fn = streams_xattr_getlock,
1655 .kernel_flock_fn = streams_xattr_kernel_flock,
1656 .linux_setlease_fn = streams_xattr_linux_setlease,
1657 .strict_lock_check_fn = streams_xattr_strict_lock_check,
1659 .fchown_fn = streams_xattr_fchown,
1660 .fchmod_fn = streams_xattr_fchmod,
1662 .fgetxattr_fn = streams_xattr_fgetxattr,
1663 .flistxattr_fn = streams_xattr_flistxattr,
1664 .fremovexattr_fn = streams_xattr_fremovexattr,
1665 .fsetxattr_fn = streams_xattr_fsetxattr,
1667 .sys_acl_get_fd_fn = streams_xattr_sys_acl_get_fd,
1668 .sys_acl_blob_get_fd_fn = streams_xattr_sys_acl_blob_get_fd,
1669 .sys_acl_set_fd_fn = streams_xattr_sys_acl_set_fd,
1671 .fget_nt_acl_fn = streams_xattr_fget_nt_acl,
1672 .fset_nt_acl_fn = streams_xattr_fset_nt_acl,
1675 static_decl_vfs;
1676 NTSTATUS vfs_streams_xattr_init(TALLOC_CTX *ctx)
1678 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "streams_xattr",
1679 &vfs_streams_xattr_fns);