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(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 saved_errno = errno; \
442 catia_fetch_fsp_post_next((_cc), (fsp), __func__); \
443 errno = 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_open(vfs_handle_struct *handle,
489 struct smb_filename *smb_fname,
494 struct catia_cache *cc = NULL;
495 char *orig_smb_fname = smb_fname->base_name;
496 char *mapped_smb_fname = NULL;
500 status = catia_string_replace_allocate(handle->conn,
501 smb_fname->base_name,
503 vfs_translate_to_unix);
504 if (!NT_STATUS_IS_OK(status)) {
508 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
510 TALLOC_FREE(mapped_smb_fname);
514 smb_fname->base_name = mapped_smb_fname;
515 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
516 smb_fname->base_name = orig_smb_fname;
518 TALLOC_FREE(mapped_smb_fname);
519 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
524 static int catia_renameat(vfs_handle_struct *handle,
525 files_struct *srcfsp,
526 const struct smb_filename *smb_fname_src,
527 files_struct *dstfsp,
528 const struct smb_filename *smb_fname_dst)
530 TALLOC_CTX *ctx = talloc_tos();
531 struct smb_filename *smb_fname_src_tmp = NULL;
532 struct smb_filename *smb_fname_dst_tmp = NULL;
533 char *src_name_mapped = NULL;
534 char *dst_name_mapped = NULL;
538 status = catia_string_replace_allocate(handle->conn,
539 smb_fname_src->base_name,
540 &src_name_mapped, vfs_translate_to_unix);
541 if (!NT_STATUS_IS_OK(status)) {
542 errno = map_errno_from_nt_status(status);
546 status = catia_string_replace_allocate(handle->conn,
547 smb_fname_dst->base_name,
548 &dst_name_mapped, vfs_translate_to_unix);
549 if (!NT_STATUS_IS_OK(status)) {
550 errno = map_errno_from_nt_status(status);
554 /* Setup temporary smb_filename structs. */
555 smb_fname_src_tmp = cp_smb_filename(ctx, smb_fname_src);
556 if (smb_fname_src_tmp == NULL) {
561 smb_fname_dst_tmp = cp_smb_filename(ctx, smb_fname_dst);
562 if (smb_fname_dst_tmp == NULL) {
567 smb_fname_src_tmp->base_name = src_name_mapped;
568 smb_fname_dst_tmp->base_name = dst_name_mapped;
569 DEBUG(10, ("converted old name: %s\n",
570 smb_fname_str_dbg(smb_fname_src_tmp)));
571 DEBUG(10, ("converted new name: %s\n",
572 smb_fname_str_dbg(smb_fname_dst_tmp)));
574 ret = SMB_VFS_NEXT_RENAMEAT(handle,
581 TALLOC_FREE(src_name_mapped);
582 TALLOC_FREE(dst_name_mapped);
583 TALLOC_FREE(smb_fname_src_tmp);
584 TALLOC_FREE(smb_fname_dst_tmp);
589 static int catia_stat(vfs_handle_struct *handle,
590 struct smb_filename *smb_fname)
597 status = catia_string_replace_allocate(handle->conn,
598 smb_fname->base_name,
599 &name, vfs_translate_to_unix);
600 if (!NT_STATUS_IS_OK(status)) {
601 errno = map_errno_from_nt_status(status);
605 tmp_base_name = smb_fname->base_name;
606 smb_fname->base_name = name;
608 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
609 smb_fname->base_name = tmp_base_name;
615 static int catia_lstat(vfs_handle_struct *handle,
616 struct smb_filename *smb_fname)
623 status = catia_string_replace_allocate(handle->conn,
624 smb_fname->base_name,
625 &name, vfs_translate_to_unix);
626 if (!NT_STATUS_IS_OK(status)) {
627 errno = map_errno_from_nt_status(status);
631 tmp_base_name = smb_fname->base_name;
632 smb_fname->base_name = name;
634 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
635 smb_fname->base_name = tmp_base_name;
641 static int catia_unlinkat(vfs_handle_struct *handle,
642 struct files_struct *dirfsp,
643 const struct smb_filename *smb_fname,
646 struct smb_filename *smb_fname_tmp = NULL;
651 status = catia_string_replace_allocate(handle->conn,
652 smb_fname->base_name,
653 &name, vfs_translate_to_unix);
654 if (!NT_STATUS_IS_OK(status)) {
655 errno = map_errno_from_nt_status(status);
659 /* Setup temporary smb_filename structs. */
660 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
661 if (smb_fname_tmp == NULL) {
666 smb_fname_tmp->base_name = name;
667 ret = SMB_VFS_NEXT_UNLINKAT(handle,
671 TALLOC_FREE(smb_fname_tmp);
677 static int catia_lchown(vfs_handle_struct *handle,
678 const struct smb_filename *smb_fname,
686 struct smb_filename *catia_smb_fname = NULL;
688 status = catia_string_replace_allocate(handle->conn,
689 smb_fname->base_name,
691 vfs_translate_to_unix);
692 if (!NT_STATUS_IS_OK(status)) {
693 errno = map_errno_from_nt_status(status);
696 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
702 if (catia_smb_fname == NULL) {
708 ret = SMB_VFS_NEXT_LCHOWN(handle, catia_smb_fname, uid, gid);
711 TALLOC_FREE(catia_smb_fname);
716 static int catia_chmod(vfs_handle_struct *handle,
717 const struct smb_filename *smb_fname,
724 struct smb_filename *catia_smb_fname = NULL;
726 status = catia_string_replace_allocate(handle->conn,
727 smb_fname->base_name,
729 vfs_translate_to_unix);
730 if (!NT_STATUS_IS_OK(status)) {
731 errno = map_errno_from_nt_status(status);
734 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
740 if (catia_smb_fname == NULL) {
746 ret = SMB_VFS_NEXT_CHMOD(handle, catia_smb_fname, mode);
749 TALLOC_FREE(catia_smb_fname);
754 static int catia_mkdirat(vfs_handle_struct *handle,
755 struct files_struct *dirfsp,
756 const struct smb_filename *smb_fname,
762 struct smb_filename *catia_smb_fname = NULL;
764 status = catia_string_replace_allocate(handle->conn,
765 smb_fname->base_name,
767 vfs_translate_to_unix);
768 if (!NT_STATUS_IS_OK(status)) {
769 errno = map_errno_from_nt_status(status);
772 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
778 if (catia_smb_fname == NULL) {
784 ret = SMB_VFS_NEXT_MKDIRAT(handle,
789 TALLOC_FREE(catia_smb_fname);
794 static int catia_chdir(vfs_handle_struct *handle,
795 const struct smb_filename *smb_fname)
798 struct smb_filename *catia_smb_fname = NULL;
802 status = catia_string_replace_allocate(handle->conn,
803 smb_fname->base_name,
805 vfs_translate_to_unix);
806 if (!NT_STATUS_IS_OK(status)) {
807 errno = map_errno_from_nt_status(status);
811 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
817 if (catia_smb_fname == NULL) {
822 ret = SMB_VFS_NEXT_CHDIR(handle, catia_smb_fname);
824 TALLOC_FREE(catia_smb_fname);
829 static int catia_ntimes(vfs_handle_struct *handle,
830 const struct smb_filename *smb_fname,
831 struct smb_file_time *ft)
833 struct smb_filename *smb_fname_tmp = NULL;
838 status = catia_string_replace_allocate(handle->conn,
839 smb_fname->base_name,
840 &name, vfs_translate_to_unix);
841 if (!NT_STATUS_IS_OK(status)) {
842 errno = map_errno_from_nt_status(status);
846 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
847 if (smb_fname_tmp == NULL) {
852 smb_fname_tmp->base_name = name;
853 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname_tmp, ft);
855 TALLOC_FREE(smb_fname_tmp);
860 static struct smb_filename *
861 catia_realpath(vfs_handle_struct *handle,
863 const struct smb_filename *smb_fname)
865 char *mapped_name = NULL;
866 struct smb_filename *catia_smb_fname = NULL;
867 struct smb_filename *return_fname = NULL;
870 status = catia_string_replace_allocate(handle->conn,
871 smb_fname->base_name,
872 &mapped_name, vfs_translate_to_unix);
873 if (!NT_STATUS_IS_OK(status)) {
874 errno = map_errno_from_nt_status(status);
878 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
884 if (catia_smb_fname == NULL) {
885 TALLOC_FREE(mapped_name);
889 return_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, catia_smb_fname);
890 TALLOC_FREE(mapped_name);
891 TALLOC_FREE(catia_smb_fname);
895 static int catia_chflags(struct vfs_handle_struct *handle,
896 const struct smb_filename *smb_fname,
900 struct smb_filename *catia_smb_fname = NULL;
904 status = catia_string_replace_allocate(handle->conn,
905 smb_fname->base_name,
907 vfs_translate_to_unix);
908 if (!NT_STATUS_IS_OK(status)) {
909 errno = map_errno_from_nt_status(status);
912 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
918 if (catia_smb_fname == NULL) {
924 ret = SMB_VFS_NEXT_CHFLAGS(handle, catia_smb_fname, flags);
926 TALLOC_FREE(catia_smb_fname);
932 catia_streaminfo(struct vfs_handle_struct *handle,
933 struct files_struct *fsp,
934 const struct smb_filename *smb_fname,
936 unsigned int *_num_streams,
937 struct stream_struct **_streams)
939 char *mapped_name = NULL;
942 struct smb_filename *catia_smb_fname = NULL;
943 unsigned int num_streams = 0;
944 struct stream_struct *streams = NULL;
949 status = catia_string_replace_allocate(handle->conn,
950 smb_fname->base_name,
952 vfs_translate_to_unix);
953 if (!NT_STATUS_IS_OK(status)) {
954 errno = map_errno_from_nt_status(status);
958 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
964 if (catia_smb_fname == NULL) {
965 TALLOC_FREE(mapped_name);
966 return NT_STATUS_NO_MEMORY;
969 status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, catia_smb_fname,
970 mem_ctx, &num_streams, &streams);
971 TALLOC_FREE(mapped_name);
972 TALLOC_FREE(catia_smb_fname);
973 if (!NT_STATUS_IS_OK(status)) {
978 * Translate stream names just like the base names
980 for (i = 0; i < num_streams; i++) {
982 * Strip ":" prefix and ":$DATA" suffix to get a
983 * "pure" stream name and only translate that.
985 void *old_ptr = streams[i].name;
986 char *stream_name = streams[i].name + 1;
987 char *stream_type = strrchr_m(stream_name, ':');
989 if (stream_type != NULL) {
994 status = catia_string_replace_allocate(handle->conn, stream_name,
995 &mapped_name, vfs_translate_to_windows);
996 if (!NT_STATUS_IS_OK(status)) {
997 TALLOC_FREE(streams);
1001 if (stream_type != NULL) {
1002 streams[i].name = talloc_asprintf(streams, ":%s:%s",
1003 mapped_name, stream_type);
1005 streams[i].name = talloc_asprintf(streams, ":%s",
1008 TALLOC_FREE(mapped_name);
1009 TALLOC_FREE(old_ptr);
1010 if (streams[i].name == NULL) {
1011 TALLOC_FREE(streams);
1012 return NT_STATUS_NO_MEMORY;
1016 *_num_streams = num_streams;
1017 *_streams = streams;
1018 return NT_STATUS_OK;
1021 static NTSTATUS catia_get_nt_acl_at(struct vfs_handle_struct *handle,
1022 struct files_struct *dirfsp,
1023 const struct smb_filename *smb_fname,
1024 uint32_t security_info,
1025 TALLOC_CTX *mem_ctx,
1026 struct security_descriptor **ppdesc)
1028 char *mapped_name = NULL;
1029 const char *path = smb_fname->base_name;
1030 struct smb_filename *mapped_smb_fname = NULL;
1033 SMB_ASSERT(dirfsp == handle->conn->cwd_fsp);
1035 status = catia_string_replace_allocate(handle->conn,
1036 path, &mapped_name, vfs_translate_to_unix);
1037 if (!NT_STATUS_IS_OK(status)) {
1038 errno = map_errno_from_nt_status(status);
1041 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1047 if (mapped_smb_fname == NULL) {
1048 TALLOC_FREE(mapped_name);
1049 return NT_STATUS_NO_MEMORY;
1052 status = SMB_VFS_NEXT_GET_NT_ACL_AT(handle,
1058 TALLOC_FREE(mapped_name);
1059 TALLOC_FREE(mapped_smb_fname);
1065 catia_sys_acl_get_file(vfs_handle_struct *handle,
1066 const struct smb_filename *smb_fname,
1067 SMB_ACL_TYPE_T type,
1068 TALLOC_CTX *mem_ctx)
1070 char *mapped_name = NULL;
1071 struct smb_filename *mapped_smb_fname = NULL;
1074 int saved_errno = 0;
1076 status = catia_string_replace_allocate(handle->conn,
1077 smb_fname->base_name,
1079 vfs_translate_to_unix);
1080 if (!NT_STATUS_IS_OK(status)) {
1081 errno = map_errno_from_nt_status(status);
1082 return (SMB_ACL_T)NULL;
1085 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1091 if (mapped_smb_fname == NULL) {
1092 TALLOC_FREE(mapped_name);
1094 return (SMB_ACL_T)NULL;
1097 ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, mapped_smb_fname,
1099 if (ret == (SMB_ACL_T)NULL) {
1100 saved_errno = errno;
1102 TALLOC_FREE(mapped_smb_fname);
1103 TALLOC_FREE(mapped_name);
1104 if (saved_errno != 0) {
1105 errno = saved_errno;
1111 catia_sys_acl_set_file(vfs_handle_struct *handle,
1112 const struct smb_filename *smb_fname,
1113 SMB_ACL_TYPE_T type,
1116 struct smb_filename *mapped_smb_fname = NULL;
1117 int saved_errno = 0;
1118 char *mapped_name = NULL;
1122 status = catia_string_replace_allocate(handle->conn,
1123 smb_fname->base_name,
1125 vfs_translate_to_unix);
1126 if (!NT_STATUS_IS_OK(status)) {
1127 errno = map_errno_from_nt_status(status);
1131 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1137 if (mapped_smb_fname == NULL) {
1138 TALLOC_FREE(mapped_name);
1143 ret = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, mapped_smb_fname,
1146 saved_errno = errno;
1148 TALLOC_FREE(mapped_smb_fname);
1149 TALLOC_FREE(mapped_name);
1150 if (saved_errno != 0) {
1151 errno = saved_errno;
1157 catia_sys_acl_delete_def_file(vfs_handle_struct *handle,
1158 const struct smb_filename *smb_fname)
1160 struct smb_filename *mapped_smb_fname = NULL;
1161 int saved_errno = 0;
1162 char *mapped_name = NULL;
1166 status = catia_string_replace_allocate(handle->conn,
1167 smb_fname->base_name,
1169 vfs_translate_to_unix);
1170 if (!NT_STATUS_IS_OK(status)) {
1171 errno = map_errno_from_nt_status(status);
1175 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1181 if (mapped_smb_fname == NULL) {
1182 TALLOC_FREE(mapped_name);
1186 ret = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, mapped_smb_fname);
1188 saved_errno = errno;
1190 TALLOC_FREE(mapped_smb_fname);
1191 TALLOC_FREE(mapped_name);
1192 if (saved_errno != 0) {
1193 errno = saved_errno;
1199 catia_getxattr(vfs_handle_struct *handle,
1200 const struct smb_filename *smb_fname,
1205 struct smb_filename *mapped_smb_fname = NULL;
1206 char *mapped_name = NULL;
1207 char *mapped_ea_name = NULL;
1210 int saved_errno = 0;
1212 status = catia_string_replace_allocate(handle->conn,
1213 smb_fname->base_name,
1215 vfs_translate_to_unix);
1216 if (!NT_STATUS_IS_OK(status)) {
1217 errno = map_errno_from_nt_status(status);
1221 status = catia_string_replace_allocate(handle->conn,
1222 name, &mapped_ea_name, vfs_translate_to_unix);
1223 if (!NT_STATUS_IS_OK(status)) {
1224 TALLOC_FREE(mapped_name);
1225 errno = map_errno_from_nt_status(status);
1229 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1235 if (mapped_smb_fname == NULL) {
1236 TALLOC_FREE(mapped_name);
1237 TALLOC_FREE(mapped_ea_name);
1242 ret = SMB_VFS_NEXT_GETXATTR(handle, mapped_smb_fname,
1243 mapped_ea_name, value, size);
1245 saved_errno = errno;
1247 TALLOC_FREE(mapped_name);
1248 TALLOC_FREE(mapped_ea_name);
1249 TALLOC_FREE(mapped_smb_fname);
1250 if (saved_errno != 0) {
1251 errno = saved_errno;
1258 catia_listxattr(vfs_handle_struct *handle,
1259 const struct smb_filename *smb_fname,
1260 char *list, size_t size)
1262 struct smb_filename *mapped_smb_fname = NULL;
1263 char *mapped_name = NULL;
1266 int saved_errno = 0;
1268 status = catia_string_replace_allocate(handle->conn,
1269 smb_fname->base_name,
1271 vfs_translate_to_unix);
1272 if (!NT_STATUS_IS_OK(status)) {
1273 errno = map_errno_from_nt_status(status);
1277 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1283 if (mapped_smb_fname == NULL) {
1284 TALLOC_FREE(mapped_name);
1289 ret = SMB_VFS_NEXT_LISTXATTR(handle, mapped_smb_fname, list, size);
1291 saved_errno = errno;
1293 TALLOC_FREE(mapped_name);
1294 TALLOC_FREE(mapped_smb_fname);
1295 if (saved_errno != 0) {
1296 errno = saved_errno;
1303 catia_removexattr(vfs_handle_struct *handle,
1304 const struct smb_filename *smb_fname,
1307 struct smb_filename *mapped_smb_fname = NULL;
1308 char *mapped_name = NULL;
1309 char *mapped_ea_name = NULL;
1312 int saved_errno = 0;
1314 status = catia_string_replace_allocate(handle->conn,
1315 smb_fname->base_name,
1317 vfs_translate_to_unix);
1318 if (!NT_STATUS_IS_OK(status)) {
1319 errno = map_errno_from_nt_status(status);
1323 status = catia_string_replace_allocate(handle->conn,
1324 name, &mapped_ea_name, vfs_translate_to_unix);
1325 if (!NT_STATUS_IS_OK(status)) {
1326 TALLOC_FREE(mapped_name);
1327 errno = map_errno_from_nt_status(status);
1331 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1337 if (mapped_smb_fname == NULL) {
1338 TALLOC_FREE(mapped_name);
1339 TALLOC_FREE(mapped_ea_name);
1344 ret = SMB_VFS_NEXT_REMOVEXATTR(handle, mapped_smb_fname,
1347 saved_errno = errno;
1349 TALLOC_FREE(mapped_name);
1350 TALLOC_FREE(mapped_ea_name);
1351 TALLOC_FREE(mapped_smb_fname);
1352 if (saved_errno != 0) {
1353 errno = saved_errno;
1360 catia_setxattr(vfs_handle_struct *handle,
1361 const struct smb_filename *smb_fname,
1367 struct smb_filename *mapped_smb_fname = NULL;
1368 char *mapped_name = NULL;
1369 char *mapped_ea_name = NULL;
1372 int saved_errno = 0;
1374 status = catia_string_replace_allocate(handle->conn,
1375 smb_fname->base_name,
1377 vfs_translate_to_unix);
1378 if (!NT_STATUS_IS_OK(status)) {
1379 errno = map_errno_from_nt_status(status);
1383 status = catia_string_replace_allocate(handle->conn,
1384 name, &mapped_ea_name, vfs_translate_to_unix);
1385 if (!NT_STATUS_IS_OK(status)) {
1386 TALLOC_FREE(mapped_name);
1387 errno = map_errno_from_nt_status(status);
1391 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1397 if (mapped_smb_fname == NULL) {
1398 TALLOC_FREE(mapped_name);
1399 TALLOC_FREE(mapped_ea_name);
1404 ret = SMB_VFS_NEXT_SETXATTR(handle, mapped_smb_fname, mapped_ea_name,
1405 value, size, flags);
1407 saved_errno = errno;
1409 TALLOC_FREE(mapped_name);
1410 TALLOC_FREE(mapped_ea_name);
1411 TALLOC_FREE(mapped_smb_fname);
1412 if (saved_errno != 0) {
1413 errno = saved_errno;
1419 static int catia_fstat(vfs_handle_struct *handle,
1421 SMB_STRUCT_STAT *sbuf)
1423 struct catia_cache *cc = NULL;
1426 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1431 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1433 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1438 static ssize_t catia_pread(vfs_handle_struct *handle,
1439 files_struct *fsp, void *data,
1440 size_t n, off_t offset)
1442 struct catia_cache *cc = NULL;
1446 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1451 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1453 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1458 static ssize_t catia_pwrite(vfs_handle_struct *handle,
1459 files_struct *fsp, const void *data,
1460 size_t n, off_t offset)
1462 struct catia_cache *cc = NULL;
1466 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1471 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1473 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1478 static int catia_ftruncate(struct vfs_handle_struct *handle,
1479 struct files_struct *fsp,
1482 struct catia_cache *cc = NULL;
1485 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1490 ret = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
1492 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1497 static int catia_fallocate(struct vfs_handle_struct *handle,
1498 struct files_struct *fsp,
1503 struct catia_cache *cc = NULL;
1506 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1511 ret = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1513 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1518 static ssize_t catia_fgetxattr(struct vfs_handle_struct *handle,
1519 struct files_struct *fsp,
1524 char *mapped_xattr_name = NULL;
1528 status = catia_string_replace_allocate(handle->conn,
1529 name, &mapped_xattr_name,
1530 vfs_translate_to_unix);
1531 if (!NT_STATUS_IS_OK(status)) {
1532 errno = map_errno_from_nt_status(status);
1536 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, mapped_xattr_name,
1539 TALLOC_FREE(mapped_xattr_name);
1544 static ssize_t catia_flistxattr(struct vfs_handle_struct *handle,
1545 struct files_struct *fsp,
1549 struct catia_cache *cc = NULL;
1553 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1558 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
1560 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1565 static int catia_fremovexattr(struct vfs_handle_struct *handle,
1566 struct files_struct *fsp,
1569 char *mapped_name = NULL;
1573 status = catia_string_replace_allocate(handle->conn,
1574 name, &mapped_name, vfs_translate_to_unix);
1575 if (!NT_STATUS_IS_OK(status)) {
1576 errno = map_errno_from_nt_status(status);
1580 ret = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, mapped_name);
1582 TALLOC_FREE(mapped_name);
1587 static int catia_fsetxattr(struct vfs_handle_struct *handle,
1588 struct files_struct *fsp,
1594 char *mapped_xattr_name = NULL;
1598 status = catia_string_replace_allocate(
1599 handle->conn, name, &mapped_xattr_name, vfs_translate_to_unix);
1600 if (!NT_STATUS_IS_OK(status)) {
1601 errno = map_errno_from_nt_status(status);
1605 ret = SMB_VFS_NEXT_FSETXATTR(handle, fsp, mapped_xattr_name,
1606 value, size, flags);
1608 TALLOC_FREE(mapped_xattr_name);
1613 static SMB_ACL_T catia_sys_acl_get_fd(vfs_handle_struct *handle,
1615 TALLOC_CTX *mem_ctx)
1617 struct catia_cache *cc = NULL;
1618 struct smb_acl_t *result = NULL;
1621 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1626 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1628 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1633 static int catia_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1635 TALLOC_CTX *mem_ctx,
1636 char **blob_description,
1639 struct catia_cache *cc = NULL;
1642 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1647 ret = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1648 blob_description, blob);
1650 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1655 static int catia_sys_acl_set_fd(vfs_handle_struct *handle,
1659 struct catia_cache *cc = NULL;
1662 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1667 ret = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1669 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1674 static NTSTATUS catia_fget_nt_acl(vfs_handle_struct *handle,
1676 uint32_t security_info,
1677 TALLOC_CTX *mem_ctx,
1678 struct security_descriptor **ppdesc)
1680 struct catia_cache *cc = NULL;
1684 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1686 return map_nt_error_from_unix(errno);
1689 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1692 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1697 static NTSTATUS catia_fset_nt_acl(vfs_handle_struct *handle,
1699 uint32_t security_info_sent,
1700 const struct security_descriptor *psd)
1702 struct catia_cache *cc = NULL;
1706 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1708 return map_nt_error_from_unix(errno);
1711 status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1713 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1718 static NTSTATUS catia_fset_dos_attributes(struct vfs_handle_struct *handle,
1719 struct files_struct *fsp,
1722 struct catia_cache *cc = NULL;
1726 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1728 return map_nt_error_from_unix(errno);
1731 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1733 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1738 static NTSTATUS catia_fget_dos_attributes(struct vfs_handle_struct *handle,
1739 struct files_struct *fsp,
1742 struct catia_cache *cc = NULL;
1746 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1748 return map_nt_error_from_unix(errno);
1751 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1753 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1758 static int catia_fchown(vfs_handle_struct *handle,
1763 struct catia_cache *cc = NULL;
1766 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1771 ret = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1773 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1778 static int catia_fchmod(vfs_handle_struct *handle,
1782 struct catia_cache *cc = NULL;
1785 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1790 ret = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1792 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1797 struct catia_pread_state {
1799 struct vfs_aio_state vfs_aio_state;
1800 struct files_struct *fsp;
1801 struct catia_cache *cc;
1804 static void catia_pread_done(struct tevent_req *subreq);
1806 static struct tevent_req *catia_pread_send(struct vfs_handle_struct *handle,
1807 TALLOC_CTX *mem_ctx,
1808 struct tevent_context *ev,
1809 struct files_struct *fsp,
1814 struct tevent_req *req = NULL, *subreq = NULL;
1815 struct catia_pread_state *state = NULL;
1818 req = tevent_req_create(mem_ctx, &state,
1819 struct catia_pread_state);
1825 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1827 tevent_req_error(req, errno);
1828 return tevent_req_post(req, ev);
1831 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1833 if (tevent_req_nomem(subreq, req)) {
1834 return tevent_req_post(req, ev);
1836 tevent_req_set_callback(subreq, catia_pread_done, req);
1841 static void catia_pread_done(struct tevent_req *subreq)
1843 struct tevent_req *req = tevent_req_callback_data(
1844 subreq, struct tevent_req);
1845 struct catia_pread_state *state = tevent_req_data(
1846 req, struct catia_pread_state);
1848 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1849 TALLOC_FREE(subreq);
1851 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1853 tevent_req_done(req);
1856 static ssize_t catia_pread_recv(struct tevent_req *req,
1857 struct vfs_aio_state *vfs_aio_state)
1859 struct catia_pread_state *state = tevent_req_data(
1860 req, struct catia_pread_state);
1862 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1866 *vfs_aio_state = state->vfs_aio_state;
1870 struct catia_pwrite_state {
1872 struct vfs_aio_state vfs_aio_state;
1873 struct files_struct *fsp;
1874 struct catia_cache *cc;
1877 static void catia_pwrite_done(struct tevent_req *subreq);
1879 static struct tevent_req *catia_pwrite_send(struct vfs_handle_struct *handle,
1880 TALLOC_CTX *mem_ctx,
1881 struct tevent_context *ev,
1882 struct files_struct *fsp,
1887 struct tevent_req *req = NULL, *subreq = NULL;
1888 struct catia_pwrite_state *state = NULL;
1891 req = tevent_req_create(mem_ctx, &state,
1892 struct catia_pwrite_state);
1898 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1900 tevent_req_error(req, errno);
1901 return tevent_req_post(req, ev);
1904 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1906 if (tevent_req_nomem(subreq, req)) {
1907 return tevent_req_post(req, ev);
1909 tevent_req_set_callback(subreq, catia_pwrite_done, req);
1914 static void catia_pwrite_done(struct tevent_req *subreq)
1916 struct tevent_req *req = tevent_req_callback_data(
1917 subreq, struct tevent_req);
1918 struct catia_pwrite_state *state = tevent_req_data(
1919 req, struct catia_pwrite_state);
1921 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1922 TALLOC_FREE(subreq);
1924 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1926 tevent_req_done(req);
1929 static ssize_t catia_pwrite_recv(struct tevent_req *req,
1930 struct vfs_aio_state *vfs_aio_state)
1932 struct catia_pwrite_state *state = tevent_req_data(
1933 req, struct catia_pwrite_state);
1935 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1939 *vfs_aio_state = state->vfs_aio_state;
1943 static off_t catia_lseek(vfs_handle_struct *handle,
1948 struct catia_cache *cc = NULL;
1952 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1957 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1959 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1964 struct catia_fsync_state {
1966 struct vfs_aio_state vfs_aio_state;
1967 struct files_struct *fsp;
1968 struct catia_cache *cc;
1971 static void catia_fsync_done(struct tevent_req *subreq);
1973 static struct tevent_req *catia_fsync_send(struct vfs_handle_struct *handle,
1974 TALLOC_CTX *mem_ctx,
1975 struct tevent_context *ev,
1976 struct files_struct *fsp)
1978 struct tevent_req *req = NULL, *subreq = NULL;
1979 struct catia_fsync_state *state = NULL;
1982 req = tevent_req_create(mem_ctx, &state,
1983 struct catia_fsync_state);
1989 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1991 tevent_req_error(req, errno);
1992 return tevent_req_post(req, ev);
1995 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1996 if (tevent_req_nomem(subreq, req)) {
1997 return tevent_req_post(req, ev);
1999 tevent_req_set_callback(subreq, catia_fsync_done, req);
2004 static void catia_fsync_done(struct tevent_req *subreq)
2006 struct tevent_req *req = tevent_req_callback_data(
2007 subreq, struct tevent_req);
2008 struct catia_fsync_state *state = tevent_req_data(
2009 req, struct catia_fsync_state);
2011 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
2012 TALLOC_FREE(subreq);
2014 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
2016 tevent_req_done(req);
2019 static int catia_fsync_recv(struct tevent_req *req,
2020 struct vfs_aio_state *vfs_aio_state)
2022 struct catia_fsync_state *state = tevent_req_data(
2023 req, struct catia_fsync_state);
2025 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2029 *vfs_aio_state = state->vfs_aio_state;
2033 static bool catia_lock(vfs_handle_struct *handle,
2040 struct catia_cache *cc = NULL;
2044 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2049 ok = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
2051 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2056 static int catia_kernel_flock(struct vfs_handle_struct *handle,
2057 struct files_struct *fsp,
2058 uint32_t share_access,
2059 uint32_t access_mask)
2061 struct catia_cache *cc = NULL;
2064 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2069 ret = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_access, access_mask);
2071 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2076 static int catia_linux_setlease(vfs_handle_struct *handle,
2080 struct catia_cache *cc = NULL;
2083 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2088 ret = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
2090 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2095 static bool catia_getlock(vfs_handle_struct *handle,
2102 struct catia_cache *cc = NULL;
2106 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2111 ok = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
2113 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2118 static bool catia_strict_lock_check(struct vfs_handle_struct *handle,
2119 struct files_struct *fsp,
2120 struct lock_struct *plock)
2122 struct catia_cache *cc = NULL;
2126 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2131 ok = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2133 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2138 static NTSTATUS catia_fsctl(struct vfs_handle_struct *handle,
2139 struct files_struct *fsp,
2143 const uint8_t *_in_data,
2145 uint8_t **_out_data,
2146 uint32_t max_out_len,
2150 struct catia_cache *cc = NULL;
2153 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2155 return map_nt_error_from_unix(errno);
2158 result = SMB_VFS_NEXT_FSCTL(handle,
2169 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2174 static NTSTATUS catia_get_compression(vfs_handle_struct *handle,
2175 TALLOC_CTX *mem_ctx,
2176 struct files_struct *fsp,
2177 struct smb_filename *smb_fname,
2178 uint16_t *_compression_fmt)
2181 struct catia_cache *cc = NULL;
2183 struct smb_filename *mapped_smb_fname = NULL;
2184 char *mapped_name = NULL;
2187 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2189 return map_nt_error_from_unix(errno);
2191 mapped_smb_fname = fsp->fsp_name;
2193 result = catia_string_replace_allocate(handle->conn,
2194 smb_fname->base_name,
2196 vfs_translate_to_unix);
2197 if (!NT_STATUS_IS_OK(result)) {
2201 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2207 if (mapped_smb_fname == NULL) {
2208 TALLOC_FREE(mapped_name);
2209 return NT_STATUS_NO_MEMORY;
2212 TALLOC_FREE(mapped_name);
2215 result = SMB_VFS_NEXT_GET_COMPRESSION(handle,
2222 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2224 TALLOC_FREE(mapped_smb_fname);
2230 static NTSTATUS catia_set_compression(vfs_handle_struct *handle,
2231 TALLOC_CTX *mem_ctx,
2232 struct files_struct *fsp,
2233 uint16_t compression_fmt)
2236 struct catia_cache *cc = NULL;
2239 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2241 return map_nt_error_from_unix(errno);
2244 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2247 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2252 static NTSTATUS catia_readdir_attr(struct vfs_handle_struct *handle,
2253 const struct smb_filename *smb_fname_in,
2254 TALLOC_CTX *mem_ctx,
2255 struct readdir_attr_data **pattr_data)
2257 struct smb_filename *smb_fname;
2261 status = catia_string_replace_allocate(handle->conn,
2262 smb_fname_in->base_name,
2264 vfs_translate_to_unix);
2265 if (!NT_STATUS_IS_OK(status)) {
2266 errno = map_errno_from_nt_status(status);
2270 smb_fname = synthetic_smb_fname(talloc_tos(),
2277 status = SMB_VFS_NEXT_READDIR_ATTR(handle, smb_fname, mem_ctx, pattr_data);
2279 TALLOC_FREE(smb_fname);
2284 static NTSTATUS catia_get_dos_attributes(struct vfs_handle_struct *handle,
2285 struct smb_filename *smb_fname,
2288 char *mapped_name = NULL;
2289 const char *path = smb_fname->base_name;
2290 struct smb_filename *mapped_smb_fname = NULL;
2293 status = catia_string_replace_allocate(handle->conn,
2294 path, &mapped_name, vfs_translate_to_unix);
2295 if (!NT_STATUS_IS_OK(status)) {
2296 errno = map_errno_from_nt_status(status);
2299 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2305 if (mapped_smb_fname == NULL) {
2306 TALLOC_FREE(mapped_name);
2307 return NT_STATUS_NO_MEMORY;
2310 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2313 if (NT_STATUS_IS_OK(status)) {
2314 smb_fname->st = mapped_smb_fname->st;
2317 TALLOC_FREE(mapped_name);
2318 TALLOC_FREE(mapped_smb_fname);
2323 static NTSTATUS catia_set_dos_attributes(struct vfs_handle_struct *handle,
2324 const struct smb_filename *smb_fname,
2327 char *mapped_name = NULL;
2328 const char *path = smb_fname->base_name;
2329 struct smb_filename *mapped_smb_fname = NULL;
2332 status = catia_string_replace_allocate(handle->conn,
2333 path, &mapped_name, vfs_translate_to_unix);
2334 if (!NT_STATUS_IS_OK(status)) {
2335 errno = map_errno_from_nt_status(status);
2338 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2344 if (mapped_smb_fname == NULL) {
2345 TALLOC_FREE(mapped_name);
2346 return NT_STATUS_NO_MEMORY;
2349 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2352 TALLOC_FREE(mapped_name);
2353 TALLOC_FREE(mapped_smb_fname);
2358 static NTSTATUS catia_create_dfs_pathat(struct vfs_handle_struct *handle,
2359 struct files_struct *dirfsp,
2360 const struct smb_filename *smb_fname,
2361 const struct referral *reflist,
2362 size_t referral_count)
2364 char *mapped_name = NULL;
2365 const char *path = smb_fname->base_name;
2366 struct smb_filename *mapped_smb_fname = NULL;
2369 status = catia_string_replace_allocate(handle->conn,
2372 vfs_translate_to_unix);
2373 if (!NT_STATUS_IS_OK(status)) {
2374 errno = map_errno_from_nt_status(status);
2377 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2383 if (mapped_smb_fname == NULL) {
2384 TALLOC_FREE(mapped_name);
2385 return NT_STATUS_NO_MEMORY;
2388 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
2393 TALLOC_FREE(mapped_name);
2394 TALLOC_FREE(mapped_smb_fname);
2398 static NTSTATUS catia_read_dfs_pathat(struct vfs_handle_struct *handle,
2399 TALLOC_CTX *mem_ctx,
2400 struct files_struct *dirfsp,
2401 const struct smb_filename *smb_fname,
2402 struct referral **ppreflist,
2403 size_t *preferral_count)
2405 char *mapped_name = NULL;
2406 const char *path = smb_fname->base_name;
2407 struct smb_filename *mapped_smb_fname = NULL;
2410 status = catia_string_replace_allocate(handle->conn,
2413 vfs_translate_to_unix);
2414 if (!NT_STATUS_IS_OK(status)) {
2415 errno = map_errno_from_nt_status(status);
2418 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2424 if (mapped_smb_fname == NULL) {
2425 TALLOC_FREE(mapped_name);
2426 return NT_STATUS_NO_MEMORY;
2429 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
2435 TALLOC_FREE(mapped_name);
2436 TALLOC_FREE(mapped_smb_fname);
2440 static struct vfs_fn_pointers vfs_catia_fns = {
2441 .connect_fn = catia_connect,
2443 /* Directory operations */
2444 .mkdirat_fn = catia_mkdirat,
2445 .readdir_attr_fn = catia_readdir_attr,
2447 /* File operations */
2448 .open_fn = catia_open,
2449 .pread_fn = catia_pread,
2450 .pread_send_fn = catia_pread_send,
2451 .pread_recv_fn = catia_pread_recv,
2452 .pwrite_fn = catia_pwrite,
2453 .pwrite_send_fn = catia_pwrite_send,
2454 .pwrite_recv_fn = catia_pwrite_recv,
2455 .lseek_fn = catia_lseek,
2456 .renameat_fn = catia_renameat,
2457 .fsync_send_fn = catia_fsync_send,
2458 .fsync_recv_fn = catia_fsync_recv,
2459 .stat_fn = catia_stat,
2460 .fstat_fn = catia_fstat,
2461 .lstat_fn = catia_lstat,
2462 .unlinkat_fn = catia_unlinkat,
2463 .chmod_fn = catia_chmod,
2464 .fchmod_fn = catia_fchmod,
2465 .fchown_fn = catia_fchown,
2466 .lchown_fn = catia_lchown,
2467 .chdir_fn = catia_chdir,
2468 .ntimes_fn = catia_ntimes,
2469 .ftruncate_fn = catia_ftruncate,
2470 .fallocate_fn = catia_fallocate,
2471 .lock_fn = catia_lock,
2472 .kernel_flock_fn = catia_kernel_flock,
2473 .linux_setlease_fn = catia_linux_setlease,
2474 .getlock_fn = catia_getlock,
2475 .realpath_fn = catia_realpath,
2476 .chflags_fn = catia_chflags,
2477 .streaminfo_fn = catia_streaminfo,
2478 .strict_lock_check_fn = catia_strict_lock_check,
2479 .translate_name_fn = catia_translate_name,
2480 .fsctl_fn = catia_fsctl,
2481 .get_dos_attributes_fn = catia_get_dos_attributes,
2482 .get_dos_attributes_send_fn = vfs_not_implemented_get_dos_attributes_send,
2483 .get_dos_attributes_recv_fn = vfs_not_implemented_get_dos_attributes_recv,
2484 .set_dos_attributes_fn = catia_set_dos_attributes,
2485 .fset_dos_attributes_fn = catia_fset_dos_attributes,
2486 .fget_dos_attributes_fn = catia_fget_dos_attributes,
2487 .get_compression_fn = catia_get_compression,
2488 .set_compression_fn = catia_set_compression,
2489 .create_dfs_pathat_fn = catia_create_dfs_pathat,
2490 .read_dfs_pathat_fn = catia_read_dfs_pathat,
2492 /* NT ACL operations. */
2493 .get_nt_acl_at_fn = catia_get_nt_acl_at,
2494 .fget_nt_acl_fn = catia_fget_nt_acl,
2495 .fset_nt_acl_fn = catia_fset_nt_acl,
2497 /* POSIX ACL operations. */
2498 .sys_acl_get_file_fn = catia_sys_acl_get_file,
2499 .sys_acl_get_fd_fn = catia_sys_acl_get_fd,
2500 .sys_acl_blob_get_fd_fn = catia_sys_acl_blob_get_fd,
2501 .sys_acl_set_file_fn = catia_sys_acl_set_file,
2502 .sys_acl_set_fd_fn = catia_sys_acl_set_fd,
2503 .sys_acl_delete_def_file_fn = catia_sys_acl_delete_def_file,
2505 /* EA operations. */
2506 .getxattr_fn = catia_getxattr,
2507 .getxattrat_send_fn = vfs_not_implemented_getxattrat_send,
2508 .getxattrat_recv_fn = vfs_not_implemented_getxattrat_recv,
2509 .listxattr_fn = catia_listxattr,
2510 .removexattr_fn = catia_removexattr,
2511 .setxattr_fn = catia_setxattr,
2512 .fgetxattr_fn = catia_fgetxattr,
2513 .flistxattr_fn = catia_flistxattr,
2514 .fremovexattr_fn = catia_fremovexattr,
2515 .fsetxattr_fn = catia_fsetxattr,
2519 NTSTATUS vfs_catia_init(TALLOC_CTX *ctx)
2523 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
2525 if (!NT_STATUS_IS_OK(ret))
2528 vfs_catia_debug_level = debug_add_class("catia");
2529 if (vfs_catia_debug_level == -1) {
2530 vfs_catia_debug_level = DBGC_VFS;
2531 DEBUG(0, ("vfs_catia: Couldn't register custom debugging "
2534 DEBUG(10, ("vfs_catia: Debug class number of "
2535 "'catia': %d\n", vfs_catia_debug_level));