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->base_fsp != NULL) &&
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->base_fsp != NULL) &&
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->base_fsp != NULL) {
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->base_fsp != NULL) {
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->base_fsp != NULL) {
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->base_fsp != NULL) {
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,
495 struct smb_filename *smb_fname = NULL;
496 struct catia_cache *cc = NULL;
497 char *mapped_name = NULL;
502 status = catia_string_replace_allocate(handle->conn,
503 smb_fname_in->base_name,
505 vfs_translate_to_unix);
506 if (!NT_STATUS_IS_OK(status)) {
510 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
512 TALLOC_FREE(mapped_name);
516 smb_fname = cp_smb_filename(talloc_tos(), smb_fname_in);
517 if (smb_fname == NULL) {
518 TALLOC_FREE(mapped_name);
522 smb_fname->base_name = mapped_name;
524 ret = SMB_VFS_NEXT_OPENAT(handle,
534 TALLOC_FREE(smb_fname);
535 TALLOC_FREE(mapped_name);
536 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
537 if (saved_errno != 0) {
543 static int catia_renameat(vfs_handle_struct *handle,
544 files_struct *srcfsp,
545 const struct smb_filename *smb_fname_src,
546 files_struct *dstfsp,
547 const struct smb_filename *smb_fname_dst)
549 TALLOC_CTX *ctx = talloc_tos();
550 struct smb_filename *smb_fname_src_tmp = NULL;
551 struct smb_filename *smb_fname_dst_tmp = NULL;
552 char *src_name_mapped = NULL;
553 char *dst_name_mapped = NULL;
557 status = catia_string_replace_allocate(handle->conn,
558 smb_fname_src->base_name,
559 &src_name_mapped, vfs_translate_to_unix);
560 if (!NT_STATUS_IS_OK(status)) {
561 errno = map_errno_from_nt_status(status);
565 status = catia_string_replace_allocate(handle->conn,
566 smb_fname_dst->base_name,
567 &dst_name_mapped, vfs_translate_to_unix);
568 if (!NT_STATUS_IS_OK(status)) {
569 errno = map_errno_from_nt_status(status);
573 /* Setup temporary smb_filename structs. */
574 smb_fname_src_tmp = cp_smb_filename(ctx, smb_fname_src);
575 if (smb_fname_src_tmp == NULL) {
580 smb_fname_dst_tmp = cp_smb_filename(ctx, smb_fname_dst);
581 if (smb_fname_dst_tmp == NULL) {
586 smb_fname_src_tmp->base_name = src_name_mapped;
587 smb_fname_dst_tmp->base_name = dst_name_mapped;
588 DEBUG(10, ("converted old name: %s\n",
589 smb_fname_str_dbg(smb_fname_src_tmp)));
590 DEBUG(10, ("converted new name: %s\n",
591 smb_fname_str_dbg(smb_fname_dst_tmp)));
593 ret = SMB_VFS_NEXT_RENAMEAT(handle,
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);
608 static int catia_stat(vfs_handle_struct *handle,
609 struct smb_filename *smb_fname)
616 status = catia_string_replace_allocate(handle->conn,
617 smb_fname->base_name,
618 &name, vfs_translate_to_unix);
619 if (!NT_STATUS_IS_OK(status)) {
620 errno = map_errno_from_nt_status(status);
624 tmp_base_name = smb_fname->base_name;
625 smb_fname->base_name = name;
627 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
628 smb_fname->base_name = tmp_base_name;
634 static int catia_lstat(vfs_handle_struct *handle,
635 struct smb_filename *smb_fname)
642 status = catia_string_replace_allocate(handle->conn,
643 smb_fname->base_name,
644 &name, vfs_translate_to_unix);
645 if (!NT_STATUS_IS_OK(status)) {
646 errno = map_errno_from_nt_status(status);
650 tmp_base_name = smb_fname->base_name;
651 smb_fname->base_name = name;
653 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
654 smb_fname->base_name = tmp_base_name;
660 static int catia_unlinkat(vfs_handle_struct *handle,
661 struct files_struct *dirfsp,
662 const struct smb_filename *smb_fname,
665 struct catia_cache *cc = NULL;
666 struct smb_filename *smb_fname_tmp = NULL;
671 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, dirfsp, &cc);
676 status = catia_string_replace_allocate(handle->conn,
677 smb_fname->base_name,
678 &name, vfs_translate_to_unix);
679 if (!NT_STATUS_IS_OK(status)) {
680 errno = map_errno_from_nt_status(status);
684 /* Setup temporary smb_filename structs. */
685 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
686 if (smb_fname_tmp == NULL) {
691 smb_fname_tmp->base_name = name;
692 smb_fname_tmp->fsp = smb_fname->fsp;
694 ret = SMB_VFS_NEXT_UNLINKAT(handle,
698 TALLOC_FREE(smb_fname_tmp);
702 CATIA_FETCH_FSP_POST_NEXT(&cc, dirfsp);
706 static int catia_lchown(vfs_handle_struct *handle,
707 const struct smb_filename *smb_fname,
715 struct smb_filename *catia_smb_fname = NULL;
717 status = catia_string_replace_allocate(handle->conn,
718 smb_fname->base_name,
720 vfs_translate_to_unix);
721 if (!NT_STATUS_IS_OK(status)) {
722 errno = map_errno_from_nt_status(status);
725 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
731 if (catia_smb_fname == NULL) {
737 ret = SMB_VFS_NEXT_LCHOWN(handle, catia_smb_fname, uid, gid);
740 TALLOC_FREE(catia_smb_fname);
745 static int catia_mkdirat(vfs_handle_struct *handle,
746 struct files_struct *dirfsp,
747 const struct smb_filename *smb_fname,
753 struct smb_filename *catia_smb_fname = NULL;
755 status = catia_string_replace_allocate(handle->conn,
756 smb_fname->base_name,
758 vfs_translate_to_unix);
759 if (!NT_STATUS_IS_OK(status)) {
760 errno = map_errno_from_nt_status(status);
763 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
769 if (catia_smb_fname == NULL) {
775 ret = SMB_VFS_NEXT_MKDIRAT(handle,
780 TALLOC_FREE(catia_smb_fname);
785 static int catia_chdir(vfs_handle_struct *handle,
786 const struct smb_filename *smb_fname)
789 struct smb_filename *catia_smb_fname = NULL;
793 status = catia_string_replace_allocate(handle->conn,
794 smb_fname->base_name,
796 vfs_translate_to_unix);
797 if (!NT_STATUS_IS_OK(status)) {
798 errno = map_errno_from_nt_status(status);
802 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
808 if (catia_smb_fname == NULL) {
813 ret = SMB_VFS_NEXT_CHDIR(handle, catia_smb_fname);
815 TALLOC_FREE(catia_smb_fname);
820 static int catia_fntimes(vfs_handle_struct *handle,
822 struct smb_file_time *ft)
824 struct catia_cache *cc = NULL;
827 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
832 ret = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
834 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
839 static struct smb_filename *
840 catia_realpath(vfs_handle_struct *handle,
842 const struct smb_filename *smb_fname)
844 char *mapped_name = NULL;
845 struct smb_filename *catia_smb_fname = NULL;
846 struct smb_filename *return_fname = NULL;
849 status = catia_string_replace_allocate(handle->conn,
850 smb_fname->base_name,
851 &mapped_name, vfs_translate_to_unix);
852 if (!NT_STATUS_IS_OK(status)) {
853 errno = map_errno_from_nt_status(status);
857 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
863 if (catia_smb_fname == NULL) {
864 TALLOC_FREE(mapped_name);
868 return_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, catia_smb_fname);
869 TALLOC_FREE(mapped_name);
870 TALLOC_FREE(catia_smb_fname);
875 catia_fstreaminfo(struct vfs_handle_struct *handle,
876 struct files_struct *fsp,
878 unsigned int *_num_streams,
879 struct stream_struct **_streams)
881 char *mapped_name = NULL;
884 struct smb_filename *catia_smb_fname = NULL;
885 struct smb_filename *smb_fname = NULL;
886 unsigned int num_streams = 0;
887 struct stream_struct *streams = NULL;
889 smb_fname = fsp->fsp_name;
893 status = catia_string_replace_allocate(handle->conn,
894 smb_fname->base_name,
896 vfs_translate_to_unix);
897 if (!NT_STATUS_IS_OK(status)) {
901 status = synthetic_pathref(talloc_tos(),
902 handle->conn->cwd_fsp,
910 if (!NT_STATUS_IS_OK(status)) {
911 TALLOC_FREE(mapped_name);
915 status = SMB_VFS_NEXT_FSTREAMINFO(handle,
916 catia_smb_fname->fsp,
920 TALLOC_FREE(mapped_name);
921 TALLOC_FREE(catia_smb_fname);
922 if (!NT_STATUS_IS_OK(status)) {
927 * Translate stream names just like the base names
929 for (i = 0; i < num_streams; i++) {
931 * Strip ":" prefix and ":$DATA" suffix to get a
932 * "pure" stream name and only translate that.
934 void *old_ptr = streams[i].name;
935 char *stream_name = streams[i].name + 1;
936 char *stream_type = strrchr_m(stream_name, ':');
938 if (stream_type != NULL) {
943 status = catia_string_replace_allocate(handle->conn,
946 vfs_translate_to_windows);
947 if (!NT_STATUS_IS_OK(status)) {
948 TALLOC_FREE(streams);
952 if (stream_type != NULL) {
953 streams[i].name = talloc_asprintf(streams,
958 streams[i].name = talloc_asprintf(streams,
962 TALLOC_FREE(mapped_name);
963 TALLOC_FREE(old_ptr);
964 if (streams[i].name == NULL) {
965 TALLOC_FREE(streams);
966 return NT_STATUS_NO_MEMORY;
970 *_num_streams = num_streams;
975 static int catia_fstat(vfs_handle_struct *handle,
977 SMB_STRUCT_STAT *sbuf)
979 struct catia_cache *cc = NULL;
982 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
987 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
989 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
994 static ssize_t catia_pread(vfs_handle_struct *handle,
995 files_struct *fsp, void *data,
996 size_t n, off_t offset)
998 struct catia_cache *cc = NULL;
1002 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1007 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1009 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1014 static ssize_t catia_pwrite(vfs_handle_struct *handle,
1015 files_struct *fsp, const void *data,
1016 size_t n, off_t offset)
1018 struct catia_cache *cc = NULL;
1022 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1027 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1029 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1034 static int catia_ftruncate(struct vfs_handle_struct *handle,
1035 struct files_struct *fsp,
1038 struct catia_cache *cc = NULL;
1041 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1046 ret = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
1048 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1053 static int catia_fallocate(struct vfs_handle_struct *handle,
1054 struct files_struct *fsp,
1059 struct catia_cache *cc = NULL;
1062 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1067 ret = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1069 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1074 static ssize_t catia_fgetxattr(struct vfs_handle_struct *handle,
1075 struct files_struct *fsp,
1080 char *mapped_xattr_name = NULL;
1084 status = catia_string_replace_allocate(handle->conn,
1085 name, &mapped_xattr_name,
1086 vfs_translate_to_unix);
1087 if (!NT_STATUS_IS_OK(status)) {
1088 errno = map_errno_from_nt_status(status);
1092 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, mapped_xattr_name,
1095 TALLOC_FREE(mapped_xattr_name);
1100 static ssize_t catia_flistxattr(struct vfs_handle_struct *handle,
1101 struct files_struct *fsp,
1105 struct catia_cache *cc = NULL;
1109 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1114 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
1116 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1121 static int catia_fremovexattr(struct vfs_handle_struct *handle,
1122 struct files_struct *fsp,
1125 char *mapped_name = NULL;
1129 status = catia_string_replace_allocate(handle->conn,
1130 name, &mapped_name, vfs_translate_to_unix);
1131 if (!NT_STATUS_IS_OK(status)) {
1132 errno = map_errno_from_nt_status(status);
1136 ret = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, mapped_name);
1138 TALLOC_FREE(mapped_name);
1143 static int catia_fsetxattr(struct vfs_handle_struct *handle,
1144 struct files_struct *fsp,
1150 char *mapped_xattr_name = NULL;
1154 status = catia_string_replace_allocate(
1155 handle->conn, name, &mapped_xattr_name, vfs_translate_to_unix);
1156 if (!NT_STATUS_IS_OK(status)) {
1157 errno = map_errno_from_nt_status(status);
1161 ret = SMB_VFS_NEXT_FSETXATTR(handle, fsp, mapped_xattr_name,
1162 value, size, flags);
1164 TALLOC_FREE(mapped_xattr_name);
1169 static SMB_ACL_T catia_sys_acl_get_fd(vfs_handle_struct *handle,
1171 SMB_ACL_TYPE_T type,
1172 TALLOC_CTX *mem_ctx)
1174 struct catia_cache *cc = NULL;
1175 struct smb_acl_t *result = NULL;
1178 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1183 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, type, mem_ctx);
1185 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1190 static int catia_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1192 TALLOC_CTX *mem_ctx,
1193 char **blob_description,
1196 struct catia_cache *cc = NULL;
1199 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1204 ret = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1205 blob_description, blob);
1207 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1212 static int catia_sys_acl_set_fd(vfs_handle_struct *handle,
1214 SMB_ACL_TYPE_T type,
1217 struct catia_cache *cc = NULL;
1220 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1225 ret = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
1227 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1232 static NTSTATUS catia_fget_nt_acl(vfs_handle_struct *handle,
1234 uint32_t security_info,
1235 TALLOC_CTX *mem_ctx,
1236 struct security_descriptor **ppdesc)
1238 struct catia_cache *cc = NULL;
1242 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1244 return map_nt_error_from_unix(errno);
1247 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1250 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1255 static NTSTATUS catia_fset_nt_acl(vfs_handle_struct *handle,
1257 uint32_t security_info_sent,
1258 const struct security_descriptor *psd)
1260 struct catia_cache *cc = NULL;
1264 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1266 return map_nt_error_from_unix(errno);
1269 status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1271 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1276 static NTSTATUS catia_fset_dos_attributes(struct vfs_handle_struct *handle,
1277 struct files_struct *fsp,
1280 struct catia_cache *cc = NULL;
1284 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1286 return map_nt_error_from_unix(errno);
1289 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1291 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1296 static NTSTATUS catia_fget_dos_attributes(struct vfs_handle_struct *handle,
1297 struct files_struct *fsp,
1300 struct catia_cache *cc = NULL;
1304 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1306 return map_nt_error_from_unix(errno);
1309 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1311 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1316 static int catia_fchown(vfs_handle_struct *handle,
1321 struct catia_cache *cc = NULL;
1324 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1329 ret = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1331 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1336 static int catia_fchmod(vfs_handle_struct *handle,
1340 struct catia_cache *cc = NULL;
1343 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1348 ret = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1350 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1355 struct catia_pread_state {
1357 struct vfs_aio_state vfs_aio_state;
1358 struct files_struct *fsp;
1359 struct catia_cache *cc;
1362 static void catia_pread_done(struct tevent_req *subreq);
1364 static struct tevent_req *catia_pread_send(struct vfs_handle_struct *handle,
1365 TALLOC_CTX *mem_ctx,
1366 struct tevent_context *ev,
1367 struct files_struct *fsp,
1372 struct tevent_req *req = NULL, *subreq = NULL;
1373 struct catia_pread_state *state = NULL;
1376 req = tevent_req_create(mem_ctx, &state,
1377 struct catia_pread_state);
1383 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1385 tevent_req_error(req, errno);
1386 return tevent_req_post(req, ev);
1389 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1391 if (tevent_req_nomem(subreq, req)) {
1392 return tevent_req_post(req, ev);
1394 tevent_req_set_callback(subreq, catia_pread_done, req);
1399 static void catia_pread_done(struct tevent_req *subreq)
1401 struct tevent_req *req = tevent_req_callback_data(
1402 subreq, struct tevent_req);
1403 struct catia_pread_state *state = tevent_req_data(
1404 req, struct catia_pread_state);
1406 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1407 TALLOC_FREE(subreq);
1409 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1411 tevent_req_done(req);
1414 static ssize_t catia_pread_recv(struct tevent_req *req,
1415 struct vfs_aio_state *vfs_aio_state)
1417 struct catia_pread_state *state = tevent_req_data(
1418 req, struct catia_pread_state);
1420 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1424 *vfs_aio_state = state->vfs_aio_state;
1428 struct catia_pwrite_state {
1430 struct vfs_aio_state vfs_aio_state;
1431 struct files_struct *fsp;
1432 struct catia_cache *cc;
1435 static void catia_pwrite_done(struct tevent_req *subreq);
1437 static struct tevent_req *catia_pwrite_send(struct vfs_handle_struct *handle,
1438 TALLOC_CTX *mem_ctx,
1439 struct tevent_context *ev,
1440 struct files_struct *fsp,
1445 struct tevent_req *req = NULL, *subreq = NULL;
1446 struct catia_pwrite_state *state = NULL;
1449 req = tevent_req_create(mem_ctx, &state,
1450 struct catia_pwrite_state);
1456 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1458 tevent_req_error(req, errno);
1459 return tevent_req_post(req, ev);
1462 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1464 if (tevent_req_nomem(subreq, req)) {
1465 return tevent_req_post(req, ev);
1467 tevent_req_set_callback(subreq, catia_pwrite_done, req);
1472 static void catia_pwrite_done(struct tevent_req *subreq)
1474 struct tevent_req *req = tevent_req_callback_data(
1475 subreq, struct tevent_req);
1476 struct catia_pwrite_state *state = tevent_req_data(
1477 req, struct catia_pwrite_state);
1479 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1480 TALLOC_FREE(subreq);
1482 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1484 tevent_req_done(req);
1487 static ssize_t catia_pwrite_recv(struct tevent_req *req,
1488 struct vfs_aio_state *vfs_aio_state)
1490 struct catia_pwrite_state *state = tevent_req_data(
1491 req, struct catia_pwrite_state);
1493 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1497 *vfs_aio_state = state->vfs_aio_state;
1501 static off_t catia_lseek(vfs_handle_struct *handle,
1506 struct catia_cache *cc = NULL;
1510 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1515 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1517 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1522 struct catia_fsync_state {
1524 struct vfs_aio_state vfs_aio_state;
1525 struct files_struct *fsp;
1526 struct catia_cache *cc;
1529 static void catia_fsync_done(struct tevent_req *subreq);
1531 static struct tevent_req *catia_fsync_send(struct vfs_handle_struct *handle,
1532 TALLOC_CTX *mem_ctx,
1533 struct tevent_context *ev,
1534 struct files_struct *fsp)
1536 struct tevent_req *req = NULL, *subreq = NULL;
1537 struct catia_fsync_state *state = NULL;
1540 req = tevent_req_create(mem_ctx, &state,
1541 struct catia_fsync_state);
1547 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1549 tevent_req_error(req, errno);
1550 return tevent_req_post(req, ev);
1553 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1554 if (tevent_req_nomem(subreq, req)) {
1555 return tevent_req_post(req, ev);
1557 tevent_req_set_callback(subreq, catia_fsync_done, req);
1562 static void catia_fsync_done(struct tevent_req *subreq)
1564 struct tevent_req *req = tevent_req_callback_data(
1565 subreq, struct tevent_req);
1566 struct catia_fsync_state *state = tevent_req_data(
1567 req, struct catia_fsync_state);
1569 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1570 TALLOC_FREE(subreq);
1572 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1574 tevent_req_done(req);
1577 static int catia_fsync_recv(struct tevent_req *req,
1578 struct vfs_aio_state *vfs_aio_state)
1580 struct catia_fsync_state *state = tevent_req_data(
1581 req, struct catia_fsync_state);
1583 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1587 *vfs_aio_state = state->vfs_aio_state;
1591 static bool catia_lock(vfs_handle_struct *handle,
1598 struct catia_cache *cc = NULL;
1602 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1607 ok = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1609 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1614 static int catia_kernel_flock(struct vfs_handle_struct *handle,
1615 struct files_struct *fsp,
1616 uint32_t share_access,
1617 uint32_t access_mask)
1619 struct catia_cache *cc = NULL;
1622 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1627 ret = SMB_VFS_NEXT_FILESYSTEM_SHAREMODE(handle,
1632 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1637 static int catia_linux_setlease(vfs_handle_struct *handle,
1641 struct catia_cache *cc = NULL;
1644 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1649 ret = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1651 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1656 static bool catia_getlock(vfs_handle_struct *handle,
1663 struct catia_cache *cc = NULL;
1667 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1672 ok = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1674 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1679 static bool catia_strict_lock_check(struct vfs_handle_struct *handle,
1680 struct files_struct *fsp,
1681 struct lock_struct *plock)
1683 struct catia_cache *cc = NULL;
1687 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1692 ok = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
1694 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1699 static NTSTATUS catia_fsctl(struct vfs_handle_struct *handle,
1700 struct files_struct *fsp,
1704 const uint8_t *_in_data,
1706 uint8_t **_out_data,
1707 uint32_t max_out_len,
1711 struct catia_cache *cc = NULL;
1714 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1716 return map_nt_error_from_unix(errno);
1719 result = SMB_VFS_NEXT_FSCTL(handle,
1730 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1735 static NTSTATUS catia_fget_compression(vfs_handle_struct *handle,
1736 TALLOC_CTX *mem_ctx,
1737 struct files_struct *fsp,
1738 uint16_t *_compression_fmt)
1741 struct catia_cache *cc = NULL;
1744 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1746 return map_nt_error_from_unix(errno);
1749 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle,
1754 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1759 static NTSTATUS catia_set_compression(vfs_handle_struct *handle,
1760 TALLOC_CTX *mem_ctx,
1761 struct files_struct *fsp,
1762 uint16_t compression_fmt)
1765 struct catia_cache *cc = NULL;
1768 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1770 return map_nt_error_from_unix(errno);
1773 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
1776 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1781 static NTSTATUS catia_create_dfs_pathat(struct vfs_handle_struct *handle,
1782 struct files_struct *dirfsp,
1783 const struct smb_filename *smb_fname,
1784 const struct referral *reflist,
1785 size_t referral_count)
1787 char *mapped_name = NULL;
1788 const char *path = smb_fname->base_name;
1789 struct smb_filename *mapped_smb_fname = NULL;
1792 status = catia_string_replace_allocate(handle->conn,
1795 vfs_translate_to_unix);
1796 if (!NT_STATUS_IS_OK(status)) {
1797 errno = map_errno_from_nt_status(status);
1800 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1806 if (mapped_smb_fname == NULL) {
1807 TALLOC_FREE(mapped_name);
1808 return NT_STATUS_NO_MEMORY;
1811 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
1816 TALLOC_FREE(mapped_name);
1817 TALLOC_FREE(mapped_smb_fname);
1821 static NTSTATUS catia_read_dfs_pathat(struct vfs_handle_struct *handle,
1822 TALLOC_CTX *mem_ctx,
1823 struct files_struct *dirfsp,
1824 struct smb_filename *smb_fname,
1825 struct referral **ppreflist,
1826 size_t *preferral_count)
1828 char *mapped_name = NULL;
1829 const char *path = smb_fname->base_name;
1830 struct smb_filename *mapped_smb_fname = NULL;
1833 status = catia_string_replace_allocate(handle->conn,
1836 vfs_translate_to_unix);
1837 if (!NT_STATUS_IS_OK(status)) {
1838 errno = map_errno_from_nt_status(status);
1841 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1847 if (mapped_smb_fname == NULL) {
1848 TALLOC_FREE(mapped_name);
1849 return NT_STATUS_NO_MEMORY;
1852 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
1858 if (NT_STATUS_IS_OK(status)) {
1859 /* Return any stat(2) info. */
1860 smb_fname->st = mapped_smb_fname->st;
1863 TALLOC_FREE(mapped_name);
1864 TALLOC_FREE(mapped_smb_fname);
1868 static struct vfs_fn_pointers vfs_catia_fns = {
1869 .connect_fn = catia_connect,
1871 /* Directory operations */
1872 .mkdirat_fn = catia_mkdirat,
1874 /* File operations */
1875 .openat_fn = catia_openat,
1876 .pread_fn = catia_pread,
1877 .pread_send_fn = catia_pread_send,
1878 .pread_recv_fn = catia_pread_recv,
1879 .pwrite_fn = catia_pwrite,
1880 .pwrite_send_fn = catia_pwrite_send,
1881 .pwrite_recv_fn = catia_pwrite_recv,
1882 .lseek_fn = catia_lseek,
1883 .renameat_fn = catia_renameat,
1884 .fsync_send_fn = catia_fsync_send,
1885 .fsync_recv_fn = catia_fsync_recv,
1886 .stat_fn = catia_stat,
1887 .fstat_fn = catia_fstat,
1888 .lstat_fn = catia_lstat,
1889 .unlinkat_fn = catia_unlinkat,
1890 .fchmod_fn = catia_fchmod,
1891 .fchown_fn = catia_fchown,
1892 .lchown_fn = catia_lchown,
1893 .chdir_fn = catia_chdir,
1894 .fntimes_fn = catia_fntimes,
1895 .ftruncate_fn = catia_ftruncate,
1896 .fallocate_fn = catia_fallocate,
1897 .lock_fn = catia_lock,
1898 .filesystem_sharemode_fn = catia_kernel_flock,
1899 .linux_setlease_fn = catia_linux_setlease,
1900 .getlock_fn = catia_getlock,
1901 .realpath_fn = catia_realpath,
1902 .fstreaminfo_fn = catia_fstreaminfo,
1903 .strict_lock_check_fn = catia_strict_lock_check,
1904 .translate_name_fn = catia_translate_name,
1905 .fsctl_fn = catia_fsctl,
1906 .get_dos_attributes_send_fn = vfs_not_implemented_get_dos_attributes_send,
1907 .get_dos_attributes_recv_fn = vfs_not_implemented_get_dos_attributes_recv,
1908 .fset_dos_attributes_fn = catia_fset_dos_attributes,
1909 .fget_dos_attributes_fn = catia_fget_dos_attributes,
1910 .fget_compression_fn = catia_fget_compression,
1911 .set_compression_fn = catia_set_compression,
1912 .create_dfs_pathat_fn = catia_create_dfs_pathat,
1913 .read_dfs_pathat_fn = catia_read_dfs_pathat,
1915 /* NT ACL operations. */
1916 .fget_nt_acl_fn = catia_fget_nt_acl,
1917 .fset_nt_acl_fn = catia_fset_nt_acl,
1919 /* POSIX ACL operations. */
1920 .sys_acl_get_fd_fn = catia_sys_acl_get_fd,
1921 .sys_acl_blob_get_fd_fn = catia_sys_acl_blob_get_fd,
1922 .sys_acl_set_fd_fn = catia_sys_acl_set_fd,
1924 /* EA operations. */
1925 .getxattrat_send_fn = vfs_not_implemented_getxattrat_send,
1926 .getxattrat_recv_fn = vfs_not_implemented_getxattrat_recv,
1927 .fgetxattr_fn = catia_fgetxattr,
1928 .flistxattr_fn = catia_flistxattr,
1929 .fremovexattr_fn = catia_fremovexattr,
1930 .fsetxattr_fn = catia_fsetxattr,
1934 NTSTATUS vfs_catia_init(TALLOC_CTX *ctx)
1938 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
1940 if (!NT_STATUS_IS_OK(ret))
1943 vfs_catia_debug_level = debug_add_class("catia");
1944 if (vfs_catia_debug_level == -1) {
1945 vfs_catia_debug_level = DBGC_VFS;
1946 DEBUG(0, ("vfs_catia: Couldn't register custom debugging "
1949 DEBUG(10, ("vfs_catia: Debug class number of "
1950 "'catia': %d\n", vfs_catia_debug_level));