s3: VFS: Catia: Ensure path name is also converted.
[Samba.git] / source3 / modules / vfs_catia.c
blob972f51a5ba693c0b29e51017fdcc6249784ea1f8
1 /*
2 * Catia VFS module
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
8 * Windows...
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/>.
30 #include "includes.h"
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;
37 #undef DBGC_CLASS
38 #define DBGC_CLASS vfs_catia_debug_level
40 #define GLOBAL_SNUM 0xFFFFFFF
41 #define MAP_SIZE 0xFF
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 {
52 int snum;
53 struct share_mapping_entry *next;
54 struct char_mappings **mappings;
57 struct catia_cache {
58 bool is_fsp_ext;
59 const struct catia_cache * const *busy;
60 char *orig_fname;
61 char *fname;
62 char *orig_base_fname;
63 char *base_fname;
66 struct share_mapping_entry *srt_head = NULL;
68 static bool build_table(struct char_mappings **cmaps, int value)
70 int i;
71 int start = T_START(value);
73 (*cmaps) = talloc_zero(NULL, struct char_mappings);
75 if (!*cmaps)
76 return False;
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;
83 return True;
86 static void set_tables(struct char_mappings **cmaps,
87 long unix_map,
88 long windows_map)
90 int i;
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,
102 long unix_map,
103 long windows_map)
106 if (!cmaps[T_PICK(unix_map)]) {
107 if (!build_table(&cmaps[T_PICK(unix_map)], unix_map))
108 return False;
111 if (!cmaps[T_PICK(windows_map)]) {
112 if (!build_table(&cmaps[T_PICK(windows_map)], windows_map))
113 return False;
116 set_tables(cmaps, unix_map, windows_map);
118 return True;
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)
128 (*global) = share;
130 if (share->snum == SNUM(conn))
131 return share;
134 return share;
137 static struct share_mapping_entry *add_srt(int snum, const char **mappings)
140 char *tmp;
141 fstring mapping;
142 int i;
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));
150 if (!ret)
151 return ret;
153 ret->snum = snum;
155 ret->next = srt_head;
156 srt_head = ret;
158 if (mappings) {
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 *));
163 } else {
164 ret->mappings = NULL;
165 return ret;
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));
179 continue;
181 windows_map = strtol(++tmp, NULL, 16);
182 if (windows_map == 0 && errno == EINVAL) {
183 DEBUG(0, ("INVALID CATIA MAPPINGS - %s\n", mapping));
184 continue;
187 if (!build_ranges(ret->mappings, unix_map, windows_map)) {
188 DEBUG(0, ("TABLE ERROR - CATIA MAPPINGS - %s\n", mapping));
189 continue;
193 return ret;
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);
205 if (share_level) {
206 *selected_out = share_level;
207 return (share_level->mappings != NULL);
210 /* see if we have a global setting */
211 if (!global) {
212 /* 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;
223 return True;
225 if (global->mappings) {
226 share_level->mappings = global->mappings;
227 (*selected_out) = share_level;
228 return True;
231 return False;
234 static NTSTATUS catia_string_replace_allocate(connection_struct *conn,
235 const char *name_in,
236 char **mapped_name,
237 enum vfs_translate_direction direction)
239 static smb_ucs2_t *tmpbuf = NULL;
240 smb_ucs2_t *ptr;
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);
249 if (!*mapped_name) {
250 errno = ENOMEM;
251 return NT_STATUS_NO_MEMORY;
253 return NT_STATUS_OK;
256 if ((push_ucs2_talloc(ctx, &tmpbuf, name_in,
257 &converted_size)) == false) {
258 return map_nt_error_from_unix(errno);
260 ptr = tmpbuf;
261 for(;*ptr;ptr++) {
262 if (*ptr == 0)
263 break;
264 map = selected->mappings[T_PICK((*ptr))];
266 /* nothing to do */
267 if (!map)
268 continue;
270 *ptr = map->entry[T_OFFSET((*ptr))][direction];
273 if ((pull_ucs2_talloc(ctx, mapped_name, tmpbuf,
274 &converted_size)) == false) {
275 TALLOC_FREE(tmpbuf);
276 return map_nt_error_from_unix(errno);
278 TALLOC_FREE(tmpbuf);
279 return NT_STATUS_OK;
282 static DIR *catia_opendir(vfs_handle_struct *handle,
283 const struct smb_filename *smb_fname,
284 const char *mask,
285 uint32_t attr)
287 char *name_mapped = NULL;
288 NTSTATUS status;
289 DIR *ret;
290 struct smb_filename *mapped_smb_fname = NULL;
292 status = catia_string_replace_allocate(handle->conn,
293 smb_fname->base_name,
294 &name_mapped,
295 vfs_translate_to_unix);
296 if (!NT_STATUS_IS_OK(status)) {
297 errno = map_errno_from_nt_status(status);
298 return NULL;
301 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
302 name_mapped,
303 NULL,
304 NULL,
305 smb_fname->flags);
306 if (mapped_smb_fname == NULL) {
307 TALLOC_FREE(mapped_smb_fname);
308 errno = ENOMEM;
309 return NULL;
312 ret = SMB_VFS_NEXT_OPENDIR(handle, mapped_smb_fname, mask, attr);
314 TALLOC_FREE(name_mapped);
315 TALLOC_FREE(mapped_smb_fname);
317 return ret;
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,
327 TALLOC_CTX *mem_ctx,
328 char **pmapped_name)
330 char *name = NULL;
331 char *mapped_name;
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);
341 if (!name) {
342 errno = ENOMEM;
343 return NT_STATUS_NO_MEMORY;
345 status = catia_string_replace_allocate(handle->conn, name,
346 &mapped_name, direction);
348 TALLOC_FREE(name);
349 if (!NT_STATUS_IS_OK(status)) {
350 return 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 */
359 ret = status;
360 } else {
361 TALLOC_FREE(mapped_name);
364 return ret;
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,
372 files_struct *fsp,
373 const char *location)
375 DEBUG(lvl, ("%s: cc [0x%p] cc->busy [0x%p] "
376 "is_fsp_ext [%s] "
377 "fsp [0x%p] fsp name [%s] "
378 "orig_fname [%s] "
379 "fname [%s] "
380 "orig_base_fname [%s] "
381 "base_fname [%s]\n",
382 location,
383 cc, cc->busy,
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,
392 files_struct *fsp)
394 struct catia_cache *cc = *_cc;
396 if (cc->is_fsp_ext) {
397 VFS_REMOVE_FSP_EXTENSION(handle, fsp);
398 cc = NULL;
399 } else {
400 TALLOC_FREE(cc);
403 *_cc = NULL;
406 static struct catia_cache *catia_validate_and_apply_cc(
407 vfs_handle_struct *handle,
408 files_struct *fsp,
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);
417 if (cc == NULL) {
418 return NULL;
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;
445 return NULL;
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);
454 return cc;
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);
471 return NULL;
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;
484 cc->busy = busy;
485 CATIA_DEBUG_CC(10, cc, fsp);
486 return cc;
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,
494 files_struct *fsp,
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;
501 NTSTATUS status;
502 bool make_tmp_cache = false;
504 *_cc = NULL;
506 DBG_DEBUG("Called from [%s]\n", function);
508 cc = catia_validate_and_apply_cc(handle,
509 fsp,
510 busy,
511 &make_tmp_cache);
512 if (cc != NULL) {
513 if (cc->busy != busy) {
514 return 0;
516 *_cc = cc;
517 return 0;
520 if (!make_tmp_cache) {
521 cc = (struct catia_cache *)VFS_ADD_FSP_EXTENSION(
522 handle, fsp, struct catia_cache, NULL);
523 if (cc == NULL) {
524 return -1;
526 *cc = (struct catia_cache) {
527 .is_fsp_ext = true,
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);
534 return -1;
536 } else {
537 cc = talloc_zero(mem_ctx, struct catia_cache);
538 if (cc == NULL) {
539 return -1;
541 mem_ctx = cc;
545 status = catia_string_replace_allocate(handle->conn,
546 fsp->fsp_name->base_name,
547 &cc->fname,
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);
552 return -1;
554 talloc_steal(mem_ctx, cc->fname);
556 if (fsp->base_fsp != NULL) {
557 status = catia_string_replace_allocate(
558 handle->conn,
559 fsp->base_fsp->fsp_name->base_name,
560 &cc->base_fname,
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);
565 return -1;
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;
578 cc->busy = busy;
579 CATIA_DEBUG_CC(10, cc, fsp);
581 *_cc = cc;
583 return 0;
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; \
590 } while(0)
592 static void catia_fetch_fsp_post_next(struct catia_cache **_cc,
593 files_struct *fsp,
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);
602 if (cc == NULL) {
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
606 * NULL.
608 return;
611 if (cc->busy != busy) {
612 CATIA_DEBUG_CC(0, cc, fsp);
613 smb_panic(__location__);
614 return;
617 cc->busy = NULL;
618 *_cc = NULL;
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) {
628 TALLOC_FREE(cc);
631 return;
634 static int catia_open(vfs_handle_struct *handle,
635 struct smb_filename *smb_fname,
636 files_struct *fsp,
637 int flags,
638 mode_t mode)
640 struct catia_cache *cc = NULL;
641 char *orig_smb_fname = smb_fname->base_name;
642 char *mapped_smb_fname = NULL;
643 NTSTATUS status;
644 int ret;
646 status = catia_string_replace_allocate(handle->conn,
647 smb_fname->base_name,
648 &mapped_smb_fname,
649 vfs_translate_to_unix);
650 if (!NT_STATUS_IS_OK(status)) {
651 return -1;
654 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
655 if (ret != 0) {
656 TALLOC_FREE(mapped_smb_fname);
657 return ret;
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);
667 return ret;
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;
679 NTSTATUS status;
680 int ret = -1;
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);
687 return -1;
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);
695 return -1;
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) {
701 errno = ENOMEM;
702 goto out;
705 smb_fname_dst_tmp = cp_smb_filename(ctx, smb_fname_dst);
706 if (smb_fname_dst_tmp == NULL) {
707 errno = ENOMEM;
708 goto out;
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,
719 smb_fname_dst_tmp);
720 out:
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);
725 return ret;
728 static int catia_stat(vfs_handle_struct *handle,
729 struct smb_filename *smb_fname)
731 char *name = NULL;
732 char *tmp_base_name;
733 int ret;
734 NTSTATUS status;
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);
741 return -1;
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;
750 TALLOC_FREE(name);
751 return ret;
754 static int catia_lstat(vfs_handle_struct *handle,
755 struct smb_filename *smb_fname)
757 char *name = NULL;
758 char *tmp_base_name;
759 int ret;
760 NTSTATUS status;
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);
767 return -1;
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;
775 TALLOC_FREE(name);
777 return ret;
780 static int catia_unlink(vfs_handle_struct *handle,
781 const struct smb_filename *smb_fname)
783 struct smb_filename *smb_fname_tmp = NULL;
784 char *name = NULL;
785 NTSTATUS status;
786 int ret;
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);
793 return -1;
796 /* Setup temporary smb_filename structs. */
797 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
798 if (smb_fname_tmp == NULL) {
799 errno = ENOMEM;
800 return -1;
803 smb_fname_tmp->base_name = name;
804 ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_tmp);
805 TALLOC_FREE(smb_fname_tmp);
806 TALLOC_FREE(name);
808 return ret;
811 static int catia_chown(vfs_handle_struct *handle,
812 const struct smb_filename *smb_fname,
813 uid_t uid,
814 gid_t gid)
816 char *name = NULL;
817 NTSTATUS status;
818 int ret;
819 int saved_errno;
820 struct smb_filename *catia_smb_fname = NULL;
822 status = catia_string_replace_allocate(handle->conn,
823 smb_fname->base_name,
824 &name,
825 vfs_translate_to_unix);
826 if (!NT_STATUS_IS_OK(status)) {
827 errno = map_errno_from_nt_status(status);
828 return -1;
830 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
831 name,
832 NULL,
833 NULL,
834 smb_fname->flags);
835 if (catia_smb_fname == NULL) {
836 TALLOC_FREE(name);
837 errno = ENOMEM;
838 return -1;
841 ret = SMB_VFS_NEXT_CHOWN(handle, catia_smb_fname, uid, gid);
842 saved_errno = errno;
843 TALLOC_FREE(name);
844 TALLOC_FREE(catia_smb_fname);
845 errno = saved_errno;
846 return ret;
849 static int catia_lchown(vfs_handle_struct *handle,
850 const struct smb_filename *smb_fname,
851 uid_t uid,
852 gid_t gid)
854 char *name = NULL;
855 NTSTATUS status;
856 int ret;
857 int saved_errno;
858 struct smb_filename *catia_smb_fname = NULL;
860 status = catia_string_replace_allocate(handle->conn,
861 smb_fname->base_name,
862 &name,
863 vfs_translate_to_unix);
864 if (!NT_STATUS_IS_OK(status)) {
865 errno = map_errno_from_nt_status(status);
866 return -1;
868 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
869 name,
870 NULL,
871 NULL,
872 smb_fname->flags);
873 if (catia_smb_fname == NULL) {
874 TALLOC_FREE(name);
875 errno = ENOMEM;
876 return -1;
879 ret = SMB_VFS_NEXT_LCHOWN(handle, catia_smb_fname, uid, gid);
880 saved_errno = errno;
881 TALLOC_FREE(name);
882 TALLOC_FREE(catia_smb_fname);
883 errno = saved_errno;
884 return ret;
887 static int catia_chmod(vfs_handle_struct *handle,
888 const struct smb_filename *smb_fname,
889 mode_t mode)
891 char *name = NULL;
892 NTSTATUS status;
893 int ret;
894 int saved_errno;
895 struct smb_filename *catia_smb_fname = NULL;
897 status = catia_string_replace_allocate(handle->conn,
898 smb_fname->base_name,
899 &name,
900 vfs_translate_to_unix);
901 if (!NT_STATUS_IS_OK(status)) {
902 errno = map_errno_from_nt_status(status);
903 return -1;
905 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
906 name,
907 NULL,
908 NULL,
909 smb_fname->flags);
910 if (catia_smb_fname == NULL) {
911 TALLOC_FREE(name);
912 errno = ENOMEM;
913 return -1;
916 ret = SMB_VFS_NEXT_CHMOD(handle, catia_smb_fname, mode);
917 saved_errno = errno;
918 TALLOC_FREE(name);
919 TALLOC_FREE(catia_smb_fname);
920 errno = saved_errno;
921 return ret;
924 static int catia_rmdir(vfs_handle_struct *handle,
925 const struct smb_filename *smb_fname)
927 char *name = NULL;
928 NTSTATUS status;
929 int ret;
930 struct smb_filename *catia_smb_fname = NULL;
932 status = catia_string_replace_allocate(handle->conn,
933 smb_fname->base_name,
934 &name,
935 vfs_translate_to_unix);
936 if (!NT_STATUS_IS_OK(status)) {
937 errno = map_errno_from_nt_status(status);
938 return -1;
940 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
941 name,
942 NULL,
943 NULL,
944 smb_fname->flags);
945 if (catia_smb_fname == NULL) {
946 TALLOC_FREE(name);
947 errno = ENOMEM;
948 return -1;
951 ret = SMB_VFS_NEXT_RMDIR(handle, catia_smb_fname);
952 TALLOC_FREE(name);
953 TALLOC_FREE(catia_smb_fname);
955 return ret;
958 static int catia_mkdir(vfs_handle_struct *handle,
959 const struct smb_filename *smb_fname,
960 mode_t mode)
962 char *name = NULL;
963 NTSTATUS status;
964 int ret;
965 struct smb_filename *catia_smb_fname = NULL;
967 status = catia_string_replace_allocate(handle->conn,
968 smb_fname->base_name,
969 &name,
970 vfs_translate_to_unix);
971 if (!NT_STATUS_IS_OK(status)) {
972 errno = map_errno_from_nt_status(status);
973 return -1;
975 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
976 name,
977 NULL,
978 NULL,
979 smb_fname->flags);
980 if (catia_smb_fname == NULL) {
981 TALLOC_FREE(name);
982 errno = ENOMEM;
983 return -1;
986 ret = SMB_VFS_NEXT_MKDIR(handle, catia_smb_fname, mode);
987 TALLOC_FREE(name);
988 TALLOC_FREE(catia_smb_fname);
990 return ret;
993 static int catia_chdir(vfs_handle_struct *handle,
994 const char *path)
996 char *name = NULL;
997 NTSTATUS status;
998 int ret;
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);
1004 return -1;
1007 ret = SMB_VFS_NEXT_CHDIR(handle, name);
1008 TALLOC_FREE(name);
1010 return ret;
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;
1018 char *name = NULL;
1019 NTSTATUS status;
1020 int ret;
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);
1027 return -1;
1030 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
1031 if (smb_fname_tmp == NULL) {
1032 errno = ENOMEM;
1033 return -1;
1036 smb_fname_tmp->base_name = name;
1037 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname_tmp, ft);
1038 TALLOC_FREE(name);
1039 TALLOC_FREE(smb_fname_tmp);
1041 return ret;
1044 static char *
1045 catia_realpath(vfs_handle_struct *handle, const char *path)
1047 char *mapped_name = NULL;
1048 NTSTATUS status;
1049 char *ret = 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);
1055 return NULL;
1058 ret = SMB_VFS_NEXT_REALPATH(handle, mapped_name);
1059 TALLOC_FREE(mapped_name);
1061 return ret;
1064 static int catia_chflags(struct vfs_handle_struct *handle,
1065 const char *path, unsigned int flags)
1067 char *mapped_name = NULL;
1068 NTSTATUS status;
1069 int ret;
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);
1075 return -1;
1078 ret = SMB_VFS_NEXT_CHFLAGS(handle, mapped_name, flags);
1079 TALLOC_FREE(mapped_name);
1081 return ret;
1084 static NTSTATUS
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;
1093 NTSTATUS status;
1094 unsigned int i;
1095 struct smb_filename *catia_smb_fname = NULL;
1096 unsigned int num_streams = 0;
1097 struct stream_struct *streams = NULL;
1099 *_num_streams = 0;
1100 *_streams = NULL;
1102 status = catia_string_replace_allocate(handle->conn,
1103 smb_fname->base_name,
1104 &mapped_name,
1105 vfs_translate_to_unix);
1106 if (!NT_STATUS_IS_OK(status)) {
1107 errno = map_errno_from_nt_status(status);
1108 return status;
1111 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
1112 mapped_name,
1113 NULL,
1114 NULL,
1115 smb_fname->flags);
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)) {
1126 return 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';
1143 stream_type += 1;
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);
1150 return status;
1153 if (stream_type != NULL) {
1154 streams[i].name = talloc_asprintf(streams, ":%s:%s",
1155 mapped_name, stream_type);
1156 } else {
1157 streams[i].name = talloc_asprintf(streams, ":%s",
1158 mapped_name);
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;
1173 static NTSTATUS
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;
1183 NTSTATUS status;
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);
1189 return status;
1191 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1192 mapped_name,
1193 NULL,
1194 NULL,
1195 smb_fname->flags);
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);
1206 return status;
1209 static int
1210 catia_chmod_acl(vfs_handle_struct *handle,
1211 const struct smb_filename *smb_fname,
1212 mode_t mode)
1214 char *mapped_name = NULL;
1215 struct smb_filename *mapped_smb_fname = NULL;
1216 NTSTATUS status;
1217 int ret;
1218 int saved_errno;
1220 status = catia_string_replace_allocate(handle->conn,
1221 smb_fname->base_name,
1222 &mapped_name,
1223 vfs_translate_to_unix);
1224 if (!NT_STATUS_IS_OK(status)) {
1225 errno = map_errno_from_nt_status(status);
1226 return -1;
1229 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1230 mapped_name,
1231 NULL,
1232 NULL,
1233 smb_fname->flags);
1234 if (mapped_smb_fname == NULL) {
1235 TALLOC_FREE(mapped_name);
1236 errno = ENOMEM;
1237 return -1;
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;
1244 return ret;
1247 static SMB_ACL_T
1248 catia_sys_acl_get_file(vfs_handle_struct *handle,
1249 const char *path,
1250 SMB_ACL_TYPE_T type,
1251 TALLOC_CTX *mem_ctx)
1253 char *mapped_name = NULL;
1254 NTSTATUS status;
1255 SMB_ACL_T ret;
1257 status = catia_string_replace_allocate(handle->conn,
1258 path, &mapped_name, vfs_translate_to_unix);
1259 if (!NT_STATUS_IS_OK(status)) {
1260 errno = map_errno_from_nt_status(status);
1261 return NULL;
1264 ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, mapped_name, type, mem_ctx);
1265 TALLOC_FREE(mapped_name);
1267 return ret;
1270 static int
1271 catia_sys_acl_set_file(vfs_handle_struct *handle,
1272 const char *path,
1273 SMB_ACL_TYPE_T type,
1274 SMB_ACL_T theacl)
1276 char *mapped_name = NULL;
1277 NTSTATUS status;
1278 int ret;
1280 status = catia_string_replace_allocate(handle->conn,
1281 path, &mapped_name, vfs_translate_to_unix);
1282 if (!NT_STATUS_IS_OK(status)) {
1283 errno = map_errno_from_nt_status(status);
1284 return -1;
1287 ret = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, mapped_name, type, theacl);
1288 TALLOC_FREE(mapped_name);
1290 return ret;
1293 static int
1294 catia_sys_acl_delete_def_file(vfs_handle_struct *handle,
1295 const char *path)
1297 char *mapped_name = NULL;
1298 NTSTATUS status;
1299 int ret;
1301 status = catia_string_replace_allocate(handle->conn,
1302 path, &mapped_name, vfs_translate_to_unix);
1303 if (!NT_STATUS_IS_OK(status)) {
1304 errno = map_errno_from_nt_status(status);
1305 return -1;
1308 ret = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, mapped_name);
1309 TALLOC_FREE(mapped_name);
1311 return ret;
1314 static ssize_t
1315 catia_getxattr(vfs_handle_struct *handle, const char *path,
1316 const char *name, void *value, size_t size)
1318 char *mapped_name = NULL;
1319 char *mapped_ea_name = NULL;
1320 NTSTATUS status;
1321 ssize_t ret;
1323 status = catia_string_replace_allocate(handle->conn,
1324 path, &mapped_name, vfs_translate_to_unix);
1325 if (!NT_STATUS_IS_OK(status)) {
1326 errno = map_errno_from_nt_status(status);
1327 return -1;
1330 status = catia_string_replace_allocate(handle->conn,
1331 name, &mapped_ea_name, vfs_translate_to_unix);
1332 if (!NT_STATUS_IS_OK(status)) {
1333 TALLOC_FREE(mapped_name);
1334 errno = map_errno_from_nt_status(status);
1335 return -1;
1338 ret = SMB_VFS_NEXT_GETXATTR(handle, mapped_name,
1339 mapped_ea_name, value, size);
1340 TALLOC_FREE(mapped_name);
1341 TALLOC_FREE(mapped_ea_name);
1343 return ret;
1346 static ssize_t
1347 catia_listxattr(vfs_handle_struct *handle, const char *path,
1348 char *list, size_t size)
1350 char *mapped_name = NULL;
1351 NTSTATUS status;
1352 ssize_t ret;
1354 status = catia_string_replace_allocate(handle->conn,
1355 path, &mapped_name, vfs_translate_to_unix);
1356 if (!NT_STATUS_IS_OK(status)) {
1357 errno = map_errno_from_nt_status(status);
1358 return -1;
1362 ret = SMB_VFS_NEXT_LISTXATTR(handle, mapped_name, list, size);
1363 TALLOC_FREE(mapped_name);
1365 return ret;
1368 static int
1369 catia_removexattr(vfs_handle_struct *handle, const char *path,
1370 const char *name)
1372 char *mapped_name = NULL;
1373 char *mapped_ea_name = NULL;
1374 NTSTATUS status;
1375 ssize_t ret;
1377 status = catia_string_replace_allocate(handle->conn,
1378 path, &mapped_name, vfs_translate_to_unix);
1379 if (!NT_STATUS_IS_OK(status)) {
1380 errno = map_errno_from_nt_status(status);
1381 return -1;
1384 status = catia_string_replace_allocate(handle->conn,
1385 name, &mapped_ea_name, vfs_translate_to_unix);
1386 if (!NT_STATUS_IS_OK(status)) {
1387 TALLOC_FREE(mapped_name);
1388 errno = map_errno_from_nt_status(status);
1389 return -1;
1392 ret = SMB_VFS_NEXT_REMOVEXATTR(handle, mapped_name, mapped_ea_name);
1393 TALLOC_FREE(mapped_name);
1394 TALLOC_FREE(mapped_ea_name);
1396 return ret;
1399 static int
1400 catia_setxattr(vfs_handle_struct *handle, const char *path,
1401 const char *name, const void *value, size_t size,
1402 int flags)
1404 char *mapped_name = NULL;
1405 char *mapped_ea_name = NULL;
1406 NTSTATUS status;
1407 ssize_t ret;
1409 status = catia_string_replace_allocate(handle->conn,
1410 path, &mapped_name, vfs_translate_to_unix);
1411 if (!NT_STATUS_IS_OK(status)) {
1412 errno = map_errno_from_nt_status(status);
1413 return -1;
1416 status = catia_string_replace_allocate(handle->conn,
1417 name, &mapped_ea_name, vfs_translate_to_unix);
1418 if (!NT_STATUS_IS_OK(status)) {
1419 TALLOC_FREE(mapped_name);
1420 errno = map_errno_from_nt_status(status);
1421 return -1;
1424 ret = SMB_VFS_NEXT_SETXATTR(handle, mapped_name, mapped_ea_name,
1425 value, size, flags);
1426 TALLOC_FREE(mapped_name);
1427 TALLOC_FREE(mapped_ea_name);
1429 return ret;
1432 static int catia_fstat(vfs_handle_struct *handle,
1433 files_struct *fsp,
1434 SMB_STRUCT_STAT *sbuf)
1436 struct catia_cache *cc = NULL;
1437 int ret;
1439 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1440 if (ret != 0) {
1441 return ret;
1444 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1446 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1448 return ret;
1451 static ssize_t catia_pread(vfs_handle_struct *handle,
1452 files_struct *fsp, void *data,
1453 size_t n, off_t offset)
1455 struct catia_cache *cc = NULL;
1456 ssize_t result;
1457 int ret;
1459 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1460 if (ret != 0) {
1461 return ret;
1464 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1466 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1468 return result;
1471 static ssize_t catia_pwrite(vfs_handle_struct *handle,
1472 files_struct *fsp, const void *data,
1473 size_t n, off_t offset)
1475 struct catia_cache *cc = NULL;
1476 ssize_t result;
1477 int ret;
1479 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1480 if (ret != 0) {
1481 return ret;
1484 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1486 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1488 return result;
1491 static int catia_ftruncate(struct vfs_handle_struct *handle,
1492 struct files_struct *fsp,
1493 off_t offset)
1495 struct catia_cache *cc = NULL;
1496 int ret;
1498 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1499 if (ret != 0) {
1500 return ret;
1503 ret = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
1505 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1507 return ret;
1510 static int catia_fallocate(struct vfs_handle_struct *handle,
1511 struct files_struct *fsp,
1512 uint32_t mode,
1513 off_t offset,
1514 off_t len)
1516 struct catia_cache *cc = NULL;
1517 int ret;
1519 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1520 if (ret != 0) {
1521 return ret;
1524 ret = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1526 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1528 return ret;
1531 static ssize_t catia_fgetxattr(struct vfs_handle_struct *handle,
1532 struct files_struct *fsp,
1533 const char *name,
1534 void *value,
1535 size_t size)
1537 char *mapped_xattr_name = NULL;
1538 NTSTATUS status;
1539 ssize_t result;
1541 status = catia_string_replace_allocate(handle->conn,
1542 name, &mapped_xattr_name,
1543 vfs_translate_to_unix);
1544 if (!NT_STATUS_IS_OK(status)) {
1545 errno = map_errno_from_nt_status(status);
1546 return -1;
1549 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, mapped_xattr_name,
1550 value, size);
1552 TALLOC_FREE(mapped_xattr_name);
1554 return result;
1557 static ssize_t catia_flistxattr(struct vfs_handle_struct *handle,
1558 struct files_struct *fsp,
1559 char *list,
1560 size_t size)
1562 struct catia_cache *cc = NULL;
1563 ssize_t result;
1564 int ret;
1566 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1567 if (ret != 0) {
1568 return ret;
1571 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
1573 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1575 return result;
1578 static int catia_fremovexattr(struct vfs_handle_struct *handle,
1579 struct files_struct *fsp,
1580 const char *name)
1582 char *mapped_name = NULL;
1583 NTSTATUS status;
1584 int ret;
1586 status = catia_string_replace_allocate(handle->conn,
1587 name, &mapped_name, vfs_translate_to_unix);
1588 if (!NT_STATUS_IS_OK(status)) {
1589 errno = map_errno_from_nt_status(status);
1590 return -1;
1593 ret = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, mapped_name);
1595 TALLOC_FREE(mapped_name);
1597 return ret;
1600 static int catia_fsetxattr(struct vfs_handle_struct *handle,
1601 struct files_struct *fsp,
1602 const char *name,
1603 const void *value,
1604 size_t size,
1605 int flags)
1607 char *mapped_xattr_name = NULL;
1608 NTSTATUS status;
1609 int ret;
1611 status = catia_string_replace_allocate(
1612 handle->conn, name, &mapped_xattr_name, vfs_translate_to_unix);
1613 if (!NT_STATUS_IS_OK(status)) {
1614 errno = map_errno_from_nt_status(status);
1615 return -1;
1618 ret = SMB_VFS_NEXT_FSETXATTR(handle, fsp, mapped_xattr_name,
1619 value, size, flags);
1621 TALLOC_FREE(mapped_xattr_name);
1623 return ret;
1626 static SMB_ACL_T catia_sys_acl_get_fd(vfs_handle_struct *handle,
1627 files_struct *fsp,
1628 TALLOC_CTX *mem_ctx)
1630 struct catia_cache *cc = NULL;
1631 struct smb_acl_t *result = NULL;
1632 int ret;
1634 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1635 if (ret != 0) {
1636 return NULL;
1639 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1641 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1643 return result;
1646 static int catia_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1647 files_struct *fsp,
1648 TALLOC_CTX *mem_ctx,
1649 char **blob_description,
1650 DATA_BLOB *blob)
1652 struct catia_cache *cc = NULL;
1653 int ret;
1655 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1656 if (ret != 0) {
1657 return ret;
1660 ret = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1661 blob_description, blob);
1663 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1665 return ret;
1668 static int catia_sys_acl_set_fd(vfs_handle_struct *handle,
1669 files_struct *fsp,
1670 SMB_ACL_T theacl)
1672 struct catia_cache *cc = NULL;
1673 int ret;
1675 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1676 if (ret != 0) {
1677 return ret;
1680 ret = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1682 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1684 return ret;
1687 static int catia_fchmod_acl(vfs_handle_struct *handle,
1688 files_struct *fsp,
1689 mode_t mode)
1691 struct catia_cache *cc = NULL;
1692 int ret;
1694 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1695 if (ret != 0) {
1696 return ret;
1699 ret = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1701 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1703 return ret;
1706 static NTSTATUS catia_fget_nt_acl(vfs_handle_struct *handle,
1707 files_struct *fsp,
1708 uint32_t security_info,
1709 TALLOC_CTX *mem_ctx,
1710 struct security_descriptor **ppdesc)
1712 struct catia_cache *cc = NULL;
1713 NTSTATUS status;
1714 int ret;
1716 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1717 if (ret != 0) {
1718 return map_nt_error_from_unix(errno);
1721 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1722 mem_ctx, ppdesc);
1724 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1726 return status;
1729 static NTSTATUS catia_fset_nt_acl(vfs_handle_struct *handle,
1730 files_struct *fsp,
1731 uint32_t security_info_sent,
1732 const struct security_descriptor *psd)
1734 struct catia_cache *cc = NULL;
1735 NTSTATUS status;
1736 int ret;
1738 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1739 if (ret != 0) {
1740 return map_nt_error_from_unix(errno);
1743 status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1745 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1747 return status;
1750 static NTSTATUS catia_fset_dos_attributes(struct vfs_handle_struct *handle,
1751 struct files_struct *fsp,
1752 uint32_t dosmode)
1754 struct catia_cache *cc = NULL;
1755 NTSTATUS status;
1756 int ret;
1758 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1759 if (ret != 0) {
1760 return map_nt_error_from_unix(errno);
1763 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1765 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1767 return status;
1770 static NTSTATUS catia_fget_dos_attributes(struct vfs_handle_struct *handle,
1771 struct files_struct *fsp,
1772 uint32_t *dosmode)
1774 struct catia_cache *cc = NULL;
1775 NTSTATUS status;
1776 int ret;
1778 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1779 if (ret != 0) {
1780 return map_nt_error_from_unix(errno);
1783 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1785 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1787 return status;
1790 static int catia_fchown(vfs_handle_struct *handle,
1791 files_struct *fsp,
1792 uid_t uid,
1793 gid_t gid)
1795 struct catia_cache *cc = NULL;
1796 int ret;
1798 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1799 if (ret != 0) {
1800 return ret;
1803 ret = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1805 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1807 return ret;
1810 static int catia_fchmod(vfs_handle_struct *handle,
1811 files_struct *fsp,
1812 mode_t mode)
1814 struct catia_cache *cc = NULL;
1815 int ret;
1817 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1818 if (ret != 0) {
1819 return ret;
1822 ret = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1824 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1826 return ret;
1829 struct catia_pread_state {
1830 ssize_t ret;
1831 struct vfs_aio_state vfs_aio_state;
1832 struct files_struct *fsp;
1833 struct catia_cache *cc;
1836 static void catia_pread_done(struct tevent_req *subreq);
1838 static struct tevent_req *catia_pread_send(struct vfs_handle_struct *handle,
1839 TALLOC_CTX *mem_ctx,
1840 struct tevent_context *ev,
1841 struct files_struct *fsp,
1842 void *data,
1843 size_t n,
1844 off_t offset)
1846 struct tevent_req *req = NULL, *subreq = NULL;
1847 struct catia_pread_state *state = NULL;
1848 int ret;
1850 req = tevent_req_create(mem_ctx, &state,
1851 struct catia_pread_state);
1852 if (req == NULL) {
1853 return NULL;
1855 state->fsp = fsp;
1857 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1858 if (ret != 0) {
1859 tevent_req_error(req, errno);
1860 return tevent_req_post(req, ev);
1863 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1864 n, offset);
1865 if (tevent_req_nomem(subreq, req)) {
1866 return tevent_req_post(req, ev);
1868 tevent_req_set_callback(subreq, catia_pread_done, req);
1870 return req;
1873 static void catia_pread_done(struct tevent_req *subreq)
1875 struct tevent_req *req = tevent_req_callback_data(
1876 subreq, struct tevent_req);
1877 struct catia_pread_state *state = tevent_req_data(
1878 req, struct catia_pread_state);
1880 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1881 TALLOC_FREE(subreq);
1883 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1885 tevent_req_done(req);
1888 static ssize_t catia_pread_recv(struct tevent_req *req,
1889 struct vfs_aio_state *vfs_aio_state)
1891 struct catia_pread_state *state = tevent_req_data(
1892 req, struct catia_pread_state);
1894 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1895 return -1;
1898 *vfs_aio_state = state->vfs_aio_state;
1899 return state->ret;
1902 struct catia_pwrite_state {
1903 ssize_t ret;
1904 struct vfs_aio_state vfs_aio_state;
1905 struct files_struct *fsp;
1906 struct catia_cache *cc;
1909 static void catia_pwrite_done(struct tevent_req *subreq);
1911 static struct tevent_req *catia_pwrite_send(struct vfs_handle_struct *handle,
1912 TALLOC_CTX *mem_ctx,
1913 struct tevent_context *ev,
1914 struct files_struct *fsp,
1915 const void *data,
1916 size_t n,
1917 off_t offset)
1919 struct tevent_req *req = NULL, *subreq = NULL;
1920 struct catia_pwrite_state *state = NULL;
1921 int ret;
1923 req = tevent_req_create(mem_ctx, &state,
1924 struct catia_pwrite_state);
1925 if (req == NULL) {
1926 return NULL;
1928 state->fsp = fsp;
1930 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1931 if (ret != 0) {
1932 tevent_req_error(req, errno);
1933 return tevent_req_post(req, ev);
1936 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1937 n, offset);
1938 if (tevent_req_nomem(subreq, req)) {
1939 return tevent_req_post(req, ev);
1941 tevent_req_set_callback(subreq, catia_pwrite_done, req);
1943 return req;
1946 static void catia_pwrite_done(struct tevent_req *subreq)
1948 struct tevent_req *req = tevent_req_callback_data(
1949 subreq, struct tevent_req);
1950 struct catia_pwrite_state *state = tevent_req_data(
1951 req, struct catia_pwrite_state);
1953 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1954 TALLOC_FREE(subreq);
1956 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1958 tevent_req_done(req);
1961 static ssize_t catia_pwrite_recv(struct tevent_req *req,
1962 struct vfs_aio_state *vfs_aio_state)
1964 struct catia_pwrite_state *state = tevent_req_data(
1965 req, struct catia_pwrite_state);
1967 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1968 return -1;
1971 *vfs_aio_state = state->vfs_aio_state;
1972 return state->ret;
1975 static off_t catia_lseek(vfs_handle_struct *handle,
1976 files_struct *fsp,
1977 off_t offset,
1978 int whence)
1980 struct catia_cache *cc = NULL;
1981 ssize_t result;
1982 int ret;
1984 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1985 if (ret != 0) {
1986 return -1;
1989 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1991 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1993 return result;
1996 static int catia_fsync(vfs_handle_struct *handle, files_struct *fsp)
1998 struct catia_cache *cc = NULL;
1999 int ret;
2001 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2002 if (ret != 0) {
2003 return -1;
2006 ret = SMB_VFS_NEXT_FSYNC(handle, fsp);
2008 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2010 return ret;
2013 struct catia_fsync_state {
2014 int ret;
2015 struct vfs_aio_state vfs_aio_state;
2016 struct files_struct *fsp;
2017 struct catia_cache *cc;
2020 static void catia_fsync_done(struct tevent_req *subreq);
2022 static struct tevent_req *catia_fsync_send(struct vfs_handle_struct *handle,
2023 TALLOC_CTX *mem_ctx,
2024 struct tevent_context *ev,
2025 struct files_struct *fsp)
2027 struct tevent_req *req = NULL, *subreq = NULL;
2028 struct catia_fsync_state *state = NULL;
2029 int ret;
2031 req = tevent_req_create(mem_ctx, &state,
2032 struct catia_fsync_state);
2033 if (req == NULL) {
2034 return NULL;
2036 state->fsp = fsp;
2038 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
2039 if (ret != 0) {
2040 tevent_req_error(req, errno);
2041 return tevent_req_post(req, ev);
2044 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
2045 if (tevent_req_nomem(subreq, req)) {
2046 return tevent_req_post(req, ev);
2048 tevent_req_set_callback(subreq, catia_fsync_done, req);
2050 return req;
2053 static void catia_fsync_done(struct tevent_req *subreq)
2055 struct tevent_req *req = tevent_req_callback_data(
2056 subreq, struct tevent_req);
2057 struct catia_fsync_state *state = tevent_req_data(
2058 req, struct catia_fsync_state);
2060 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
2061 TALLOC_FREE(subreq);
2063 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
2065 tevent_req_done(req);
2068 static int catia_fsync_recv(struct tevent_req *req,
2069 struct vfs_aio_state *vfs_aio_state)
2071 struct catia_fsync_state *state = tevent_req_data(
2072 req, struct catia_fsync_state);
2074 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2075 return -1;
2078 *vfs_aio_state = state->vfs_aio_state;
2079 return state->ret;
2082 static bool catia_lock(vfs_handle_struct *handle,
2083 files_struct *fsp,
2084 int op,
2085 off_t offset,
2086 off_t count,
2087 int type)
2089 struct catia_cache *cc = NULL;
2090 bool ok;
2091 int ret;
2093 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2094 if (ret != 0) {
2095 return -1;
2098 ok = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
2100 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2102 return ok;
2105 static int catia_kernel_flock(struct vfs_handle_struct *handle,
2106 struct files_struct *fsp,
2107 uint32_t share_mode,
2108 uint32_t access_mask)
2110 struct catia_cache *cc = NULL;
2111 int ret;
2113 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2114 if (ret != 0) {
2115 return -1;
2118 ret = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
2120 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2122 return ret;
2125 static int catia_linux_setlease(vfs_handle_struct *handle,
2126 files_struct *fsp,
2127 int leasetype)
2129 struct catia_cache *cc = NULL;
2130 int ret;
2132 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2133 if (ret != 0) {
2134 return -1;
2137 ret = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
2139 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2141 return ret;
2144 static bool catia_getlock(vfs_handle_struct *handle,
2145 files_struct *fsp,
2146 off_t *poffset,
2147 off_t *pcount,
2148 int *ptype,
2149 pid_t *ppid)
2151 struct catia_cache *cc = NULL;
2152 int ret;
2153 bool ok;
2155 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2156 if (ret != 0) {
2157 return -1;
2160 ok = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
2162 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2164 return ok;
2167 static bool catia_strict_lock(struct vfs_handle_struct *handle,
2168 struct files_struct *fsp,
2169 struct lock_struct *plock)
2171 struct catia_cache *cc = NULL;
2172 int ret;
2173 bool ok;
2175 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2176 if (ret != 0) {
2177 return -1;
2180 ok = SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
2182 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2184 return ok;
2187 static void catia_strict_unlock(struct vfs_handle_struct *handle,
2188 struct files_struct *fsp,
2189 struct lock_struct *plock)
2191 struct catia_cache *cc = NULL;
2192 int ret;
2194 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2195 if (ret != 0) {
2196 smb_panic("CATIA_FETCH_FSP_PRE_NEXT failed\n");
2199 SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
2201 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2204 static NTSTATUS catia_fsctl(struct vfs_handle_struct *handle,
2205 struct files_struct *fsp,
2206 TALLOC_CTX *ctx,
2207 uint32_t function,
2208 uint16_t req_flags,
2209 const uint8_t *_in_data,
2210 uint32_t in_len,
2211 uint8_t **_out_data,
2212 uint32_t max_out_len,
2213 uint32_t *out_len)
2215 NTSTATUS result;
2216 struct catia_cache *cc = NULL;
2217 int ret;
2219 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2220 if (ret != 0) {
2221 return map_nt_error_from_unix(errno);
2224 result = SMB_VFS_NEXT_FSCTL(handle,
2225 fsp,
2226 ctx,
2227 function,
2228 req_flags,
2229 _in_data,
2230 in_len,
2231 _out_data,
2232 max_out_len,
2233 out_len);
2235 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2237 return result;
2240 static NTSTATUS catia_get_compression(vfs_handle_struct *handle,
2241 TALLOC_CTX *mem_ctx,
2242 struct files_struct *fsp,
2243 struct smb_filename *smb_fname,
2244 uint16_t *_compression_fmt)
2246 NTSTATUS result;
2247 struct catia_cache *cc = NULL;
2248 int ret;
2250 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2251 if (ret != 0) {
2252 return map_nt_error_from_unix(errno);
2255 result = SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
2256 _compression_fmt);
2258 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2260 return result;
2263 static NTSTATUS catia_set_compression(vfs_handle_struct *handle,
2264 TALLOC_CTX *mem_ctx,
2265 struct files_struct *fsp,
2266 uint16_t compression_fmt)
2268 NTSTATUS result;
2269 struct catia_cache *cc = NULL;
2270 int ret;
2272 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2273 if (ret != 0) {
2274 return map_nt_error_from_unix(errno);
2277 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2278 compression_fmt);
2280 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2282 return result;
2285 static NTSTATUS catia_readdir_attr(struct vfs_handle_struct *handle,
2286 const struct smb_filename *smb_fname_in,
2287 TALLOC_CTX *mem_ctx,
2288 struct readdir_attr_data **pattr_data)
2290 struct smb_filename *smb_fname;
2291 char *fname = NULL;
2292 NTSTATUS status;
2294 status = catia_string_replace_allocate(handle->conn,
2295 smb_fname_in->base_name,
2296 &fname,
2297 vfs_translate_to_unix);
2298 if (!NT_STATUS_IS_OK(status)) {
2299 errno = map_errno_from_nt_status(status);
2300 return status;
2303 smb_fname = synthetic_smb_fname(talloc_tos(), fname, NULL,
2304 &smb_fname_in->st, 0);
2306 status = SMB_VFS_NEXT_READDIR_ATTR(handle, smb_fname, mem_ctx, pattr_data);
2308 TALLOC_FREE(smb_fname);
2309 return status;
2312 static NTSTATUS catia_get_dos_attributes(struct vfs_handle_struct *handle,
2313 struct smb_filename *smb_fname,
2314 uint32_t *dosmode)
2316 char *mapped_name = NULL;
2317 const char *path = smb_fname->base_name;
2318 struct smb_filename *mapped_smb_fname = NULL;
2319 NTSTATUS status;
2321 status = catia_string_replace_allocate(handle->conn,
2322 path, &mapped_name, vfs_translate_to_unix);
2323 if (!NT_STATUS_IS_OK(status)) {
2324 errno = map_errno_from_nt_status(status);
2325 return status;
2327 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2328 mapped_name,
2329 NULL,
2330 NULL,
2331 smb_fname->flags);
2332 if (mapped_smb_fname == NULL) {
2333 TALLOC_FREE(mapped_name);
2334 return NT_STATUS_NO_MEMORY;
2337 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2338 mapped_smb_fname,
2339 dosmode);
2340 TALLOC_FREE(mapped_name);
2341 TALLOC_FREE(mapped_smb_fname);
2343 return status;
2346 static NTSTATUS catia_set_dos_attributes(struct vfs_handle_struct *handle,
2347 const struct smb_filename *smb_fname,
2348 uint32_t dosmode)
2350 char *mapped_name = NULL;
2351 const char *path = smb_fname->base_name;
2352 struct smb_filename *mapped_smb_fname = NULL;
2353 NTSTATUS status;
2355 status = catia_string_replace_allocate(handle->conn,
2356 path, &mapped_name, vfs_translate_to_unix);
2357 if (!NT_STATUS_IS_OK(status)) {
2358 errno = map_errno_from_nt_status(status);
2359 return status;
2361 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2362 mapped_name,
2363 NULL,
2364 NULL,
2365 smb_fname->flags);
2366 if (mapped_smb_fname == NULL) {
2367 TALLOC_FREE(mapped_name);
2368 return NT_STATUS_NO_MEMORY;
2371 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2372 mapped_smb_fname,
2373 dosmode);
2374 TALLOC_FREE(mapped_name);
2375 TALLOC_FREE(mapped_smb_fname);
2377 return status;
2380 static struct vfs_fn_pointers vfs_catia_fns = {
2381 /* Directory operations */
2382 .mkdir_fn = catia_mkdir,
2383 .rmdir_fn = catia_rmdir,
2384 .opendir_fn = catia_opendir,
2385 .readdir_attr_fn = catia_readdir_attr,
2387 /* File operations */
2388 .open_fn = catia_open,
2389 .pread_fn = catia_pread,
2390 .pread_send_fn = catia_pread_send,
2391 .pread_recv_fn = catia_pread_recv,
2392 .pwrite_fn = catia_pwrite,
2393 .pwrite_send_fn = catia_pwrite_send,
2394 .pwrite_recv_fn = catia_pwrite_recv,
2395 .lseek_fn = catia_lseek,
2396 .rename_fn = catia_rename,
2397 .fsync_fn = catia_fsync,
2398 .fsync_send_fn = catia_fsync_send,
2399 .fsync_recv_fn = catia_fsync_recv,
2400 .stat_fn = catia_stat,
2401 .fstat_fn = catia_fstat,
2402 .lstat_fn = catia_lstat,
2403 .unlink_fn = catia_unlink,
2404 .chmod_fn = catia_chmod,
2405 .fchmod_fn = catia_fchmod,
2406 .chown_fn = catia_chown,
2407 .fchown_fn = catia_fchown,
2408 .lchown_fn = catia_lchown,
2409 .chdir_fn = catia_chdir,
2410 .ntimes_fn = catia_ntimes,
2411 .ftruncate_fn = catia_ftruncate,
2412 .fallocate_fn = catia_fallocate,
2413 .lock_fn = catia_lock,
2414 .kernel_flock_fn = catia_kernel_flock,
2415 .linux_setlease_fn = catia_linux_setlease,
2416 .getlock_fn = catia_getlock,
2417 .realpath_fn = catia_realpath,
2418 .chflags_fn = catia_chflags,
2419 .streaminfo_fn = catia_streaminfo,
2420 .strict_lock_fn = catia_strict_lock,
2421 .strict_unlock_fn = catia_strict_unlock,
2422 .translate_name_fn = catia_translate_name,
2423 .fsctl_fn = catia_fsctl,
2424 .get_dos_attributes_fn = catia_get_dos_attributes,
2425 .set_dos_attributes_fn = catia_set_dos_attributes,
2426 .fset_dos_attributes_fn = catia_fset_dos_attributes,
2427 .fget_dos_attributes_fn = catia_fget_dos_attributes,
2428 .get_compression_fn = catia_get_compression,
2429 .set_compression_fn = catia_set_compression,
2431 /* NT ACL operations. */
2432 .get_nt_acl_fn = catia_get_nt_acl,
2433 .fget_nt_acl_fn = catia_fget_nt_acl,
2434 .fset_nt_acl_fn = catia_fset_nt_acl,
2436 /* POSIX ACL operations. */
2437 .chmod_acl_fn = catia_chmod_acl,
2438 .fchmod_acl_fn = catia_fchmod_acl,
2440 .sys_acl_get_file_fn = catia_sys_acl_get_file,
2441 .sys_acl_get_fd_fn = catia_sys_acl_get_fd,
2442 .sys_acl_blob_get_fd_fn = catia_sys_acl_blob_get_fd,
2443 .sys_acl_set_file_fn = catia_sys_acl_set_file,
2444 .sys_acl_set_fd_fn = catia_sys_acl_set_fd,
2445 .sys_acl_delete_def_file_fn = catia_sys_acl_delete_def_file,
2447 /* EA operations. */
2448 .getxattr_fn = catia_getxattr,
2449 .listxattr_fn = catia_listxattr,
2450 .removexattr_fn = catia_removexattr,
2451 .setxattr_fn = catia_setxattr,
2452 .fgetxattr_fn = catia_fgetxattr,
2453 .flistxattr_fn = catia_flistxattr,
2454 .fremovexattr_fn = catia_fremovexattr,
2455 .fsetxattr_fn = catia_fsetxattr,
2458 static_decl_vfs;
2459 NTSTATUS vfs_catia_init(TALLOC_CTX *ctx)
2461 NTSTATUS ret;
2463 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
2464 &vfs_catia_fns);
2465 if (!NT_STATUS_IS_OK(ret))
2466 return ret;
2468 vfs_catia_debug_level = debug_add_class("catia");
2469 if (vfs_catia_debug_level == -1) {
2470 vfs_catia_debug_level = DBGC_VFS;
2471 DEBUG(0, ("vfs_catia: Couldn't register custom debugging "
2472 "class!\n"));
2473 } else {
2474 DEBUG(10, ("vfs_catia: Debug class number of "
2475 "'catia': %d\n", vfs_catia_debug_level));
2478 return ret;