4 * Implement a fixed mapping of forbidden NT characters in filenames that are
5 * used a lot by the CAD package Catia.
7 * Catia V4 on AIX uses characters like "<*$ a *lot*, all forbidden under
10 * Copyright (C) Volker Lendecke, 2005
11 * Copyright (C) Aravind Srinivasan, 2009
12 * Copyright (C) Guenter Kukkukk, 2013
13 * Copyright (C) Ralph Boehme, 2017
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
31 #include "smbd/smbd.h"
32 #include "lib/util/tevent_unix.h"
33 #include "lib/util/tevent_ntstatus.h"
34 #include "string_replace.h"
36 static int vfs_catia_debug_level = DBGC_VFS;
39 #define DBGC_CLASS vfs_catia_debug_level
41 struct share_mapping_entry {
43 struct share_mapping_entry *next;
44 struct char_mappings **mappings;
49 const struct catia_cache * const *busy;
52 char *orig_base_fname;
56 static struct share_mapping_entry *srt_head = NULL;
58 static struct share_mapping_entry *get_srt(connection_struct *conn,
59 struct share_mapping_entry **global)
61 struct share_mapping_entry *share;
63 for (share = srt_head; share != NULL; share = share->next) {
64 if (share->snum == GLOBAL_SECTION_SNUM)
67 if (share->snum == SNUM(conn))
74 static struct share_mapping_entry *add_srt(int snum, const char **mappings)
76 struct share_mapping_entry *sme = NULL;
78 sme = TALLOC_ZERO(NULL, sizeof(struct share_mapping_entry));
86 if (mappings == NULL) {
91 sme->mappings = string_replace_init_map(mappings);
96 static bool init_mappings(connection_struct *conn,
97 struct share_mapping_entry **selected_out)
99 const char **mappings = NULL;
100 struct share_mapping_entry *share_level = NULL;
101 struct share_mapping_entry *global = NULL;
103 /* check srt cache */
104 share_level = get_srt(conn, &global);
106 *selected_out = share_level;
107 return (share_level->mappings != NULL);
110 /* see if we have a global setting */
113 mappings = lp_parm_string_list(-1, "catia", "mappings", NULL);
114 global = add_srt(GLOBAL_SECTION_SNUM, mappings);
117 /* no global setting - what about share level ? */
118 mappings = lp_parm_string_list(SNUM(conn), "catia", "mappings", NULL);
119 share_level = add_srt(SNUM(conn), mappings);
121 if (share_level->mappings) {
122 (*selected_out) = share_level;
125 if (global->mappings) {
126 share_level->mappings = global->mappings;
127 (*selected_out) = share_level;
134 static NTSTATUS catia_string_replace_allocate(connection_struct *conn,
137 enum vfs_translate_direction direction)
139 struct share_mapping_entry *selected;
142 if (!init_mappings(conn, &selected)) {
143 /* No mappings found. Just use the old name */
144 *mapped_name = talloc_strdup(talloc_tos(), name_in);
147 return NT_STATUS_NO_MEMORY;
152 status = string_replace_allocate(conn,
161 static DIR *catia_opendir(vfs_handle_struct *handle,
162 const struct smb_filename *smb_fname,
166 char *name_mapped = NULL;
169 struct smb_filename *mapped_smb_fname = NULL;
171 status = catia_string_replace_allocate(handle->conn,
172 smb_fname->base_name,
174 vfs_translate_to_unix);
175 if (!NT_STATUS_IS_OK(status)) {
176 errno = map_errno_from_nt_status(status);
180 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
185 if (mapped_smb_fname == NULL) {
186 TALLOC_FREE(mapped_smb_fname);
191 ret = SMB_VFS_NEXT_OPENDIR(handle, mapped_smb_fname, mask, attr);
193 TALLOC_FREE(name_mapped);
194 TALLOC_FREE(mapped_smb_fname);
200 * TRANSLATE_NAME call which converts the given name to
201 * "WINDOWS displayable" name
203 static NTSTATUS catia_translate_name(struct vfs_handle_struct *handle,
204 const char *orig_name,
205 enum vfs_translate_direction direction,
211 NTSTATUS status, ret;
214 * Copy the supplied name and free the memory for mapped_name,
215 * already allocated by the caller.
216 * We will be allocating new memory for mapped_name in
217 * catia_string_replace_allocate
219 name = talloc_strdup(talloc_tos(), orig_name);
222 return NT_STATUS_NO_MEMORY;
224 status = catia_string_replace_allocate(handle->conn, name,
225 &mapped_name, direction);
228 if (!NT_STATUS_IS_OK(status)) {
232 ret = SMB_VFS_NEXT_TRANSLATE_NAME(handle, mapped_name, direction,
233 mem_ctx, pmapped_name);
235 if (NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED)) {
236 *pmapped_name = talloc_move(mem_ctx, &mapped_name);
237 /* we need to return the former translation result here */
240 TALLOC_FREE(mapped_name);
246 #define CATIA_DEBUG_CC(lvl, cc, fsp) \
247 catia_debug_cc((lvl), (cc), (fsp), __location__);
249 static void catia_debug_cc(int lvl,
250 struct catia_cache *cc,
252 const char *location)
254 DEBUG(lvl, ("%s: cc [%p] cc->busy [%p] "
256 "fsp [%p] fsp name [%s] "
259 "orig_base_fname [%s] "
263 cc->is_fsp_ext ? "yes" : "no",
264 fsp, fsp_str_dbg(fsp),
265 cc->orig_fname, cc->fname,
266 cc->orig_base_fname, cc->base_fname));
269 static void catia_free_cc(struct catia_cache **_cc,
270 vfs_handle_struct *handle,
273 struct catia_cache *cc = *_cc;
275 if (cc->is_fsp_ext) {
276 VFS_REMOVE_FSP_EXTENSION(handle, fsp);
285 static struct catia_cache *catia_validate_and_apply_cc(
286 vfs_handle_struct *handle,
288 const struct catia_cache * const *busy,
289 bool *make_tmp_cache)
291 struct catia_cache *cc = NULL;
293 *make_tmp_cache = false;
295 cc = (struct catia_cache *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
300 if (cc->busy != NULL) {
301 if (cc->busy == busy) {
302 /* This should never happen */
303 CATIA_DEBUG_CC(0, cc, fsp);
304 smb_panic(__location__);
308 * Recursion. Validate names, the names in the fsp's should be
309 * the translated names we had set.
312 if ((cc->fname != fsp->fsp_name->base_name)
314 ((fsp->base_fsp != NULL) &&
315 (cc->base_fname != fsp->base_fsp->fsp_name->base_name)))
317 CATIA_DEBUG_CC(10, cc, fsp);
320 * Names changed. Setting don't expose the cache on the
321 * fsp and ask the caller to create a temporary cache.
323 *make_tmp_cache = true;
328 * Ok, a validated cache while in a recursion, just let the
329 * caller detect that cc->busy is != busy and there's
330 * nothing else to do.
332 CATIA_DEBUG_CC(10, cc, fsp);
336 /* Not in a recursion */
338 if ((cc->orig_fname != fsp->fsp_name->base_name)
340 ((fsp->base_fsp != NULL) &&
341 (cc->orig_base_fname != fsp->base_fsp->fsp_name->base_name)))
344 * fsp names changed, this can happen in an rename op.
345 * Trigger recreation as a full fledged fsp extension.
348 CATIA_DEBUG_CC(10, cc, fsp);
349 catia_free_cc(&cc, handle, fsp);
355 * Ok, we found a valid cache entry, no recursion. Just set translated
356 * names from the cache and mark the cc as busy.
358 fsp->fsp_name->base_name = cc->fname;
359 if (fsp->base_fsp != NULL) {
360 fsp->base_fsp->fsp_name->base_name = cc->base_fname;
364 CATIA_DEBUG_CC(10, cc, fsp);
368 #define CATIA_FETCH_FSP_PRE_NEXT(mem_ctx, handle, fsp, _cc) \
369 catia_fetch_fsp_pre_next((mem_ctx), (handle), (fsp), (_cc), __func__);
371 static int catia_fetch_fsp_pre_next(TALLOC_CTX *mem_ctx,
372 vfs_handle_struct *handle,
374 struct catia_cache **_cc,
375 const char *function)
377 const struct catia_cache * const *busy =
378 (const struct catia_cache * const *)_cc;
379 struct catia_cache *cc = NULL;
381 bool make_tmp_cache = false;
385 DBG_DEBUG("Called from [%s]\n", function);
387 cc = catia_validate_and_apply_cc(handle,
392 if (cc->busy != busy) {
399 if (!make_tmp_cache) {
400 cc = VFS_ADD_FSP_EXTENSION(
401 handle, fsp, struct catia_cache, NULL);
405 *cc = (struct catia_cache) {
409 mem_ctx = VFS_MEMCTX_FSP_EXTENSION(handle, fsp);
410 if (mem_ctx == NULL) {
411 DBG_ERR("VFS_MEMCTX_FSP_EXTENSION failed\n");
412 catia_free_cc(&cc, handle, fsp);
416 cc = talloc_zero(mem_ctx, struct catia_cache);
424 status = catia_string_replace_allocate(handle->conn,
425 fsp->fsp_name->base_name,
427 vfs_translate_to_unix);
428 if (!NT_STATUS_IS_OK(status)) {
429 catia_free_cc(&cc, handle, fsp);
430 errno = map_errno_from_nt_status(status);
433 talloc_steal(mem_ctx, cc->fname);
435 if (fsp->base_fsp != NULL) {
436 status = catia_string_replace_allocate(
438 fsp->base_fsp->fsp_name->base_name,
440 vfs_translate_to_unix);
441 if (!NT_STATUS_IS_OK(status)) {
442 catia_free_cc(&cc, handle, fsp);
443 errno = map_errno_from_nt_status(status);
446 talloc_steal(mem_ctx, cc->base_fname);
449 cc->orig_fname = fsp->fsp_name->base_name;
450 fsp->fsp_name->base_name = cc->fname;
452 if (fsp->base_fsp != NULL) {
453 cc->orig_base_fname = fsp->base_fsp->fsp_name->base_name;
454 fsp->base_fsp->fsp_name->base_name = cc->base_fname;
458 CATIA_DEBUG_CC(10, cc, fsp);
465 #define CATIA_FETCH_FSP_POST_NEXT(_cc, fsp) do { \
466 int saved_errno = errno; \
467 catia_fetch_fsp_post_next((_cc), (fsp), __func__); \
468 errno = saved_errno; \
471 static void catia_fetch_fsp_post_next(struct catia_cache **_cc,
473 const char *function)
475 const struct catia_cache * const *busy =
476 (const struct catia_cache * const *)_cc;
477 struct catia_cache *cc = *_cc;
479 DBG_DEBUG("Called from [%s]\n", function);
483 * This can happen when recursing in the VFS on the fsp when the
484 * pre_next func noticed the recursion and set out cc pointer to
490 if (cc->busy != busy) {
491 CATIA_DEBUG_CC(0, cc, fsp);
492 smb_panic(__location__);
499 fsp->fsp_name->base_name = cc->orig_fname;
500 if (fsp->base_fsp != NULL) {
501 fsp->base_fsp->fsp_name->base_name = cc->orig_base_fname;
504 CATIA_DEBUG_CC(10, cc, fsp);
506 if (!cc->is_fsp_ext) {
513 static int catia_open(vfs_handle_struct *handle,
514 struct smb_filename *smb_fname,
519 struct catia_cache *cc = NULL;
520 char *orig_smb_fname = smb_fname->base_name;
521 char *mapped_smb_fname = NULL;
525 status = catia_string_replace_allocate(handle->conn,
526 smb_fname->base_name,
528 vfs_translate_to_unix);
529 if (!NT_STATUS_IS_OK(status)) {
533 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
535 TALLOC_FREE(mapped_smb_fname);
539 smb_fname->base_name = mapped_smb_fname;
540 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
541 smb_fname->base_name = orig_smb_fname;
543 TALLOC_FREE(mapped_smb_fname);
544 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
549 static int catia_rename(vfs_handle_struct *handle,
550 const struct smb_filename *smb_fname_src,
551 const struct smb_filename *smb_fname_dst)
553 TALLOC_CTX *ctx = talloc_tos();
554 struct smb_filename *smb_fname_src_tmp = NULL;
555 struct smb_filename *smb_fname_dst_tmp = NULL;
556 char *src_name_mapped = NULL;
557 char *dst_name_mapped = NULL;
561 status = catia_string_replace_allocate(handle->conn,
562 smb_fname_src->base_name,
563 &src_name_mapped, vfs_translate_to_unix);
564 if (!NT_STATUS_IS_OK(status)) {
565 errno = map_errno_from_nt_status(status);
569 status = catia_string_replace_allocate(handle->conn,
570 smb_fname_dst->base_name,
571 &dst_name_mapped, vfs_translate_to_unix);
572 if (!NT_STATUS_IS_OK(status)) {
573 errno = map_errno_from_nt_status(status);
577 /* Setup temporary smb_filename structs. */
578 smb_fname_src_tmp = cp_smb_filename(ctx, smb_fname_src);
579 if (smb_fname_src_tmp == NULL) {
584 smb_fname_dst_tmp = cp_smb_filename(ctx, smb_fname_dst);
585 if (smb_fname_dst_tmp == NULL) {
590 smb_fname_src_tmp->base_name = src_name_mapped;
591 smb_fname_dst_tmp->base_name = dst_name_mapped;
592 DEBUG(10, ("converted old name: %s\n",
593 smb_fname_str_dbg(smb_fname_src_tmp)));
594 DEBUG(10, ("converted new name: %s\n",
595 smb_fname_str_dbg(smb_fname_dst_tmp)));
597 ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src_tmp,
600 TALLOC_FREE(src_name_mapped);
601 TALLOC_FREE(dst_name_mapped);
602 TALLOC_FREE(smb_fname_src_tmp);
603 TALLOC_FREE(smb_fname_dst_tmp);
607 static int catia_stat(vfs_handle_struct *handle,
608 struct smb_filename *smb_fname)
615 status = catia_string_replace_allocate(handle->conn,
616 smb_fname->base_name,
617 &name, vfs_translate_to_unix);
618 if (!NT_STATUS_IS_OK(status)) {
619 errno = map_errno_from_nt_status(status);
623 tmp_base_name = smb_fname->base_name;
624 smb_fname->base_name = name;
626 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
627 smb_fname->base_name = tmp_base_name;
633 static int catia_lstat(vfs_handle_struct *handle,
634 struct smb_filename *smb_fname)
641 status = catia_string_replace_allocate(handle->conn,
642 smb_fname->base_name,
643 &name, vfs_translate_to_unix);
644 if (!NT_STATUS_IS_OK(status)) {
645 errno = map_errno_from_nt_status(status);
649 tmp_base_name = smb_fname->base_name;
650 smb_fname->base_name = name;
652 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
653 smb_fname->base_name = tmp_base_name;
659 static int catia_unlink(vfs_handle_struct *handle,
660 const struct smb_filename *smb_fname)
662 struct smb_filename *smb_fname_tmp = NULL;
667 status = catia_string_replace_allocate(handle->conn,
668 smb_fname->base_name,
669 &name, vfs_translate_to_unix);
670 if (!NT_STATUS_IS_OK(status)) {
671 errno = map_errno_from_nt_status(status);
675 /* Setup temporary smb_filename structs. */
676 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
677 if (smb_fname_tmp == NULL) {
682 smb_fname_tmp->base_name = name;
683 ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_tmp);
684 TALLOC_FREE(smb_fname_tmp);
690 static int catia_chown(vfs_handle_struct *handle,
691 const struct smb_filename *smb_fname,
699 struct smb_filename *catia_smb_fname = NULL;
701 status = catia_string_replace_allocate(handle->conn,
702 smb_fname->base_name,
704 vfs_translate_to_unix);
705 if (!NT_STATUS_IS_OK(status)) {
706 errno = map_errno_from_nt_status(status);
709 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
714 if (catia_smb_fname == NULL) {
720 ret = SMB_VFS_NEXT_CHOWN(handle, catia_smb_fname, uid, gid);
723 TALLOC_FREE(catia_smb_fname);
728 static int catia_lchown(vfs_handle_struct *handle,
729 const struct smb_filename *smb_fname,
737 struct smb_filename *catia_smb_fname = NULL;
739 status = catia_string_replace_allocate(handle->conn,
740 smb_fname->base_name,
742 vfs_translate_to_unix);
743 if (!NT_STATUS_IS_OK(status)) {
744 errno = map_errno_from_nt_status(status);
747 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
752 if (catia_smb_fname == NULL) {
758 ret = SMB_VFS_NEXT_LCHOWN(handle, catia_smb_fname, uid, gid);
761 TALLOC_FREE(catia_smb_fname);
766 static int catia_chmod(vfs_handle_struct *handle,
767 const struct smb_filename *smb_fname,
774 struct smb_filename *catia_smb_fname = NULL;
776 status = catia_string_replace_allocate(handle->conn,
777 smb_fname->base_name,
779 vfs_translate_to_unix);
780 if (!NT_STATUS_IS_OK(status)) {
781 errno = map_errno_from_nt_status(status);
784 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
789 if (catia_smb_fname == NULL) {
795 ret = SMB_VFS_NEXT_CHMOD(handle, catia_smb_fname, mode);
798 TALLOC_FREE(catia_smb_fname);
803 static int catia_rmdir(vfs_handle_struct *handle,
804 const struct smb_filename *smb_fname)
809 struct smb_filename *catia_smb_fname = NULL;
811 status = catia_string_replace_allocate(handle->conn,
812 smb_fname->base_name,
814 vfs_translate_to_unix);
815 if (!NT_STATUS_IS_OK(status)) {
816 errno = map_errno_from_nt_status(status);
819 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
824 if (catia_smb_fname == NULL) {
830 ret = SMB_VFS_NEXT_RMDIR(handle, catia_smb_fname);
832 TALLOC_FREE(catia_smb_fname);
837 static int catia_mkdir(vfs_handle_struct *handle,
838 const struct smb_filename *smb_fname,
844 struct smb_filename *catia_smb_fname = NULL;
846 status = catia_string_replace_allocate(handle->conn,
847 smb_fname->base_name,
849 vfs_translate_to_unix);
850 if (!NT_STATUS_IS_OK(status)) {
851 errno = map_errno_from_nt_status(status);
854 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
859 if (catia_smb_fname == NULL) {
865 ret = SMB_VFS_NEXT_MKDIR(handle, catia_smb_fname, mode);
867 TALLOC_FREE(catia_smb_fname);
872 static int catia_chdir(vfs_handle_struct *handle,
873 const struct smb_filename *smb_fname)
876 struct smb_filename *catia_smb_fname = NULL;
880 status = catia_string_replace_allocate(handle->conn,
881 smb_fname->base_name,
883 vfs_translate_to_unix);
884 if (!NT_STATUS_IS_OK(status)) {
885 errno = map_errno_from_nt_status(status);
889 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
894 if (catia_smb_fname == NULL) {
899 ret = SMB_VFS_NEXT_CHDIR(handle, catia_smb_fname);
901 TALLOC_FREE(catia_smb_fname);
906 static int catia_ntimes(vfs_handle_struct *handle,
907 const struct smb_filename *smb_fname,
908 struct smb_file_time *ft)
910 struct smb_filename *smb_fname_tmp = NULL;
915 status = catia_string_replace_allocate(handle->conn,
916 smb_fname->base_name,
917 &name, vfs_translate_to_unix);
918 if (!NT_STATUS_IS_OK(status)) {
919 errno = map_errno_from_nt_status(status);
923 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
924 if (smb_fname_tmp == NULL) {
929 smb_fname_tmp->base_name = name;
930 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname_tmp, ft);
932 TALLOC_FREE(smb_fname_tmp);
937 static struct smb_filename *
938 catia_realpath(vfs_handle_struct *handle,
940 const struct smb_filename *smb_fname)
942 char *mapped_name = NULL;
943 struct smb_filename *catia_smb_fname = NULL;
944 struct smb_filename *return_fname = NULL;
947 status = catia_string_replace_allocate(handle->conn,
948 smb_fname->base_name,
949 &mapped_name, vfs_translate_to_unix);
950 if (!NT_STATUS_IS_OK(status)) {
951 errno = map_errno_from_nt_status(status);
955 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
960 if (catia_smb_fname == NULL) {
961 TALLOC_FREE(mapped_name);
965 return_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, catia_smb_fname);
966 TALLOC_FREE(mapped_name);
967 TALLOC_FREE(catia_smb_fname);
971 static int catia_chflags(struct vfs_handle_struct *handle,
972 const struct smb_filename *smb_fname,
976 struct smb_filename *catia_smb_fname = NULL;
980 status = catia_string_replace_allocate(handle->conn,
981 smb_fname->base_name,
983 vfs_translate_to_unix);
984 if (!NT_STATUS_IS_OK(status)) {
985 errno = map_errno_from_nt_status(status);
988 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
993 if (catia_smb_fname == NULL) {
999 ret = SMB_VFS_NEXT_CHFLAGS(handle, catia_smb_fname, flags);
1001 TALLOC_FREE(catia_smb_fname);
1007 catia_streaminfo(struct vfs_handle_struct *handle,
1008 struct files_struct *fsp,
1009 const struct smb_filename *smb_fname,
1010 TALLOC_CTX *mem_ctx,
1011 unsigned int *_num_streams,
1012 struct stream_struct **_streams)
1014 char *mapped_name = NULL;
1017 struct smb_filename *catia_smb_fname = NULL;
1018 unsigned int num_streams = 0;
1019 struct stream_struct *streams = NULL;
1024 status = catia_string_replace_allocate(handle->conn,
1025 smb_fname->base_name,
1027 vfs_translate_to_unix);
1028 if (!NT_STATUS_IS_OK(status)) {
1029 errno = map_errno_from_nt_status(status);
1033 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
1038 if (catia_smb_fname == NULL) {
1039 TALLOC_FREE(mapped_name);
1040 return NT_STATUS_NO_MEMORY;
1043 status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, catia_smb_fname,
1044 mem_ctx, &num_streams, &streams);
1045 TALLOC_FREE(mapped_name);
1046 TALLOC_FREE(catia_smb_fname);
1047 if (!NT_STATUS_IS_OK(status)) {
1052 * Translate stream names just like the base names
1054 for (i = 0; i < num_streams; i++) {
1056 * Strip ":" prefix and ":$DATA" suffix to get a
1057 * "pure" stream name and only translate that.
1059 void *old_ptr = streams[i].name;
1060 char *stream_name = streams[i].name + 1;
1061 char *stream_type = strrchr_m(stream_name, ':');
1063 if (stream_type != NULL) {
1064 *stream_type = '\0';
1068 status = catia_string_replace_allocate(handle->conn, stream_name,
1069 &mapped_name, vfs_translate_to_windows);
1070 if (!NT_STATUS_IS_OK(status)) {
1071 TALLOC_FREE(streams);
1075 if (stream_type != NULL) {
1076 streams[i].name = talloc_asprintf(streams, ":%s:%s",
1077 mapped_name, stream_type);
1079 streams[i].name = talloc_asprintf(streams, ":%s",
1082 TALLOC_FREE(mapped_name);
1083 TALLOC_FREE(old_ptr);
1084 if (streams[i].name == NULL) {
1085 TALLOC_FREE(streams);
1086 return NT_STATUS_NO_MEMORY;
1090 *_num_streams = num_streams;
1091 *_streams = streams;
1092 return NT_STATUS_OK;
1096 catia_get_nt_acl(struct vfs_handle_struct *handle,
1097 const struct smb_filename *smb_fname,
1098 uint32_t security_info,
1099 TALLOC_CTX *mem_ctx,
1100 struct security_descriptor **ppdesc)
1102 char *mapped_name = NULL;
1103 const char *path = smb_fname->base_name;
1104 struct smb_filename *mapped_smb_fname = NULL;
1107 status = catia_string_replace_allocate(handle->conn,
1108 path, &mapped_name, vfs_translate_to_unix);
1109 if (!NT_STATUS_IS_OK(status)) {
1110 errno = map_errno_from_nt_status(status);
1113 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1118 if (mapped_smb_fname == NULL) {
1119 TALLOC_FREE(mapped_name);
1120 return NT_STATUS_NO_MEMORY;
1123 status = SMB_VFS_NEXT_GET_NT_ACL(handle, mapped_smb_fname,
1124 security_info, mem_ctx, ppdesc);
1125 TALLOC_FREE(mapped_name);
1126 TALLOC_FREE(mapped_smb_fname);
1132 catia_sys_acl_get_file(vfs_handle_struct *handle,
1133 const struct smb_filename *smb_fname,
1134 SMB_ACL_TYPE_T type,
1135 TALLOC_CTX *mem_ctx)
1137 char *mapped_name = NULL;
1138 struct smb_filename *mapped_smb_fname = NULL;
1141 int saved_errno = 0;
1143 status = catia_string_replace_allocate(handle->conn,
1144 smb_fname->base_name,
1146 vfs_translate_to_unix);
1147 if (!NT_STATUS_IS_OK(status)) {
1148 errno = map_errno_from_nt_status(status);
1149 return (SMB_ACL_T)NULL;
1152 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1157 if (mapped_smb_fname == NULL) {
1158 TALLOC_FREE(mapped_name);
1160 return (SMB_ACL_T)NULL;
1163 ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, mapped_smb_fname,
1165 if (ret == (SMB_ACL_T)NULL) {
1166 saved_errno = errno;
1168 TALLOC_FREE(mapped_smb_fname);
1169 TALLOC_FREE(mapped_name);
1170 if (saved_errno != 0) {
1171 errno = saved_errno;
1177 catia_sys_acl_set_file(vfs_handle_struct *handle,
1178 const struct smb_filename *smb_fname,
1179 SMB_ACL_TYPE_T type,
1182 struct smb_filename *mapped_smb_fname = NULL;
1183 int saved_errno = 0;
1184 char *mapped_name = NULL;
1188 status = catia_string_replace_allocate(handle->conn,
1189 smb_fname->base_name,
1191 vfs_translate_to_unix);
1192 if (!NT_STATUS_IS_OK(status)) {
1193 errno = map_errno_from_nt_status(status);
1197 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1202 if (mapped_smb_fname == NULL) {
1203 TALLOC_FREE(mapped_name);
1208 ret = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, mapped_smb_fname,
1211 saved_errno = errno;
1213 TALLOC_FREE(mapped_smb_fname);
1214 TALLOC_FREE(mapped_name);
1215 if (saved_errno != 0) {
1216 errno = saved_errno;
1222 catia_sys_acl_delete_def_file(vfs_handle_struct *handle,
1223 const struct smb_filename *smb_fname)
1225 struct smb_filename *mapped_smb_fname = NULL;
1226 int saved_errno = 0;
1227 char *mapped_name = NULL;
1231 status = catia_string_replace_allocate(handle->conn,
1232 smb_fname->base_name,
1234 vfs_translate_to_unix);
1235 if (!NT_STATUS_IS_OK(status)) {
1236 errno = map_errno_from_nt_status(status);
1240 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1245 if (mapped_smb_fname == NULL) {
1246 TALLOC_FREE(mapped_name);
1250 ret = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, mapped_smb_fname);
1252 saved_errno = errno;
1254 TALLOC_FREE(mapped_smb_fname);
1255 TALLOC_FREE(mapped_name);
1256 if (saved_errno != 0) {
1257 errno = saved_errno;
1263 catia_getxattr(vfs_handle_struct *handle,
1264 const struct smb_filename *smb_fname,
1269 struct smb_filename *mapped_smb_fname = NULL;
1270 char *mapped_name = NULL;
1271 char *mapped_ea_name = NULL;
1274 int saved_errno = 0;
1276 status = catia_string_replace_allocate(handle->conn,
1277 smb_fname->base_name,
1279 vfs_translate_to_unix);
1280 if (!NT_STATUS_IS_OK(status)) {
1281 errno = map_errno_from_nt_status(status);
1285 status = catia_string_replace_allocate(handle->conn,
1286 name, &mapped_ea_name, vfs_translate_to_unix);
1287 if (!NT_STATUS_IS_OK(status)) {
1288 TALLOC_FREE(mapped_name);
1289 errno = map_errno_from_nt_status(status);
1293 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1298 if (mapped_smb_fname == NULL) {
1299 TALLOC_FREE(mapped_name);
1300 TALLOC_FREE(mapped_ea_name);
1305 ret = SMB_VFS_NEXT_GETXATTR(handle, mapped_smb_fname,
1306 mapped_ea_name, value, size);
1308 saved_errno = errno;
1310 TALLOC_FREE(mapped_name);
1311 TALLOC_FREE(mapped_ea_name);
1312 TALLOC_FREE(mapped_smb_fname);
1313 if (saved_errno != 0) {
1314 errno = saved_errno;
1321 catia_listxattr(vfs_handle_struct *handle,
1322 const struct smb_filename *smb_fname,
1323 char *list, size_t size)
1325 struct smb_filename *mapped_smb_fname = NULL;
1326 char *mapped_name = NULL;
1329 int saved_errno = 0;
1331 status = catia_string_replace_allocate(handle->conn,
1332 smb_fname->base_name,
1334 vfs_translate_to_unix);
1335 if (!NT_STATUS_IS_OK(status)) {
1336 errno = map_errno_from_nt_status(status);
1340 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1345 if (mapped_smb_fname == NULL) {
1346 TALLOC_FREE(mapped_name);
1351 ret = SMB_VFS_NEXT_LISTXATTR(handle, mapped_smb_fname, list, size);
1353 saved_errno = errno;
1355 TALLOC_FREE(mapped_name);
1356 TALLOC_FREE(mapped_smb_fname);
1357 if (saved_errno != 0) {
1358 errno = saved_errno;
1365 catia_removexattr(vfs_handle_struct *handle,
1366 const struct smb_filename *smb_fname,
1369 struct smb_filename *mapped_smb_fname = NULL;
1370 char *mapped_name = NULL;
1371 char *mapped_ea_name = NULL;
1374 int saved_errno = 0;
1376 status = catia_string_replace_allocate(handle->conn,
1377 smb_fname->base_name,
1379 vfs_translate_to_unix);
1380 if (!NT_STATUS_IS_OK(status)) {
1381 errno = map_errno_from_nt_status(status);
1385 status = catia_string_replace_allocate(handle->conn,
1386 name, &mapped_ea_name, vfs_translate_to_unix);
1387 if (!NT_STATUS_IS_OK(status)) {
1388 TALLOC_FREE(mapped_name);
1389 errno = map_errno_from_nt_status(status);
1393 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1398 if (mapped_smb_fname == NULL) {
1399 TALLOC_FREE(mapped_name);
1400 TALLOC_FREE(mapped_ea_name);
1405 ret = SMB_VFS_NEXT_REMOVEXATTR(handle, mapped_smb_fname,
1408 saved_errno = errno;
1410 TALLOC_FREE(mapped_name);
1411 TALLOC_FREE(mapped_ea_name);
1412 TALLOC_FREE(mapped_smb_fname);
1413 if (saved_errno != 0) {
1414 errno = saved_errno;
1421 catia_setxattr(vfs_handle_struct *handle,
1422 const struct smb_filename *smb_fname,
1428 struct smb_filename *mapped_smb_fname = NULL;
1429 char *mapped_name = NULL;
1430 char *mapped_ea_name = NULL;
1433 int saved_errno = 0;
1435 status = catia_string_replace_allocate(handle->conn,
1436 smb_fname->base_name,
1438 vfs_translate_to_unix);
1439 if (!NT_STATUS_IS_OK(status)) {
1440 errno = map_errno_from_nt_status(status);
1444 status = catia_string_replace_allocate(handle->conn,
1445 name, &mapped_ea_name, vfs_translate_to_unix);
1446 if (!NT_STATUS_IS_OK(status)) {
1447 TALLOC_FREE(mapped_name);
1448 errno = map_errno_from_nt_status(status);
1452 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1457 if (mapped_smb_fname == NULL) {
1458 TALLOC_FREE(mapped_name);
1459 TALLOC_FREE(mapped_ea_name);
1464 ret = SMB_VFS_NEXT_SETXATTR(handle, mapped_smb_fname, mapped_ea_name,
1465 value, size, flags);
1467 saved_errno = errno;
1469 TALLOC_FREE(mapped_name);
1470 TALLOC_FREE(mapped_ea_name);
1471 TALLOC_FREE(mapped_smb_fname);
1472 if (saved_errno != 0) {
1473 errno = saved_errno;
1479 static int catia_fstat(vfs_handle_struct *handle,
1481 SMB_STRUCT_STAT *sbuf)
1483 struct catia_cache *cc = NULL;
1486 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1491 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1493 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1498 static ssize_t catia_pread(vfs_handle_struct *handle,
1499 files_struct *fsp, void *data,
1500 size_t n, off_t offset)
1502 struct catia_cache *cc = NULL;
1506 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1511 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1513 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1518 static ssize_t catia_pwrite(vfs_handle_struct *handle,
1519 files_struct *fsp, const void *data,
1520 size_t n, off_t offset)
1522 struct catia_cache *cc = NULL;
1526 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1531 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1533 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1538 static int catia_ftruncate(struct vfs_handle_struct *handle,
1539 struct files_struct *fsp,
1542 struct catia_cache *cc = NULL;
1545 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1550 ret = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
1552 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1557 static int catia_fallocate(struct vfs_handle_struct *handle,
1558 struct files_struct *fsp,
1563 struct catia_cache *cc = NULL;
1566 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1571 ret = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1573 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1578 static ssize_t catia_fgetxattr(struct vfs_handle_struct *handle,
1579 struct files_struct *fsp,
1584 char *mapped_xattr_name = NULL;
1588 status = catia_string_replace_allocate(handle->conn,
1589 name, &mapped_xattr_name,
1590 vfs_translate_to_unix);
1591 if (!NT_STATUS_IS_OK(status)) {
1592 errno = map_errno_from_nt_status(status);
1596 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, mapped_xattr_name,
1599 TALLOC_FREE(mapped_xattr_name);
1604 static ssize_t catia_flistxattr(struct vfs_handle_struct *handle,
1605 struct files_struct *fsp,
1609 struct catia_cache *cc = NULL;
1613 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1618 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
1620 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1625 static int catia_fremovexattr(struct vfs_handle_struct *handle,
1626 struct files_struct *fsp,
1629 char *mapped_name = NULL;
1633 status = catia_string_replace_allocate(handle->conn,
1634 name, &mapped_name, vfs_translate_to_unix);
1635 if (!NT_STATUS_IS_OK(status)) {
1636 errno = map_errno_from_nt_status(status);
1640 ret = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, mapped_name);
1642 TALLOC_FREE(mapped_name);
1647 static int catia_fsetxattr(struct vfs_handle_struct *handle,
1648 struct files_struct *fsp,
1654 char *mapped_xattr_name = NULL;
1658 status = catia_string_replace_allocate(
1659 handle->conn, name, &mapped_xattr_name, vfs_translate_to_unix);
1660 if (!NT_STATUS_IS_OK(status)) {
1661 errno = map_errno_from_nt_status(status);
1665 ret = SMB_VFS_NEXT_FSETXATTR(handle, fsp, mapped_xattr_name,
1666 value, size, flags);
1668 TALLOC_FREE(mapped_xattr_name);
1673 static SMB_ACL_T catia_sys_acl_get_fd(vfs_handle_struct *handle,
1675 TALLOC_CTX *mem_ctx)
1677 struct catia_cache *cc = NULL;
1678 struct smb_acl_t *result = NULL;
1681 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1686 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1688 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1693 static int catia_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1695 TALLOC_CTX *mem_ctx,
1696 char **blob_description,
1699 struct catia_cache *cc = NULL;
1702 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1707 ret = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1708 blob_description, blob);
1710 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1715 static int catia_sys_acl_set_fd(vfs_handle_struct *handle,
1719 struct catia_cache *cc = NULL;
1722 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1727 ret = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1729 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1734 static int catia_fchmod_acl(vfs_handle_struct *handle,
1738 struct catia_cache *cc = NULL;
1741 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1746 ret = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1748 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1753 static NTSTATUS catia_fget_nt_acl(vfs_handle_struct *handle,
1755 uint32_t security_info,
1756 TALLOC_CTX *mem_ctx,
1757 struct security_descriptor **ppdesc)
1759 struct catia_cache *cc = NULL;
1763 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1765 return map_nt_error_from_unix(errno);
1768 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1771 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1776 static NTSTATUS catia_fset_nt_acl(vfs_handle_struct *handle,
1778 uint32_t security_info_sent,
1779 const struct security_descriptor *psd)
1781 struct catia_cache *cc = NULL;
1785 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1787 return map_nt_error_from_unix(errno);
1790 status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1792 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1797 static NTSTATUS catia_fset_dos_attributes(struct vfs_handle_struct *handle,
1798 struct files_struct *fsp,
1801 struct catia_cache *cc = NULL;
1805 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1807 return map_nt_error_from_unix(errno);
1810 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1812 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1817 static NTSTATUS catia_fget_dos_attributes(struct vfs_handle_struct *handle,
1818 struct files_struct *fsp,
1821 struct catia_cache *cc = NULL;
1825 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1827 return map_nt_error_from_unix(errno);
1830 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1832 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1837 static int catia_fchown(vfs_handle_struct *handle,
1842 struct catia_cache *cc = NULL;
1845 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1850 ret = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1852 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1857 static int catia_fchmod(vfs_handle_struct *handle,
1861 struct catia_cache *cc = NULL;
1864 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1869 ret = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1871 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1876 struct catia_pread_state {
1878 struct vfs_aio_state vfs_aio_state;
1879 struct files_struct *fsp;
1880 struct catia_cache *cc;
1883 static void catia_pread_done(struct tevent_req *subreq);
1885 static struct tevent_req *catia_pread_send(struct vfs_handle_struct *handle,
1886 TALLOC_CTX *mem_ctx,
1887 struct tevent_context *ev,
1888 struct files_struct *fsp,
1893 struct tevent_req *req = NULL, *subreq = NULL;
1894 struct catia_pread_state *state = NULL;
1897 req = tevent_req_create(mem_ctx, &state,
1898 struct catia_pread_state);
1904 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1906 tevent_req_error(req, errno);
1907 return tevent_req_post(req, ev);
1910 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1912 if (tevent_req_nomem(subreq, req)) {
1913 return tevent_req_post(req, ev);
1915 tevent_req_set_callback(subreq, catia_pread_done, req);
1920 static void catia_pread_done(struct tevent_req *subreq)
1922 struct tevent_req *req = tevent_req_callback_data(
1923 subreq, struct tevent_req);
1924 struct catia_pread_state *state = tevent_req_data(
1925 req, struct catia_pread_state);
1927 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1928 TALLOC_FREE(subreq);
1930 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1932 tevent_req_done(req);
1935 static ssize_t catia_pread_recv(struct tevent_req *req,
1936 struct vfs_aio_state *vfs_aio_state)
1938 struct catia_pread_state *state = tevent_req_data(
1939 req, struct catia_pread_state);
1941 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1945 *vfs_aio_state = state->vfs_aio_state;
1949 struct catia_pwrite_state {
1951 struct vfs_aio_state vfs_aio_state;
1952 struct files_struct *fsp;
1953 struct catia_cache *cc;
1956 static void catia_pwrite_done(struct tevent_req *subreq);
1958 static struct tevent_req *catia_pwrite_send(struct vfs_handle_struct *handle,
1959 TALLOC_CTX *mem_ctx,
1960 struct tevent_context *ev,
1961 struct files_struct *fsp,
1966 struct tevent_req *req = NULL, *subreq = NULL;
1967 struct catia_pwrite_state *state = NULL;
1970 req = tevent_req_create(mem_ctx, &state,
1971 struct catia_pwrite_state);
1977 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1979 tevent_req_error(req, errno);
1980 return tevent_req_post(req, ev);
1983 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1985 if (tevent_req_nomem(subreq, req)) {
1986 return tevent_req_post(req, ev);
1988 tevent_req_set_callback(subreq, catia_pwrite_done, req);
1993 static void catia_pwrite_done(struct tevent_req *subreq)
1995 struct tevent_req *req = tevent_req_callback_data(
1996 subreq, struct tevent_req);
1997 struct catia_pwrite_state *state = tevent_req_data(
1998 req, struct catia_pwrite_state);
2000 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
2001 TALLOC_FREE(subreq);
2003 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
2005 tevent_req_done(req);
2008 static ssize_t catia_pwrite_recv(struct tevent_req *req,
2009 struct vfs_aio_state *vfs_aio_state)
2011 struct catia_pwrite_state *state = tevent_req_data(
2012 req, struct catia_pwrite_state);
2014 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2018 *vfs_aio_state = state->vfs_aio_state;
2022 static off_t catia_lseek(vfs_handle_struct *handle,
2027 struct catia_cache *cc = NULL;
2031 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2036 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
2038 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2043 struct catia_fsync_state {
2045 struct vfs_aio_state vfs_aio_state;
2046 struct files_struct *fsp;
2047 struct catia_cache *cc;
2050 static void catia_fsync_done(struct tevent_req *subreq);
2052 static struct tevent_req *catia_fsync_send(struct vfs_handle_struct *handle,
2053 TALLOC_CTX *mem_ctx,
2054 struct tevent_context *ev,
2055 struct files_struct *fsp)
2057 struct tevent_req *req = NULL, *subreq = NULL;
2058 struct catia_fsync_state *state = NULL;
2061 req = tevent_req_create(mem_ctx, &state,
2062 struct catia_fsync_state);
2068 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
2070 tevent_req_error(req, errno);
2071 return tevent_req_post(req, ev);
2074 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
2075 if (tevent_req_nomem(subreq, req)) {
2076 return tevent_req_post(req, ev);
2078 tevent_req_set_callback(subreq, catia_fsync_done, req);
2083 static void catia_fsync_done(struct tevent_req *subreq)
2085 struct tevent_req *req = tevent_req_callback_data(
2086 subreq, struct tevent_req);
2087 struct catia_fsync_state *state = tevent_req_data(
2088 req, struct catia_fsync_state);
2090 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
2091 TALLOC_FREE(subreq);
2093 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
2095 tevent_req_done(req);
2098 static int catia_fsync_recv(struct tevent_req *req,
2099 struct vfs_aio_state *vfs_aio_state)
2101 struct catia_fsync_state *state = tevent_req_data(
2102 req, struct catia_fsync_state);
2104 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2108 *vfs_aio_state = state->vfs_aio_state;
2112 static bool catia_lock(vfs_handle_struct *handle,
2119 struct catia_cache *cc = NULL;
2123 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2128 ok = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
2130 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2135 static int catia_kernel_flock(struct vfs_handle_struct *handle,
2136 struct files_struct *fsp,
2137 uint32_t share_mode,
2138 uint32_t access_mask)
2140 struct catia_cache *cc = NULL;
2143 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2148 ret = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
2150 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2155 static int catia_linux_setlease(vfs_handle_struct *handle,
2159 struct catia_cache *cc = NULL;
2162 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2167 ret = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
2169 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2174 static bool catia_getlock(vfs_handle_struct *handle,
2181 struct catia_cache *cc = NULL;
2185 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2190 ok = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
2192 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2197 static bool catia_strict_lock_check(struct vfs_handle_struct *handle,
2198 struct files_struct *fsp,
2199 struct lock_struct *plock)
2201 struct catia_cache *cc = NULL;
2205 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2210 ok = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2212 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2217 static NTSTATUS catia_fsctl(struct vfs_handle_struct *handle,
2218 struct files_struct *fsp,
2222 const uint8_t *_in_data,
2224 uint8_t **_out_data,
2225 uint32_t max_out_len,
2229 struct catia_cache *cc = NULL;
2232 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2234 return map_nt_error_from_unix(errno);
2237 result = SMB_VFS_NEXT_FSCTL(handle,
2248 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2253 static NTSTATUS catia_get_compression(vfs_handle_struct *handle,
2254 TALLOC_CTX *mem_ctx,
2255 struct files_struct *fsp,
2256 struct smb_filename *smb_fname,
2257 uint16_t *_compression_fmt)
2260 struct catia_cache *cc = NULL;
2262 struct smb_filename *mapped_smb_fname = NULL;
2263 char *mapped_name = NULL;
2266 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2268 return map_nt_error_from_unix(errno);
2270 mapped_smb_fname = fsp->fsp_name;
2272 result = catia_string_replace_allocate(handle->conn,
2273 smb_fname->base_name,
2275 vfs_translate_to_unix);
2276 if (!NT_STATUS_IS_OK(result)) {
2280 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2285 if (mapped_smb_fname == NULL) {
2286 TALLOC_FREE(mapped_name);
2287 return NT_STATUS_NO_MEMORY;
2290 TALLOC_FREE(mapped_name);
2293 result = SMB_VFS_NEXT_GET_COMPRESSION(handle,
2300 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2302 TALLOC_FREE(mapped_smb_fname);
2308 static NTSTATUS catia_set_compression(vfs_handle_struct *handle,
2309 TALLOC_CTX *mem_ctx,
2310 struct files_struct *fsp,
2311 uint16_t compression_fmt)
2314 struct catia_cache *cc = NULL;
2317 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2319 return map_nt_error_from_unix(errno);
2322 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2325 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2330 static NTSTATUS catia_readdir_attr(struct vfs_handle_struct *handle,
2331 const struct smb_filename *smb_fname_in,
2332 TALLOC_CTX *mem_ctx,
2333 struct readdir_attr_data **pattr_data)
2335 struct smb_filename *smb_fname;
2339 status = catia_string_replace_allocate(handle->conn,
2340 smb_fname_in->base_name,
2342 vfs_translate_to_unix);
2343 if (!NT_STATUS_IS_OK(status)) {
2344 errno = map_errno_from_nt_status(status);
2348 smb_fname = synthetic_smb_fname(talloc_tos(), fname, NULL,
2349 &smb_fname_in->st, 0);
2351 status = SMB_VFS_NEXT_READDIR_ATTR(handle, smb_fname, mem_ctx, pattr_data);
2353 TALLOC_FREE(smb_fname);
2358 static NTSTATUS catia_get_dos_attributes(struct vfs_handle_struct *handle,
2359 struct smb_filename *smb_fname,
2362 char *mapped_name = NULL;
2363 const char *path = smb_fname->base_name;
2364 struct smb_filename *mapped_smb_fname = NULL;
2367 status = catia_string_replace_allocate(handle->conn,
2368 path, &mapped_name, vfs_translate_to_unix);
2369 if (!NT_STATUS_IS_OK(status)) {
2370 errno = map_errno_from_nt_status(status);
2373 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2378 if (mapped_smb_fname == NULL) {
2379 TALLOC_FREE(mapped_name);
2380 return NT_STATUS_NO_MEMORY;
2383 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2386 TALLOC_FREE(mapped_name);
2387 TALLOC_FREE(mapped_smb_fname);
2392 static NTSTATUS catia_set_dos_attributes(struct vfs_handle_struct *handle,
2393 const struct smb_filename *smb_fname,
2396 char *mapped_name = NULL;
2397 const char *path = smb_fname->base_name;
2398 struct smb_filename *mapped_smb_fname = NULL;
2401 status = catia_string_replace_allocate(handle->conn,
2402 path, &mapped_name, vfs_translate_to_unix);
2403 if (!NT_STATUS_IS_OK(status)) {
2404 errno = map_errno_from_nt_status(status);
2407 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2412 if (mapped_smb_fname == NULL) {
2413 TALLOC_FREE(mapped_name);
2414 return NT_STATUS_NO_MEMORY;
2417 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2420 TALLOC_FREE(mapped_name);
2421 TALLOC_FREE(mapped_smb_fname);
2426 static struct vfs_fn_pointers vfs_catia_fns = {
2427 /* Directory operations */
2428 .mkdir_fn = catia_mkdir,
2429 .rmdir_fn = catia_rmdir,
2430 .opendir_fn = catia_opendir,
2431 .readdir_attr_fn = catia_readdir_attr,
2433 /* File operations */
2434 .open_fn = catia_open,
2435 .pread_fn = catia_pread,
2436 .pread_send_fn = catia_pread_send,
2437 .pread_recv_fn = catia_pread_recv,
2438 .pwrite_fn = catia_pwrite,
2439 .pwrite_send_fn = catia_pwrite_send,
2440 .pwrite_recv_fn = catia_pwrite_recv,
2441 .lseek_fn = catia_lseek,
2442 .rename_fn = catia_rename,
2443 .fsync_send_fn = catia_fsync_send,
2444 .fsync_recv_fn = catia_fsync_recv,
2445 .stat_fn = catia_stat,
2446 .fstat_fn = catia_fstat,
2447 .lstat_fn = catia_lstat,
2448 .unlink_fn = catia_unlink,
2449 .chmod_fn = catia_chmod,
2450 .fchmod_fn = catia_fchmod,
2451 .chown_fn = catia_chown,
2452 .fchown_fn = catia_fchown,
2453 .lchown_fn = catia_lchown,
2454 .chdir_fn = catia_chdir,
2455 .ntimes_fn = catia_ntimes,
2456 .ftruncate_fn = catia_ftruncate,
2457 .fallocate_fn = catia_fallocate,
2458 .lock_fn = catia_lock,
2459 .kernel_flock_fn = catia_kernel_flock,
2460 .linux_setlease_fn = catia_linux_setlease,
2461 .getlock_fn = catia_getlock,
2462 .realpath_fn = catia_realpath,
2463 .chflags_fn = catia_chflags,
2464 .streaminfo_fn = catia_streaminfo,
2465 .strict_lock_check_fn = catia_strict_lock_check,
2466 .translate_name_fn = catia_translate_name,
2467 .fsctl_fn = catia_fsctl,
2468 .get_dos_attributes_fn = catia_get_dos_attributes,
2469 .set_dos_attributes_fn = catia_set_dos_attributes,
2470 .fset_dos_attributes_fn = catia_fset_dos_attributes,
2471 .fget_dos_attributes_fn = catia_fget_dos_attributes,
2472 .get_compression_fn = catia_get_compression,
2473 .set_compression_fn = catia_set_compression,
2475 /* NT ACL operations. */
2476 .get_nt_acl_fn = catia_get_nt_acl,
2477 .fget_nt_acl_fn = catia_fget_nt_acl,
2478 .fset_nt_acl_fn = catia_fset_nt_acl,
2480 /* POSIX ACL operations. */
2481 .fchmod_acl_fn = catia_fchmod_acl,
2483 .sys_acl_get_file_fn = catia_sys_acl_get_file,
2484 .sys_acl_get_fd_fn = catia_sys_acl_get_fd,
2485 .sys_acl_blob_get_fd_fn = catia_sys_acl_blob_get_fd,
2486 .sys_acl_set_file_fn = catia_sys_acl_set_file,
2487 .sys_acl_set_fd_fn = catia_sys_acl_set_fd,
2488 .sys_acl_delete_def_file_fn = catia_sys_acl_delete_def_file,
2490 /* EA operations. */
2491 .getxattr_fn = catia_getxattr,
2492 .listxattr_fn = catia_listxattr,
2493 .removexattr_fn = catia_removexattr,
2494 .setxattr_fn = catia_setxattr,
2495 .fgetxattr_fn = catia_fgetxattr,
2496 .flistxattr_fn = catia_flistxattr,
2497 .fremovexattr_fn = catia_fremovexattr,
2498 .fsetxattr_fn = catia_fsetxattr,
2502 NTSTATUS vfs_catia_init(TALLOC_CTX *ctx)
2506 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
2508 if (!NT_STATUS_IS_OK(ret))
2511 vfs_catia_debug_level = debug_add_class("catia");
2512 if (vfs_catia_debug_level == -1) {
2513 vfs_catia_debug_level = DBGC_VFS;
2514 DEBUG(0, ("vfs_catia: Couldn't register custom debugging "
2517 DEBUG(10, ("vfs_catia: Debug class number of "
2518 "'catia': %d\n", vfs_catia_debug_level));