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 smb_filename *smb_fname_tmp = NULL;
670 status = catia_string_replace_allocate(handle->conn,
671 smb_fname->base_name,
672 &name, vfs_translate_to_unix);
673 if (!NT_STATUS_IS_OK(status)) {
674 errno = map_errno_from_nt_status(status);
678 /* Setup temporary smb_filename structs. */
679 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
680 if (smb_fname_tmp == NULL) {
685 smb_fname_tmp->base_name = name;
686 ret = SMB_VFS_NEXT_UNLINKAT(handle,
690 TALLOC_FREE(smb_fname_tmp);
696 static int catia_lchown(vfs_handle_struct *handle,
697 const struct smb_filename *smb_fname,
705 struct smb_filename *catia_smb_fname = NULL;
707 status = catia_string_replace_allocate(handle->conn,
708 smb_fname->base_name,
710 vfs_translate_to_unix);
711 if (!NT_STATUS_IS_OK(status)) {
712 errno = map_errno_from_nt_status(status);
715 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
721 if (catia_smb_fname == NULL) {
727 ret = SMB_VFS_NEXT_LCHOWN(handle, catia_smb_fname, uid, gid);
730 TALLOC_FREE(catia_smb_fname);
735 static int catia_chmod(vfs_handle_struct *handle,
736 const struct smb_filename *smb_fname,
743 struct smb_filename *catia_smb_fname = NULL;
745 status = catia_string_replace_allocate(handle->conn,
746 smb_fname->base_name,
748 vfs_translate_to_unix);
749 if (!NT_STATUS_IS_OK(status)) {
750 errno = map_errno_from_nt_status(status);
753 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
759 if (catia_smb_fname == NULL) {
765 ret = SMB_VFS_NEXT_CHMOD(handle, catia_smb_fname, mode);
768 TALLOC_FREE(catia_smb_fname);
773 static int catia_mkdirat(vfs_handle_struct *handle,
774 struct files_struct *dirfsp,
775 const struct smb_filename *smb_fname,
781 struct smb_filename *catia_smb_fname = NULL;
783 status = catia_string_replace_allocate(handle->conn,
784 smb_fname->base_name,
786 vfs_translate_to_unix);
787 if (!NT_STATUS_IS_OK(status)) {
788 errno = map_errno_from_nt_status(status);
791 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
797 if (catia_smb_fname == NULL) {
803 ret = SMB_VFS_NEXT_MKDIRAT(handle,
808 TALLOC_FREE(catia_smb_fname);
813 static int catia_chdir(vfs_handle_struct *handle,
814 const struct smb_filename *smb_fname)
817 struct smb_filename *catia_smb_fname = NULL;
821 status = catia_string_replace_allocate(handle->conn,
822 smb_fname->base_name,
824 vfs_translate_to_unix);
825 if (!NT_STATUS_IS_OK(status)) {
826 errno = map_errno_from_nt_status(status);
830 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
836 if (catia_smb_fname == NULL) {
841 ret = SMB_VFS_NEXT_CHDIR(handle, catia_smb_fname);
843 TALLOC_FREE(catia_smb_fname);
848 static int catia_ntimes(vfs_handle_struct *handle,
849 const struct smb_filename *smb_fname,
850 struct smb_file_time *ft)
852 struct smb_filename *smb_fname_tmp = NULL;
857 status = catia_string_replace_allocate(handle->conn,
858 smb_fname->base_name,
859 &name, vfs_translate_to_unix);
860 if (!NT_STATUS_IS_OK(status)) {
861 errno = map_errno_from_nt_status(status);
865 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
866 if (smb_fname_tmp == NULL) {
871 smb_fname_tmp->base_name = name;
872 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname_tmp, ft);
874 TALLOC_FREE(smb_fname_tmp);
879 static struct smb_filename *
880 catia_realpath(vfs_handle_struct *handle,
882 const struct smb_filename *smb_fname)
884 char *mapped_name = NULL;
885 struct smb_filename *catia_smb_fname = NULL;
886 struct smb_filename *return_fname = NULL;
889 status = catia_string_replace_allocate(handle->conn,
890 smb_fname->base_name,
891 &mapped_name, vfs_translate_to_unix);
892 if (!NT_STATUS_IS_OK(status)) {
893 errno = map_errno_from_nt_status(status);
897 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
903 if (catia_smb_fname == NULL) {
904 TALLOC_FREE(mapped_name);
908 return_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, catia_smb_fname);
909 TALLOC_FREE(mapped_name);
910 TALLOC_FREE(catia_smb_fname);
914 static int catia_chflags(struct vfs_handle_struct *handle,
915 const struct smb_filename *smb_fname,
919 struct smb_filename *catia_smb_fname = NULL;
923 status = catia_string_replace_allocate(handle->conn,
924 smb_fname->base_name,
926 vfs_translate_to_unix);
927 if (!NT_STATUS_IS_OK(status)) {
928 errno = map_errno_from_nt_status(status);
931 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
937 if (catia_smb_fname == NULL) {
943 ret = SMB_VFS_NEXT_CHFLAGS(handle, catia_smb_fname, flags);
945 TALLOC_FREE(catia_smb_fname);
951 catia_streaminfo(struct vfs_handle_struct *handle,
952 struct files_struct *fsp,
953 const struct smb_filename *smb_fname,
955 unsigned int *_num_streams,
956 struct stream_struct **_streams)
958 char *mapped_name = NULL;
961 struct smb_filename *catia_smb_fname = NULL;
962 unsigned int num_streams = 0;
963 struct stream_struct *streams = NULL;
968 status = catia_string_replace_allocate(handle->conn,
969 smb_fname->base_name,
971 vfs_translate_to_unix);
972 if (!NT_STATUS_IS_OK(status)) {
973 errno = map_errno_from_nt_status(status);
977 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
983 if (catia_smb_fname == NULL) {
984 TALLOC_FREE(mapped_name);
985 return NT_STATUS_NO_MEMORY;
988 status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, catia_smb_fname,
989 mem_ctx, &num_streams, &streams);
990 TALLOC_FREE(mapped_name);
991 TALLOC_FREE(catia_smb_fname);
992 if (!NT_STATUS_IS_OK(status)) {
997 * Translate stream names just like the base names
999 for (i = 0; i < num_streams; i++) {
1001 * Strip ":" prefix and ":$DATA" suffix to get a
1002 * "pure" stream name and only translate that.
1004 void *old_ptr = streams[i].name;
1005 char *stream_name = streams[i].name + 1;
1006 char *stream_type = strrchr_m(stream_name, ':');
1008 if (stream_type != NULL) {
1009 *stream_type = '\0';
1013 status = catia_string_replace_allocate(handle->conn, stream_name,
1014 &mapped_name, vfs_translate_to_windows);
1015 if (!NT_STATUS_IS_OK(status)) {
1016 TALLOC_FREE(streams);
1020 if (stream_type != NULL) {
1021 streams[i].name = talloc_asprintf(streams, ":%s:%s",
1022 mapped_name, stream_type);
1024 streams[i].name = talloc_asprintf(streams, ":%s",
1027 TALLOC_FREE(mapped_name);
1028 TALLOC_FREE(old_ptr);
1029 if (streams[i].name == NULL) {
1030 TALLOC_FREE(streams);
1031 return NT_STATUS_NO_MEMORY;
1035 *_num_streams = num_streams;
1036 *_streams = streams;
1037 return NT_STATUS_OK;
1040 static NTSTATUS catia_get_nt_acl_at(struct vfs_handle_struct *handle,
1041 struct files_struct *dirfsp,
1042 const struct smb_filename *smb_fname,
1043 uint32_t security_info,
1044 TALLOC_CTX *mem_ctx,
1045 struct security_descriptor **ppdesc)
1047 char *mapped_name = NULL;
1048 const char *path = smb_fname->base_name;
1049 struct smb_filename *mapped_smb_fname = NULL;
1052 SMB_ASSERT(dirfsp == handle->conn->cwd_fsp);
1054 status = catia_string_replace_allocate(handle->conn,
1055 path, &mapped_name, vfs_translate_to_unix);
1056 if (!NT_STATUS_IS_OK(status)) {
1057 errno = map_errno_from_nt_status(status);
1060 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1066 if (mapped_smb_fname == NULL) {
1067 TALLOC_FREE(mapped_name);
1068 return NT_STATUS_NO_MEMORY;
1071 status = SMB_VFS_NEXT_GET_NT_ACL_AT(handle,
1077 TALLOC_FREE(mapped_name);
1078 TALLOC_FREE(mapped_smb_fname);
1084 catia_sys_acl_get_file(vfs_handle_struct *handle,
1085 const struct smb_filename *smb_fname,
1086 SMB_ACL_TYPE_T type,
1087 TALLOC_CTX *mem_ctx)
1089 char *mapped_name = NULL;
1090 struct smb_filename *mapped_smb_fname = NULL;
1093 int saved_errno = 0;
1095 status = catia_string_replace_allocate(handle->conn,
1096 smb_fname->base_name,
1098 vfs_translate_to_unix);
1099 if (!NT_STATUS_IS_OK(status)) {
1100 errno = map_errno_from_nt_status(status);
1101 return (SMB_ACL_T)NULL;
1104 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1110 if (mapped_smb_fname == NULL) {
1111 TALLOC_FREE(mapped_name);
1113 return (SMB_ACL_T)NULL;
1116 ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, mapped_smb_fname,
1118 if (ret == (SMB_ACL_T)NULL) {
1119 saved_errno = errno;
1121 TALLOC_FREE(mapped_smb_fname);
1122 TALLOC_FREE(mapped_name);
1123 if (saved_errno != 0) {
1124 errno = saved_errno;
1130 catia_sys_acl_set_file(vfs_handle_struct *handle,
1131 const struct smb_filename *smb_fname,
1132 SMB_ACL_TYPE_T type,
1135 struct smb_filename *mapped_smb_fname = NULL;
1136 int saved_errno = 0;
1137 char *mapped_name = NULL;
1141 status = catia_string_replace_allocate(handle->conn,
1142 smb_fname->base_name,
1144 vfs_translate_to_unix);
1145 if (!NT_STATUS_IS_OK(status)) {
1146 errno = map_errno_from_nt_status(status);
1150 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1156 if (mapped_smb_fname == NULL) {
1157 TALLOC_FREE(mapped_name);
1162 ret = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, mapped_smb_fname,
1165 saved_errno = errno;
1167 TALLOC_FREE(mapped_smb_fname);
1168 TALLOC_FREE(mapped_name);
1169 if (saved_errno != 0) {
1170 errno = saved_errno;
1176 catia_sys_acl_delete_def_file(vfs_handle_struct *handle,
1177 const struct smb_filename *smb_fname)
1179 struct smb_filename *mapped_smb_fname = NULL;
1180 int saved_errno = 0;
1181 char *mapped_name = NULL;
1185 status = catia_string_replace_allocate(handle->conn,
1186 smb_fname->base_name,
1188 vfs_translate_to_unix);
1189 if (!NT_STATUS_IS_OK(status)) {
1190 errno = map_errno_from_nt_status(status);
1194 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1200 if (mapped_smb_fname == NULL) {
1201 TALLOC_FREE(mapped_name);
1205 ret = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, mapped_smb_fname);
1207 saved_errno = errno;
1209 TALLOC_FREE(mapped_smb_fname);
1210 TALLOC_FREE(mapped_name);
1211 if (saved_errno != 0) {
1212 errno = saved_errno;
1218 catia_getxattr(vfs_handle_struct *handle,
1219 const struct smb_filename *smb_fname,
1224 struct smb_filename *mapped_smb_fname = NULL;
1225 char *mapped_name = NULL;
1226 char *mapped_ea_name = NULL;
1229 int saved_errno = 0;
1231 status = catia_string_replace_allocate(handle->conn,
1232 smb_fname->base_name,
1234 vfs_translate_to_unix);
1235 if (!NT_STATUS_IS_OK(status)) {
1236 errno = map_errno_from_nt_status(status);
1240 status = catia_string_replace_allocate(handle->conn,
1241 name, &mapped_ea_name, vfs_translate_to_unix);
1242 if (!NT_STATUS_IS_OK(status)) {
1243 TALLOC_FREE(mapped_name);
1244 errno = map_errno_from_nt_status(status);
1248 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1254 if (mapped_smb_fname == NULL) {
1255 TALLOC_FREE(mapped_name);
1256 TALLOC_FREE(mapped_ea_name);
1261 ret = SMB_VFS_NEXT_GETXATTR(handle, mapped_smb_fname,
1262 mapped_ea_name, value, size);
1264 saved_errno = errno;
1266 TALLOC_FREE(mapped_name);
1267 TALLOC_FREE(mapped_ea_name);
1268 TALLOC_FREE(mapped_smb_fname);
1269 if (saved_errno != 0) {
1270 errno = saved_errno;
1277 catia_listxattr(vfs_handle_struct *handle,
1278 const struct smb_filename *smb_fname,
1279 char *list, size_t size)
1281 struct smb_filename *mapped_smb_fname = NULL;
1282 char *mapped_name = NULL;
1285 int saved_errno = 0;
1287 status = catia_string_replace_allocate(handle->conn,
1288 smb_fname->base_name,
1290 vfs_translate_to_unix);
1291 if (!NT_STATUS_IS_OK(status)) {
1292 errno = map_errno_from_nt_status(status);
1296 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1302 if (mapped_smb_fname == NULL) {
1303 TALLOC_FREE(mapped_name);
1308 ret = SMB_VFS_NEXT_LISTXATTR(handle, mapped_smb_fname, list, size);
1310 saved_errno = errno;
1312 TALLOC_FREE(mapped_name);
1313 TALLOC_FREE(mapped_smb_fname);
1314 if (saved_errno != 0) {
1315 errno = saved_errno;
1322 catia_removexattr(vfs_handle_struct *handle,
1323 const struct smb_filename *smb_fname,
1326 struct smb_filename *mapped_smb_fname = NULL;
1327 char *mapped_name = NULL;
1328 char *mapped_ea_name = NULL;
1331 int saved_errno = 0;
1333 status = catia_string_replace_allocate(handle->conn,
1334 smb_fname->base_name,
1336 vfs_translate_to_unix);
1337 if (!NT_STATUS_IS_OK(status)) {
1338 errno = map_errno_from_nt_status(status);
1342 status = catia_string_replace_allocate(handle->conn,
1343 name, &mapped_ea_name, vfs_translate_to_unix);
1344 if (!NT_STATUS_IS_OK(status)) {
1345 TALLOC_FREE(mapped_name);
1346 errno = map_errno_from_nt_status(status);
1350 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1356 if (mapped_smb_fname == NULL) {
1357 TALLOC_FREE(mapped_name);
1358 TALLOC_FREE(mapped_ea_name);
1363 ret = SMB_VFS_NEXT_REMOVEXATTR(handle, mapped_smb_fname,
1366 saved_errno = errno;
1368 TALLOC_FREE(mapped_name);
1369 TALLOC_FREE(mapped_ea_name);
1370 TALLOC_FREE(mapped_smb_fname);
1371 if (saved_errno != 0) {
1372 errno = saved_errno;
1379 catia_setxattr(vfs_handle_struct *handle,
1380 const struct smb_filename *smb_fname,
1386 struct smb_filename *mapped_smb_fname = NULL;
1387 char *mapped_name = NULL;
1388 char *mapped_ea_name = NULL;
1391 int saved_errno = 0;
1393 status = catia_string_replace_allocate(handle->conn,
1394 smb_fname->base_name,
1396 vfs_translate_to_unix);
1397 if (!NT_STATUS_IS_OK(status)) {
1398 errno = map_errno_from_nt_status(status);
1402 status = catia_string_replace_allocate(handle->conn,
1403 name, &mapped_ea_name, vfs_translate_to_unix);
1404 if (!NT_STATUS_IS_OK(status)) {
1405 TALLOC_FREE(mapped_name);
1406 errno = map_errno_from_nt_status(status);
1410 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1416 if (mapped_smb_fname == NULL) {
1417 TALLOC_FREE(mapped_name);
1418 TALLOC_FREE(mapped_ea_name);
1423 ret = SMB_VFS_NEXT_SETXATTR(handle, mapped_smb_fname, mapped_ea_name,
1424 value, size, flags);
1426 saved_errno = errno;
1428 TALLOC_FREE(mapped_name);
1429 TALLOC_FREE(mapped_ea_name);
1430 TALLOC_FREE(mapped_smb_fname);
1431 if (saved_errno != 0) {
1432 errno = saved_errno;
1438 static int catia_fstat(vfs_handle_struct *handle,
1440 SMB_STRUCT_STAT *sbuf)
1442 struct catia_cache *cc = NULL;
1445 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1450 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1452 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1457 static ssize_t catia_pread(vfs_handle_struct *handle,
1458 files_struct *fsp, void *data,
1459 size_t n, off_t offset)
1461 struct catia_cache *cc = NULL;
1465 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1470 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1472 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1477 static ssize_t catia_pwrite(vfs_handle_struct *handle,
1478 files_struct *fsp, const void *data,
1479 size_t n, off_t offset)
1481 struct catia_cache *cc = NULL;
1485 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1490 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1492 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1497 static int catia_ftruncate(struct vfs_handle_struct *handle,
1498 struct files_struct *fsp,
1501 struct catia_cache *cc = NULL;
1504 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1509 ret = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
1511 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1516 static int catia_fallocate(struct vfs_handle_struct *handle,
1517 struct files_struct *fsp,
1522 struct catia_cache *cc = NULL;
1525 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1530 ret = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1532 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1537 static ssize_t catia_fgetxattr(struct vfs_handle_struct *handle,
1538 struct files_struct *fsp,
1543 char *mapped_xattr_name = NULL;
1547 status = catia_string_replace_allocate(handle->conn,
1548 name, &mapped_xattr_name,
1549 vfs_translate_to_unix);
1550 if (!NT_STATUS_IS_OK(status)) {
1551 errno = map_errno_from_nt_status(status);
1555 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, mapped_xattr_name,
1558 TALLOC_FREE(mapped_xattr_name);
1563 static ssize_t catia_flistxattr(struct vfs_handle_struct *handle,
1564 struct files_struct *fsp,
1568 struct catia_cache *cc = NULL;
1572 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1577 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
1579 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1584 static int catia_fremovexattr(struct vfs_handle_struct *handle,
1585 struct files_struct *fsp,
1588 char *mapped_name = NULL;
1592 status = catia_string_replace_allocate(handle->conn,
1593 name, &mapped_name, vfs_translate_to_unix);
1594 if (!NT_STATUS_IS_OK(status)) {
1595 errno = map_errno_from_nt_status(status);
1599 ret = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, mapped_name);
1601 TALLOC_FREE(mapped_name);
1606 static int catia_fsetxattr(struct vfs_handle_struct *handle,
1607 struct files_struct *fsp,
1613 char *mapped_xattr_name = NULL;
1617 status = catia_string_replace_allocate(
1618 handle->conn, name, &mapped_xattr_name, vfs_translate_to_unix);
1619 if (!NT_STATUS_IS_OK(status)) {
1620 errno = map_errno_from_nt_status(status);
1624 ret = SMB_VFS_NEXT_FSETXATTR(handle, fsp, mapped_xattr_name,
1625 value, size, flags);
1627 TALLOC_FREE(mapped_xattr_name);
1632 static SMB_ACL_T catia_sys_acl_get_fd(vfs_handle_struct *handle,
1634 TALLOC_CTX *mem_ctx)
1636 struct catia_cache *cc = NULL;
1637 struct smb_acl_t *result = NULL;
1640 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1645 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1647 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1652 static int catia_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1654 TALLOC_CTX *mem_ctx,
1655 char **blob_description,
1658 struct catia_cache *cc = NULL;
1661 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1666 ret = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1667 blob_description, blob);
1669 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1674 static int catia_sys_acl_set_fd(vfs_handle_struct *handle,
1678 struct catia_cache *cc = NULL;
1681 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1686 ret = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1688 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1693 static NTSTATUS catia_fget_nt_acl(vfs_handle_struct *handle,
1695 uint32_t security_info,
1696 TALLOC_CTX *mem_ctx,
1697 struct security_descriptor **ppdesc)
1699 struct catia_cache *cc = NULL;
1703 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1705 return map_nt_error_from_unix(errno);
1708 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1711 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1716 static NTSTATUS catia_fset_nt_acl(vfs_handle_struct *handle,
1718 uint32_t security_info_sent,
1719 const struct security_descriptor *psd)
1721 struct catia_cache *cc = NULL;
1725 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1727 return map_nt_error_from_unix(errno);
1730 status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1732 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1737 static NTSTATUS catia_fset_dos_attributes(struct vfs_handle_struct *handle,
1738 struct files_struct *fsp,
1741 struct catia_cache *cc = NULL;
1745 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1747 return map_nt_error_from_unix(errno);
1750 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1752 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1757 static NTSTATUS catia_fget_dos_attributes(struct vfs_handle_struct *handle,
1758 struct files_struct *fsp,
1761 struct catia_cache *cc = NULL;
1765 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1767 return map_nt_error_from_unix(errno);
1770 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1772 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1777 static int catia_fchown(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_FCHOWN(handle, fsp, uid, gid);
1792 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1797 static int catia_fchmod(vfs_handle_struct *handle,
1801 struct catia_cache *cc = NULL;
1804 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1809 ret = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1811 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1816 struct catia_pread_state {
1818 struct vfs_aio_state vfs_aio_state;
1819 struct files_struct *fsp;
1820 struct catia_cache *cc;
1823 static void catia_pread_done(struct tevent_req *subreq);
1825 static struct tevent_req *catia_pread_send(struct vfs_handle_struct *handle,
1826 TALLOC_CTX *mem_ctx,
1827 struct tevent_context *ev,
1828 struct files_struct *fsp,
1833 struct tevent_req *req = NULL, *subreq = NULL;
1834 struct catia_pread_state *state = NULL;
1837 req = tevent_req_create(mem_ctx, &state,
1838 struct catia_pread_state);
1844 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1846 tevent_req_error(req, errno);
1847 return tevent_req_post(req, ev);
1850 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1852 if (tevent_req_nomem(subreq, req)) {
1853 return tevent_req_post(req, ev);
1855 tevent_req_set_callback(subreq, catia_pread_done, req);
1860 static void catia_pread_done(struct tevent_req *subreq)
1862 struct tevent_req *req = tevent_req_callback_data(
1863 subreq, struct tevent_req);
1864 struct catia_pread_state *state = tevent_req_data(
1865 req, struct catia_pread_state);
1867 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1868 TALLOC_FREE(subreq);
1870 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1872 tevent_req_done(req);
1875 static ssize_t catia_pread_recv(struct tevent_req *req,
1876 struct vfs_aio_state *vfs_aio_state)
1878 struct catia_pread_state *state = tevent_req_data(
1879 req, struct catia_pread_state);
1881 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1885 *vfs_aio_state = state->vfs_aio_state;
1889 struct catia_pwrite_state {
1891 struct vfs_aio_state vfs_aio_state;
1892 struct files_struct *fsp;
1893 struct catia_cache *cc;
1896 static void catia_pwrite_done(struct tevent_req *subreq);
1898 static struct tevent_req *catia_pwrite_send(struct vfs_handle_struct *handle,
1899 TALLOC_CTX *mem_ctx,
1900 struct tevent_context *ev,
1901 struct files_struct *fsp,
1906 struct tevent_req *req = NULL, *subreq = NULL;
1907 struct catia_pwrite_state *state = NULL;
1910 req = tevent_req_create(mem_ctx, &state,
1911 struct catia_pwrite_state);
1917 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1919 tevent_req_error(req, errno);
1920 return tevent_req_post(req, ev);
1923 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1925 if (tevent_req_nomem(subreq, req)) {
1926 return tevent_req_post(req, ev);
1928 tevent_req_set_callback(subreq, catia_pwrite_done, req);
1933 static void catia_pwrite_done(struct tevent_req *subreq)
1935 struct tevent_req *req = tevent_req_callback_data(
1936 subreq, struct tevent_req);
1937 struct catia_pwrite_state *state = tevent_req_data(
1938 req, struct catia_pwrite_state);
1940 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1941 TALLOC_FREE(subreq);
1943 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1945 tevent_req_done(req);
1948 static ssize_t catia_pwrite_recv(struct tevent_req *req,
1949 struct vfs_aio_state *vfs_aio_state)
1951 struct catia_pwrite_state *state = tevent_req_data(
1952 req, struct catia_pwrite_state);
1954 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1958 *vfs_aio_state = state->vfs_aio_state;
1962 static off_t catia_lseek(vfs_handle_struct *handle,
1967 struct catia_cache *cc = NULL;
1971 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1976 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1978 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1983 struct catia_fsync_state {
1985 struct vfs_aio_state vfs_aio_state;
1986 struct files_struct *fsp;
1987 struct catia_cache *cc;
1990 static void catia_fsync_done(struct tevent_req *subreq);
1992 static struct tevent_req *catia_fsync_send(struct vfs_handle_struct *handle,
1993 TALLOC_CTX *mem_ctx,
1994 struct tevent_context *ev,
1995 struct files_struct *fsp)
1997 struct tevent_req *req = NULL, *subreq = NULL;
1998 struct catia_fsync_state *state = NULL;
2001 req = tevent_req_create(mem_ctx, &state,
2002 struct catia_fsync_state);
2008 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
2010 tevent_req_error(req, errno);
2011 return tevent_req_post(req, ev);
2014 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
2015 if (tevent_req_nomem(subreq, req)) {
2016 return tevent_req_post(req, ev);
2018 tevent_req_set_callback(subreq, catia_fsync_done, req);
2023 static void catia_fsync_done(struct tevent_req *subreq)
2025 struct tevent_req *req = tevent_req_callback_data(
2026 subreq, struct tevent_req);
2027 struct catia_fsync_state *state = tevent_req_data(
2028 req, struct catia_fsync_state);
2030 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
2031 TALLOC_FREE(subreq);
2033 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
2035 tevent_req_done(req);
2038 static int catia_fsync_recv(struct tevent_req *req,
2039 struct vfs_aio_state *vfs_aio_state)
2041 struct catia_fsync_state *state = tevent_req_data(
2042 req, struct catia_fsync_state);
2044 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2048 *vfs_aio_state = state->vfs_aio_state;
2052 static bool catia_lock(vfs_handle_struct *handle,
2059 struct catia_cache *cc = NULL;
2063 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2068 ok = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
2070 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2075 static int catia_kernel_flock(struct vfs_handle_struct *handle,
2076 struct files_struct *fsp,
2077 uint32_t share_access,
2078 uint32_t access_mask)
2080 struct catia_cache *cc = NULL;
2083 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2088 ret = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_access, access_mask);
2090 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2095 static int catia_linux_setlease(vfs_handle_struct *handle,
2099 struct catia_cache *cc = NULL;
2102 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2107 ret = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
2109 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2114 static bool catia_getlock(vfs_handle_struct *handle,
2121 struct catia_cache *cc = NULL;
2125 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2130 ok = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
2132 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2137 static bool catia_strict_lock_check(struct vfs_handle_struct *handle,
2138 struct files_struct *fsp,
2139 struct lock_struct *plock)
2141 struct catia_cache *cc = NULL;
2145 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2150 ok = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2152 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2157 static NTSTATUS catia_fsctl(struct vfs_handle_struct *handle,
2158 struct files_struct *fsp,
2162 const uint8_t *_in_data,
2164 uint8_t **_out_data,
2165 uint32_t max_out_len,
2169 struct catia_cache *cc = NULL;
2172 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2174 return map_nt_error_from_unix(errno);
2177 result = SMB_VFS_NEXT_FSCTL(handle,
2188 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2193 static NTSTATUS catia_get_compression(vfs_handle_struct *handle,
2194 TALLOC_CTX *mem_ctx,
2195 struct files_struct *fsp,
2196 struct smb_filename *smb_fname,
2197 uint16_t *_compression_fmt)
2200 struct catia_cache *cc = NULL;
2202 struct smb_filename *mapped_smb_fname = NULL;
2203 char *mapped_name = NULL;
2206 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2208 return map_nt_error_from_unix(errno);
2210 mapped_smb_fname = fsp->fsp_name;
2212 result = catia_string_replace_allocate(handle->conn,
2213 smb_fname->base_name,
2215 vfs_translate_to_unix);
2216 if (!NT_STATUS_IS_OK(result)) {
2220 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2226 if (mapped_smb_fname == NULL) {
2227 TALLOC_FREE(mapped_name);
2228 return NT_STATUS_NO_MEMORY;
2231 TALLOC_FREE(mapped_name);
2234 result = SMB_VFS_NEXT_GET_COMPRESSION(handle,
2241 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2243 TALLOC_FREE(mapped_smb_fname);
2249 static NTSTATUS catia_set_compression(vfs_handle_struct *handle,
2250 TALLOC_CTX *mem_ctx,
2251 struct files_struct *fsp,
2252 uint16_t compression_fmt)
2255 struct catia_cache *cc = NULL;
2258 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2260 return map_nt_error_from_unix(errno);
2263 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2266 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2271 static NTSTATUS catia_readdir_attr(struct vfs_handle_struct *handle,
2272 const struct smb_filename *smb_fname_in,
2273 TALLOC_CTX *mem_ctx,
2274 struct readdir_attr_data **pattr_data)
2276 struct smb_filename *smb_fname;
2280 status = catia_string_replace_allocate(handle->conn,
2281 smb_fname_in->base_name,
2283 vfs_translate_to_unix);
2284 if (!NT_STATUS_IS_OK(status)) {
2285 errno = map_errno_from_nt_status(status);
2289 smb_fname = synthetic_smb_fname(talloc_tos(),
2296 status = SMB_VFS_NEXT_READDIR_ATTR(handle, smb_fname, mem_ctx, pattr_data);
2298 TALLOC_FREE(smb_fname);
2303 static NTSTATUS catia_get_dos_attributes(struct vfs_handle_struct *handle,
2304 struct smb_filename *smb_fname,
2307 char *mapped_name = NULL;
2308 const char *path = smb_fname->base_name;
2309 struct smb_filename *mapped_smb_fname = NULL;
2312 status = catia_string_replace_allocate(handle->conn,
2313 path, &mapped_name, vfs_translate_to_unix);
2314 if (!NT_STATUS_IS_OK(status)) {
2315 errno = map_errno_from_nt_status(status);
2318 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2324 if (mapped_smb_fname == NULL) {
2325 TALLOC_FREE(mapped_name);
2326 return NT_STATUS_NO_MEMORY;
2329 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2332 if (NT_STATUS_IS_OK(status)) {
2333 smb_fname->st = mapped_smb_fname->st;
2336 TALLOC_FREE(mapped_name);
2337 TALLOC_FREE(mapped_smb_fname);
2342 static NTSTATUS catia_set_dos_attributes(struct vfs_handle_struct *handle,
2343 const struct smb_filename *smb_fname,
2346 char *mapped_name = NULL;
2347 const char *path = smb_fname->base_name;
2348 struct smb_filename *mapped_smb_fname = NULL;
2351 status = catia_string_replace_allocate(handle->conn,
2352 path, &mapped_name, vfs_translate_to_unix);
2353 if (!NT_STATUS_IS_OK(status)) {
2354 errno = map_errno_from_nt_status(status);
2357 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2363 if (mapped_smb_fname == NULL) {
2364 TALLOC_FREE(mapped_name);
2365 return NT_STATUS_NO_MEMORY;
2368 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2371 TALLOC_FREE(mapped_name);
2372 TALLOC_FREE(mapped_smb_fname);
2377 static NTSTATUS catia_create_dfs_pathat(struct vfs_handle_struct *handle,
2378 struct files_struct *dirfsp,
2379 const struct smb_filename *smb_fname,
2380 const struct referral *reflist,
2381 size_t referral_count)
2383 char *mapped_name = NULL;
2384 const char *path = smb_fname->base_name;
2385 struct smb_filename *mapped_smb_fname = NULL;
2388 status = catia_string_replace_allocate(handle->conn,
2391 vfs_translate_to_unix);
2392 if (!NT_STATUS_IS_OK(status)) {
2393 errno = map_errno_from_nt_status(status);
2396 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2402 if (mapped_smb_fname == NULL) {
2403 TALLOC_FREE(mapped_name);
2404 return NT_STATUS_NO_MEMORY;
2407 status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
2412 TALLOC_FREE(mapped_name);
2413 TALLOC_FREE(mapped_smb_fname);
2417 static NTSTATUS catia_read_dfs_pathat(struct vfs_handle_struct *handle,
2418 TALLOC_CTX *mem_ctx,
2419 struct files_struct *dirfsp,
2420 const struct smb_filename *smb_fname,
2421 struct referral **ppreflist,
2422 size_t *preferral_count)
2424 char *mapped_name = NULL;
2425 const char *path = smb_fname->base_name;
2426 struct smb_filename *mapped_smb_fname = NULL;
2429 status = catia_string_replace_allocate(handle->conn,
2432 vfs_translate_to_unix);
2433 if (!NT_STATUS_IS_OK(status)) {
2434 errno = map_errno_from_nt_status(status);
2437 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2443 if (mapped_smb_fname == NULL) {
2444 TALLOC_FREE(mapped_name);
2445 return NT_STATUS_NO_MEMORY;
2448 status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
2454 TALLOC_FREE(mapped_name);
2455 TALLOC_FREE(mapped_smb_fname);
2459 static struct vfs_fn_pointers vfs_catia_fns = {
2460 .connect_fn = catia_connect,
2462 /* Directory operations */
2463 .mkdirat_fn = catia_mkdirat,
2464 .readdir_attr_fn = catia_readdir_attr,
2466 /* File operations */
2467 .openat_fn = catia_openat,
2468 .pread_fn = catia_pread,
2469 .pread_send_fn = catia_pread_send,
2470 .pread_recv_fn = catia_pread_recv,
2471 .pwrite_fn = catia_pwrite,
2472 .pwrite_send_fn = catia_pwrite_send,
2473 .pwrite_recv_fn = catia_pwrite_recv,
2474 .lseek_fn = catia_lseek,
2475 .renameat_fn = catia_renameat,
2476 .fsync_send_fn = catia_fsync_send,
2477 .fsync_recv_fn = catia_fsync_recv,
2478 .stat_fn = catia_stat,
2479 .fstat_fn = catia_fstat,
2480 .lstat_fn = catia_lstat,
2481 .unlinkat_fn = catia_unlinkat,
2482 .chmod_fn = catia_chmod,
2483 .fchmod_fn = catia_fchmod,
2484 .fchown_fn = catia_fchown,
2485 .lchown_fn = catia_lchown,
2486 .chdir_fn = catia_chdir,
2487 .ntimes_fn = catia_ntimes,
2488 .ftruncate_fn = catia_ftruncate,
2489 .fallocate_fn = catia_fallocate,
2490 .lock_fn = catia_lock,
2491 .kernel_flock_fn = catia_kernel_flock,
2492 .linux_setlease_fn = catia_linux_setlease,
2493 .getlock_fn = catia_getlock,
2494 .realpath_fn = catia_realpath,
2495 .chflags_fn = catia_chflags,
2496 .streaminfo_fn = catia_streaminfo,
2497 .strict_lock_check_fn = catia_strict_lock_check,
2498 .translate_name_fn = catia_translate_name,
2499 .fsctl_fn = catia_fsctl,
2500 .get_dos_attributes_fn = catia_get_dos_attributes,
2501 .get_dos_attributes_send_fn = vfs_not_implemented_get_dos_attributes_send,
2502 .get_dos_attributes_recv_fn = vfs_not_implemented_get_dos_attributes_recv,
2503 .set_dos_attributes_fn = catia_set_dos_attributes,
2504 .fset_dos_attributes_fn = catia_fset_dos_attributes,
2505 .fget_dos_attributes_fn = catia_fget_dos_attributes,
2506 .get_compression_fn = catia_get_compression,
2507 .set_compression_fn = catia_set_compression,
2508 .create_dfs_pathat_fn = catia_create_dfs_pathat,
2509 .read_dfs_pathat_fn = catia_read_dfs_pathat,
2511 /* NT ACL operations. */
2512 .get_nt_acl_at_fn = catia_get_nt_acl_at,
2513 .fget_nt_acl_fn = catia_fget_nt_acl,
2514 .fset_nt_acl_fn = catia_fset_nt_acl,
2516 /* POSIX ACL operations. */
2517 .sys_acl_get_file_fn = catia_sys_acl_get_file,
2518 .sys_acl_get_fd_fn = catia_sys_acl_get_fd,
2519 .sys_acl_blob_get_fd_fn = catia_sys_acl_blob_get_fd,
2520 .sys_acl_set_file_fn = catia_sys_acl_set_file,
2521 .sys_acl_set_fd_fn = catia_sys_acl_set_fd,
2522 .sys_acl_delete_def_file_fn = catia_sys_acl_delete_def_file,
2524 /* EA operations. */
2525 .getxattr_fn = catia_getxattr,
2526 .getxattrat_send_fn = vfs_not_implemented_getxattrat_send,
2527 .getxattrat_recv_fn = vfs_not_implemented_getxattrat_recv,
2528 .listxattr_fn = catia_listxattr,
2529 .removexattr_fn = catia_removexattr,
2530 .setxattr_fn = catia_setxattr,
2531 .fgetxattr_fn = catia_fgetxattr,
2532 .flistxattr_fn = catia_flistxattr,
2533 .fremovexattr_fn = catia_fremovexattr,
2534 .fsetxattr_fn = catia_fsetxattr,
2538 NTSTATUS vfs_catia_init(TALLOC_CTX *ctx)
2542 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
2544 if (!NT_STATUS_IS_OK(ret))
2547 vfs_catia_debug_level = debug_add_class("catia");
2548 if (vfs_catia_debug_level == -1) {
2549 vfs_catia_debug_level = DBGC_VFS;
2550 DEBUG(0, ("vfs_catia: Couldn't register custom debugging "
2553 DEBUG(10, ("vfs_catia: Debug class number of "
2554 "'catia': %d\n", vfs_catia_debug_level));