s3: vfs: catia: compression get/set must act only on base file, and must cope with...
[Samba.git] / source3 / modules / vfs_catia.c
blobc47b64d8657c6e9b902517b7acf541615ca8b832
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 struct smb_filename *smb_fname)
996 char *name = NULL;
997 struct smb_filename *catia_smb_fname = NULL;
998 NTSTATUS status;
999 int ret;
1001 status = catia_string_replace_allocate(handle->conn,
1002 smb_fname->base_name,
1003 &name,
1004 vfs_translate_to_unix);
1005 if (!NT_STATUS_IS_OK(status)) {
1006 errno = map_errno_from_nt_status(status);
1007 return -1;
1010 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
1011 name,
1012 NULL,
1013 NULL,
1014 smb_fname->flags);
1015 if (catia_smb_fname == NULL) {
1016 TALLOC_FREE(name);
1017 errno = ENOMEM;
1018 return -1;
1020 ret = SMB_VFS_NEXT_CHDIR(handle, catia_smb_fname);
1021 TALLOC_FREE(name);
1022 TALLOC_FREE(catia_smb_fname);
1024 return ret;
1027 static int catia_ntimes(vfs_handle_struct *handle,
1028 const struct smb_filename *smb_fname,
1029 struct smb_file_time *ft)
1031 struct smb_filename *smb_fname_tmp = NULL;
1032 char *name = NULL;
1033 NTSTATUS status;
1034 int ret;
1036 status = catia_string_replace_allocate(handle->conn,
1037 smb_fname->base_name,
1038 &name, vfs_translate_to_unix);
1039 if (!NT_STATUS_IS_OK(status)) {
1040 errno = map_errno_from_nt_status(status);
1041 return -1;
1044 smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
1045 if (smb_fname_tmp == NULL) {
1046 errno = ENOMEM;
1047 return -1;
1050 smb_fname_tmp->base_name = name;
1051 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname_tmp, ft);
1052 TALLOC_FREE(name);
1053 TALLOC_FREE(smb_fname_tmp);
1055 return ret;
1058 static struct smb_filename *
1059 catia_realpath(vfs_handle_struct *handle,
1060 TALLOC_CTX *ctx,
1061 const struct smb_filename *smb_fname)
1063 char *mapped_name = NULL;
1064 struct smb_filename *catia_smb_fname = NULL;
1065 struct smb_filename *return_fname = NULL;
1066 NTSTATUS status;
1068 status = catia_string_replace_allocate(handle->conn,
1069 smb_fname->base_name,
1070 &mapped_name, vfs_translate_to_unix);
1071 if (!NT_STATUS_IS_OK(status)) {
1072 errno = map_errno_from_nt_status(status);
1073 return NULL;
1076 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
1077 mapped_name,
1078 NULL,
1079 NULL,
1080 smb_fname->flags);
1081 if (catia_smb_fname == NULL) {
1082 TALLOC_FREE(mapped_name);
1083 errno = ENOMEM;
1084 return NULL;
1086 return_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, catia_smb_fname);
1087 TALLOC_FREE(mapped_name);
1088 TALLOC_FREE(catia_smb_fname);
1089 return return_fname;
1092 static int catia_chflags(struct vfs_handle_struct *handle,
1093 const struct smb_filename *smb_fname,
1094 unsigned int flags)
1096 char *name = NULL;
1097 struct smb_filename *catia_smb_fname = NULL;
1098 NTSTATUS status;
1099 int ret;
1101 status = catia_string_replace_allocate(handle->conn,
1102 smb_fname->base_name,
1103 &name,
1104 vfs_translate_to_unix);
1105 if (!NT_STATUS_IS_OK(status)) {
1106 errno = map_errno_from_nt_status(status);
1107 return -1;
1109 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
1110 name,
1111 NULL,
1112 NULL,
1113 smb_fname->flags);
1114 if (catia_smb_fname == NULL) {
1115 TALLOC_FREE(name);
1116 errno = ENOMEM;
1117 return -1;
1120 ret = SMB_VFS_NEXT_CHFLAGS(handle, catia_smb_fname, flags);
1121 TALLOC_FREE(name);
1122 TALLOC_FREE(catia_smb_fname);
1124 return ret;
1127 static NTSTATUS
1128 catia_streaminfo(struct vfs_handle_struct *handle,
1129 struct files_struct *fsp,
1130 const struct smb_filename *smb_fname,
1131 TALLOC_CTX *mem_ctx,
1132 unsigned int *_num_streams,
1133 struct stream_struct **_streams)
1135 char *mapped_name = NULL;
1136 NTSTATUS status;
1137 unsigned int i;
1138 struct smb_filename *catia_smb_fname = NULL;
1139 unsigned int num_streams = 0;
1140 struct stream_struct *streams = NULL;
1142 *_num_streams = 0;
1143 *_streams = NULL;
1145 status = catia_string_replace_allocate(handle->conn,
1146 smb_fname->base_name,
1147 &mapped_name,
1148 vfs_translate_to_unix);
1149 if (!NT_STATUS_IS_OK(status)) {
1150 errno = map_errno_from_nt_status(status);
1151 return status;
1154 catia_smb_fname = synthetic_smb_fname(talloc_tos(),
1155 mapped_name,
1156 NULL,
1157 NULL,
1158 smb_fname->flags);
1159 if (catia_smb_fname == NULL) {
1160 TALLOC_FREE(mapped_name);
1161 return NT_STATUS_NO_MEMORY;
1164 status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, catia_smb_fname,
1165 mem_ctx, &num_streams, &streams);
1166 TALLOC_FREE(mapped_name);
1167 TALLOC_FREE(catia_smb_fname);
1168 if (!NT_STATUS_IS_OK(status)) {
1169 return status;
1173 * Translate stream names just like the base names
1175 for (i = 0; i < num_streams; i++) {
1177 * Strip ":" prefix and ":$DATA" suffix to get a
1178 * "pure" stream name and only translate that.
1180 void *old_ptr = streams[i].name;
1181 char *stream_name = streams[i].name + 1;
1182 char *stream_type = strrchr_m(stream_name, ':');
1184 if (stream_type != NULL) {
1185 *stream_type = '\0';
1186 stream_type += 1;
1189 status = catia_string_replace_allocate(handle->conn, stream_name,
1190 &mapped_name, vfs_translate_to_windows);
1191 if (!NT_STATUS_IS_OK(status)) {
1192 TALLOC_FREE(streams);
1193 return status;
1196 if (stream_type != NULL) {
1197 streams[i].name = talloc_asprintf(streams, ":%s:%s",
1198 mapped_name, stream_type);
1199 } else {
1200 streams[i].name = talloc_asprintf(streams, ":%s",
1201 mapped_name);
1203 TALLOC_FREE(mapped_name);
1204 TALLOC_FREE(old_ptr);
1205 if (streams[i].name == NULL) {
1206 TALLOC_FREE(streams);
1207 return NT_STATUS_NO_MEMORY;
1211 *_num_streams = num_streams;
1212 *_streams = streams;
1213 return NT_STATUS_OK;
1216 static NTSTATUS
1217 catia_get_nt_acl(struct vfs_handle_struct *handle,
1218 const struct smb_filename *smb_fname,
1219 uint32_t security_info,
1220 TALLOC_CTX *mem_ctx,
1221 struct security_descriptor **ppdesc)
1223 char *mapped_name = NULL;
1224 const char *path = smb_fname->base_name;
1225 struct smb_filename *mapped_smb_fname = NULL;
1226 NTSTATUS status;
1228 status = catia_string_replace_allocate(handle->conn,
1229 path, &mapped_name, vfs_translate_to_unix);
1230 if (!NT_STATUS_IS_OK(status)) {
1231 errno = map_errno_from_nt_status(status);
1232 return status;
1234 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1235 mapped_name,
1236 NULL,
1237 NULL,
1238 smb_fname->flags);
1239 if (mapped_smb_fname == NULL) {
1240 TALLOC_FREE(mapped_name);
1241 return NT_STATUS_NO_MEMORY;
1244 status = SMB_VFS_NEXT_GET_NT_ACL(handle, mapped_smb_fname,
1245 security_info, mem_ctx, ppdesc);
1246 TALLOC_FREE(mapped_name);
1247 TALLOC_FREE(mapped_smb_fname);
1249 return status;
1252 static int
1253 catia_chmod_acl(vfs_handle_struct *handle,
1254 const struct smb_filename *smb_fname,
1255 mode_t mode)
1257 char *mapped_name = NULL;
1258 struct smb_filename *mapped_smb_fname = NULL;
1259 NTSTATUS status;
1260 int ret;
1261 int saved_errno;
1263 status = catia_string_replace_allocate(handle->conn,
1264 smb_fname->base_name,
1265 &mapped_name,
1266 vfs_translate_to_unix);
1267 if (!NT_STATUS_IS_OK(status)) {
1268 errno = map_errno_from_nt_status(status);
1269 return -1;
1272 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1273 mapped_name,
1274 NULL,
1275 NULL,
1276 smb_fname->flags);
1277 if (mapped_smb_fname == NULL) {
1278 TALLOC_FREE(mapped_name);
1279 errno = ENOMEM;
1280 return -1;
1282 ret = SMB_VFS_NEXT_CHMOD_ACL(handle, mapped_smb_fname, mode);
1283 saved_errno = errno;
1284 TALLOC_FREE(mapped_name);
1285 TALLOC_FREE(mapped_smb_fname);
1286 errno = saved_errno;
1287 return ret;
1290 static SMB_ACL_T
1291 catia_sys_acl_get_file(vfs_handle_struct *handle,
1292 const struct smb_filename *smb_fname,
1293 SMB_ACL_TYPE_T type,
1294 TALLOC_CTX *mem_ctx)
1296 char *mapped_name = NULL;
1297 struct smb_filename *mapped_smb_fname = NULL;
1298 NTSTATUS status;
1299 SMB_ACL_T ret;
1300 int saved_errno = 0;
1302 status = catia_string_replace_allocate(handle->conn,
1303 smb_fname->base_name,
1304 &mapped_name,
1305 vfs_translate_to_unix);
1306 if (!NT_STATUS_IS_OK(status)) {
1307 errno = map_errno_from_nt_status(status);
1308 return (SMB_ACL_T)NULL;
1311 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1312 mapped_name,
1313 NULL,
1314 NULL,
1315 smb_fname->flags);
1316 if (mapped_smb_fname == NULL) {
1317 TALLOC_FREE(mapped_name);
1318 errno = ENOMEM;
1319 return (SMB_ACL_T)NULL;
1322 ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, mapped_smb_fname,
1323 type, mem_ctx);
1324 if (ret == (SMB_ACL_T)NULL) {
1325 saved_errno = errno;
1327 TALLOC_FREE(mapped_smb_fname);
1328 TALLOC_FREE(mapped_name);
1329 if (saved_errno != 0) {
1330 errno = saved_errno;
1332 return ret;
1335 static int
1336 catia_sys_acl_set_file(vfs_handle_struct *handle,
1337 const struct smb_filename *smb_fname,
1338 SMB_ACL_TYPE_T type,
1339 SMB_ACL_T theacl)
1341 struct smb_filename *mapped_smb_fname = NULL;
1342 int saved_errno = 0;
1343 char *mapped_name = NULL;
1344 NTSTATUS status;
1345 int ret;
1347 status = catia_string_replace_allocate(handle->conn,
1348 smb_fname->base_name,
1349 &mapped_name,
1350 vfs_translate_to_unix);
1351 if (!NT_STATUS_IS_OK(status)) {
1352 errno = map_errno_from_nt_status(status);
1353 return -1;
1356 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1357 mapped_name,
1358 NULL,
1359 NULL,
1360 smb_fname->flags);
1361 if (mapped_smb_fname == NULL) {
1362 TALLOC_FREE(mapped_name);
1363 errno = ENOMEM;
1364 return -1;
1367 ret = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, mapped_smb_fname,
1368 type, theacl);
1369 if (ret == -1) {
1370 saved_errno = errno;
1372 TALLOC_FREE(mapped_smb_fname);
1373 TALLOC_FREE(mapped_name);
1374 if (saved_errno != 0) {
1375 errno = saved_errno;
1377 return ret;
1380 static int
1381 catia_sys_acl_delete_def_file(vfs_handle_struct *handle,
1382 const struct smb_filename *smb_fname)
1384 struct smb_filename *mapped_smb_fname = NULL;
1385 int saved_errno = 0;
1386 char *mapped_name = NULL;
1387 NTSTATUS status;
1388 int ret;
1390 status = catia_string_replace_allocate(handle->conn,
1391 smb_fname->base_name,
1392 &mapped_name,
1393 vfs_translate_to_unix);
1394 if (!NT_STATUS_IS_OK(status)) {
1395 errno = map_errno_from_nt_status(status);
1396 return -1;
1399 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1400 mapped_name,
1401 NULL,
1402 NULL,
1403 smb_fname->flags);
1404 if (mapped_smb_fname == NULL) {
1405 TALLOC_FREE(mapped_name);
1406 errno = ENOMEM;
1407 return -1;
1409 ret = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, mapped_smb_fname);
1410 if (ret == -1) {
1411 saved_errno = errno;
1413 TALLOC_FREE(mapped_smb_fname);
1414 TALLOC_FREE(mapped_name);
1415 if (saved_errno != 0) {
1416 errno = saved_errno;
1418 return ret;
1421 static ssize_t
1422 catia_getxattr(vfs_handle_struct *handle,
1423 const struct smb_filename *smb_fname,
1424 const char *name,
1425 void *value,
1426 size_t size)
1428 struct smb_filename *mapped_smb_fname = NULL;
1429 char *mapped_name = NULL;
1430 char *mapped_ea_name = NULL;
1431 NTSTATUS status;
1432 ssize_t ret;
1433 int saved_errno = 0;
1435 status = catia_string_replace_allocate(handle->conn,
1436 smb_fname->base_name,
1437 &mapped_name,
1438 vfs_translate_to_unix);
1439 if (!NT_STATUS_IS_OK(status)) {
1440 errno = map_errno_from_nt_status(status);
1441 return -1;
1444 status = catia_string_replace_allocate(handle->conn,
1445 name, &mapped_ea_name, vfs_translate_to_unix);
1446 if (!NT_STATUS_IS_OK(status)) {
1447 TALLOC_FREE(mapped_name);
1448 errno = map_errno_from_nt_status(status);
1449 return -1;
1452 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1453 mapped_name,
1454 NULL,
1455 NULL,
1456 smb_fname->flags);
1457 if (mapped_smb_fname == NULL) {
1458 TALLOC_FREE(mapped_name);
1459 TALLOC_FREE(mapped_ea_name);
1460 errno = ENOMEM;
1461 return -1;
1464 ret = SMB_VFS_NEXT_GETXATTR(handle, mapped_smb_fname,
1465 mapped_ea_name, value, size);
1466 if (ret == -1) {
1467 saved_errno = errno;
1469 TALLOC_FREE(mapped_name);
1470 TALLOC_FREE(mapped_ea_name);
1471 TALLOC_FREE(mapped_smb_fname);
1472 if (saved_errno != 0) {
1473 errno = saved_errno;
1476 return ret;
1479 static ssize_t
1480 catia_listxattr(vfs_handle_struct *handle,
1481 const struct smb_filename *smb_fname,
1482 char *list, size_t size)
1484 struct smb_filename *mapped_smb_fname = NULL;
1485 char *mapped_name = NULL;
1486 NTSTATUS status;
1487 ssize_t ret;
1488 int saved_errno = 0;
1490 status = catia_string_replace_allocate(handle->conn,
1491 smb_fname->base_name,
1492 &mapped_name,
1493 vfs_translate_to_unix);
1494 if (!NT_STATUS_IS_OK(status)) {
1495 errno = map_errno_from_nt_status(status);
1496 return -1;
1499 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1500 mapped_name,
1501 NULL,
1502 NULL,
1503 smb_fname->flags);
1504 if (mapped_smb_fname == NULL) {
1505 TALLOC_FREE(mapped_name);
1506 errno = ENOMEM;
1507 return -1;
1510 ret = SMB_VFS_NEXT_LISTXATTR(handle, mapped_smb_fname, list, size);
1511 if (ret == -1) {
1512 saved_errno = errno;
1514 TALLOC_FREE(mapped_name);
1515 TALLOC_FREE(mapped_smb_fname);
1516 if (saved_errno != 0) {
1517 errno = saved_errno;
1520 return ret;
1523 static int
1524 catia_removexattr(vfs_handle_struct *handle,
1525 const struct smb_filename *smb_fname,
1526 const char *name)
1528 struct smb_filename *mapped_smb_fname = NULL;
1529 char *mapped_name = NULL;
1530 char *mapped_ea_name = NULL;
1531 NTSTATUS status;
1532 ssize_t ret;
1533 int saved_errno = 0;
1535 status = catia_string_replace_allocate(handle->conn,
1536 smb_fname->base_name,
1537 &mapped_name,
1538 vfs_translate_to_unix);
1539 if (!NT_STATUS_IS_OK(status)) {
1540 errno = map_errno_from_nt_status(status);
1541 return -1;
1544 status = catia_string_replace_allocate(handle->conn,
1545 name, &mapped_ea_name, vfs_translate_to_unix);
1546 if (!NT_STATUS_IS_OK(status)) {
1547 TALLOC_FREE(mapped_name);
1548 errno = map_errno_from_nt_status(status);
1549 return -1;
1552 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1553 mapped_name,
1554 NULL,
1555 NULL,
1556 smb_fname->flags);
1557 if (mapped_smb_fname == NULL) {
1558 TALLOC_FREE(mapped_name);
1559 TALLOC_FREE(mapped_ea_name);
1560 errno = ENOMEM;
1561 return -1;
1564 ret = SMB_VFS_NEXT_REMOVEXATTR(handle, mapped_smb_fname,
1565 mapped_ea_name);
1566 if (ret == -1) {
1567 saved_errno = errno;
1569 TALLOC_FREE(mapped_name);
1570 TALLOC_FREE(mapped_ea_name);
1571 TALLOC_FREE(mapped_smb_fname);
1572 if (saved_errno != 0) {
1573 errno = saved_errno;
1576 return ret;
1579 static int
1580 catia_setxattr(vfs_handle_struct *handle,
1581 const struct smb_filename *smb_fname,
1582 const char *name,
1583 const void *value,
1584 size_t size,
1585 int flags)
1587 struct smb_filename *mapped_smb_fname = NULL;
1588 char *mapped_name = NULL;
1589 char *mapped_ea_name = NULL;
1590 NTSTATUS status;
1591 ssize_t ret;
1592 int saved_errno = 0;
1594 status = catia_string_replace_allocate(handle->conn,
1595 smb_fname->base_name,
1596 &mapped_name,
1597 vfs_translate_to_unix);
1598 if (!NT_STATUS_IS_OK(status)) {
1599 errno = map_errno_from_nt_status(status);
1600 return -1;
1603 status = catia_string_replace_allocate(handle->conn,
1604 name, &mapped_ea_name, vfs_translate_to_unix);
1605 if (!NT_STATUS_IS_OK(status)) {
1606 TALLOC_FREE(mapped_name);
1607 errno = map_errno_from_nt_status(status);
1608 return -1;
1611 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1612 mapped_name,
1613 NULL,
1614 NULL,
1615 smb_fname->flags);
1616 if (mapped_smb_fname == NULL) {
1617 TALLOC_FREE(mapped_name);
1618 TALLOC_FREE(mapped_ea_name);
1619 errno = ENOMEM;
1620 return -1;
1623 ret = SMB_VFS_NEXT_SETXATTR(handle, mapped_smb_fname, mapped_ea_name,
1624 value, size, flags);
1625 if (ret == -1) {
1626 saved_errno = errno;
1628 TALLOC_FREE(mapped_name);
1629 TALLOC_FREE(mapped_ea_name);
1630 TALLOC_FREE(mapped_smb_fname);
1631 if (saved_errno != 0) {
1632 errno = saved_errno;
1635 return ret;
1638 static int catia_fstat(vfs_handle_struct *handle,
1639 files_struct *fsp,
1640 SMB_STRUCT_STAT *sbuf)
1642 struct catia_cache *cc = NULL;
1643 int ret;
1645 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1646 if (ret != 0) {
1647 return ret;
1650 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1652 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1654 return ret;
1657 static ssize_t catia_pread(vfs_handle_struct *handle,
1658 files_struct *fsp, void *data,
1659 size_t n, off_t offset)
1661 struct catia_cache *cc = NULL;
1662 ssize_t result;
1663 int ret;
1665 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1666 if (ret != 0) {
1667 return ret;
1670 result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1672 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1674 return result;
1677 static ssize_t catia_pwrite(vfs_handle_struct *handle,
1678 files_struct *fsp, const void *data,
1679 size_t n, off_t offset)
1681 struct catia_cache *cc = NULL;
1682 ssize_t result;
1683 int ret;
1685 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1686 if (ret != 0) {
1687 return ret;
1690 result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1692 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1694 return result;
1697 static int catia_ftruncate(struct vfs_handle_struct *handle,
1698 struct files_struct *fsp,
1699 off_t offset)
1701 struct catia_cache *cc = NULL;
1702 int ret;
1704 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1705 if (ret != 0) {
1706 return ret;
1709 ret = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
1711 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1713 return ret;
1716 static int catia_fallocate(struct vfs_handle_struct *handle,
1717 struct files_struct *fsp,
1718 uint32_t mode,
1719 off_t offset,
1720 off_t len)
1722 struct catia_cache *cc = NULL;
1723 int ret;
1725 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1726 if (ret != 0) {
1727 return ret;
1730 ret = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1732 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1734 return ret;
1737 static ssize_t catia_fgetxattr(struct vfs_handle_struct *handle,
1738 struct files_struct *fsp,
1739 const char *name,
1740 void *value,
1741 size_t size)
1743 char *mapped_xattr_name = NULL;
1744 NTSTATUS status;
1745 ssize_t result;
1747 status = catia_string_replace_allocate(handle->conn,
1748 name, &mapped_xattr_name,
1749 vfs_translate_to_unix);
1750 if (!NT_STATUS_IS_OK(status)) {
1751 errno = map_errno_from_nt_status(status);
1752 return -1;
1755 result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, mapped_xattr_name,
1756 value, size);
1758 TALLOC_FREE(mapped_xattr_name);
1760 return result;
1763 static ssize_t catia_flistxattr(struct vfs_handle_struct *handle,
1764 struct files_struct *fsp,
1765 char *list,
1766 size_t size)
1768 struct catia_cache *cc = NULL;
1769 ssize_t result;
1770 int ret;
1772 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1773 if (ret != 0) {
1774 return ret;
1777 result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
1779 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1781 return result;
1784 static int catia_fremovexattr(struct vfs_handle_struct *handle,
1785 struct files_struct *fsp,
1786 const char *name)
1788 char *mapped_name = NULL;
1789 NTSTATUS status;
1790 int ret;
1792 status = catia_string_replace_allocate(handle->conn,
1793 name, &mapped_name, vfs_translate_to_unix);
1794 if (!NT_STATUS_IS_OK(status)) {
1795 errno = map_errno_from_nt_status(status);
1796 return -1;
1799 ret = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, mapped_name);
1801 TALLOC_FREE(mapped_name);
1803 return ret;
1806 static int catia_fsetxattr(struct vfs_handle_struct *handle,
1807 struct files_struct *fsp,
1808 const char *name,
1809 const void *value,
1810 size_t size,
1811 int flags)
1813 char *mapped_xattr_name = NULL;
1814 NTSTATUS status;
1815 int ret;
1817 status = catia_string_replace_allocate(
1818 handle->conn, name, &mapped_xattr_name, vfs_translate_to_unix);
1819 if (!NT_STATUS_IS_OK(status)) {
1820 errno = map_errno_from_nt_status(status);
1821 return -1;
1824 ret = SMB_VFS_NEXT_FSETXATTR(handle, fsp, mapped_xattr_name,
1825 value, size, flags);
1827 TALLOC_FREE(mapped_xattr_name);
1829 return ret;
1832 static SMB_ACL_T catia_sys_acl_get_fd(vfs_handle_struct *handle,
1833 files_struct *fsp,
1834 TALLOC_CTX *mem_ctx)
1836 struct catia_cache *cc = NULL;
1837 struct smb_acl_t *result = NULL;
1838 int ret;
1840 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1841 if (ret != 0) {
1842 return NULL;
1845 result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1847 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1849 return result;
1852 static int catia_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1853 files_struct *fsp,
1854 TALLOC_CTX *mem_ctx,
1855 char **blob_description,
1856 DATA_BLOB *blob)
1858 struct catia_cache *cc = NULL;
1859 int ret;
1861 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1862 if (ret != 0) {
1863 return ret;
1866 ret = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1867 blob_description, blob);
1869 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1871 return ret;
1874 static int catia_sys_acl_set_fd(vfs_handle_struct *handle,
1875 files_struct *fsp,
1876 SMB_ACL_T theacl)
1878 struct catia_cache *cc = NULL;
1879 int ret;
1881 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1882 if (ret != 0) {
1883 return ret;
1886 ret = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1888 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1890 return ret;
1893 static int catia_fchmod_acl(vfs_handle_struct *handle,
1894 files_struct *fsp,
1895 mode_t mode)
1897 struct catia_cache *cc = NULL;
1898 int ret;
1900 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1901 if (ret != 0) {
1902 return ret;
1905 ret = SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
1907 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1909 return ret;
1912 static NTSTATUS catia_fget_nt_acl(vfs_handle_struct *handle,
1913 files_struct *fsp,
1914 uint32_t security_info,
1915 TALLOC_CTX *mem_ctx,
1916 struct security_descriptor **ppdesc)
1918 struct catia_cache *cc = NULL;
1919 NTSTATUS status;
1920 int ret;
1922 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1923 if (ret != 0) {
1924 return map_nt_error_from_unix(errno);
1927 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1928 mem_ctx, ppdesc);
1930 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1932 return status;
1935 static NTSTATUS catia_fset_nt_acl(vfs_handle_struct *handle,
1936 files_struct *fsp,
1937 uint32_t security_info_sent,
1938 const struct security_descriptor *psd)
1940 struct catia_cache *cc = NULL;
1941 NTSTATUS status;
1942 int ret;
1944 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1945 if (ret != 0) {
1946 return map_nt_error_from_unix(errno);
1949 status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1951 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1953 return status;
1956 static NTSTATUS catia_fset_dos_attributes(struct vfs_handle_struct *handle,
1957 struct files_struct *fsp,
1958 uint32_t dosmode)
1960 struct catia_cache *cc = NULL;
1961 NTSTATUS status;
1962 int ret;
1964 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1965 if (ret != 0) {
1966 return map_nt_error_from_unix(errno);
1969 status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1971 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1973 return status;
1976 static NTSTATUS catia_fget_dos_attributes(struct vfs_handle_struct *handle,
1977 struct files_struct *fsp,
1978 uint32_t *dosmode)
1980 struct catia_cache *cc = NULL;
1981 NTSTATUS status;
1982 int ret;
1984 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1985 if (ret != 0) {
1986 return map_nt_error_from_unix(errno);
1989 status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1991 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1993 return status;
1996 static int catia_fchown(vfs_handle_struct *handle,
1997 files_struct *fsp,
1998 uid_t uid,
1999 gid_t gid)
2001 struct catia_cache *cc = NULL;
2002 int ret;
2004 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2005 if (ret != 0) {
2006 return ret;
2009 ret = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
2011 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2013 return ret;
2016 static int catia_fchmod(vfs_handle_struct *handle,
2017 files_struct *fsp,
2018 mode_t mode)
2020 struct catia_cache *cc = NULL;
2021 int ret;
2023 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2024 if (ret != 0) {
2025 return ret;
2028 ret = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
2030 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2032 return ret;
2035 struct catia_pread_state {
2036 ssize_t ret;
2037 struct vfs_aio_state vfs_aio_state;
2038 struct files_struct *fsp;
2039 struct catia_cache *cc;
2042 static void catia_pread_done(struct tevent_req *subreq);
2044 static struct tevent_req *catia_pread_send(struct vfs_handle_struct *handle,
2045 TALLOC_CTX *mem_ctx,
2046 struct tevent_context *ev,
2047 struct files_struct *fsp,
2048 void *data,
2049 size_t n,
2050 off_t offset)
2052 struct tevent_req *req = NULL, *subreq = NULL;
2053 struct catia_pread_state *state = NULL;
2054 int ret;
2056 req = tevent_req_create(mem_ctx, &state,
2057 struct catia_pread_state);
2058 if (req == NULL) {
2059 return NULL;
2061 state->fsp = fsp;
2063 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
2064 if (ret != 0) {
2065 tevent_req_error(req, errno);
2066 return tevent_req_post(req, ev);
2069 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
2070 n, offset);
2071 if (tevent_req_nomem(subreq, req)) {
2072 return tevent_req_post(req, ev);
2074 tevent_req_set_callback(subreq, catia_pread_done, req);
2076 return req;
2079 static void catia_pread_done(struct tevent_req *subreq)
2081 struct tevent_req *req = tevent_req_callback_data(
2082 subreq, struct tevent_req);
2083 struct catia_pread_state *state = tevent_req_data(
2084 req, struct catia_pread_state);
2086 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
2087 TALLOC_FREE(subreq);
2089 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
2091 tevent_req_done(req);
2094 static ssize_t catia_pread_recv(struct tevent_req *req,
2095 struct vfs_aio_state *vfs_aio_state)
2097 struct catia_pread_state *state = tevent_req_data(
2098 req, struct catia_pread_state);
2100 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2101 return -1;
2104 *vfs_aio_state = state->vfs_aio_state;
2105 return state->ret;
2108 struct catia_pwrite_state {
2109 ssize_t ret;
2110 struct vfs_aio_state vfs_aio_state;
2111 struct files_struct *fsp;
2112 struct catia_cache *cc;
2115 static void catia_pwrite_done(struct tevent_req *subreq);
2117 static struct tevent_req *catia_pwrite_send(struct vfs_handle_struct *handle,
2118 TALLOC_CTX *mem_ctx,
2119 struct tevent_context *ev,
2120 struct files_struct *fsp,
2121 const void *data,
2122 size_t n,
2123 off_t offset)
2125 struct tevent_req *req = NULL, *subreq = NULL;
2126 struct catia_pwrite_state *state = NULL;
2127 int ret;
2129 req = tevent_req_create(mem_ctx, &state,
2130 struct catia_pwrite_state);
2131 if (req == NULL) {
2132 return NULL;
2134 state->fsp = fsp;
2136 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
2137 if (ret != 0) {
2138 tevent_req_error(req, errno);
2139 return tevent_req_post(req, ev);
2142 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
2143 n, offset);
2144 if (tevent_req_nomem(subreq, req)) {
2145 return tevent_req_post(req, ev);
2147 tevent_req_set_callback(subreq, catia_pwrite_done, req);
2149 return req;
2152 static void catia_pwrite_done(struct tevent_req *subreq)
2154 struct tevent_req *req = tevent_req_callback_data(
2155 subreq, struct tevent_req);
2156 struct catia_pwrite_state *state = tevent_req_data(
2157 req, struct catia_pwrite_state);
2159 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
2160 TALLOC_FREE(subreq);
2162 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
2164 tevent_req_done(req);
2167 static ssize_t catia_pwrite_recv(struct tevent_req *req,
2168 struct vfs_aio_state *vfs_aio_state)
2170 struct catia_pwrite_state *state = tevent_req_data(
2171 req, struct catia_pwrite_state);
2173 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2174 return -1;
2177 *vfs_aio_state = state->vfs_aio_state;
2178 return state->ret;
2181 static off_t catia_lseek(vfs_handle_struct *handle,
2182 files_struct *fsp,
2183 off_t offset,
2184 int whence)
2186 struct catia_cache *cc = NULL;
2187 ssize_t result;
2188 int ret;
2190 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2191 if (ret != 0) {
2192 return -1;
2195 result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
2197 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2199 return result;
2202 static int catia_fsync(vfs_handle_struct *handle, files_struct *fsp)
2204 struct catia_cache *cc = NULL;
2205 int ret;
2207 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2208 if (ret != 0) {
2209 return -1;
2212 ret = SMB_VFS_NEXT_FSYNC(handle, fsp);
2214 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2216 return ret;
2219 struct catia_fsync_state {
2220 int ret;
2221 struct vfs_aio_state vfs_aio_state;
2222 struct files_struct *fsp;
2223 struct catia_cache *cc;
2226 static void catia_fsync_done(struct tevent_req *subreq);
2228 static struct tevent_req *catia_fsync_send(struct vfs_handle_struct *handle,
2229 TALLOC_CTX *mem_ctx,
2230 struct tevent_context *ev,
2231 struct files_struct *fsp)
2233 struct tevent_req *req = NULL, *subreq = NULL;
2234 struct catia_fsync_state *state = NULL;
2235 int ret;
2237 req = tevent_req_create(mem_ctx, &state,
2238 struct catia_fsync_state);
2239 if (req == NULL) {
2240 return NULL;
2242 state->fsp = fsp;
2244 ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
2245 if (ret != 0) {
2246 tevent_req_error(req, errno);
2247 return tevent_req_post(req, ev);
2250 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
2251 if (tevent_req_nomem(subreq, req)) {
2252 return tevent_req_post(req, ev);
2254 tevent_req_set_callback(subreq, catia_fsync_done, req);
2256 return req;
2259 static void catia_fsync_done(struct tevent_req *subreq)
2261 struct tevent_req *req = tevent_req_callback_data(
2262 subreq, struct tevent_req);
2263 struct catia_fsync_state *state = tevent_req_data(
2264 req, struct catia_fsync_state);
2266 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
2267 TALLOC_FREE(subreq);
2269 CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
2271 tevent_req_done(req);
2274 static int catia_fsync_recv(struct tevent_req *req,
2275 struct vfs_aio_state *vfs_aio_state)
2277 struct catia_fsync_state *state = tevent_req_data(
2278 req, struct catia_fsync_state);
2280 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
2281 return -1;
2284 *vfs_aio_state = state->vfs_aio_state;
2285 return state->ret;
2288 static bool catia_lock(vfs_handle_struct *handle,
2289 files_struct *fsp,
2290 int op,
2291 off_t offset,
2292 off_t count,
2293 int type)
2295 struct catia_cache *cc = NULL;
2296 bool ok;
2297 int ret;
2299 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2300 if (ret != 0) {
2301 return -1;
2304 ok = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
2306 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2308 return ok;
2311 static int catia_kernel_flock(struct vfs_handle_struct *handle,
2312 struct files_struct *fsp,
2313 uint32_t share_mode,
2314 uint32_t access_mask)
2316 struct catia_cache *cc = NULL;
2317 int ret;
2319 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2320 if (ret != 0) {
2321 return -1;
2324 ret = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
2326 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2328 return ret;
2331 static int catia_linux_setlease(vfs_handle_struct *handle,
2332 files_struct *fsp,
2333 int leasetype)
2335 struct catia_cache *cc = NULL;
2336 int ret;
2338 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2339 if (ret != 0) {
2340 return -1;
2343 ret = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
2345 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2347 return ret;
2350 static bool catia_getlock(vfs_handle_struct *handle,
2351 files_struct *fsp,
2352 off_t *poffset,
2353 off_t *pcount,
2354 int *ptype,
2355 pid_t *ppid)
2357 struct catia_cache *cc = NULL;
2358 int ret;
2359 bool ok;
2361 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2362 if (ret != 0) {
2363 return -1;
2366 ok = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
2368 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2370 return ok;
2373 static bool catia_strict_lock_check(struct vfs_handle_struct *handle,
2374 struct files_struct *fsp,
2375 struct lock_struct *plock)
2377 struct catia_cache *cc = NULL;
2378 int ret;
2379 bool ok;
2381 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2382 if (ret != 0) {
2383 return -1;
2386 ok = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
2388 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2390 return ok;
2393 static NTSTATUS catia_fsctl(struct vfs_handle_struct *handle,
2394 struct files_struct *fsp,
2395 TALLOC_CTX *ctx,
2396 uint32_t function,
2397 uint16_t req_flags,
2398 const uint8_t *_in_data,
2399 uint32_t in_len,
2400 uint8_t **_out_data,
2401 uint32_t max_out_len,
2402 uint32_t *out_len)
2404 NTSTATUS result;
2405 struct catia_cache *cc = NULL;
2406 int ret;
2408 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2409 if (ret != 0) {
2410 return map_nt_error_from_unix(errno);
2413 result = SMB_VFS_NEXT_FSCTL(handle,
2414 fsp,
2415 ctx,
2416 function,
2417 req_flags,
2418 _in_data,
2419 in_len,
2420 _out_data,
2421 max_out_len,
2422 out_len);
2424 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2426 return result;
2429 static NTSTATUS catia_get_compression(vfs_handle_struct *handle,
2430 TALLOC_CTX *mem_ctx,
2431 struct files_struct *fsp,
2432 struct smb_filename *smb_fname,
2433 uint16_t *_compression_fmt)
2435 NTSTATUS result;
2436 struct catia_cache *cc = NULL;
2437 int ret;
2438 struct smb_filename *mapped_smb_fname = NULL;
2439 char *mapped_name = NULL;
2441 if (fsp != NULL) {
2442 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2443 if (ret != 0) {
2444 return map_nt_error_from_unix(errno);
2446 mapped_smb_fname = fsp->fsp_name;
2447 } else {
2448 result = catia_string_replace_allocate(handle->conn,
2449 smb_fname->base_name,
2450 &mapped_name,
2451 vfs_translate_to_unix);
2452 if (!NT_STATUS_IS_OK(result)) {
2453 return result;
2456 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2457 mapped_name,
2458 NULL,
2459 NULL,
2460 smb_fname->flags);
2461 if (mapped_smb_fname == NULL) {
2462 TALLOC_FREE(mapped_name);
2463 return NT_STATUS_NO_MEMORY;
2466 TALLOC_FREE(mapped_name);
2469 result = SMB_VFS_NEXT_GET_COMPRESSION(handle,
2470 mem_ctx,
2471 fsp,
2472 mapped_smb_fname,
2473 _compression_fmt);
2475 if (fsp != NULL) {
2476 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2477 } else {
2478 TALLOC_FREE(mapped_smb_fname);
2481 return result;
2484 static NTSTATUS catia_set_compression(vfs_handle_struct *handle,
2485 TALLOC_CTX *mem_ctx,
2486 struct files_struct *fsp,
2487 uint16_t compression_fmt)
2489 NTSTATUS result;
2490 struct catia_cache *cc = NULL;
2491 int ret;
2493 ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
2494 if (ret != 0) {
2495 return map_nt_error_from_unix(errno);
2498 result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
2499 compression_fmt);
2501 CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
2503 return result;
2506 static NTSTATUS catia_readdir_attr(struct vfs_handle_struct *handle,
2507 const struct smb_filename *smb_fname_in,
2508 TALLOC_CTX *mem_ctx,
2509 struct readdir_attr_data **pattr_data)
2511 struct smb_filename *smb_fname;
2512 char *fname = NULL;
2513 NTSTATUS status;
2515 status = catia_string_replace_allocate(handle->conn,
2516 smb_fname_in->base_name,
2517 &fname,
2518 vfs_translate_to_unix);
2519 if (!NT_STATUS_IS_OK(status)) {
2520 errno = map_errno_from_nt_status(status);
2521 return status;
2524 smb_fname = synthetic_smb_fname(talloc_tos(), fname, NULL,
2525 &smb_fname_in->st, 0);
2527 status = SMB_VFS_NEXT_READDIR_ATTR(handle, smb_fname, mem_ctx, pattr_data);
2529 TALLOC_FREE(smb_fname);
2530 return status;
2533 static NTSTATUS catia_get_dos_attributes(struct vfs_handle_struct *handle,
2534 struct smb_filename *smb_fname,
2535 uint32_t *dosmode)
2537 char *mapped_name = NULL;
2538 const char *path = smb_fname->base_name;
2539 struct smb_filename *mapped_smb_fname = NULL;
2540 NTSTATUS status;
2542 status = catia_string_replace_allocate(handle->conn,
2543 path, &mapped_name, vfs_translate_to_unix);
2544 if (!NT_STATUS_IS_OK(status)) {
2545 errno = map_errno_from_nt_status(status);
2546 return status;
2548 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2549 mapped_name,
2550 NULL,
2551 NULL,
2552 smb_fname->flags);
2553 if (mapped_smb_fname == NULL) {
2554 TALLOC_FREE(mapped_name);
2555 return NT_STATUS_NO_MEMORY;
2558 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
2559 mapped_smb_fname,
2560 dosmode);
2561 TALLOC_FREE(mapped_name);
2562 TALLOC_FREE(mapped_smb_fname);
2564 return status;
2567 static NTSTATUS catia_set_dos_attributes(struct vfs_handle_struct *handle,
2568 const struct smb_filename *smb_fname,
2569 uint32_t dosmode)
2571 char *mapped_name = NULL;
2572 const char *path = smb_fname->base_name;
2573 struct smb_filename *mapped_smb_fname = NULL;
2574 NTSTATUS status;
2576 status = catia_string_replace_allocate(handle->conn,
2577 path, &mapped_name, vfs_translate_to_unix);
2578 if (!NT_STATUS_IS_OK(status)) {
2579 errno = map_errno_from_nt_status(status);
2580 return status;
2582 mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2583 mapped_name,
2584 NULL,
2585 NULL,
2586 smb_fname->flags);
2587 if (mapped_smb_fname == NULL) {
2588 TALLOC_FREE(mapped_name);
2589 return NT_STATUS_NO_MEMORY;
2592 status = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
2593 mapped_smb_fname,
2594 dosmode);
2595 TALLOC_FREE(mapped_name);
2596 TALLOC_FREE(mapped_smb_fname);
2598 return status;
2601 static struct vfs_fn_pointers vfs_catia_fns = {
2602 /* Directory operations */
2603 .mkdir_fn = catia_mkdir,
2604 .rmdir_fn = catia_rmdir,
2605 .opendir_fn = catia_opendir,
2606 .readdir_attr_fn = catia_readdir_attr,
2608 /* File operations */
2609 .open_fn = catia_open,
2610 .pread_fn = catia_pread,
2611 .pread_send_fn = catia_pread_send,
2612 .pread_recv_fn = catia_pread_recv,
2613 .pwrite_fn = catia_pwrite,
2614 .pwrite_send_fn = catia_pwrite_send,
2615 .pwrite_recv_fn = catia_pwrite_recv,
2616 .lseek_fn = catia_lseek,
2617 .rename_fn = catia_rename,
2618 .fsync_fn = catia_fsync,
2619 .fsync_send_fn = catia_fsync_send,
2620 .fsync_recv_fn = catia_fsync_recv,
2621 .stat_fn = catia_stat,
2622 .fstat_fn = catia_fstat,
2623 .lstat_fn = catia_lstat,
2624 .unlink_fn = catia_unlink,
2625 .chmod_fn = catia_chmod,
2626 .fchmod_fn = catia_fchmod,
2627 .chown_fn = catia_chown,
2628 .fchown_fn = catia_fchown,
2629 .lchown_fn = catia_lchown,
2630 .chdir_fn = catia_chdir,
2631 .ntimes_fn = catia_ntimes,
2632 .ftruncate_fn = catia_ftruncate,
2633 .fallocate_fn = catia_fallocate,
2634 .lock_fn = catia_lock,
2635 .kernel_flock_fn = catia_kernel_flock,
2636 .linux_setlease_fn = catia_linux_setlease,
2637 .getlock_fn = catia_getlock,
2638 .realpath_fn = catia_realpath,
2639 .chflags_fn = catia_chflags,
2640 .streaminfo_fn = catia_streaminfo,
2641 .strict_lock_check_fn = catia_strict_lock_check,
2642 .translate_name_fn = catia_translate_name,
2643 .fsctl_fn = catia_fsctl,
2644 .get_dos_attributes_fn = catia_get_dos_attributes,
2645 .set_dos_attributes_fn = catia_set_dos_attributes,
2646 .fset_dos_attributes_fn = catia_fset_dos_attributes,
2647 .fget_dos_attributes_fn = catia_fget_dos_attributes,
2648 .get_compression_fn = catia_get_compression,
2649 .set_compression_fn = catia_set_compression,
2651 /* NT ACL operations. */
2652 .get_nt_acl_fn = catia_get_nt_acl,
2653 .fget_nt_acl_fn = catia_fget_nt_acl,
2654 .fset_nt_acl_fn = catia_fset_nt_acl,
2656 /* POSIX ACL operations. */
2657 .chmod_acl_fn = catia_chmod_acl,
2658 .fchmod_acl_fn = catia_fchmod_acl,
2660 .sys_acl_get_file_fn = catia_sys_acl_get_file,
2661 .sys_acl_get_fd_fn = catia_sys_acl_get_fd,
2662 .sys_acl_blob_get_fd_fn = catia_sys_acl_blob_get_fd,
2663 .sys_acl_set_file_fn = catia_sys_acl_set_file,
2664 .sys_acl_set_fd_fn = catia_sys_acl_set_fd,
2665 .sys_acl_delete_def_file_fn = catia_sys_acl_delete_def_file,
2667 /* EA operations. */
2668 .getxattr_fn = catia_getxattr,
2669 .listxattr_fn = catia_listxattr,
2670 .removexattr_fn = catia_removexattr,
2671 .setxattr_fn = catia_setxattr,
2672 .fgetxattr_fn = catia_fgetxattr,
2673 .flistxattr_fn = catia_flistxattr,
2674 .fremovexattr_fn = catia_fremovexattr,
2675 .fsetxattr_fn = catia_fsetxattr,
2678 static_decl_vfs;
2679 NTSTATUS vfs_catia_init(TALLOC_CTX *ctx)
2681 NTSTATUS ret;
2683 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
2684 &vfs_catia_fns);
2685 if (!NT_STATUS_IS_OK(ret))
2686 return ret;
2688 vfs_catia_debug_level = debug_add_class("catia");
2689 if (vfs_catia_debug_level == -1) {
2690 vfs_catia_debug_level = DBGC_VFS;
2691 DEBUG(0, ("vfs_catia: Couldn't register custom debugging "
2692 "class!\n"));
2693 } else {
2694 DEBUG(10, ("vfs_catia: Debug class number of "
2695 "'catia': %d\n", vfs_catia_debug_level));
2698 return ret;