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 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_chmod(vfs_handle_struct *handle,
746 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_CHMOD(handle, catia_smb_fname, mode);
778 TALLOC_FREE(catia_smb_fname);
783 static int catia_mkdirat(vfs_handle_struct *handle,
784 struct files_struct *dirfsp,
785 const struct smb_filename *smb_fname,
791 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);
801 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
807 if (catia_smb_fname == NULL) {
813 ret = SMB_VFS_NEXT_MKDIRAT(handle,
818 TALLOC_FREE(catia_smb_fname);
823 static int catia_chdir(vfs_handle_struct *handle,
824 const struct smb_filename *smb_fname)
827 struct smb_filename *catia_smb_fname = NULL;
831 status = catia_string_replace_allocate(handle->conn,
832 smb_fname->base_name,
834 vfs_translate_to_unix);
835 if (!NT_STATUS_IS_OK(status)) {
836 errno = map_errno_from_nt_status(status);
840 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
846 if (catia_smb_fname == NULL) {
851 ret = SMB_VFS_NEXT_CHDIR(handle, catia_smb_fname);
853 TALLOC_FREE(catia_smb_fname);
858 static int catia_ntimes(vfs_handle_struct *handle,
859 const struct smb_filename *smb_fname,
860 struct smb_file_time *ft)
862 struct smb_filename *smb_fname_tmp = NULL;
867 status = catia_string_replace_allocate(handle->conn,
868 smb_fname->base_name,
869 &name, vfs_translate_to_unix);
870 if (!NT_STATUS_IS_OK(status)) {
871 errno = map_errno_from_nt_status(status);
875 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
876 if (smb_fname_tmp == NULL) {
881 smb_fname_tmp->base_name = name;
882 smb_fname_tmp->fsp = smb_fname->fsp;
884 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname_tmp, ft);
886 TALLOC_FREE(smb_fname_tmp);
891 static struct smb_filename *
892 catia_realpath(vfs_handle_struct *handle,
894 const struct smb_filename *smb_fname)
896 char *mapped_name = NULL;
897 struct smb_filename *catia_smb_fname = NULL;
898 struct smb_filename *return_fname = NULL;
901 status = catia_string_replace_allocate(handle->conn,
902 smb_fname->base_name,
903 &mapped_name, vfs_translate_to_unix);
904 if (!NT_STATUS_IS_OK(status)) {
905 errno = map_errno_from_nt_status(status);
909 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
915 if (catia_smb_fname == NULL) {
916 TALLOC_FREE(mapped_name);
920 return_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, catia_smb_fname);
921 TALLOC_FREE(mapped_name);
922 TALLOC_FREE(catia_smb_fname);
926 static int catia_chflags(struct vfs_handle_struct *handle,
927 const struct smb_filename *smb_fname,
931 struct smb_filename *catia_smb_fname = NULL;
935 status = catia_string_replace_allocate(handle->conn,
936 smb_fname->base_name,
938 vfs_translate_to_unix);
939 if (!NT_STATUS_IS_OK(status)) {
940 errno = map_errno_from_nt_status(status);
943 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
949 if (catia_smb_fname == NULL) {
955 ret = SMB_VFS_NEXT_CHFLAGS(handle, catia_smb_fname, flags);
957 TALLOC_FREE(catia_smb_fname);
963 catia_streaminfo(struct vfs_handle_struct *handle,
964 struct files_struct *fsp,
965 const struct smb_filename *smb_fname,
967 unsigned int *_num_streams,
968 struct stream_struct **_streams)
970 char *mapped_name = NULL;
973 struct smb_filename *catia_smb_fname = NULL;
974 unsigned int num_streams = 0;
975 struct stream_struct *streams = NULL;
980 status = catia_string_replace_allocate(handle->conn,
981 smb_fname->base_name,
983 vfs_translate_to_unix);
984 if (!NT_STATUS_IS_OK(status)) {
988 status = synthetic_pathref(talloc_tos(),
989 handle->conn->cwd_fsp,
997 if (!NT_STATUS_IS_OK(status)) {
998 TALLOC_FREE(mapped_name);
1002 status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, catia_smb_fname,
1003 mem_ctx, &num_streams, &streams);
1004 TALLOC_FREE(mapped_name);
1005 TALLOC_FREE(catia_smb_fname);
1006 if (!NT_STATUS_IS_OK(status)) {
1011 * Translate stream names just like the base names
1013 for (i = 0; i < num_streams; i++) {
1015 * Strip ":" prefix and ":$DATA" suffix to get a
1016 * "pure" stream name and only translate that.
1018 void *old_ptr = streams[i].name;
1019 char *stream_name = streams[i].name + 1;
1020 char *stream_type = strrchr_m(stream_name, ':');
1022 if (stream_type != NULL) {
1023 *stream_type = '\0';
1027 status = catia_string_replace_allocate(handle->conn, stream_name,
1028 &mapped_name, vfs_translate_to_windows);
1029 if (!NT_STATUS_IS_OK(status)) {
1030 TALLOC_FREE(streams);
1034 if (stream_type != NULL) {
1035 streams[i].name = talloc_asprintf(streams, ":%s:%s",
1036 mapped_name, stream_type);
1038 streams[i].name = talloc_asprintf(streams, ":%s",
1041 TALLOC_FREE(mapped_name);
1042 TALLOC_FREE(old_ptr);
1043 if (streams[i].name == NULL) {
1044 TALLOC_FREE(streams);
1045 return NT_STATUS_NO_MEMORY;
1049 *_num_streams = num_streams;
1050 *_streams = streams;
1051 return NT_STATUS_OK;
1054 static NTSTATUS catia_get_nt_acl_at(struct vfs_handle_struct *handle,
1055 struct files_struct *dirfsp,
1056 const struct smb_filename *smb_fname,
1057 uint32_t security_info,
1058 TALLOC_CTX *mem_ctx,
1059 struct security_descriptor **ppdesc)
1061 char *mapped_name = NULL;
1062 const char *path = smb_fname->base_name;
1063 struct smb_filename *mapped_smb_fname = NULL;
1066 SMB_ASSERT(dirfsp == handle->conn->cwd_fsp);
1068 status = catia_string_replace_allocate(handle->conn,
1069 path, &mapped_name, vfs_translate_to_unix);
1070 if (!NT_STATUS_IS_OK(status)) {
1071 errno = map_errno_from_nt_status(status);
1074 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1080 if (mapped_smb_fname == NULL) {
1081 TALLOC_FREE(mapped_name);
1082 return NT_STATUS_NO_MEMORY;
1085 status = SMB_VFS_NEXT_GET_NT_ACL_AT(handle,
1091 TALLOC_FREE(mapped_name);
1092 TALLOC_FREE(mapped_smb_fname);
1098 catia_sys_acl_get_file(vfs_handle_struct *handle,
1099 const struct smb_filename *smb_fname,
1100 SMB_ACL_TYPE_T type,
1101 TALLOC_CTX *mem_ctx)
1103 char *mapped_name = NULL;
1104 struct smb_filename *mapped_smb_fname = NULL;
1107 int saved_errno = 0;
1109 status = catia_string_replace_allocate(handle->conn,
1110 smb_fname->base_name,
1112 vfs_translate_to_unix);
1113 if (!NT_STATUS_IS_OK(status)) {
1114 errno = map_errno_from_nt_status(status);
1115 return (SMB_ACL_T)NULL;
1118 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1124 if (mapped_smb_fname == NULL) {
1125 TALLOC_FREE(mapped_name);
1127 return (SMB_ACL_T)NULL;
1130 ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, mapped_smb_fname,
1132 if (ret == (SMB_ACL_T)NULL) {
1133 saved_errno = errno;
1135 TALLOC_FREE(mapped_smb_fname);
1136 TALLOC_FREE(mapped_name);
1137 if (saved_errno != 0) {
1138 errno = saved_errno;
1144 catia_sys_acl_delete_def_file(vfs_handle_struct *handle,
1145 const struct smb_filename *smb_fname)
1147 struct smb_filename *mapped_smb_fname = NULL;
1148 int saved_errno = 0;
1149 char *mapped_name = NULL;
1153 status = catia_string_replace_allocate(handle->conn,
1154 smb_fname->base_name,
1156 vfs_translate_to_unix);
1157 if (!NT_STATUS_IS_OK(status)) {
1158 errno = map_errno_from_nt_status(status);
1162 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1168 if (mapped_smb_fname == NULL) {
1169 TALLOC_FREE(mapped_name);
1173 ret = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, mapped_smb_fname);
1175 saved_errno = errno;
1177 TALLOC_FREE(mapped_smb_fname);
1178 TALLOC_FREE(mapped_name);
1179 if (saved_errno != 0) {
1180 errno = saved_errno;
1186 catia_getxattr(vfs_handle_struct *handle,
1187 const struct smb_filename *smb_fname,
1192 struct smb_filename *mapped_smb_fname = NULL;
1193 char *mapped_name = NULL;
1194 char *mapped_ea_name = NULL;
1197 int saved_errno = 0;
1199 status = catia_string_replace_allocate(handle->conn,
1200 smb_fname->base_name,
1202 vfs_translate_to_unix);
1203 if (!NT_STATUS_IS_OK(status)) {
1204 errno = map_errno_from_nt_status(status);
1208 status = catia_string_replace_allocate(handle->conn,
1209 name, &mapped_ea_name, vfs_translate_to_unix);
1210 if (!NT_STATUS_IS_OK(status)) {
1211 TALLOC_FREE(mapped_name);
1212 errno = map_errno_from_nt_status(status);
1216 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1222 if (mapped_smb_fname == NULL) {
1223 TALLOC_FREE(mapped_name);
1224 TALLOC_FREE(mapped_ea_name);
1229 ret = SMB_VFS_NEXT_GETXATTR(handle, mapped_smb_fname,
1230 mapped_ea_name, value, size);
1232 saved_errno = errno;
1234 TALLOC_FREE(mapped_name);
1235 TALLOC_FREE(mapped_ea_name);
1236 TALLOC_FREE(mapped_smb_fname);
1237 if (saved_errno != 0) {
1238 errno = saved_errno;
1245 catia_listxattr(vfs_handle_struct *handle,
1246 const struct smb_filename *smb_fname,
1247 char *list, size_t size)
1249 struct smb_filename *mapped_smb_fname = NULL;
1250 char *mapped_name = NULL;
1253 int saved_errno = 0;
1255 status = catia_string_replace_allocate(handle->conn,
1256 smb_fname->base_name,
1258 vfs_translate_to_unix);
1259 if (!NT_STATUS_IS_OK(status)) {
1260 errno = map_errno_from_nt_status(status);
1264 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1270 if (mapped_smb_fname == NULL) {
1271 TALLOC_FREE(mapped_name);
1276 ret = SMB_VFS_NEXT_LISTXATTR(handle, mapped_smb_fname, list, size);
1278 saved_errno = errno;
1280 TALLOC_FREE(mapped_name);
1281 TALLOC_FREE(mapped_smb_fname);
1282 if (saved_errno != 0) {
1283 errno = saved_errno;
1290 catia_removexattr(vfs_handle_struct *handle,
1291 const struct smb_filename *smb_fname,
1294 struct smb_filename *mapped_smb_fname = NULL;
1295 char *mapped_name = NULL;
1296 char *mapped_ea_name = NULL;
1299 int saved_errno = 0;
1301 status = catia_string_replace_allocate(handle->conn,
1302 smb_fname->base_name,
1304 vfs_translate_to_unix);
1305 if (!NT_STATUS_IS_OK(status)) {
1306 errno = map_errno_from_nt_status(status);
1310 status = catia_string_replace_allocate(handle->conn,
1311 name, &mapped_ea_name, vfs_translate_to_unix);
1312 if (!NT_STATUS_IS_OK(status)) {
1313 TALLOC_FREE(mapped_name);
1314 errno = map_errno_from_nt_status(status);
1318 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1324 if (mapped_smb_fname == NULL) {
1325 TALLOC_FREE(mapped_name);
1326 TALLOC_FREE(mapped_ea_name);
1331 ret = SMB_VFS_NEXT_REMOVEXATTR(handle, mapped_smb_fname,
1334 saved_errno = errno;
1336 TALLOC_FREE(mapped_name);
1337 TALLOC_FREE(mapped_ea_name);
1338 TALLOC_FREE(mapped_smb_fname);
1339 if (saved_errno != 0) {
1340 errno = saved_errno;
1347 catia_setxattr(vfs_handle_struct *handle,
1348 const struct smb_filename *smb_fname,
1354 struct smb_filename *mapped_smb_fname = NULL;
1355 char *mapped_name = NULL;
1356 char *mapped_ea_name = NULL;
1359 int saved_errno = 0;
1361 status = catia_string_replace_allocate(handle->conn,
1362 smb_fname->base_name,
1364 vfs_translate_to_unix);
1365 if (!NT_STATUS_IS_OK(status)) {
1366 errno = map_errno_from_nt_status(status);
1370 status = catia_string_replace_allocate(handle->conn,
1371 name, &mapped_ea_name, vfs_translate_to_unix);
1372 if (!NT_STATUS_IS_OK(status)) {
1373 TALLOC_FREE(mapped_name);
1374 errno = map_errno_from_nt_status(status);
1378 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1384 if (mapped_smb_fname == NULL) {
1385 TALLOC_FREE(mapped_name);
1386 TALLOC_FREE(mapped_ea_name);
1391 ret = SMB_VFS_NEXT_SETXATTR(handle, mapped_smb_fname, mapped_ea_name,
1392 value, size, flags);
1394 saved_errno = errno;
1396 TALLOC_FREE(mapped_name);
1397 TALLOC_FREE(mapped_ea_name);
1398 TALLOC_FREE(mapped_smb_fname);
1399 if (saved_errno != 0) {
1400 errno = saved_errno;
1406 static int catia_fstat(vfs_handle_struct *handle,
1408 SMB_STRUCT_STAT *sbuf)
1410 struct catia_cache *cc = NULL;
1413 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1418 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1420 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1425 static ssize_t catia_pread(vfs_handle_struct *handle,
1426 files_struct *fsp, void *data,
1427 size_t n, off_t offset)
1429 struct catia_cache *cc = NULL;
1433 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1438 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1440 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1445 static ssize_t catia_pwrite(vfs_handle_struct *handle,
1446 files_struct *fsp, const void *data,
1447 size_t n, off_t offset)
1449 struct catia_cache *cc = NULL;
1453 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1458 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1460 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1465 static int catia_ftruncate(struct vfs_handle_struct *handle,
1466 struct files_struct *fsp,
1469 struct catia_cache *cc = NULL;
1472 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1477 ret = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
1479 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1484 static int catia_fallocate(struct vfs_handle_struct *handle,
1485 struct files_struct *fsp,
1490 struct catia_cache *cc = NULL;
1493 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1498 ret = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1500 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1505 static ssize_t catia_fgetxattr(struct vfs_handle_struct *handle,
1506 struct files_struct *fsp,
1511 char *mapped_xattr_name = NULL;
1515 status = catia_string_replace_allocate(handle->conn,
1516 name, &mapped_xattr_name,
1517 vfs_translate_to_unix);
1518 if (!NT_STATUS_IS_OK(status)) {
1519 errno = map_errno_from_nt_status(status);
1523 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, mapped_xattr_name,
1526 TALLOC_FREE(mapped_xattr_name);
1531 static ssize_t catia_flistxattr(struct vfs_handle_struct *handle,
1532 struct files_struct *fsp,
1536 struct catia_cache *cc = NULL;
1540 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1545 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
1547 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1552 static int catia_fremovexattr(struct vfs_handle_struct *handle,
1553 struct files_struct *fsp,
1556 char *mapped_name = NULL;
1560 status = catia_string_replace_allocate(handle->conn,
1561 name, &mapped_name, vfs_translate_to_unix);
1562 if (!NT_STATUS_IS_OK(status)) {
1563 errno = map_errno_from_nt_status(status);
1567 ret = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, mapped_name);
1569 TALLOC_FREE(mapped_name);
1574 static int catia_fsetxattr(struct vfs_handle_struct *handle,
1575 struct files_struct *fsp,
1581 char *mapped_xattr_name = NULL;
1585 status = catia_string_replace_allocate(
1586 handle->conn, name, &mapped_xattr_name, vfs_translate_to_unix);
1587 if (!NT_STATUS_IS_OK(status)) {
1588 errno = map_errno_from_nt_status(status);
1592 ret = SMB_VFS_NEXT_FSETXATTR(handle, fsp, mapped_xattr_name,
1593 value, size, flags);
1595 TALLOC_FREE(mapped_xattr_name);
1600 static SMB_ACL_T catia_sys_acl_get_fd(vfs_handle_struct *handle,
1602 TALLOC_CTX *mem_ctx)
1604 struct catia_cache *cc = NULL;
1605 struct smb_acl_t *result = NULL;
1608 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1613 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1615 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1620 static int catia_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1622 TALLOC_CTX *mem_ctx,
1623 char **blob_description,
1626 struct catia_cache *cc = NULL;
1629 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1634 ret = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1635 blob_description, blob);
1637 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1642 static int catia_sys_acl_set_fd(vfs_handle_struct *handle,
1644 SMB_ACL_TYPE_T type,
1647 struct catia_cache *cc = NULL;
1650 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1655 ret = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
1657 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1662 static NTSTATUS catia_fget_nt_acl(vfs_handle_struct *handle,
1664 uint32_t security_info,
1665 TALLOC_CTX *mem_ctx,
1666 struct security_descriptor **ppdesc)
1668 struct catia_cache *cc = NULL;
1672 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1674 return map_nt_error_from_unix(errno);
1677 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1680 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1685 static NTSTATUS catia_fset_nt_acl(vfs_handle_struct *handle,
1687 uint32_t security_info_sent,
1688 const struct security_descriptor *psd)
1690 struct catia_cache *cc = NULL;
1694 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1696 return map_nt_error_from_unix(errno);
1699 status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1701 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1706 static NTSTATUS catia_fset_dos_attributes(struct vfs_handle_struct *handle,
1707 struct files_struct *fsp,
1710 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 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1721 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1726 static NTSTATUS catia_fget_dos_attributes(struct vfs_handle_struct *handle,
1727 struct files_struct *fsp,
1730 struct catia_cache *cc = NULL;
1734 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1736 return map_nt_error_from_unix(errno);
1739 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1741 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1746 static int catia_fchown(vfs_handle_struct *handle,
1751 struct catia_cache *cc = NULL;
1754 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1759 ret = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1761 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1766 static int catia_fchmod(vfs_handle_struct *handle,
1770 struct catia_cache *cc = NULL;
1773 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1778 ret = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1780 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1785 struct catia_pread_state {
1787 struct vfs_aio_state vfs_aio_state;
1788 struct files_struct *fsp;
1789 struct catia_cache *cc;
1792 static void catia_pread_done(struct tevent_req *subreq);
1794 static struct tevent_req *catia_pread_send(struct vfs_handle_struct *handle,
1795 TALLOC_CTX *mem_ctx,
1796 struct tevent_context *ev,
1797 struct files_struct *fsp,
1802 struct tevent_req *req = NULL, *subreq = NULL;
1803 struct catia_pread_state *state = NULL;
1806 req = tevent_req_create(mem_ctx, &state,
1807 struct catia_pread_state);
1813 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1815 tevent_req_error(req, errno);
1816 return tevent_req_post(req, ev);
1819 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1821 if (tevent_req_nomem(subreq, req)) {
1822 return tevent_req_post(req, ev);
1824 tevent_req_set_callback(subreq, catia_pread_done, req);
1829 static void catia_pread_done(struct tevent_req *subreq)
1831 struct tevent_req *req = tevent_req_callback_data(
1832 subreq, struct tevent_req);
1833 struct catia_pread_state *state = tevent_req_data(
1834 req, struct catia_pread_state);
1836 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1837 TALLOC_FREE(subreq);
1839 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1841 tevent_req_done(req);
1844 static ssize_t catia_pread_recv(struct tevent_req *req,
1845 struct vfs_aio_state *vfs_aio_state)
1847 struct catia_pread_state *state = tevent_req_data(
1848 req, struct catia_pread_state);
1850 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1854 *vfs_aio_state = state->vfs_aio_state;
1858 struct catia_pwrite_state {
1860 struct vfs_aio_state vfs_aio_state;
1861 struct files_struct *fsp;
1862 struct catia_cache *cc;
1865 static void catia_pwrite_done(struct tevent_req *subreq);
1867 static struct tevent_req *catia_pwrite_send(struct vfs_handle_struct *handle,
1868 TALLOC_CTX *mem_ctx,
1869 struct tevent_context *ev,
1870 struct files_struct *fsp,
1875 struct tevent_req *req = NULL, *subreq = NULL;
1876 struct catia_pwrite_state *state = NULL;
1879 req = tevent_req_create(mem_ctx, &state,
1880 struct catia_pwrite_state);
1886 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1888 tevent_req_error(req, errno);
1889 return tevent_req_post(req, ev);
1892 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1894 if (tevent_req_nomem(subreq, req)) {
1895 return tevent_req_post(req, ev);
1897 tevent_req_set_callback(subreq, catia_pwrite_done, req);
1902 static void catia_pwrite_done(struct tevent_req *subreq)
1904 struct tevent_req *req = tevent_req_callback_data(
1905 subreq, struct tevent_req);
1906 struct catia_pwrite_state *state = tevent_req_data(
1907 req, struct catia_pwrite_state);
1909 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1910 TALLOC_FREE(subreq);
1912 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1914 tevent_req_done(req);
1917 static ssize_t catia_pwrite_recv(struct tevent_req *req,
1918 struct vfs_aio_state *vfs_aio_state)
1920 struct catia_pwrite_state *state = tevent_req_data(
1921 req, struct catia_pwrite_state);
1923 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1927 *vfs_aio_state = state->vfs_aio_state;
1931 static off_t catia_lseek(vfs_handle_struct *handle,
1936 struct catia_cache *cc = NULL;
1940 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1945 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1947 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1952 struct catia_fsync_state {
1954 struct vfs_aio_state vfs_aio_state;
1955 struct files_struct *fsp;
1956 struct catia_cache *cc;
1959 static void catia_fsync_done(struct tevent_req *subreq);
1961 static struct tevent_req *catia_fsync_send(struct vfs_handle_struct *handle,
1962 TALLOC_CTX *mem_ctx,
1963 struct tevent_context *ev,
1964 struct files_struct *fsp)
1966 struct tevent_req *req = NULL, *subreq = NULL;
1967 struct catia_fsync_state *state = NULL;
1970 req = tevent_req_create(mem_ctx, &state,
1971 struct catia_fsync_state);
1977 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1979 tevent_req_error(req, errno);
1980 return tevent_req_post(req, ev);
1983 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1984 if (tevent_req_nomem(subreq, req)) {
1985 return tevent_req_post(req, ev);
1987 tevent_req_set_callback(subreq, catia_fsync_done, req);
1992 static void catia_fsync_done(struct tevent_req *subreq)
1994 struct tevent_req *req = tevent_req_callback_data(
1995 subreq, struct tevent_req);
1996 struct catia_fsync_state *state = tevent_req_data(
1997 req, struct catia_fsync_state);
1999 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
2000 TALLOC_FREE(subreq);
2002 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
2004 tevent_req_done(req);
2007 static int catia_fsync_recv(struct tevent_req *req,
2008 struct vfs_aio_state *vfs_aio_state)
2010 struct catia_fsync_state *state = tevent_req_data(
2011 req, struct catia_fsync_state);
2013 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2017 *vfs_aio_state = state->vfs_aio_state;
2021 static bool catia_lock(vfs_handle_struct *handle,
2028 struct catia_cache *cc = NULL;
2032 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2037 ok = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
2039 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2044 static int catia_kernel_flock(struct vfs_handle_struct *handle,
2045 struct files_struct *fsp,
2046 uint32_t share_access,
2047 uint32_t access_mask)
2049 struct catia_cache *cc = NULL;
2052 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2057 ret = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_access, access_mask);
2059 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2064 static int catia_linux_setlease(vfs_handle_struct *handle,
2068 struct catia_cache *cc = NULL;
2071 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2076 ret = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
2078 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2083 static bool catia_getlock(vfs_handle_struct *handle,
2090 struct catia_cache *cc = NULL;
2094 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2099 ok = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
2101 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2106 static bool catia_strict_lock_check(struct vfs_handle_struct *handle,
2107 struct files_struct *fsp,
2108 struct lock_struct *plock)
2110 struct catia_cache *cc = NULL;
2114 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2119 ok = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2121 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2126 static NTSTATUS catia_fsctl(struct vfs_handle_struct *handle,
2127 struct files_struct *fsp,
2131 const uint8_t *_in_data,
2133 uint8_t **_out_data,
2134 uint32_t max_out_len,
2138 struct catia_cache *cc = NULL;
2141 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2143 return map_nt_error_from_unix(errno);
2146 result = SMB_VFS_NEXT_FSCTL(handle,
2157 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2162 static NTSTATUS catia_fget_compression(vfs_handle_struct *handle,
2163 TALLOC_CTX *mem_ctx,
2164 struct files_struct *fsp,
2165 uint16_t *_compression_fmt)
2168 struct catia_cache *cc = NULL;
2171 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2173 return map_nt_error_from_unix(errno);
2176 result = SMB_VFS_NEXT_FGET_COMPRESSION(handle,
2181 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2186 static NTSTATUS catia_set_compression(vfs_handle_struct *handle,
2187 TALLOC_CTX *mem_ctx,
2188 struct files_struct *fsp,
2189 uint16_t compression_fmt)
2192 struct catia_cache *cc = NULL;
2195 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2197 return map_nt_error_from_unix(errno);
2200 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2203 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2208 static NTSTATUS catia_readdir_attr(struct vfs_handle_struct *handle,
2209 const struct smb_filename *smb_fname_in,
2210 TALLOC_CTX *mem_ctx,
2211 struct readdir_attr_data **pattr_data)
2213 struct smb_filename *smb_fname;
2217 status = catia_string_replace_allocate(handle->conn,
2218 smb_fname_in->base_name,
2220 vfs_translate_to_unix);
2221 if (!NT_STATUS_IS_OK(status)) {
2222 errno = map_errno_from_nt_status(status);
2226 smb_fname = synthetic_smb_fname(talloc_tos(),
2233 status = SMB_VFS_NEXT_READDIR_ATTR(handle, smb_fname, mem_ctx, pattr_data);
2235 TALLOC_FREE(smb_fname);
2240 static NTSTATUS catia_set_dos_attributes(struct vfs_handle_struct *handle,
2241 const struct smb_filename *smb_fname,
2244 char *mapped_name = NULL;
2245 const char *path = smb_fname->base_name;
2246 struct smb_filename *mapped_smb_fname = NULL;
2249 status = catia_string_replace_allocate(handle->conn,
2250 path, &mapped_name, vfs_translate_to_unix);
2251 if (!NT_STATUS_IS_OK(status)) {
2252 errno = map_errno_from_nt_status(status);
2255 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2261 if (mapped_smb_fname == NULL) {
2262 TALLOC_FREE(mapped_name);
2263 return NT_STATUS_NO_MEMORY;
2266 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2269 TALLOC_FREE(mapped_name);
2270 TALLOC_FREE(mapped_smb_fname);
2275 static NTSTATUS catia_create_dfs_pathat(struct vfs_handle_struct *handle,
2276 struct files_struct *dirfsp,
2277 const struct smb_filename *smb_fname,
2278 const struct referral *reflist,
2279 size_t referral_count)
2281 char *mapped_name = NULL;
2282 const char *path = smb_fname->base_name;
2283 struct smb_filename *mapped_smb_fname = NULL;
2286 status = catia_string_replace_allocate(handle->conn,
2289 vfs_translate_to_unix);
2290 if (!NT_STATUS_IS_OK(status)) {
2291 errno = map_errno_from_nt_status(status);
2294 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2300 if (mapped_smb_fname == NULL) {
2301 TALLOC_FREE(mapped_name);
2302 return NT_STATUS_NO_MEMORY;
2305 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
2310 TALLOC_FREE(mapped_name);
2311 TALLOC_FREE(mapped_smb_fname);
2315 static NTSTATUS catia_read_dfs_pathat(struct vfs_handle_struct *handle,
2316 TALLOC_CTX *mem_ctx,
2317 struct files_struct *dirfsp,
2318 struct smb_filename *smb_fname,
2319 struct referral **ppreflist,
2320 size_t *preferral_count)
2322 char *mapped_name = NULL;
2323 const char *path = smb_fname->base_name;
2324 struct smb_filename *mapped_smb_fname = NULL;
2327 status = catia_string_replace_allocate(handle->conn,
2330 vfs_translate_to_unix);
2331 if (!NT_STATUS_IS_OK(status)) {
2332 errno = map_errno_from_nt_status(status);
2335 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2341 if (mapped_smb_fname == NULL) {
2342 TALLOC_FREE(mapped_name);
2343 return NT_STATUS_NO_MEMORY;
2346 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
2352 if (NT_STATUS_IS_OK(status)) {
2353 /* Return any stat(2) info. */
2354 smb_fname->st = mapped_smb_fname->st;
2357 TALLOC_FREE(mapped_name);
2358 TALLOC_FREE(mapped_smb_fname);
2362 static struct vfs_fn_pointers vfs_catia_fns = {
2363 .connect_fn = catia_connect,
2365 /* Directory operations */
2366 .mkdirat_fn = catia_mkdirat,
2367 .readdir_attr_fn = catia_readdir_attr,
2369 /* File operations */
2370 .openat_fn = catia_openat,
2371 .pread_fn = catia_pread,
2372 .pread_send_fn = catia_pread_send,
2373 .pread_recv_fn = catia_pread_recv,
2374 .pwrite_fn = catia_pwrite,
2375 .pwrite_send_fn = catia_pwrite_send,
2376 .pwrite_recv_fn = catia_pwrite_recv,
2377 .lseek_fn = catia_lseek,
2378 .renameat_fn = catia_renameat,
2379 .fsync_send_fn = catia_fsync_send,
2380 .fsync_recv_fn = catia_fsync_recv,
2381 .stat_fn = catia_stat,
2382 .fstat_fn = catia_fstat,
2383 .lstat_fn = catia_lstat,
2384 .unlinkat_fn = catia_unlinkat,
2385 .chmod_fn = catia_chmod,
2386 .fchmod_fn = catia_fchmod,
2387 .fchown_fn = catia_fchown,
2388 .lchown_fn = catia_lchown,
2389 .chdir_fn = catia_chdir,
2390 .ntimes_fn = catia_ntimes,
2391 .ftruncate_fn = catia_ftruncate,
2392 .fallocate_fn = catia_fallocate,
2393 .lock_fn = catia_lock,
2394 .kernel_flock_fn = catia_kernel_flock,
2395 .linux_setlease_fn = catia_linux_setlease,
2396 .getlock_fn = catia_getlock,
2397 .realpath_fn = catia_realpath,
2398 .chflags_fn = catia_chflags,
2399 .streaminfo_fn = catia_streaminfo,
2400 .strict_lock_check_fn = catia_strict_lock_check,
2401 .translate_name_fn = catia_translate_name,
2402 .fsctl_fn = catia_fsctl,
2403 .get_dos_attributes_send_fn = vfs_not_implemented_get_dos_attributes_send,
2404 .get_dos_attributes_recv_fn = vfs_not_implemented_get_dos_attributes_recv,
2405 .set_dos_attributes_fn = catia_set_dos_attributes,
2406 .fset_dos_attributes_fn = catia_fset_dos_attributes,
2407 .fget_dos_attributes_fn = catia_fget_dos_attributes,
2408 .fget_compression_fn = catia_fget_compression,
2409 .set_compression_fn = catia_set_compression,
2410 .create_dfs_pathat_fn = catia_create_dfs_pathat,
2411 .read_dfs_pathat_fn = catia_read_dfs_pathat,
2413 /* NT ACL operations. */
2414 .get_nt_acl_at_fn = catia_get_nt_acl_at,
2415 .fget_nt_acl_fn = catia_fget_nt_acl,
2416 .fset_nt_acl_fn = catia_fset_nt_acl,
2418 /* POSIX ACL operations. */
2419 .sys_acl_get_file_fn = catia_sys_acl_get_file,
2420 .sys_acl_get_fd_fn = catia_sys_acl_get_fd,
2421 .sys_acl_blob_get_fd_fn = catia_sys_acl_blob_get_fd,
2422 .sys_acl_set_fd_fn = catia_sys_acl_set_fd,
2423 .sys_acl_delete_def_file_fn = catia_sys_acl_delete_def_file,
2425 /* EA operations. */
2426 .getxattr_fn = catia_getxattr,
2427 .getxattrat_send_fn = vfs_not_implemented_getxattrat_send,
2428 .getxattrat_recv_fn = vfs_not_implemented_getxattrat_recv,
2429 .listxattr_fn = catia_listxattr,
2430 .removexattr_fn = catia_removexattr,
2431 .setxattr_fn = catia_setxattr,
2432 .fgetxattr_fn = catia_fgetxattr,
2433 .flistxattr_fn = catia_flistxattr,
2434 .fremovexattr_fn = catia_fremovexattr,
2435 .fsetxattr_fn = catia_fsetxattr,
2439 NTSTATUS vfs_catia_init(TALLOC_CTX *ctx)
2443 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
2445 if (!NT_STATUS_IS_OK(ret))
2448 vfs_catia_debug_level = debug_add_class("catia");
2449 if (vfs_catia_debug_level == -1) {
2450 vfs_catia_debug_level = DBGC_VFS;
2451 DEBUG(0, ("vfs_catia: Couldn't register custom debugging "
2454 DEBUG(10, ("vfs_catia: Debug class number of "
2455 "'catia': %d\n", vfs_catia_debug_level));