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, struct share_mapping_entry);
86 if (mappings == NULL) {
91 sme->mappings = string_replace_init_map(sme, 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 int catia_connect(struct vfs_handle_struct *handle,
166 * Unless we have an async implementation of get_dos_attributes turn
169 lp_do_parameter(SNUM(handle->conn), "smbd async dosmode", "false");
171 return SMB_VFS_NEXT_CONNECT(handle, service, user);
175 * TRANSLATE_NAME call which converts the given name to
176 * "WINDOWS displayable" name
178 static NTSTATUS catia_translate_name(struct vfs_handle_struct *handle,
179 const char *orig_name,
180 enum vfs_translate_direction direction,
186 NTSTATUS status, ret;
189 * Copy the supplied name and free the memory for mapped_name,
190 * already allocated by the caller.
191 * We will be allocating new memory for mapped_name in
192 * catia_string_replace_allocate
194 name = talloc_strdup(talloc_tos(), orig_name);
197 return NT_STATUS_NO_MEMORY;
199 status = catia_string_replace_allocate(handle->conn, name,
200 &mapped_name, direction);
203 if (!NT_STATUS_IS_OK(status)) {
207 ret = SMB_VFS_NEXT_TRANSLATE_NAME(handle, mapped_name, direction,
208 mem_ctx, pmapped_name);
210 if (NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED)) {
211 *pmapped_name = talloc_move(mem_ctx, &mapped_name);
212 /* we need to return the former translation result here */
215 TALLOC_FREE(mapped_name);
221 #define CATIA_DEBUG_CC(lvl, cc, fsp) \
222 catia_debug_cc((lvl), (cc), (fsp), __location__);
224 static void catia_debug_cc(int lvl,
225 struct catia_cache *cc,
227 const char *location)
229 DEBUG(lvl, ("%s: cc [%p] cc->busy [%p] "
231 "fsp [%p] fsp name [%s] "
234 "orig_base_fname [%s] "
238 cc->is_fsp_ext ? "yes" : "no",
239 fsp, fsp_str_dbg(fsp),
240 cc->orig_fname, cc->fname,
241 cc->orig_base_fname, cc->base_fname));
244 static void catia_free_cc(struct catia_cache **_cc,
245 vfs_handle_struct *handle,
248 struct catia_cache *cc = *_cc;
250 if (cc->is_fsp_ext) {
251 VFS_REMOVE_FSP_EXTENSION(handle, fsp);
260 static struct catia_cache *catia_validate_and_apply_cc(
261 vfs_handle_struct *handle,
263 const struct catia_cache * const *busy,
264 bool *make_tmp_cache)
266 struct catia_cache *cc = NULL;
268 *make_tmp_cache = false;
270 cc = (struct catia_cache *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
275 if (cc->busy != NULL) {
276 if (cc->busy == busy) {
277 /* This should never happen */
278 CATIA_DEBUG_CC(0, cc, fsp);
279 smb_panic(__location__);
283 * Recursion. Validate names, the names in the fsp's should be
284 * the translated names we had set.
287 if ((cc->fname != fsp->fsp_name->base_name)
289 (fsp_is_alternate_stream(fsp) &&
290 (cc->base_fname != fsp->base_fsp->fsp_name->base_name)))
292 CATIA_DEBUG_CC(10, cc, fsp);
295 * Names changed. Setting don't expose the cache on the
296 * fsp and ask the caller to create a temporary cache.
298 *make_tmp_cache = true;
303 * Ok, a validated cache while in a recursion, just let the
304 * caller detect that cc->busy is != busy and there's
305 * nothing else to do.
307 CATIA_DEBUG_CC(10, cc, fsp);
311 /* Not in a recursion */
313 if ((cc->orig_fname != fsp->fsp_name->base_name)
315 (fsp_is_alternate_stream(fsp) &&
316 (cc->orig_base_fname != fsp->base_fsp->fsp_name->base_name)))
319 * fsp names changed, this can happen in an rename op.
320 * Trigger recreation as a full fledged fsp extension.
323 CATIA_DEBUG_CC(10, cc, fsp);
324 catia_free_cc(&cc, handle, fsp);
330 * Ok, we found a valid cache entry, no recursion. Just set translated
331 * names from the cache and mark the cc as busy.
333 fsp->fsp_name->base_name = cc->fname;
334 if (fsp_is_alternate_stream(fsp)) {
335 fsp->base_fsp->fsp_name->base_name = cc->base_fname;
339 CATIA_DEBUG_CC(10, cc, fsp);
343 #define CATIA_FETCH_FSP_PRE_NEXT(mem_ctx, handle, fsp, _cc) \
344 catia_fetch_fsp_pre_next((mem_ctx), (handle), (fsp), (_cc), __func__);
346 static int catia_fetch_fsp_pre_next(TALLOC_CTX *mem_ctx,
347 vfs_handle_struct *handle,
349 struct catia_cache **_cc,
350 const char *function)
352 const struct catia_cache * const *busy =
353 (const struct catia_cache * const *)_cc;
354 struct catia_cache *cc = NULL;
356 bool make_tmp_cache = false;
360 DBG_DEBUG("Called from [%s]\n", function);
362 cc = catia_validate_and_apply_cc(handle,
367 if (cc->busy != busy) {
374 if (!make_tmp_cache) {
375 cc = VFS_ADD_FSP_EXTENSION(
376 handle, fsp, struct catia_cache, NULL);
380 *cc = (struct catia_cache) {
384 mem_ctx = VFS_MEMCTX_FSP_EXTENSION(handle, fsp);
385 if (mem_ctx == NULL) {
386 DBG_ERR("VFS_MEMCTX_FSP_EXTENSION failed\n");
387 catia_free_cc(&cc, handle, fsp);
391 cc = talloc_zero(mem_ctx, struct catia_cache);
399 status = catia_string_replace_allocate(handle->conn,
400 fsp->fsp_name->base_name,
402 vfs_translate_to_unix);
403 if (!NT_STATUS_IS_OK(status)) {
404 catia_free_cc(&cc, handle, fsp);
405 errno = map_errno_from_nt_status(status);
408 talloc_steal(mem_ctx, cc->fname);
410 if (fsp_is_alternate_stream(fsp)) {
411 status = catia_string_replace_allocate(
413 fsp->base_fsp->fsp_name->base_name,
415 vfs_translate_to_unix);
416 if (!NT_STATUS_IS_OK(status)) {
417 catia_free_cc(&cc, handle, fsp);
418 errno = map_errno_from_nt_status(status);
421 talloc_steal(mem_ctx, cc->base_fname);
424 cc->orig_fname = fsp->fsp_name->base_name;
425 fsp->fsp_name->base_name = cc->fname;
427 if (fsp_is_alternate_stream(fsp)) {
428 cc->orig_base_fname = fsp->base_fsp->fsp_name->base_name;
429 fsp->base_fsp->fsp_name->base_name = cc->base_fname;
433 CATIA_DEBUG_CC(10, cc, fsp);
440 #define CATIA_FETCH_FSP_POST_NEXT(_cc, fsp) do { \
441 int catia_saved_errno = errno; \
442 catia_fetch_fsp_post_next((_cc), (fsp), __func__); \
443 errno = catia_saved_errno; \
446 static void catia_fetch_fsp_post_next(struct catia_cache **_cc,
448 const char *function)
450 const struct catia_cache * const *busy =
451 (const struct catia_cache * const *)_cc;
452 struct catia_cache *cc = *_cc;
454 DBG_DEBUG("Called from [%s]\n", function);
458 * This can happen when recursing in the VFS on the fsp when the
459 * pre_next func noticed the recursion and set out cc pointer to
465 if (cc->busy != busy) {
466 CATIA_DEBUG_CC(0, cc, fsp);
467 smb_panic(__location__);
474 fsp->fsp_name->base_name = cc->orig_fname;
475 if (fsp_is_alternate_stream(fsp)) {
476 fsp->base_fsp->fsp_name->base_name = cc->orig_base_fname;
479 CATIA_DEBUG_CC(10, cc, fsp);
481 if (!cc->is_fsp_ext) {
488 static int catia_openat(vfs_handle_struct *handle,
489 const struct files_struct *dirfsp,
490 const struct smb_filename *smb_fname_in,
492 const struct vfs_open_how *how)
494 struct smb_filename *smb_fname = NULL;
495 struct catia_cache *cc = NULL;
496 char *mapped_name = NULL;
501 status = catia_string_replace_allocate(handle->conn,
502 smb_fname_in->base_name,
504 vfs_translate_to_unix);
505 if (!NT_STATUS_IS_OK(status)) {
509 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
511 TALLOC_FREE(mapped_name);
515 smb_fname = cp_smb_filename(talloc_tos(), smb_fname_in);
516 if (smb_fname == NULL) {
517 TALLOC_FREE(mapped_name);
521 smb_fname->base_name = mapped_name;
523 ret = SMB_VFS_NEXT_OPENAT(handle,
531 TALLOC_FREE(smb_fname);
532 TALLOC_FREE(mapped_name);
533 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
534 if (saved_errno != 0) {
540 static int catia_renameat(vfs_handle_struct *handle,
541 files_struct *srcfsp,
542 const struct smb_filename *smb_fname_src,
543 files_struct *dstfsp,
544 const struct smb_filename *smb_fname_dst)
546 TALLOC_CTX *ctx = talloc_tos();
547 struct smb_filename *smb_fname_src_tmp = NULL;
548 struct smb_filename *smb_fname_dst_tmp = NULL;
549 char *src_name_mapped = NULL;
550 char *dst_name_mapped = NULL;
554 status = catia_string_replace_allocate(handle->conn,
555 smb_fname_src->base_name,
556 &src_name_mapped, vfs_translate_to_unix);
557 if (!NT_STATUS_IS_OK(status)) {
558 errno = map_errno_from_nt_status(status);
562 status = catia_string_replace_allocate(handle->conn,
563 smb_fname_dst->base_name,
564 &dst_name_mapped, vfs_translate_to_unix);
565 if (!NT_STATUS_IS_OK(status)) {
566 errno = map_errno_from_nt_status(status);
570 /* Setup temporary smb_filename structs. */
571 smb_fname_src_tmp = cp_smb_filename(ctx, smb_fname_src);
572 if (smb_fname_src_tmp == NULL) {
577 smb_fname_dst_tmp = cp_smb_filename(ctx, smb_fname_dst);
578 if (smb_fname_dst_tmp == NULL) {
583 smb_fname_src_tmp->base_name = src_name_mapped;
584 smb_fname_dst_tmp->base_name = dst_name_mapped;
585 DEBUG(10, ("converted old name: %s\n",
586 smb_fname_str_dbg(smb_fname_src_tmp)));
587 DEBUG(10, ("converted new name: %s\n",
588 smb_fname_str_dbg(smb_fname_dst_tmp)));
590 ret = SMB_VFS_NEXT_RENAMEAT(handle,
597 TALLOC_FREE(src_name_mapped);
598 TALLOC_FREE(dst_name_mapped);
599 TALLOC_FREE(smb_fname_src_tmp);
600 TALLOC_FREE(smb_fname_dst_tmp);
605 static int catia_stat(vfs_handle_struct *handle,
606 struct smb_filename *smb_fname)
613 status = catia_string_replace_allocate(handle->conn,
614 smb_fname->base_name,
615 &name, vfs_translate_to_unix);
616 if (!NT_STATUS_IS_OK(status)) {
617 errno = map_errno_from_nt_status(status);
621 tmp_base_name = smb_fname->base_name;
622 smb_fname->base_name = name;
624 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
625 smb_fname->base_name = tmp_base_name;
631 static int catia_lstat(vfs_handle_struct *handle,
632 struct smb_filename *smb_fname)
639 status = catia_string_replace_allocate(handle->conn,
640 smb_fname->base_name,
641 &name, vfs_translate_to_unix);
642 if (!NT_STATUS_IS_OK(status)) {
643 errno = map_errno_from_nt_status(status);
647 tmp_base_name = smb_fname->base_name;
648 smb_fname->base_name = name;
650 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
651 smb_fname->base_name = tmp_base_name;
657 static int catia_unlinkat(vfs_handle_struct *handle,
658 struct files_struct *dirfsp,
659 const struct smb_filename *smb_fname,
662 struct catia_cache *cc = NULL;
663 struct smb_filename *smb_fname_tmp = NULL;
668 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, dirfsp, &cc);
673 status = catia_string_replace_allocate(handle->conn,
674 smb_fname->base_name,
675 &name, vfs_translate_to_unix);
676 if (!NT_STATUS_IS_OK(status)) {
677 errno = map_errno_from_nt_status(status);
681 /* Setup temporary smb_filename structs. */
682 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
683 if (smb_fname_tmp == NULL) {
688 smb_fname_tmp->base_name = name;
689 smb_fname_tmp->fsp = smb_fname->fsp;
691 ret = SMB_VFS_NEXT_UNLINKAT(handle,
695 TALLOC_FREE(smb_fname_tmp);
699 CATIA_FETCH_FSP_POST_NEXT(&cc, dirfsp);
703 static int catia_lchown(vfs_handle_struct *handle,
704 const struct smb_filename *smb_fname,
712 struct smb_filename *catia_smb_fname = NULL;
714 status = catia_string_replace_allocate(handle->conn,
715 smb_fname->base_name,
717 vfs_translate_to_unix);
718 if (!NT_STATUS_IS_OK(status)) {
719 errno = map_errno_from_nt_status(status);
722 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
728 if (catia_smb_fname == NULL) {
734 ret = SMB_VFS_NEXT_LCHOWN(handle, catia_smb_fname, uid, gid);
737 TALLOC_FREE(catia_smb_fname);
742 static int catia_mkdirat(vfs_handle_struct *handle,
743 struct files_struct *dirfsp,
744 const struct smb_filename *smb_fname,
750 struct smb_filename *catia_smb_fname = NULL;
752 status = catia_string_replace_allocate(handle->conn,
753 smb_fname->base_name,
755 vfs_translate_to_unix);
756 if (!NT_STATUS_IS_OK(status)) {
757 errno = map_errno_from_nt_status(status);
760 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
766 if (catia_smb_fname == NULL) {
772 ret = SMB_VFS_NEXT_MKDIRAT(handle,
777 TALLOC_FREE(catia_smb_fname);
782 static int catia_chdir(vfs_handle_struct *handle,
783 const struct smb_filename *smb_fname)
786 struct smb_filename *catia_smb_fname = NULL;
790 status = catia_string_replace_allocate(handle->conn,
791 smb_fname->base_name,
793 vfs_translate_to_unix);
794 if (!NT_STATUS_IS_OK(status)) {
795 errno = map_errno_from_nt_status(status);
799 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
805 if (catia_smb_fname == NULL) {
810 ret = SMB_VFS_NEXT_CHDIR(handle, catia_smb_fname);
812 TALLOC_FREE(catia_smb_fname);
817 static int catia_fntimes(vfs_handle_struct *handle,
819 struct smb_file_time *ft)
821 struct catia_cache *cc = NULL;
824 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
829 ret = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
831 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
836 static struct smb_filename *
837 catia_realpath(vfs_handle_struct *handle,
839 const struct smb_filename *smb_fname)
841 char *mapped_name = NULL;
842 struct smb_filename *catia_smb_fname = NULL;
843 struct smb_filename *return_fname = NULL;
846 status = catia_string_replace_allocate(handle->conn,
847 smb_fname->base_name,
848 &mapped_name, vfs_translate_to_unix);
849 if (!NT_STATUS_IS_OK(status)) {
850 errno = map_errno_from_nt_status(status);
854 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
860 if (catia_smb_fname == NULL) {
861 TALLOC_FREE(mapped_name);
865 return_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, catia_smb_fname);
866 TALLOC_FREE(mapped_name);
867 TALLOC_FREE(catia_smb_fname);
872 catia_fstreaminfo(struct vfs_handle_struct *handle,
873 struct files_struct *fsp,
875 unsigned int *_num_streams,
876 struct stream_struct **_streams)
878 char *mapped_name = NULL;
881 struct smb_filename *catia_smb_fname = NULL;
882 struct smb_filename *smb_fname = NULL;
883 unsigned int num_streams = 0;
884 struct stream_struct *streams = NULL;
886 smb_fname = fsp->fsp_name;
890 status = catia_string_replace_allocate(handle->conn,
891 smb_fname->base_name,
893 vfs_translate_to_unix);
894 if (!NT_STATUS_IS_OK(status)) {
898 status = synthetic_pathref(talloc_tos(),
899 handle->conn->cwd_fsp,
907 if (!NT_STATUS_IS_OK(status)) {
908 TALLOC_FREE(mapped_name);
912 status = SMB_VFS_NEXT_FSTREAMINFO(handle,
913 catia_smb_fname->fsp,
917 TALLOC_FREE(mapped_name);
918 TALLOC_FREE(catia_smb_fname);
919 if (!NT_STATUS_IS_OK(status)) {
924 * Translate stream names just like the base names
926 for (i = 0; i < num_streams; i++) {
928 * Strip ":" prefix and ":$DATA" suffix to get a
929 * "pure" stream name and only translate that.
931 void *old_ptr = streams[i].name;
932 char *stream_name = streams[i].name + 1;
933 char *stream_type = strrchr_m(stream_name, ':');
935 if (stream_type != NULL) {
940 status = catia_string_replace_allocate(handle->conn,
943 vfs_translate_to_windows);
944 if (!NT_STATUS_IS_OK(status)) {
945 TALLOC_FREE(streams);
949 if (stream_type != NULL) {
950 streams[i].name = talloc_asprintf(streams,
955 streams[i].name = talloc_asprintf(streams,
959 TALLOC_FREE(mapped_name);
960 TALLOC_FREE(old_ptr);
961 if (streams[i].name == NULL) {
962 TALLOC_FREE(streams);
963 return NT_STATUS_NO_MEMORY;
967 *_num_streams = num_streams;
972 static int catia_fstat(vfs_handle_struct *handle,
974 SMB_STRUCT_STAT *sbuf)
976 struct catia_cache *cc = NULL;
979 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
984 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
986 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
991 static ssize_t catia_pread(vfs_handle_struct *handle,
992 files_struct *fsp, void *data,
993 size_t n, off_t offset)
995 struct catia_cache *cc = NULL;
999 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1004 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1006 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1011 static ssize_t catia_pwrite(vfs_handle_struct *handle,
1012 files_struct *fsp, const void *data,
1013 size_t n, off_t offset)
1015 struct catia_cache *cc = NULL;
1019 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1024 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1026 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1031 static int catia_ftruncate(struct vfs_handle_struct *handle,
1032 struct files_struct *fsp,
1035 struct catia_cache *cc = NULL;
1038 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1043 ret = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
1045 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1050 static int catia_fallocate(struct vfs_handle_struct *handle,
1051 struct files_struct *fsp,
1056 struct catia_cache *cc = NULL;
1059 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1064 ret = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1066 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1071 static ssize_t catia_fgetxattr(struct vfs_handle_struct *handle,
1072 struct files_struct *fsp,
1077 char *mapped_xattr_name = NULL;
1081 status = catia_string_replace_allocate(handle->conn,
1082 name, &mapped_xattr_name,
1083 vfs_translate_to_unix);
1084 if (!NT_STATUS_IS_OK(status)) {
1085 errno = map_errno_from_nt_status(status);
1089 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, mapped_xattr_name,
1092 TALLOC_FREE(mapped_xattr_name);
1097 static ssize_t catia_flistxattr(struct vfs_handle_struct *handle,
1098 struct files_struct *fsp,
1102 struct catia_cache *cc = NULL;
1106 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1111 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
1113 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1118 static int catia_fremovexattr(struct vfs_handle_struct *handle,
1119 struct files_struct *fsp,
1122 char *mapped_name = NULL;
1126 status = catia_string_replace_allocate(handle->conn,
1127 name, &mapped_name, vfs_translate_to_unix);
1128 if (!NT_STATUS_IS_OK(status)) {
1129 errno = map_errno_from_nt_status(status);
1133 ret = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, mapped_name);
1135 TALLOC_FREE(mapped_name);
1140 static int catia_fsetxattr(struct vfs_handle_struct *handle,
1141 struct files_struct *fsp,
1147 char *mapped_xattr_name = NULL;
1151 status = catia_string_replace_allocate(
1152 handle->conn, name, &mapped_xattr_name, vfs_translate_to_unix);
1153 if (!NT_STATUS_IS_OK(status)) {
1154 errno = map_errno_from_nt_status(status);
1158 ret = SMB_VFS_NEXT_FSETXATTR(handle, fsp, mapped_xattr_name,
1159 value, size, flags);
1161 TALLOC_FREE(mapped_xattr_name);
1166 static SMB_ACL_T catia_sys_acl_get_fd(vfs_handle_struct *handle,
1168 SMB_ACL_TYPE_T type,
1169 TALLOC_CTX *mem_ctx)
1171 struct catia_cache *cc = NULL;
1172 struct smb_acl_t *result = NULL;
1175 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1180 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, type, mem_ctx);
1182 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1187 static int catia_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1189 TALLOC_CTX *mem_ctx,
1190 char **blob_description,
1193 struct catia_cache *cc = NULL;
1196 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1201 ret = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1202 blob_description, blob);
1204 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1209 static int catia_sys_acl_set_fd(vfs_handle_struct *handle,
1211 SMB_ACL_TYPE_T type,
1214 struct catia_cache *cc = NULL;
1217 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1222 ret = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
1224 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1229 static NTSTATUS catia_fget_nt_acl(vfs_handle_struct *handle,
1231 uint32_t security_info,
1232 TALLOC_CTX *mem_ctx,
1233 struct security_descriptor **ppdesc)
1235 struct catia_cache *cc = NULL;
1239 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1241 return map_nt_error_from_unix(errno);
1244 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1247 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1252 static NTSTATUS catia_fset_nt_acl(vfs_handle_struct *handle,
1254 uint32_t security_info_sent,
1255 const struct security_descriptor *psd)
1257 struct catia_cache *cc = NULL;
1261 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1263 return map_nt_error_from_unix(errno);
1266 status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1268 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1273 static NTSTATUS catia_fset_dos_attributes(struct vfs_handle_struct *handle,
1274 struct files_struct *fsp,
1277 struct catia_cache *cc = NULL;
1281 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1283 return map_nt_error_from_unix(errno);
1286 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1288 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1293 static NTSTATUS catia_fget_dos_attributes(struct vfs_handle_struct *handle,
1294 struct files_struct *fsp,
1297 struct catia_cache *cc = NULL;
1301 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1303 return map_nt_error_from_unix(errno);
1306 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1308 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1313 static int catia_fchown(vfs_handle_struct *handle,
1318 struct catia_cache *cc = NULL;
1321 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1326 ret = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1328 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1333 static int catia_fchmod(vfs_handle_struct *handle,
1337 struct catia_cache *cc = NULL;
1340 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1345 ret = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1347 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1352 struct catia_pread_state {
1354 struct vfs_aio_state vfs_aio_state;
1355 struct files_struct *fsp;
1356 struct catia_cache *cc;
1359 static void catia_pread_done(struct tevent_req *subreq);
1361 static struct tevent_req *catia_pread_send(struct vfs_handle_struct *handle,
1362 TALLOC_CTX *mem_ctx,
1363 struct tevent_context *ev,
1364 struct files_struct *fsp,
1369 struct tevent_req *req = NULL, *subreq = NULL;
1370 struct catia_pread_state *state = NULL;
1373 req = tevent_req_create(mem_ctx, &state,
1374 struct catia_pread_state);
1380 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1382 tevent_req_error(req, errno);
1383 return tevent_req_post(req, ev);
1386 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1388 if (tevent_req_nomem(subreq, req)) {
1389 return tevent_req_post(req, ev);
1391 tevent_req_set_callback(subreq, catia_pread_done, req);
1396 static void catia_pread_done(struct tevent_req *subreq)
1398 struct tevent_req *req = tevent_req_callback_data(
1399 subreq, struct tevent_req);
1400 struct catia_pread_state *state = tevent_req_data(
1401 req, struct catia_pread_state);
1403 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1404 TALLOC_FREE(subreq);
1406 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1408 tevent_req_done(req);
1411 static ssize_t catia_pread_recv(struct tevent_req *req,
1412 struct vfs_aio_state *vfs_aio_state)
1414 struct catia_pread_state *state = tevent_req_data(
1415 req, struct catia_pread_state);
1417 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1421 *vfs_aio_state = state->vfs_aio_state;
1425 struct catia_pwrite_state {
1427 struct vfs_aio_state vfs_aio_state;
1428 struct files_struct *fsp;
1429 struct catia_cache *cc;
1432 static void catia_pwrite_done(struct tevent_req *subreq);
1434 static struct tevent_req *catia_pwrite_send(struct vfs_handle_struct *handle,
1435 TALLOC_CTX *mem_ctx,
1436 struct tevent_context *ev,
1437 struct files_struct *fsp,
1442 struct tevent_req *req = NULL, *subreq = NULL;
1443 struct catia_pwrite_state *state = NULL;
1446 req = tevent_req_create(mem_ctx, &state,
1447 struct catia_pwrite_state);
1453 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1455 tevent_req_error(req, errno);
1456 return tevent_req_post(req, ev);
1459 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1461 if (tevent_req_nomem(subreq, req)) {
1462 return tevent_req_post(req, ev);
1464 tevent_req_set_callback(subreq, catia_pwrite_done, req);
1469 static void catia_pwrite_done(struct tevent_req *subreq)
1471 struct tevent_req *req = tevent_req_callback_data(
1472 subreq, struct tevent_req);
1473 struct catia_pwrite_state *state = tevent_req_data(
1474 req, struct catia_pwrite_state);
1476 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1477 TALLOC_FREE(subreq);
1479 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1481 tevent_req_done(req);
1484 static ssize_t catia_pwrite_recv(struct tevent_req *req,
1485 struct vfs_aio_state *vfs_aio_state)
1487 struct catia_pwrite_state *state = tevent_req_data(
1488 req, struct catia_pwrite_state);
1490 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1494 *vfs_aio_state = state->vfs_aio_state;
1498 static off_t catia_lseek(vfs_handle_struct *handle,
1503 struct catia_cache *cc = NULL;
1507 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1512 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1514 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1519 struct catia_fsync_state {
1521 struct vfs_aio_state vfs_aio_state;
1522 struct files_struct *fsp;
1523 struct catia_cache *cc;
1526 static void catia_fsync_done(struct tevent_req *subreq);
1528 static struct tevent_req *catia_fsync_send(struct vfs_handle_struct *handle,
1529 TALLOC_CTX *mem_ctx,
1530 struct tevent_context *ev,
1531 struct files_struct *fsp)
1533 struct tevent_req *req = NULL, *subreq = NULL;
1534 struct catia_fsync_state *state = NULL;
1537 req = tevent_req_create(mem_ctx, &state,
1538 struct catia_fsync_state);
1544 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1546 tevent_req_error(req, errno);
1547 return tevent_req_post(req, ev);
1550 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1551 if (tevent_req_nomem(subreq, req)) {
1552 return tevent_req_post(req, ev);
1554 tevent_req_set_callback(subreq, catia_fsync_done, req);
1559 static void catia_fsync_done(struct tevent_req *subreq)
1561 struct tevent_req *req = tevent_req_callback_data(
1562 subreq, struct tevent_req);
1563 struct catia_fsync_state *state = tevent_req_data(
1564 req, struct catia_fsync_state);
1566 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1567 TALLOC_FREE(subreq);
1569 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1571 tevent_req_done(req);
1574 static int catia_fsync_recv(struct tevent_req *req,
1575 struct vfs_aio_state *vfs_aio_state)
1577 struct catia_fsync_state *state = tevent_req_data(
1578 req, struct catia_fsync_state);
1580 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1584 *vfs_aio_state = state->vfs_aio_state;
1588 static bool catia_lock(vfs_handle_struct *handle,
1595 struct catia_cache *cc = NULL;
1599 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1604 ok = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1606 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1611 static int catia_filesystem_sharemode(struct vfs_handle_struct *handle,
1612 struct files_struct *fsp,
1613 uint32_t share_access,
1614 uint32_t access_mask)
1616 struct catia_cache *cc = NULL;
1619 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1624 ret = SMB_VFS_NEXT_FILESYSTEM_SHAREMODE(handle,
1629 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1634 static int catia_linux_setlease(vfs_handle_struct *handle,
1638 struct catia_cache *cc = NULL;
1641 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1646 ret = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1648 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1653 static bool catia_getlock(vfs_handle_struct *handle,
1660 struct catia_cache *cc = NULL;
1664 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1669 ok = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1671 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1676 static bool catia_strict_lock_check(struct vfs_handle_struct *handle,
1677 struct files_struct *fsp,
1678 struct lock_struct *plock)
1680 struct catia_cache *cc = NULL;
1684 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1689 ok = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
1691 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1696 static NTSTATUS catia_fsctl(struct vfs_handle_struct *handle,
1697 struct files_struct *fsp,
1701 const uint8_t *_in_data,
1703 uint8_t **_out_data,
1704 uint32_t max_out_len,
1708 struct catia_cache *cc = NULL;
1711 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1713 return map_nt_error_from_unix(errno);
1716 result = SMB_VFS_NEXT_FSCTL(handle,
1727 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1732 static NTSTATUS catia_fget_compression(vfs_handle_struct *handle,
1733 TALLOC_CTX *mem_ctx,
1734 struct files_struct *fsp,
1735 uint16_t *_compression_fmt)
1738 struct catia_cache *cc = NULL;
1741 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1743 return map_nt_error_from_unix(errno);
1746 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle,
1751 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1756 static NTSTATUS catia_set_compression(vfs_handle_struct *handle,
1757 TALLOC_CTX *mem_ctx,
1758 struct files_struct *fsp,
1759 uint16_t compression_fmt)
1762 struct catia_cache *cc = NULL;
1765 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1767 return map_nt_error_from_unix(errno);
1770 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
1773 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1778 static NTSTATUS catia_create_dfs_pathat(struct vfs_handle_struct *handle,
1779 struct files_struct *dirfsp,
1780 const struct smb_filename *smb_fname,
1781 const struct referral *reflist,
1782 size_t referral_count)
1784 char *mapped_name = NULL;
1785 const char *path = smb_fname->base_name;
1786 struct smb_filename *mapped_smb_fname = NULL;
1789 status = catia_string_replace_allocate(handle->conn,
1792 vfs_translate_to_unix);
1793 if (!NT_STATUS_IS_OK(status)) {
1794 errno = map_errno_from_nt_status(status);
1797 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1803 if (mapped_smb_fname == NULL) {
1804 TALLOC_FREE(mapped_name);
1805 return NT_STATUS_NO_MEMORY;
1808 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
1813 TALLOC_FREE(mapped_name);
1814 TALLOC_FREE(mapped_smb_fname);
1818 static NTSTATUS catia_read_dfs_pathat(struct vfs_handle_struct *handle,
1819 TALLOC_CTX *mem_ctx,
1820 struct files_struct *dirfsp,
1821 struct smb_filename *smb_fname,
1822 struct referral **ppreflist,
1823 size_t *preferral_count)
1825 char *mapped_name = NULL;
1826 const char *path = smb_fname->base_name;
1827 struct smb_filename *mapped_smb_fname = NULL;
1830 status = catia_string_replace_allocate(handle->conn,
1833 vfs_translate_to_unix);
1834 if (!NT_STATUS_IS_OK(status)) {
1835 errno = map_errno_from_nt_status(status);
1838 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1844 if (mapped_smb_fname == NULL) {
1845 TALLOC_FREE(mapped_name);
1846 return NT_STATUS_NO_MEMORY;
1849 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
1855 if (NT_STATUS_IS_OK(status)) {
1856 /* Return any stat(2) info. */
1857 smb_fname->st = mapped_smb_fname->st;
1860 TALLOC_FREE(mapped_name);
1861 TALLOC_FREE(mapped_smb_fname);
1865 static struct vfs_fn_pointers vfs_catia_fns = {
1866 .connect_fn = catia_connect,
1868 /* Directory operations */
1869 .mkdirat_fn = catia_mkdirat,
1871 /* File operations */
1872 .openat_fn = catia_openat,
1873 .pread_fn = catia_pread,
1874 .pread_send_fn = catia_pread_send,
1875 .pread_recv_fn = catia_pread_recv,
1876 .pwrite_fn = catia_pwrite,
1877 .pwrite_send_fn = catia_pwrite_send,
1878 .pwrite_recv_fn = catia_pwrite_recv,
1879 .lseek_fn = catia_lseek,
1880 .renameat_fn = catia_renameat,
1881 .fsync_send_fn = catia_fsync_send,
1882 .fsync_recv_fn = catia_fsync_recv,
1883 .stat_fn = catia_stat,
1884 .fstat_fn = catia_fstat,
1885 .lstat_fn = catia_lstat,
1886 .unlinkat_fn = catia_unlinkat,
1887 .fchmod_fn = catia_fchmod,
1888 .fchown_fn = catia_fchown,
1889 .lchown_fn = catia_lchown,
1890 .chdir_fn = catia_chdir,
1891 .fntimes_fn = catia_fntimes,
1892 .ftruncate_fn = catia_ftruncate,
1893 .fallocate_fn = catia_fallocate,
1894 .lock_fn = catia_lock,
1895 .filesystem_sharemode_fn = catia_filesystem_sharemode,
1896 .linux_setlease_fn = catia_linux_setlease,
1897 .getlock_fn = catia_getlock,
1898 .realpath_fn = catia_realpath,
1899 .fstreaminfo_fn = catia_fstreaminfo,
1900 .strict_lock_check_fn = catia_strict_lock_check,
1901 .translate_name_fn = catia_translate_name,
1902 .fsctl_fn = catia_fsctl,
1903 .get_dos_attributes_send_fn = vfs_not_implemented_get_dos_attributes_send,
1904 .get_dos_attributes_recv_fn = vfs_not_implemented_get_dos_attributes_recv,
1905 .fset_dos_attributes_fn = catia_fset_dos_attributes,
1906 .fget_dos_attributes_fn = catia_fget_dos_attributes,
1907 .fget_compression_fn = catia_fget_compression,
1908 .set_compression_fn = catia_set_compression,
1909 .create_dfs_pathat_fn = catia_create_dfs_pathat,
1910 .read_dfs_pathat_fn = catia_read_dfs_pathat,
1912 /* NT ACL operations. */
1913 .fget_nt_acl_fn = catia_fget_nt_acl,
1914 .fset_nt_acl_fn = catia_fset_nt_acl,
1916 /* POSIX ACL operations. */
1917 .sys_acl_get_fd_fn = catia_sys_acl_get_fd,
1918 .sys_acl_blob_get_fd_fn = catia_sys_acl_blob_get_fd,
1919 .sys_acl_set_fd_fn = catia_sys_acl_set_fd,
1921 /* EA operations. */
1922 .getxattrat_send_fn = vfs_not_implemented_getxattrat_send,
1923 .getxattrat_recv_fn = vfs_not_implemented_getxattrat_recv,
1924 .fgetxattr_fn = catia_fgetxattr,
1925 .flistxattr_fn = catia_flistxattr,
1926 .fremovexattr_fn = catia_fremovexattr,
1927 .fsetxattr_fn = catia_fsetxattr,
1931 NTSTATUS vfs_catia_init(TALLOC_CTX *ctx)
1935 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
1937 if (!NT_STATUS_IS_OK(ret))
1940 vfs_catia_debug_level = debug_add_class("catia");
1941 if (vfs_catia_debug_level == -1) {
1942 vfs_catia_debug_level = DBGC_VFS;
1943 DEBUG(0, ("vfs_catia: Couldn't register custom debugging "
1946 DEBUG(10, ("vfs_catia: Debug class number of "
1947 "'catia': %d\n", vfs_catia_debug_level));