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"
35 static int vfs_catia_debug_level
= DBGC_VFS
;
38 #define DBGC_CLASS vfs_catia_debug_level
40 #define GLOBAL_SNUM 0xFFFFFFF
42 #define MAP_NUM 0x101 /* max unicode charval / MAP_SIZE */
43 #define T_OFFSET(_v_) ((_v_ % MAP_SIZE))
44 #define T_START(_v_) (((_v_ / MAP_SIZE) * MAP_SIZE))
45 #define T_PICK(_v_) ((_v_ / MAP_SIZE))
47 struct char_mappings
{
48 smb_ucs2_t entry
[MAP_SIZE
][2];
51 struct share_mapping_entry
{
53 struct share_mapping_entry
*next
;
54 struct char_mappings
**mappings
;
59 const struct catia_cache
* const *busy
;
62 char *orig_base_fname
;
66 struct share_mapping_entry
*srt_head
= NULL
;
68 static bool build_table(struct char_mappings
**cmaps
, int value
)
71 int start
= T_START(value
);
73 (*cmaps
) = talloc_zero(NULL
, struct char_mappings
);
78 for (i
= 0; i
< MAP_SIZE
;i
++) {
79 (*cmaps
)->entry
[i
][vfs_translate_to_unix
] = start
+ i
;
80 (*cmaps
)->entry
[i
][vfs_translate_to_windows
] = start
+ i
;
86 static void set_tables(struct char_mappings
**cmaps
,
92 /* set unix -> windows */
93 i
= T_OFFSET(unix_map
);
94 cmaps
[T_PICK(unix_map
)]->entry
[i
][vfs_translate_to_windows
] = windows_map
;
96 /* set windows -> unix */
97 i
= T_OFFSET(windows_map
);
98 cmaps
[T_PICK(windows_map
)]->entry
[i
][vfs_translate_to_unix
] = unix_map
;
101 static bool build_ranges(struct char_mappings
**cmaps
,
106 if (!cmaps
[T_PICK(unix_map
)]) {
107 if (!build_table(&cmaps
[T_PICK(unix_map
)], unix_map
))
111 if (!cmaps
[T_PICK(windows_map
)]) {
112 if (!build_table(&cmaps
[T_PICK(windows_map
)], windows_map
))
116 set_tables(cmaps
, unix_map
, windows_map
);
121 static struct share_mapping_entry
*get_srt(connection_struct
*conn
,
122 struct share_mapping_entry
**global
)
124 struct share_mapping_entry
*share
;
126 for (share
= srt_head
; share
!= NULL
; share
= share
->next
) {
127 if (share
->snum
== GLOBAL_SNUM
)
130 if (share
->snum
== SNUM(conn
))
137 static struct share_mapping_entry
*add_srt(int snum
, const char **mappings
)
143 long unix_map
, windows_map
;
144 struct share_mapping_entry
*ret
= NULL
;
146 ret
= (struct share_mapping_entry
*)
147 TALLOC_ZERO(NULL
, sizeof(struct share_mapping_entry
) +
148 (mappings
? (MAP_NUM
* sizeof(struct char_mappings
*)) : 0));
155 ret
->next
= srt_head
;
159 ret
->mappings
= (struct char_mappings
**) ((unsigned char*) ret
+
160 sizeof(struct share_mapping_entry
));
161 memset(ret
->mappings
, 0,
162 MAP_NUM
* sizeof(struct char_mappings
*));
164 ret
->mappings
= NULL
;
169 * catia mappings are of the form :
170 * UNIX char (in 0xnn hex) : WINDOWS char (in 0xnn hex)
172 * multiple mappings are comma separated in smb.conf
174 for (i
=0;mappings
[i
];i
++) {
175 fstrcpy(mapping
, mappings
[i
]);
176 unix_map
= strtol(mapping
, &tmp
, 16);
177 if (unix_map
== 0 && errno
== EINVAL
) {
178 DEBUG(0, ("INVALID CATIA MAPPINGS - %s\n", mapping
));
181 windows_map
= strtol(++tmp
, NULL
, 16);
182 if (windows_map
== 0 && errno
== EINVAL
) {
183 DEBUG(0, ("INVALID CATIA MAPPINGS - %s\n", mapping
));
187 if (!build_ranges(ret
->mappings
, unix_map
, windows_map
)) {
188 DEBUG(0, ("TABLE ERROR - CATIA MAPPINGS - %s\n", mapping
));
196 static bool init_mappings(connection_struct
*conn
,
197 struct share_mapping_entry
**selected_out
)
199 const char **mappings
= NULL
;
200 struct share_mapping_entry
*share_level
= NULL
;
201 struct share_mapping_entry
*global
= NULL
;
203 /* check srt cache */
204 share_level
= get_srt(conn
, &global
);
206 *selected_out
= share_level
;
207 return (share_level
->mappings
!= NULL
);
210 /* see if we have a global setting */
213 mappings
= lp_parm_string_list(-1, "catia", "mappings", NULL
);
214 global
= add_srt(GLOBAL_SNUM
, mappings
);
217 /* no global setting - what about share level ? */
218 mappings
= lp_parm_string_list(SNUM(conn
), "catia", "mappings", NULL
);
219 share_level
= add_srt(SNUM(conn
), mappings
);
221 if (share_level
->mappings
) {
222 (*selected_out
) = share_level
;
225 if (global
->mappings
) {
226 share_level
->mappings
= global
->mappings
;
227 (*selected_out
) = share_level
;
234 static NTSTATUS
catia_string_replace_allocate(connection_struct
*conn
,
237 enum vfs_translate_direction direction
)
239 static smb_ucs2_t
*tmpbuf
= NULL
;
241 struct share_mapping_entry
*selected
;
242 struct char_mappings
*map
= NULL
;
243 size_t converted_size
;
244 TALLOC_CTX
*ctx
= talloc_tos();
246 if (!init_mappings(conn
, &selected
)) {
247 /* No mappings found. Just use the old name */
248 *mapped_name
= talloc_strdup(NULL
, name_in
);
251 return NT_STATUS_NO_MEMORY
;
256 if ((push_ucs2_talloc(ctx
, &tmpbuf
, name_in
,
257 &converted_size
)) == false) {
258 return map_nt_error_from_unix(errno
);
264 map
= selected
->mappings
[T_PICK((*ptr
))];
270 *ptr
= map
->entry
[T_OFFSET((*ptr
))][direction
];
273 if ((pull_ucs2_talloc(ctx
, mapped_name
, tmpbuf
,
274 &converted_size
)) == false) {
276 return map_nt_error_from_unix(errno
);
282 static DIR *catia_opendir(vfs_handle_struct
*handle
,
283 const struct smb_filename
*smb_fname
,
287 char *name_mapped
= NULL
;
290 struct smb_filename
*mapped_smb_fname
= NULL
;
292 status
= catia_string_replace_allocate(handle
->conn
,
293 smb_fname
->base_name
,
295 vfs_translate_to_unix
);
296 if (!NT_STATUS_IS_OK(status
)) {
297 errno
= map_errno_from_nt_status(status
);
301 mapped_smb_fname
= synthetic_smb_fname(talloc_tos(),
306 if (mapped_smb_fname
== NULL
) {
307 TALLOC_FREE(mapped_smb_fname
);
312 ret
= SMB_VFS_NEXT_OPENDIR(handle
, mapped_smb_fname
, mask
, attr
);
314 TALLOC_FREE(name_mapped
);
315 TALLOC_FREE(mapped_smb_fname
);
321 * TRANSLATE_NAME call which converts the given name to
322 * "WINDOWS displayable" name
324 static NTSTATUS
catia_translate_name(struct vfs_handle_struct
*handle
,
325 const char *orig_name
,
326 enum vfs_translate_direction direction
,
332 NTSTATUS status
, ret
;
335 * Copy the supplied name and free the memory for mapped_name,
336 * already allocated by the caller.
337 * We will be allocating new memory for mapped_name in
338 * catia_string_replace_allocate
340 name
= talloc_strdup(talloc_tos(), orig_name
);
343 return NT_STATUS_NO_MEMORY
;
345 status
= catia_string_replace_allocate(handle
->conn
, name
,
346 &mapped_name
, direction
);
349 if (!NT_STATUS_IS_OK(status
)) {
353 ret
= SMB_VFS_NEXT_TRANSLATE_NAME(handle
, mapped_name
, direction
,
354 mem_ctx
, pmapped_name
);
356 if (NT_STATUS_EQUAL(ret
, NT_STATUS_NONE_MAPPED
)) {
357 *pmapped_name
= talloc_move(mem_ctx
, &mapped_name
);
358 /* we need to return the former translation result here */
361 TALLOC_FREE(mapped_name
);
367 #define CATIA_DEBUG_CC(lvl, cc, fsp) \
368 catia_debug_cc((lvl), (cc), (fsp), __location__);
370 static void catia_debug_cc(int lvl
,
371 struct catia_cache
*cc
,
373 const char *location
)
375 DEBUG(lvl
, ("%s: cc [0x%p] cc->busy [0x%p] "
377 "fsp [0x%p] fsp name [%s] "
380 "orig_base_fname [%s] "
384 cc
->is_fsp_ext
? "yes" : "no",
385 fsp
, fsp_str_dbg(fsp
),
386 cc
->orig_fname
, cc
->fname
,
387 cc
->orig_base_fname
, cc
->base_fname
));
390 static void catia_free_cc(struct catia_cache
**_cc
,
391 vfs_handle_struct
*handle
,
394 struct catia_cache
*cc
= *_cc
;
396 if (cc
->is_fsp_ext
) {
397 VFS_REMOVE_FSP_EXTENSION(handle
, fsp
);
406 static struct catia_cache
*catia_validate_and_apply_cc(
407 vfs_handle_struct
*handle
,
409 const struct catia_cache
* const *busy
,
410 bool *make_tmp_cache
)
412 struct catia_cache
*cc
= NULL
;
414 *make_tmp_cache
= false;
416 cc
= (struct catia_cache
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
421 if (cc
->busy
!= NULL
) {
422 if (cc
->busy
== busy
) {
423 /* This should never happen */
424 CATIA_DEBUG_CC(0, cc
, fsp
);
425 smb_panic(__location__
);
429 * Recursion. Validate names, the names in the fsp's should be
430 * the translated names we had set.
433 if ((cc
->fname
!= fsp
->fsp_name
->base_name
)
435 ((fsp
->base_fsp
!= NULL
) &&
436 (cc
->base_fname
!= fsp
->base_fsp
->fsp_name
->base_name
)))
438 CATIA_DEBUG_CC(10, cc
, fsp
);
441 * Names changed. Setting don't expose the cache on the
442 * fsp and ask the caller to create a temporary cache.
444 *make_tmp_cache
= true;
449 * Ok, a validated cache while in a recursion, just let the
450 * caller detect that cc->busy is != busy and there's
451 * nothing else to do.
453 CATIA_DEBUG_CC(10, cc
, fsp
);
457 /* Not in a recursion */
459 if ((cc
->orig_fname
!= fsp
->fsp_name
->base_name
)
461 ((fsp
->base_fsp
!= NULL
) &&
462 (cc
->orig_base_fname
!= fsp
->base_fsp
->fsp_name
->base_name
)))
465 * fsp names changed, this can happen in an rename op.
466 * Trigger recreation as a full fledged fsp extension.
469 CATIA_DEBUG_CC(10, cc
, fsp
);
470 catia_free_cc(&cc
, handle
, fsp
);
476 * Ok, we found a valid cache entry, no recursion. Just set translated
477 * names from the cache and mark the cc as busy.
479 fsp
->fsp_name
->base_name
= cc
->fname
;
480 if (fsp
->base_fsp
!= NULL
) {
481 fsp
->base_fsp
->fsp_name
->base_name
= cc
->base_fname
;
485 CATIA_DEBUG_CC(10, cc
, fsp
);
489 #define CATIA_FETCH_FSP_PRE_NEXT(mem_ctx, handle, fsp, _cc) \
490 catia_fetch_fsp_pre_next((mem_ctx), (handle), (fsp), (_cc), __func__);
492 static int catia_fetch_fsp_pre_next(TALLOC_CTX
*mem_ctx
,
493 vfs_handle_struct
*handle
,
495 struct catia_cache
**_cc
,
496 const char *function
)
498 const struct catia_cache
* const *busy
=
499 (const struct catia_cache
* const *)_cc
;
500 struct catia_cache
*cc
= NULL
;
502 bool make_tmp_cache
= false;
506 DBG_DEBUG("Called from [%s]\n", function
);
508 cc
= catia_validate_and_apply_cc(handle
,
513 if (cc
->busy
!= busy
) {
520 if (!make_tmp_cache
) {
521 cc
= (struct catia_cache
*)VFS_ADD_FSP_EXTENSION(
522 handle
, fsp
, struct catia_cache
, NULL
);
526 *cc
= (struct catia_cache
) {
530 mem_ctx
= VFS_MEMCTX_FSP_EXTENSION(handle
, fsp
);
531 if (mem_ctx
== NULL
) {
532 DBG_ERR("VFS_MEMCTX_FSP_EXTENSION failed\n");
533 catia_free_cc(&cc
, handle
, fsp
);
537 cc
= talloc_zero(mem_ctx
, struct catia_cache
);
545 status
= catia_string_replace_allocate(handle
->conn
,
546 fsp
->fsp_name
->base_name
,
548 vfs_translate_to_unix
);
549 if (!NT_STATUS_IS_OK(status
)) {
550 catia_free_cc(&cc
, handle
, fsp
);
551 errno
= map_errno_from_nt_status(status
);
554 talloc_steal(mem_ctx
, cc
->fname
);
556 if (fsp
->base_fsp
!= NULL
) {
557 status
= catia_string_replace_allocate(
559 fsp
->base_fsp
->fsp_name
->base_name
,
561 vfs_translate_to_unix
);
562 if (!NT_STATUS_IS_OK(status
)) {
563 catia_free_cc(&cc
, handle
, fsp
);
564 errno
= map_errno_from_nt_status(status
);
567 talloc_steal(mem_ctx
, cc
->base_fname
);
570 cc
->orig_fname
= fsp
->fsp_name
->base_name
;
571 fsp
->fsp_name
->base_name
= cc
->fname
;
573 if (fsp
->base_fsp
!= NULL
) {
574 cc
->orig_base_fname
= fsp
->base_fsp
->fsp_name
->base_name
;
575 fsp
->base_fsp
->fsp_name
->base_name
= cc
->base_fname
;
579 CATIA_DEBUG_CC(10, cc
, fsp
);
586 #define CATIA_FETCH_FSP_POST_NEXT(_cc, fsp) do { \
587 int saved_errno = errno; \
588 catia_fetch_fsp_post_next((_cc), (fsp), __func__); \
589 errno = saved_errno; \
592 static void catia_fetch_fsp_post_next(struct catia_cache
**_cc
,
594 const char *function
)
596 const struct catia_cache
* const *busy
=
597 (const struct catia_cache
* const *)_cc
;
598 struct catia_cache
*cc
= *_cc
;
600 DBG_DEBUG("Called from [%s]\n", function
);
604 * This can happen when recursing in the VFS on the fsp when the
605 * pre_next func noticed the recursion and set out cc pointer to
611 if (cc
->busy
!= busy
) {
612 CATIA_DEBUG_CC(0, cc
, fsp
);
613 smb_panic(__location__
);
620 fsp
->fsp_name
->base_name
= cc
->orig_fname
;
621 if (fsp
->base_fsp
!= NULL
) {
622 fsp
->base_fsp
->fsp_name
->base_name
= cc
->orig_base_fname
;
625 CATIA_DEBUG_CC(10, cc
, fsp
);
627 if (!cc
->is_fsp_ext
) {
634 static int catia_open(vfs_handle_struct
*handle
,
635 struct smb_filename
*smb_fname
,
640 struct catia_cache
*cc
= NULL
;
641 char *orig_smb_fname
= smb_fname
->base_name
;
642 char *mapped_smb_fname
= NULL
;
646 status
= catia_string_replace_allocate(handle
->conn
,
647 smb_fname
->base_name
,
649 vfs_translate_to_unix
);
650 if (!NT_STATUS_IS_OK(status
)) {
654 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
656 TALLOC_FREE(mapped_smb_fname
);
660 smb_fname
->base_name
= mapped_smb_fname
;
661 ret
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
662 smb_fname
->base_name
= orig_smb_fname
;
664 TALLOC_FREE(mapped_smb_fname
);
665 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
670 static int catia_rename(vfs_handle_struct
*handle
,
671 const struct smb_filename
*smb_fname_src
,
672 const struct smb_filename
*smb_fname_dst
)
674 TALLOC_CTX
*ctx
= talloc_tos();
675 struct smb_filename
*smb_fname_src_tmp
= NULL
;
676 struct smb_filename
*smb_fname_dst_tmp
= NULL
;
677 char *src_name_mapped
= NULL
;
678 char *dst_name_mapped
= NULL
;
682 status
= catia_string_replace_allocate(handle
->conn
,
683 smb_fname_src
->base_name
,
684 &src_name_mapped
, vfs_translate_to_unix
);
685 if (!NT_STATUS_IS_OK(status
)) {
686 errno
= map_errno_from_nt_status(status
);
690 status
= catia_string_replace_allocate(handle
->conn
,
691 smb_fname_dst
->base_name
,
692 &dst_name_mapped
, vfs_translate_to_unix
);
693 if (!NT_STATUS_IS_OK(status
)) {
694 errno
= map_errno_from_nt_status(status
);
698 /* Setup temporary smb_filename structs. */
699 smb_fname_src_tmp
= cp_smb_filename(ctx
, smb_fname_src
);
700 if (smb_fname_src_tmp
== NULL
) {
705 smb_fname_dst_tmp
= cp_smb_filename(ctx
, smb_fname_dst
);
706 if (smb_fname_dst_tmp
== NULL
) {
711 smb_fname_src_tmp
->base_name
= src_name_mapped
;
712 smb_fname_dst_tmp
->base_name
= dst_name_mapped
;
713 DEBUG(10, ("converted old name: %s\n",
714 smb_fname_str_dbg(smb_fname_src_tmp
)));
715 DEBUG(10, ("converted new name: %s\n",
716 smb_fname_str_dbg(smb_fname_dst_tmp
)));
718 ret
= SMB_VFS_NEXT_RENAME(handle
, smb_fname_src_tmp
,
721 TALLOC_FREE(src_name_mapped
);
722 TALLOC_FREE(dst_name_mapped
);
723 TALLOC_FREE(smb_fname_src_tmp
);
724 TALLOC_FREE(smb_fname_dst_tmp
);
728 static int catia_stat(vfs_handle_struct
*handle
,
729 struct smb_filename
*smb_fname
)
736 status
= catia_string_replace_allocate(handle
->conn
,
737 smb_fname
->base_name
,
738 &name
, vfs_translate_to_unix
);
739 if (!NT_STATUS_IS_OK(status
)) {
740 errno
= map_errno_from_nt_status(status
);
744 tmp_base_name
= smb_fname
->base_name
;
745 smb_fname
->base_name
= name
;
747 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
748 smb_fname
->base_name
= tmp_base_name
;
754 static int catia_lstat(vfs_handle_struct
*handle
,
755 struct smb_filename
*smb_fname
)
762 status
= catia_string_replace_allocate(handle
->conn
,
763 smb_fname
->base_name
,
764 &name
, vfs_translate_to_unix
);
765 if (!NT_STATUS_IS_OK(status
)) {
766 errno
= map_errno_from_nt_status(status
);
770 tmp_base_name
= smb_fname
->base_name
;
771 smb_fname
->base_name
= name
;
773 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
774 smb_fname
->base_name
= tmp_base_name
;
780 static int catia_unlink(vfs_handle_struct
*handle
,
781 const struct smb_filename
*smb_fname
)
783 struct smb_filename
*smb_fname_tmp
= NULL
;
788 status
= catia_string_replace_allocate(handle
->conn
,
789 smb_fname
->base_name
,
790 &name
, vfs_translate_to_unix
);
791 if (!NT_STATUS_IS_OK(status
)) {
792 errno
= map_errno_from_nt_status(status
);
796 /* Setup temporary smb_filename structs. */
797 smb_fname_tmp
= cp_smb_filename(talloc_tos(), smb_fname
);
798 if (smb_fname_tmp
== NULL
) {
803 smb_fname_tmp
->base_name
= name
;
804 ret
= SMB_VFS_NEXT_UNLINK(handle
, smb_fname_tmp
);
805 TALLOC_FREE(smb_fname_tmp
);
811 static int catia_chown(vfs_handle_struct
*handle
,
812 const struct smb_filename
*smb_fname
,
820 struct smb_filename
*catia_smb_fname
= NULL
;
822 status
= catia_string_replace_allocate(handle
->conn
,
823 smb_fname
->base_name
,
825 vfs_translate_to_unix
);
826 if (!NT_STATUS_IS_OK(status
)) {
827 errno
= map_errno_from_nt_status(status
);
830 catia_smb_fname
= synthetic_smb_fname(talloc_tos(),
835 if (catia_smb_fname
== NULL
) {
841 ret
= SMB_VFS_NEXT_CHOWN(handle
, catia_smb_fname
, uid
, gid
);
844 TALLOC_FREE(catia_smb_fname
);
849 static int catia_lchown(vfs_handle_struct
*handle
,
850 const struct smb_filename
*smb_fname
,
858 struct smb_filename
*catia_smb_fname
= NULL
;
860 status
= catia_string_replace_allocate(handle
->conn
,
861 smb_fname
->base_name
,
863 vfs_translate_to_unix
);
864 if (!NT_STATUS_IS_OK(status
)) {
865 errno
= map_errno_from_nt_status(status
);
868 catia_smb_fname
= synthetic_smb_fname(talloc_tos(),
873 if (catia_smb_fname
== NULL
) {
879 ret
= SMB_VFS_NEXT_LCHOWN(handle
, catia_smb_fname
, uid
, gid
);
882 TALLOC_FREE(catia_smb_fname
);
887 static int catia_chmod(vfs_handle_struct
*handle
,
888 const struct smb_filename
*smb_fname
,
895 struct smb_filename
*catia_smb_fname
= NULL
;
897 status
= catia_string_replace_allocate(handle
->conn
,
898 smb_fname
->base_name
,
900 vfs_translate_to_unix
);
901 if (!NT_STATUS_IS_OK(status
)) {
902 errno
= map_errno_from_nt_status(status
);
905 catia_smb_fname
= synthetic_smb_fname(talloc_tos(),
910 if (catia_smb_fname
== NULL
) {
916 ret
= SMB_VFS_NEXT_CHMOD(handle
, catia_smb_fname
, mode
);
919 TALLOC_FREE(catia_smb_fname
);
924 static int catia_rmdir(vfs_handle_struct
*handle
,
925 const struct smb_filename
*smb_fname
)
930 struct smb_filename
*catia_smb_fname
= NULL
;
932 status
= catia_string_replace_allocate(handle
->conn
,
933 smb_fname
->base_name
,
935 vfs_translate_to_unix
);
936 if (!NT_STATUS_IS_OK(status
)) {
937 errno
= map_errno_from_nt_status(status
);
940 catia_smb_fname
= synthetic_smb_fname(talloc_tos(),
945 if (catia_smb_fname
== NULL
) {
951 ret
= SMB_VFS_NEXT_RMDIR(handle
, catia_smb_fname
);
953 TALLOC_FREE(catia_smb_fname
);
958 static int catia_mkdir(vfs_handle_struct
*handle
,
959 const struct smb_filename
*smb_fname
,
965 struct smb_filename
*catia_smb_fname
= NULL
;
967 status
= catia_string_replace_allocate(handle
->conn
,
968 smb_fname
->base_name
,
970 vfs_translate_to_unix
);
971 if (!NT_STATUS_IS_OK(status
)) {
972 errno
= map_errno_from_nt_status(status
);
975 catia_smb_fname
= synthetic_smb_fname(talloc_tos(),
980 if (catia_smb_fname
== NULL
) {
986 ret
= SMB_VFS_NEXT_MKDIR(handle
, catia_smb_fname
, mode
);
988 TALLOC_FREE(catia_smb_fname
);
993 static int catia_chdir(vfs_handle_struct
*handle
,
1000 status
= catia_string_replace_allocate(handle
->conn
, path
,
1001 &name
, vfs_translate_to_unix
);
1002 if (!NT_STATUS_IS_OK(status
)) {
1003 errno
= map_errno_from_nt_status(status
);
1007 ret
= SMB_VFS_NEXT_CHDIR(handle
, name
);
1013 static int catia_ntimes(vfs_handle_struct
*handle
,
1014 const struct smb_filename
*smb_fname
,
1015 struct smb_file_time
*ft
)
1017 struct smb_filename
*smb_fname_tmp
= NULL
;
1022 status
= catia_string_replace_allocate(handle
->conn
,
1023 smb_fname
->base_name
,
1024 &name
, vfs_translate_to_unix
);
1025 if (!NT_STATUS_IS_OK(status
)) {
1026 errno
= map_errno_from_nt_status(status
);
1030 smb_fname_tmp
= cp_smb_filename(talloc_tos(), smb_fname
);
1031 if (smb_fname_tmp
== NULL
) {
1036 smb_fname_tmp
->base_name
= name
;
1037 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname_tmp
, ft
);
1039 TALLOC_FREE(smb_fname_tmp
);
1045 catia_realpath(vfs_handle_struct
*handle
, const char *path
)
1047 char *mapped_name
= NULL
;
1051 status
= catia_string_replace_allocate(handle
->conn
, path
,
1052 &mapped_name
, vfs_translate_to_unix
);
1053 if (!NT_STATUS_IS_OK(status
)) {
1054 errno
= map_errno_from_nt_status(status
);
1058 ret
= SMB_VFS_NEXT_REALPATH(handle
, mapped_name
);
1059 TALLOC_FREE(mapped_name
);
1064 static int catia_chflags(struct vfs_handle_struct
*handle
,
1065 const char *path
, unsigned int flags
)
1067 char *mapped_name
= NULL
;
1071 status
= catia_string_replace_allocate(handle
->conn
, path
,
1072 &mapped_name
, vfs_translate_to_unix
);
1073 if (!NT_STATUS_IS_OK(status
)) {
1074 errno
= map_errno_from_nt_status(status
);
1078 ret
= SMB_VFS_NEXT_CHFLAGS(handle
, mapped_name
, flags
);
1079 TALLOC_FREE(mapped_name
);
1085 catia_streaminfo(struct vfs_handle_struct
*handle
,
1086 struct files_struct
*fsp
,
1087 const struct smb_filename
*smb_fname
,
1088 TALLOC_CTX
*mem_ctx
,
1089 unsigned int *_num_streams
,
1090 struct stream_struct
**_streams
)
1092 char *mapped_name
= NULL
;
1095 struct smb_filename
*catia_smb_fname
= NULL
;
1096 unsigned int num_streams
= 0;
1097 struct stream_struct
*streams
= NULL
;
1102 status
= catia_string_replace_allocate(handle
->conn
,
1103 smb_fname
->base_name
,
1105 vfs_translate_to_unix
);
1106 if (!NT_STATUS_IS_OK(status
)) {
1107 errno
= map_errno_from_nt_status(status
);
1111 catia_smb_fname
= synthetic_smb_fname(talloc_tos(),
1116 if (catia_smb_fname
== NULL
) {
1117 TALLOC_FREE(mapped_name
);
1118 return NT_STATUS_NO_MEMORY
;
1121 status
= SMB_VFS_NEXT_STREAMINFO(handle
, fsp
, catia_smb_fname
,
1122 mem_ctx
, &num_streams
, &streams
);
1123 TALLOC_FREE(mapped_name
);
1124 TALLOC_FREE(catia_smb_fname
);
1125 if (!NT_STATUS_IS_OK(status
)) {
1130 * Translate stream names just like the base names
1132 for (i
= 0; i
< num_streams
; i
++) {
1134 * Strip ":" prefix and ":$DATA" suffix to get a
1135 * "pure" stream name and only translate that.
1137 void *old_ptr
= streams
[i
].name
;
1138 char *stream_name
= streams
[i
].name
+ 1;
1139 char *stream_type
= strrchr_m(stream_name
, ':');
1141 if (stream_type
!= NULL
) {
1142 *stream_type
= '\0';
1146 status
= catia_string_replace_allocate(handle
->conn
, stream_name
,
1147 &mapped_name
, vfs_translate_to_windows
);
1148 if (!NT_STATUS_IS_OK(status
)) {
1149 TALLOC_FREE(streams
);
1153 if (stream_type
!= NULL
) {
1154 streams
[i
].name
= talloc_asprintf(streams
, ":%s:%s",
1155 mapped_name
, stream_type
);
1157 streams
[i
].name
= talloc_asprintf(streams
, ":%s",
1160 TALLOC_FREE(mapped_name
);
1161 TALLOC_FREE(old_ptr
);
1162 if (streams
[i
].name
== NULL
) {
1163 TALLOC_FREE(streams
);
1164 return NT_STATUS_NO_MEMORY
;
1168 *_num_streams
= num_streams
;
1169 *_streams
= streams
;
1170 return NT_STATUS_OK
;
1174 catia_get_nt_acl(struct vfs_handle_struct
*handle
,
1175 const struct smb_filename
*smb_fname
,
1176 uint32_t security_info
,
1177 TALLOC_CTX
*mem_ctx
,
1178 struct security_descriptor
**ppdesc
)
1180 char *mapped_name
= NULL
;
1181 const char *path
= smb_fname
->base_name
;
1182 struct smb_filename
*mapped_smb_fname
= NULL
;
1185 status
= catia_string_replace_allocate(handle
->conn
,
1186 path
, &mapped_name
, vfs_translate_to_unix
);
1187 if (!NT_STATUS_IS_OK(status
)) {
1188 errno
= map_errno_from_nt_status(status
);
1191 mapped_smb_fname
= synthetic_smb_fname(talloc_tos(),
1196 if (mapped_smb_fname
== NULL
) {
1197 TALLOC_FREE(mapped_name
);
1198 return NT_STATUS_NO_MEMORY
;
1201 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, mapped_smb_fname
,
1202 security_info
, mem_ctx
, ppdesc
);
1203 TALLOC_FREE(mapped_name
);
1204 TALLOC_FREE(mapped_smb_fname
);
1210 catia_chmod_acl(vfs_handle_struct
*handle
,
1211 const struct smb_filename
*smb_fname
,
1214 char *mapped_name
= NULL
;
1215 struct smb_filename
*mapped_smb_fname
= NULL
;
1220 status
= catia_string_replace_allocate(handle
->conn
,
1221 smb_fname
->base_name
,
1223 vfs_translate_to_unix
);
1224 if (!NT_STATUS_IS_OK(status
)) {
1225 errno
= map_errno_from_nt_status(status
);
1229 mapped_smb_fname
= synthetic_smb_fname(talloc_tos(),
1234 if (mapped_smb_fname
== NULL
) {
1235 TALLOC_FREE(mapped_name
);
1239 ret
= SMB_VFS_NEXT_CHMOD_ACL(handle
, mapped_smb_fname
, mode
);
1240 saved_errno
= errno
;
1241 TALLOC_FREE(mapped_name
);
1242 TALLOC_FREE(mapped_smb_fname
);
1243 errno
= saved_errno
;
1248 catia_sys_acl_get_file(vfs_handle_struct
*handle
,
1249 const struct smb_filename
*smb_fname
,
1250 SMB_ACL_TYPE_T type
,
1251 TALLOC_CTX
*mem_ctx
)
1253 char *mapped_name
= NULL
;
1254 struct smb_filename
*mapped_smb_fname
= NULL
;
1257 int saved_errno
= 0;
1259 status
= catia_string_replace_allocate(handle
->conn
,
1260 smb_fname
->base_name
,
1262 vfs_translate_to_unix
);
1263 if (!NT_STATUS_IS_OK(status
)) {
1264 errno
= map_errno_from_nt_status(status
);
1265 return (SMB_ACL_T
)NULL
;
1268 mapped_smb_fname
= synthetic_smb_fname(talloc_tos(),
1273 if (mapped_smb_fname
== NULL
) {
1274 TALLOC_FREE(mapped_name
);
1276 return (SMB_ACL_T
)NULL
;
1279 ret
= SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, mapped_smb_fname
,
1281 if (ret
== (SMB_ACL_T
)NULL
) {
1282 saved_errno
= errno
;
1284 TALLOC_FREE(mapped_smb_fname
);
1285 TALLOC_FREE(mapped_name
);
1286 if (saved_errno
!= 0) {
1287 errno
= saved_errno
;
1293 catia_sys_acl_set_file(vfs_handle_struct
*handle
,
1294 const struct smb_filename
*smb_fname
,
1295 SMB_ACL_TYPE_T type
,
1298 struct smb_filename
*mapped_smb_fname
= NULL
;
1299 int saved_errno
= 0;
1300 char *mapped_name
= NULL
;
1304 status
= catia_string_replace_allocate(handle
->conn
,
1305 smb_fname
->base_name
,
1307 vfs_translate_to_unix
);
1308 if (!NT_STATUS_IS_OK(status
)) {
1309 errno
= map_errno_from_nt_status(status
);
1313 mapped_smb_fname
= synthetic_smb_fname(talloc_tos(),
1318 if (mapped_smb_fname
== NULL
) {
1319 TALLOC_FREE(mapped_name
);
1324 ret
= SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, mapped_smb_fname
,
1327 saved_errno
= errno
;
1329 TALLOC_FREE(mapped_smb_fname
);
1330 TALLOC_FREE(mapped_name
);
1331 if (saved_errno
!= 0) {
1332 errno
= saved_errno
;
1338 catia_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1339 const struct smb_filename
*smb_fname
)
1341 struct smb_filename
*mapped_smb_fname
= NULL
;
1342 int saved_errno
= 0;
1343 char *mapped_name
= NULL
;
1347 status
= catia_string_replace_allocate(handle
->conn
,
1348 smb_fname
->base_name
,
1350 vfs_translate_to_unix
);
1351 if (!NT_STATUS_IS_OK(status
)) {
1352 errno
= map_errno_from_nt_status(status
);
1356 mapped_smb_fname
= synthetic_smb_fname(talloc_tos(),
1361 if (mapped_smb_fname
== NULL
) {
1362 TALLOC_FREE(mapped_name
);
1366 ret
= SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, mapped_smb_fname
);
1368 saved_errno
= errno
;
1370 TALLOC_FREE(mapped_smb_fname
);
1371 TALLOC_FREE(mapped_name
);
1372 if (saved_errno
!= 0) {
1373 errno
= saved_errno
;
1379 catia_getxattr(vfs_handle_struct
*handle
,
1380 const struct smb_filename
*smb_fname
,
1385 struct smb_filename
*mapped_smb_fname
= NULL
;
1386 char *mapped_name
= NULL
;
1387 char *mapped_ea_name
= NULL
;
1390 int saved_errno
= 0;
1392 status
= catia_string_replace_allocate(handle
->conn
,
1393 smb_fname
->base_name
,
1395 vfs_translate_to_unix
);
1396 if (!NT_STATUS_IS_OK(status
)) {
1397 errno
= map_errno_from_nt_status(status
);
1401 status
= catia_string_replace_allocate(handle
->conn
,
1402 name
, &mapped_ea_name
, vfs_translate_to_unix
);
1403 if (!NT_STATUS_IS_OK(status
)) {
1404 TALLOC_FREE(mapped_name
);
1405 errno
= map_errno_from_nt_status(status
);
1409 mapped_smb_fname
= synthetic_smb_fname(talloc_tos(),
1414 if (mapped_smb_fname
== NULL
) {
1415 TALLOC_FREE(mapped_name
);
1416 TALLOC_FREE(mapped_ea_name
);
1421 ret
= SMB_VFS_NEXT_GETXATTR(handle
, mapped_smb_fname
,
1422 mapped_ea_name
, value
, size
);
1424 saved_errno
= errno
;
1426 TALLOC_FREE(mapped_name
);
1427 TALLOC_FREE(mapped_ea_name
);
1428 TALLOC_FREE(mapped_smb_fname
);
1429 if (saved_errno
!= 0) {
1430 errno
= saved_errno
;
1437 catia_listxattr(vfs_handle_struct
*handle
,
1438 const struct smb_filename
*smb_fname
,
1439 char *list
, size_t size
)
1441 struct smb_filename
*mapped_smb_fname
= NULL
;
1442 char *mapped_name
= NULL
;
1445 int saved_errno
= 0;
1447 status
= catia_string_replace_allocate(handle
->conn
,
1448 smb_fname
->base_name
,
1450 vfs_translate_to_unix
);
1451 if (!NT_STATUS_IS_OK(status
)) {
1452 errno
= map_errno_from_nt_status(status
);
1456 mapped_smb_fname
= synthetic_smb_fname(talloc_tos(),
1461 if (mapped_smb_fname
== NULL
) {
1462 TALLOC_FREE(mapped_name
);
1467 ret
= SMB_VFS_NEXT_LISTXATTR(handle
, mapped_smb_fname
, list
, size
);
1469 saved_errno
= errno
;
1471 TALLOC_FREE(mapped_name
);
1472 TALLOC_FREE(mapped_smb_fname
);
1473 if (saved_errno
!= 0) {
1474 errno
= saved_errno
;
1481 catia_removexattr(vfs_handle_struct
*handle
,
1482 const struct smb_filename
*smb_fname
,
1485 struct smb_filename
*mapped_smb_fname
= NULL
;
1486 char *mapped_name
= NULL
;
1487 char *mapped_ea_name
= NULL
;
1490 int saved_errno
= 0;
1492 status
= catia_string_replace_allocate(handle
->conn
,
1493 smb_fname
->base_name
,
1495 vfs_translate_to_unix
);
1496 if (!NT_STATUS_IS_OK(status
)) {
1497 errno
= map_errno_from_nt_status(status
);
1501 status
= catia_string_replace_allocate(handle
->conn
,
1502 name
, &mapped_ea_name
, vfs_translate_to_unix
);
1503 if (!NT_STATUS_IS_OK(status
)) {
1504 TALLOC_FREE(mapped_name
);
1505 errno
= map_errno_from_nt_status(status
);
1509 mapped_smb_fname
= synthetic_smb_fname(talloc_tos(),
1514 if (mapped_smb_fname
== NULL
) {
1515 TALLOC_FREE(mapped_name
);
1516 TALLOC_FREE(mapped_ea_name
);
1521 ret
= SMB_VFS_NEXT_REMOVEXATTR(handle
, mapped_smb_fname
,
1524 saved_errno
= errno
;
1526 TALLOC_FREE(mapped_name
);
1527 TALLOC_FREE(mapped_ea_name
);
1528 TALLOC_FREE(mapped_smb_fname
);
1529 if (saved_errno
!= 0) {
1530 errno
= saved_errno
;
1537 catia_setxattr(vfs_handle_struct
*handle
,
1538 const struct smb_filename
*smb_fname
,
1544 struct smb_filename
*mapped_smb_fname
= NULL
;
1545 char *mapped_name
= NULL
;
1546 char *mapped_ea_name
= NULL
;
1549 int saved_errno
= 0;
1551 status
= catia_string_replace_allocate(handle
->conn
,
1552 smb_fname
->base_name
,
1554 vfs_translate_to_unix
);
1555 if (!NT_STATUS_IS_OK(status
)) {
1556 errno
= map_errno_from_nt_status(status
);
1560 status
= catia_string_replace_allocate(handle
->conn
,
1561 name
, &mapped_ea_name
, vfs_translate_to_unix
);
1562 if (!NT_STATUS_IS_OK(status
)) {
1563 TALLOC_FREE(mapped_name
);
1564 errno
= map_errno_from_nt_status(status
);
1568 mapped_smb_fname
= synthetic_smb_fname(talloc_tos(),
1573 if (mapped_smb_fname
== NULL
) {
1574 TALLOC_FREE(mapped_name
);
1575 TALLOC_FREE(mapped_ea_name
);
1580 ret
= SMB_VFS_NEXT_SETXATTR(handle
, mapped_smb_fname
, mapped_ea_name
,
1581 value
, size
, flags
);
1583 saved_errno
= errno
;
1585 TALLOC_FREE(mapped_name
);
1586 TALLOC_FREE(mapped_ea_name
);
1587 TALLOC_FREE(mapped_smb_fname
);
1588 if (saved_errno
!= 0) {
1589 errno
= saved_errno
;
1595 static int catia_fstat(vfs_handle_struct
*handle
,
1597 SMB_STRUCT_STAT
*sbuf
)
1599 struct catia_cache
*cc
= NULL
;
1602 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1607 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1609 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1614 static ssize_t
catia_pread(vfs_handle_struct
*handle
,
1615 files_struct
*fsp
, void *data
,
1616 size_t n
, off_t offset
)
1618 struct catia_cache
*cc
= NULL
;
1622 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1627 result
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
1629 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1634 static ssize_t
catia_pwrite(vfs_handle_struct
*handle
,
1635 files_struct
*fsp
, const void *data
,
1636 size_t n
, off_t offset
)
1638 struct catia_cache
*cc
= NULL
;
1642 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1647 result
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
1649 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1654 static int catia_ftruncate(struct vfs_handle_struct
*handle
,
1655 struct files_struct
*fsp
,
1658 struct catia_cache
*cc
= NULL
;
1661 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1666 ret
= SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, offset
);
1668 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1673 static int catia_fallocate(struct vfs_handle_struct
*handle
,
1674 struct files_struct
*fsp
,
1679 struct catia_cache
*cc
= NULL
;
1682 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1687 ret
= SMB_VFS_NEXT_FALLOCATE(handle
, fsp
, mode
, offset
, len
);
1689 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1694 static ssize_t
catia_fgetxattr(struct vfs_handle_struct
*handle
,
1695 struct files_struct
*fsp
,
1700 char *mapped_xattr_name
= NULL
;
1704 status
= catia_string_replace_allocate(handle
->conn
,
1705 name
, &mapped_xattr_name
,
1706 vfs_translate_to_unix
);
1707 if (!NT_STATUS_IS_OK(status
)) {
1708 errno
= map_errno_from_nt_status(status
);
1712 result
= SMB_VFS_NEXT_FGETXATTR(handle
, fsp
, mapped_xattr_name
,
1715 TALLOC_FREE(mapped_xattr_name
);
1720 static ssize_t
catia_flistxattr(struct vfs_handle_struct
*handle
,
1721 struct files_struct
*fsp
,
1725 struct catia_cache
*cc
= NULL
;
1729 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1734 result
= SMB_VFS_NEXT_FLISTXATTR(handle
, fsp
, list
, size
);
1736 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1741 static int catia_fremovexattr(struct vfs_handle_struct
*handle
,
1742 struct files_struct
*fsp
,
1745 char *mapped_name
= NULL
;
1749 status
= catia_string_replace_allocate(handle
->conn
,
1750 name
, &mapped_name
, vfs_translate_to_unix
);
1751 if (!NT_STATUS_IS_OK(status
)) {
1752 errno
= map_errno_from_nt_status(status
);
1756 ret
= SMB_VFS_NEXT_FREMOVEXATTR(handle
, fsp
, mapped_name
);
1758 TALLOC_FREE(mapped_name
);
1763 static int catia_fsetxattr(struct vfs_handle_struct
*handle
,
1764 struct files_struct
*fsp
,
1770 char *mapped_xattr_name
= NULL
;
1774 status
= catia_string_replace_allocate(
1775 handle
->conn
, name
, &mapped_xattr_name
, vfs_translate_to_unix
);
1776 if (!NT_STATUS_IS_OK(status
)) {
1777 errno
= map_errno_from_nt_status(status
);
1781 ret
= SMB_VFS_NEXT_FSETXATTR(handle
, fsp
, mapped_xattr_name
,
1782 value
, size
, flags
);
1784 TALLOC_FREE(mapped_xattr_name
);
1789 static SMB_ACL_T
catia_sys_acl_get_fd(vfs_handle_struct
*handle
,
1791 TALLOC_CTX
*mem_ctx
)
1793 struct catia_cache
*cc
= NULL
;
1794 struct smb_acl_t
*result
= NULL
;
1797 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1802 result
= SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
, mem_ctx
);
1804 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1809 static int catia_sys_acl_blob_get_fd(vfs_handle_struct
*handle
,
1811 TALLOC_CTX
*mem_ctx
,
1812 char **blob_description
,
1815 struct catia_cache
*cc
= NULL
;
1818 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1823 ret
= SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle
, fsp
, mem_ctx
,
1824 blob_description
, blob
);
1826 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1831 static int catia_sys_acl_set_fd(vfs_handle_struct
*handle
,
1835 struct catia_cache
*cc
= NULL
;
1838 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1843 ret
= SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
1845 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1850 static int catia_fchmod_acl(vfs_handle_struct
*handle
,
1854 struct catia_cache
*cc
= NULL
;
1857 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1862 ret
= SMB_VFS_NEXT_FCHMOD_ACL(handle
, fsp
, mode
);
1864 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1869 static NTSTATUS
catia_fget_nt_acl(vfs_handle_struct
*handle
,
1871 uint32_t security_info
,
1872 TALLOC_CTX
*mem_ctx
,
1873 struct security_descriptor
**ppdesc
)
1875 struct catia_cache
*cc
= NULL
;
1879 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1881 return map_nt_error_from_unix(errno
);
1884 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
1887 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1892 static NTSTATUS
catia_fset_nt_acl(vfs_handle_struct
*handle
,
1894 uint32_t security_info_sent
,
1895 const struct security_descriptor
*psd
)
1897 struct catia_cache
*cc
= NULL
;
1901 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1903 return map_nt_error_from_unix(errno
);
1906 status
= SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
1908 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1913 static NTSTATUS
catia_fset_dos_attributes(struct vfs_handle_struct
*handle
,
1914 struct files_struct
*fsp
,
1917 struct catia_cache
*cc
= NULL
;
1921 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1923 return map_nt_error_from_unix(errno
);
1926 status
= SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1928 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1933 static NTSTATUS
catia_fget_dos_attributes(struct vfs_handle_struct
*handle
,
1934 struct files_struct
*fsp
,
1937 struct catia_cache
*cc
= NULL
;
1941 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1943 return map_nt_error_from_unix(errno
);
1946 status
= SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle
, fsp
, dosmode
);
1948 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1953 static int catia_fchown(vfs_handle_struct
*handle
,
1958 struct catia_cache
*cc
= NULL
;
1961 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1966 ret
= SMB_VFS_NEXT_FCHOWN(handle
, fsp
, uid
, gid
);
1968 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1973 static int catia_fchmod(vfs_handle_struct
*handle
,
1977 struct catia_cache
*cc
= NULL
;
1980 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
1985 ret
= SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1987 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
1992 struct catia_pread_state
{
1994 struct vfs_aio_state vfs_aio_state
;
1995 struct files_struct
*fsp
;
1996 struct catia_cache
*cc
;
1999 static void catia_pread_done(struct tevent_req
*subreq
);
2001 static struct tevent_req
*catia_pread_send(struct vfs_handle_struct
*handle
,
2002 TALLOC_CTX
*mem_ctx
,
2003 struct tevent_context
*ev
,
2004 struct files_struct
*fsp
,
2009 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
2010 struct catia_pread_state
*state
= NULL
;
2013 req
= tevent_req_create(mem_ctx
, &state
,
2014 struct catia_pread_state
);
2020 ret
= CATIA_FETCH_FSP_PRE_NEXT(state
, handle
, fsp
, &state
->cc
);
2022 tevent_req_error(req
, errno
);
2023 return tevent_req_post(req
, ev
);
2026 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
, data
,
2028 if (tevent_req_nomem(subreq
, req
)) {
2029 return tevent_req_post(req
, ev
);
2031 tevent_req_set_callback(subreq
, catia_pread_done
, req
);
2036 static void catia_pread_done(struct tevent_req
*subreq
)
2038 struct tevent_req
*req
= tevent_req_callback_data(
2039 subreq
, struct tevent_req
);
2040 struct catia_pread_state
*state
= tevent_req_data(
2041 req
, struct catia_pread_state
);
2043 state
->ret
= SMB_VFS_PREAD_RECV(subreq
, &state
->vfs_aio_state
);
2044 TALLOC_FREE(subreq
);
2046 CATIA_FETCH_FSP_POST_NEXT(&state
->cc
, state
->fsp
);
2048 tevent_req_done(req
);
2051 static ssize_t
catia_pread_recv(struct tevent_req
*req
,
2052 struct vfs_aio_state
*vfs_aio_state
)
2054 struct catia_pread_state
*state
= tevent_req_data(
2055 req
, struct catia_pread_state
);
2057 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
2061 *vfs_aio_state
= state
->vfs_aio_state
;
2065 struct catia_pwrite_state
{
2067 struct vfs_aio_state vfs_aio_state
;
2068 struct files_struct
*fsp
;
2069 struct catia_cache
*cc
;
2072 static void catia_pwrite_done(struct tevent_req
*subreq
);
2074 static struct tevent_req
*catia_pwrite_send(struct vfs_handle_struct
*handle
,
2075 TALLOC_CTX
*mem_ctx
,
2076 struct tevent_context
*ev
,
2077 struct files_struct
*fsp
,
2082 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
2083 struct catia_pwrite_state
*state
= NULL
;
2086 req
= tevent_req_create(mem_ctx
, &state
,
2087 struct catia_pwrite_state
);
2093 ret
= CATIA_FETCH_FSP_PRE_NEXT(state
, handle
, fsp
, &state
->cc
);
2095 tevent_req_error(req
, errno
);
2096 return tevent_req_post(req
, ev
);
2099 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
, data
,
2101 if (tevent_req_nomem(subreq
, req
)) {
2102 return tevent_req_post(req
, ev
);
2104 tevent_req_set_callback(subreq
, catia_pwrite_done
, req
);
2109 static void catia_pwrite_done(struct tevent_req
*subreq
)
2111 struct tevent_req
*req
= tevent_req_callback_data(
2112 subreq
, struct tevent_req
);
2113 struct catia_pwrite_state
*state
= tevent_req_data(
2114 req
, struct catia_pwrite_state
);
2116 state
->ret
= SMB_VFS_PWRITE_RECV(subreq
, &state
->vfs_aio_state
);
2117 TALLOC_FREE(subreq
);
2119 CATIA_FETCH_FSP_POST_NEXT(&state
->cc
, state
->fsp
);
2121 tevent_req_done(req
);
2124 static ssize_t
catia_pwrite_recv(struct tevent_req
*req
,
2125 struct vfs_aio_state
*vfs_aio_state
)
2127 struct catia_pwrite_state
*state
= tevent_req_data(
2128 req
, struct catia_pwrite_state
);
2130 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
2134 *vfs_aio_state
= state
->vfs_aio_state
;
2138 static off_t
catia_lseek(vfs_handle_struct
*handle
,
2143 struct catia_cache
*cc
= NULL
;
2147 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
2152 result
= SMB_VFS_NEXT_LSEEK(handle
, fsp
, offset
, whence
);
2154 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
2159 static int catia_fsync(vfs_handle_struct
*handle
, files_struct
*fsp
)
2161 struct catia_cache
*cc
= NULL
;
2164 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
2169 ret
= SMB_VFS_NEXT_FSYNC(handle
, fsp
);
2171 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
2176 struct catia_fsync_state
{
2178 struct vfs_aio_state vfs_aio_state
;
2179 struct files_struct
*fsp
;
2180 struct catia_cache
*cc
;
2183 static void catia_fsync_done(struct tevent_req
*subreq
);
2185 static struct tevent_req
*catia_fsync_send(struct vfs_handle_struct
*handle
,
2186 TALLOC_CTX
*mem_ctx
,
2187 struct tevent_context
*ev
,
2188 struct files_struct
*fsp
)
2190 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
2191 struct catia_fsync_state
*state
= NULL
;
2194 req
= tevent_req_create(mem_ctx
, &state
,
2195 struct catia_fsync_state
);
2201 ret
= CATIA_FETCH_FSP_PRE_NEXT(state
, handle
, fsp
, &state
->cc
);
2203 tevent_req_error(req
, errno
);
2204 return tevent_req_post(req
, ev
);
2207 subreq
= SMB_VFS_NEXT_FSYNC_SEND(state
, ev
, handle
, fsp
);
2208 if (tevent_req_nomem(subreq
, req
)) {
2209 return tevent_req_post(req
, ev
);
2211 tevent_req_set_callback(subreq
, catia_fsync_done
, req
);
2216 static void catia_fsync_done(struct tevent_req
*subreq
)
2218 struct tevent_req
*req
= tevent_req_callback_data(
2219 subreq
, struct tevent_req
);
2220 struct catia_fsync_state
*state
= tevent_req_data(
2221 req
, struct catia_fsync_state
);
2223 state
->ret
= SMB_VFS_FSYNC_RECV(subreq
, &state
->vfs_aio_state
);
2224 TALLOC_FREE(subreq
);
2226 CATIA_FETCH_FSP_POST_NEXT(&state
->cc
, state
->fsp
);
2228 tevent_req_done(req
);
2231 static int catia_fsync_recv(struct tevent_req
*req
,
2232 struct vfs_aio_state
*vfs_aio_state
)
2234 struct catia_fsync_state
*state
= tevent_req_data(
2235 req
, struct catia_fsync_state
);
2237 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
2241 *vfs_aio_state
= state
->vfs_aio_state
;
2245 static bool catia_lock(vfs_handle_struct
*handle
,
2252 struct catia_cache
*cc
= NULL
;
2256 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
2261 ok
= SMB_VFS_NEXT_LOCK(handle
, fsp
, op
, offset
, count
, type
);
2263 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
2268 static int catia_kernel_flock(struct vfs_handle_struct
*handle
,
2269 struct files_struct
*fsp
,
2270 uint32_t share_mode
,
2271 uint32_t access_mask
)
2273 struct catia_cache
*cc
= NULL
;
2276 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
2281 ret
= SMB_VFS_NEXT_KERNEL_FLOCK(handle
, fsp
, share_mode
, access_mask
);
2283 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
2288 static int catia_linux_setlease(vfs_handle_struct
*handle
,
2292 struct catia_cache
*cc
= NULL
;
2295 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
2300 ret
= SMB_VFS_NEXT_LINUX_SETLEASE(handle
, fsp
, leasetype
);
2302 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
2307 static bool catia_getlock(vfs_handle_struct
*handle
,
2314 struct catia_cache
*cc
= NULL
;
2318 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
2323 ok
= SMB_VFS_NEXT_GETLOCK(handle
, fsp
, poffset
, pcount
, ptype
, ppid
);
2325 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
2330 static bool catia_strict_lock(struct vfs_handle_struct
*handle
,
2331 struct files_struct
*fsp
,
2332 struct lock_struct
*plock
)
2334 struct catia_cache
*cc
= NULL
;
2338 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
2343 ok
= SMB_VFS_NEXT_STRICT_LOCK(handle
, fsp
, plock
);
2345 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
2350 static void catia_strict_unlock(struct vfs_handle_struct
*handle
,
2351 struct files_struct
*fsp
,
2352 struct lock_struct
*plock
)
2354 struct catia_cache
*cc
= NULL
;
2357 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
2359 smb_panic("CATIA_FETCH_FSP_PRE_NEXT failed\n");
2362 SMB_VFS_NEXT_STRICT_UNLOCK(handle
, fsp
, plock
);
2364 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
2367 static NTSTATUS
catia_fsctl(struct vfs_handle_struct
*handle
,
2368 struct files_struct
*fsp
,
2372 const uint8_t *_in_data
,
2374 uint8_t **_out_data
,
2375 uint32_t max_out_len
,
2379 struct catia_cache
*cc
= NULL
;
2382 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
2384 return map_nt_error_from_unix(errno
);
2387 result
= SMB_VFS_NEXT_FSCTL(handle
,
2398 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
2403 static NTSTATUS
catia_get_compression(vfs_handle_struct
*handle
,
2404 TALLOC_CTX
*mem_ctx
,
2405 struct files_struct
*fsp
,
2406 struct smb_filename
*smb_fname
,
2407 uint16_t *_compression_fmt
)
2410 struct catia_cache
*cc
= NULL
;
2413 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
2415 return map_nt_error_from_unix(errno
);
2418 result
= SMB_VFS_NEXT_GET_COMPRESSION(handle
, mem_ctx
, fsp
, smb_fname
,
2421 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
2426 static NTSTATUS
catia_set_compression(vfs_handle_struct
*handle
,
2427 TALLOC_CTX
*mem_ctx
,
2428 struct files_struct
*fsp
,
2429 uint16_t compression_fmt
)
2432 struct catia_cache
*cc
= NULL
;
2435 ret
= CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle
, fsp
, &cc
);
2437 return map_nt_error_from_unix(errno
);
2440 result
= SMB_VFS_NEXT_SET_COMPRESSION(handle
, mem_ctx
, fsp
,
2443 CATIA_FETCH_FSP_POST_NEXT(&cc
, fsp
);
2448 static NTSTATUS
catia_readdir_attr(struct vfs_handle_struct
*handle
,
2449 const struct smb_filename
*smb_fname_in
,
2450 TALLOC_CTX
*mem_ctx
,
2451 struct readdir_attr_data
**pattr_data
)
2453 struct smb_filename
*smb_fname
;
2457 status
= catia_string_replace_allocate(handle
->conn
,
2458 smb_fname_in
->base_name
,
2460 vfs_translate_to_unix
);
2461 if (!NT_STATUS_IS_OK(status
)) {
2462 errno
= map_errno_from_nt_status(status
);
2466 smb_fname
= synthetic_smb_fname(talloc_tos(), fname
, NULL
,
2467 &smb_fname_in
->st
, 0);
2469 status
= SMB_VFS_NEXT_READDIR_ATTR(handle
, smb_fname
, mem_ctx
, pattr_data
);
2471 TALLOC_FREE(smb_fname
);
2475 static NTSTATUS
catia_get_dos_attributes(struct vfs_handle_struct
*handle
,
2476 struct smb_filename
*smb_fname
,
2479 char *mapped_name
= NULL
;
2480 const char *path
= smb_fname
->base_name
;
2481 struct smb_filename
*mapped_smb_fname
= NULL
;
2484 status
= catia_string_replace_allocate(handle
->conn
,
2485 path
, &mapped_name
, vfs_translate_to_unix
);
2486 if (!NT_STATUS_IS_OK(status
)) {
2487 errno
= map_errno_from_nt_status(status
);
2490 mapped_smb_fname
= synthetic_smb_fname(talloc_tos(),
2495 if (mapped_smb_fname
== NULL
) {
2496 TALLOC_FREE(mapped_name
);
2497 return NT_STATUS_NO_MEMORY
;
2500 status
= SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle
,
2503 TALLOC_FREE(mapped_name
);
2504 TALLOC_FREE(mapped_smb_fname
);
2509 static NTSTATUS
catia_set_dos_attributes(struct vfs_handle_struct
*handle
,
2510 const struct smb_filename
*smb_fname
,
2513 char *mapped_name
= NULL
;
2514 const char *path
= smb_fname
->base_name
;
2515 struct smb_filename
*mapped_smb_fname
= NULL
;
2518 status
= catia_string_replace_allocate(handle
->conn
,
2519 path
, &mapped_name
, vfs_translate_to_unix
);
2520 if (!NT_STATUS_IS_OK(status
)) {
2521 errno
= map_errno_from_nt_status(status
);
2524 mapped_smb_fname
= synthetic_smb_fname(talloc_tos(),
2529 if (mapped_smb_fname
== NULL
) {
2530 TALLOC_FREE(mapped_name
);
2531 return NT_STATUS_NO_MEMORY
;
2534 status
= SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle
,
2537 TALLOC_FREE(mapped_name
);
2538 TALLOC_FREE(mapped_smb_fname
);
2543 static struct vfs_fn_pointers vfs_catia_fns
= {
2544 /* Directory operations */
2545 .mkdir_fn
= catia_mkdir
,
2546 .rmdir_fn
= catia_rmdir
,
2547 .opendir_fn
= catia_opendir
,
2548 .readdir_attr_fn
= catia_readdir_attr
,
2550 /* File operations */
2551 .open_fn
= catia_open
,
2552 .pread_fn
= catia_pread
,
2553 .pread_send_fn
= catia_pread_send
,
2554 .pread_recv_fn
= catia_pread_recv
,
2555 .pwrite_fn
= catia_pwrite
,
2556 .pwrite_send_fn
= catia_pwrite_send
,
2557 .pwrite_recv_fn
= catia_pwrite_recv
,
2558 .lseek_fn
= catia_lseek
,
2559 .rename_fn
= catia_rename
,
2560 .fsync_fn
= catia_fsync
,
2561 .fsync_send_fn
= catia_fsync_send
,
2562 .fsync_recv_fn
= catia_fsync_recv
,
2563 .stat_fn
= catia_stat
,
2564 .fstat_fn
= catia_fstat
,
2565 .lstat_fn
= catia_lstat
,
2566 .unlink_fn
= catia_unlink
,
2567 .chmod_fn
= catia_chmod
,
2568 .fchmod_fn
= catia_fchmod
,
2569 .chown_fn
= catia_chown
,
2570 .fchown_fn
= catia_fchown
,
2571 .lchown_fn
= catia_lchown
,
2572 .chdir_fn
= catia_chdir
,
2573 .ntimes_fn
= catia_ntimes
,
2574 .ftruncate_fn
= catia_ftruncate
,
2575 .fallocate_fn
= catia_fallocate
,
2576 .lock_fn
= catia_lock
,
2577 .kernel_flock_fn
= catia_kernel_flock
,
2578 .linux_setlease_fn
= catia_linux_setlease
,
2579 .getlock_fn
= catia_getlock
,
2580 .realpath_fn
= catia_realpath
,
2581 .chflags_fn
= catia_chflags
,
2582 .streaminfo_fn
= catia_streaminfo
,
2583 .strict_lock_fn
= catia_strict_lock
,
2584 .strict_unlock_fn
= catia_strict_unlock
,
2585 .translate_name_fn
= catia_translate_name
,
2586 .fsctl_fn
= catia_fsctl
,
2587 .get_dos_attributes_fn
= catia_get_dos_attributes
,
2588 .set_dos_attributes_fn
= catia_set_dos_attributes
,
2589 .fset_dos_attributes_fn
= catia_fset_dos_attributes
,
2590 .fget_dos_attributes_fn
= catia_fget_dos_attributes
,
2591 .get_compression_fn
= catia_get_compression
,
2592 .set_compression_fn
= catia_set_compression
,
2594 /* NT ACL operations. */
2595 .get_nt_acl_fn
= catia_get_nt_acl
,
2596 .fget_nt_acl_fn
= catia_fget_nt_acl
,
2597 .fset_nt_acl_fn
= catia_fset_nt_acl
,
2599 /* POSIX ACL operations. */
2600 .chmod_acl_fn
= catia_chmod_acl
,
2601 .fchmod_acl_fn
= catia_fchmod_acl
,
2603 .sys_acl_get_file_fn
= catia_sys_acl_get_file
,
2604 .sys_acl_get_fd_fn
= catia_sys_acl_get_fd
,
2605 .sys_acl_blob_get_fd_fn
= catia_sys_acl_blob_get_fd
,
2606 .sys_acl_set_file_fn
= catia_sys_acl_set_file
,
2607 .sys_acl_set_fd_fn
= catia_sys_acl_set_fd
,
2608 .sys_acl_delete_def_file_fn
= catia_sys_acl_delete_def_file
,
2610 /* EA operations. */
2611 .getxattr_fn
= catia_getxattr
,
2612 .listxattr_fn
= catia_listxattr
,
2613 .removexattr_fn
= catia_removexattr
,
2614 .setxattr_fn
= catia_setxattr
,
2615 .fgetxattr_fn
= catia_fgetxattr
,
2616 .flistxattr_fn
= catia_flistxattr
,
2617 .fremovexattr_fn
= catia_fremovexattr
,
2618 .fsetxattr_fn
= catia_fsetxattr
,
2622 NTSTATUS
vfs_catia_init(TALLOC_CTX
*ctx
)
2626 ret
= smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "catia",
2628 if (!NT_STATUS_IS_OK(ret
))
2631 vfs_catia_debug_level
= debug_add_class("catia");
2632 if (vfs_catia_debug_level
== -1) {
2633 vfs_catia_debug_level
= DBGC_VFS
;
2634 DEBUG(0, ("vfs_catia: Couldn't register custom debugging "
2637 DEBUG(10, ("vfs_catia: Debug class number of "
2638 "'catia': %d\n", vfs_catia_debug_level
));