s3: VFS: catia: Remove catia_sys_acl_delete_def_file().
[samba.git] / source3 / modules / vfs_catia.c
1 /*
2  * Catia VFS module
3  *
4  * Implement a fixed mapping of forbidden NT characters in filenames that are
5  * used a lot by the CAD package Catia.
6  *
7  * Catia V4 on AIX uses characters like "<*$ a *lot*, all forbidden under
8  * Windows...
9  *
10  * Copyright (C) Volker Lendecke, 2005
11  * Copyright (C) Aravind Srinivasan, 2009
12  * Copyright (C) Guenter Kukkukk, 2013
13  * Copyright (C) Ralph Boehme, 2017
14  *
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.
19  *
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.
24  *
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/>.
27  */
28
29
30 #include "includes.h"
31 #include "smbd/smbd.h"
32 #include "lib/util/tevent_unix.h"
33 #include "lib/util/tevent_ntstatus.h"
34 #include "string_replace.h"
35
36 static int vfs_catia_debug_level = DBGC_VFS;
37
38 #undef DBGC_CLASS
39 #define DBGC_CLASS vfs_catia_debug_level
40
41 struct share_mapping_entry {
42         int snum;
43         struct share_mapping_entry *next;
44         struct char_mappings **mappings;
45 };
46
47 struct catia_cache {
48         bool is_fsp_ext;
49         const struct catia_cache * const *busy;
50         char *orig_fname;
51         char *fname;
52         char *orig_base_fname;
53         char *base_fname;
54 };
55
56 static struct share_mapping_entry *srt_head = NULL;
57
58 static struct share_mapping_entry *get_srt(connection_struct *conn,
59                                            struct share_mapping_entry **global)
60 {
61         struct share_mapping_entry *share;
62
63         for (share = srt_head; share != NULL; share = share->next) {
64                 if (share->snum == GLOBAL_SECTION_SNUM)
65                         (*global) = share;
66
67                 if (share->snum == SNUM(conn))
68                         return share;
69         }
70
71         return share;
72 }
73
74 static struct share_mapping_entry *add_srt(int snum, const char **mappings)
75 {
76         struct share_mapping_entry *sme = NULL;
77
78         sme = talloc_zero(NULL, struct share_mapping_entry);
79         if (sme == NULL)
80                 return sme;
81
82         sme->snum = snum;
83         sme->next = srt_head;
84         srt_head = sme;
85
86         if (mappings == NULL) {
87                 sme->mappings = NULL;
88                 return sme;
89         }
90
91         sme->mappings = string_replace_init_map(sme, mappings);
92
93         return sme;
94 }
95
96 static bool init_mappings(connection_struct *conn,
97                           struct share_mapping_entry **selected_out)
98 {
99         const char **mappings = NULL;
100         struct share_mapping_entry *share_level = NULL;
101         struct share_mapping_entry *global = NULL;
102
103         /* check srt cache */
104         share_level = get_srt(conn, &global);
105         if (share_level) {
106                 *selected_out = share_level;
107                 return (share_level->mappings != NULL);
108         }
109
110         /* see if we have a global setting */
111         if (!global) {
112                 /* global setting */
113                 mappings = lp_parm_string_list(-1, "catia", "mappings", NULL);
114                 global = add_srt(GLOBAL_SECTION_SNUM, mappings);
115         }
116
117         /* no global setting - what about share level ? */
118         mappings = lp_parm_string_list(SNUM(conn), "catia", "mappings", NULL);
119         share_level = add_srt(SNUM(conn), mappings);
120
121         if (share_level->mappings) {
122                 (*selected_out) = share_level;
123                 return True;
124         }
125         if (global->mappings) {
126                 share_level->mappings = global->mappings;
127                 (*selected_out) = share_level;
128                 return True;
129         }
130
131         return False;
132 }
133
134 static NTSTATUS catia_string_replace_allocate(connection_struct *conn,
135                                               const char *name_in,
136                                               char **mapped_name,
137                                         enum vfs_translate_direction direction)
138 {
139         struct share_mapping_entry *selected;
140         NTSTATUS status;
141
142         if (!init_mappings(conn, &selected)) {
143                 /* No mappings found. Just use the old name */
144                 *mapped_name = talloc_strdup(talloc_tos(), name_in);
145                 if (!*mapped_name) {
146                         errno = ENOMEM;
147                         return NT_STATUS_NO_MEMORY;
148                 }
149                 return NT_STATUS_OK;
150         }
151
152         status = string_replace_allocate(conn,
153                                          name_in,
154                                          selected->mappings,
155                                          talloc_tos(),
156                                          mapped_name,
157                                          direction);
158         return status;
159 }
160
161 static int catia_connect(struct vfs_handle_struct *handle,
162                          const char *service,
163                          const char *user)
164 {
165         /*
166          * Unless we have an async implementation of get_dos_attributes turn
167          * this off.
168          */
169         lp_do_parameter(SNUM(handle->conn), "smbd:async dosmode", "false");
170
171         return SMB_VFS_NEXT_CONNECT(handle, service, user);
172 }
173
174 /*
175  * TRANSLATE_NAME call which converts the given name to
176  * "WINDOWS displayable" name
177  */
178 static NTSTATUS catia_translate_name(struct vfs_handle_struct *handle,
179                                      const char *orig_name,
180                                      enum vfs_translate_direction direction,
181                                      TALLOC_CTX *mem_ctx,
182                                      char **pmapped_name)
183 {
184         char *name = NULL;
185         char *mapped_name;
186         NTSTATUS status, ret;
187
188         /*
189          * Copy the supplied name and free the memory for mapped_name,
190          * already allocated by the caller.
191          * We will be allocating new memory for mapped_name in
192          * catia_string_replace_allocate
193          */
194         name = talloc_strdup(talloc_tos(), orig_name);
195         if (!name) {
196                 errno = ENOMEM;
197                 return NT_STATUS_NO_MEMORY;
198         }
199         status = catia_string_replace_allocate(handle->conn, name,
200                         &mapped_name, direction);
201
202         TALLOC_FREE(name);
203         if (!NT_STATUS_IS_OK(status)) {
204                 return status;
205         }
206
207         ret = SMB_VFS_NEXT_TRANSLATE_NAME(handle, mapped_name, direction,
208                                           mem_ctx, pmapped_name);
209
210         if (NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED)) {
211                 *pmapped_name = talloc_move(mem_ctx, &mapped_name);
212                 /* we need to return the former translation result here */
213                 ret = status;
214         } else {
215                 TALLOC_FREE(mapped_name);
216         }
217
218         return ret;
219 }
220
221 #define CATIA_DEBUG_CC(lvl, cc, fsp) \
222         catia_debug_cc((lvl), (cc), (fsp), __location__);
223
224 static void catia_debug_cc(int lvl,
225                            struct catia_cache *cc,
226                            files_struct *fsp,
227                            const char *location)
228 {
229         DEBUG(lvl, ("%s: cc [%p] cc->busy [%p] "
230                     "is_fsp_ext [%s] "
231                     "fsp [%p] fsp name [%s] "
232                     "orig_fname [%s] "
233                     "fname [%s] "
234                     "orig_base_fname [%s] "
235                     "base_fname [%s]\n",
236                     location,
237                     cc, cc->busy,
238                     cc->is_fsp_ext ? "yes" : "no",
239                     fsp, fsp_str_dbg(fsp),
240                     cc->orig_fname, cc->fname,
241                     cc->orig_base_fname, cc->base_fname));
242 }
243
244 static void catia_free_cc(struct catia_cache **_cc,
245                           vfs_handle_struct *handle,
246                           files_struct *fsp)
247 {
248         struct catia_cache *cc = *_cc;
249
250         if (cc->is_fsp_ext) {
251                 VFS_REMOVE_FSP_EXTENSION(handle, fsp);
252                 cc = NULL;
253         } else {
254                 TALLOC_FREE(cc);
255         }
256
257         *_cc = NULL;
258 }
259
260 static struct catia_cache *catia_validate_and_apply_cc(
261                                        vfs_handle_struct *handle,
262                                        files_struct *fsp,
263                                        const struct catia_cache * const *busy,
264                                        bool *make_tmp_cache)
265 {
266         struct catia_cache *cc = NULL;
267
268         *make_tmp_cache = false;
269
270         cc = (struct catia_cache *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
271         if (cc == NULL) {
272                 return NULL;
273         }
274
275         if (cc->busy != NULL) {
276                 if (cc->busy == busy) {
277                         /* This should never happen */
278                         CATIA_DEBUG_CC(0, cc, fsp);
279                         smb_panic(__location__);
280                 }
281
282                 /*
283                  * Recursion. Validate names, the names in the fsp's should be
284                  * the translated names we had set.
285                  */
286
287                 if ((cc->fname != fsp->fsp_name->base_name)
288                     ||
289                     ((fsp->base_fsp != NULL) &&
290                      (cc->base_fname != fsp->base_fsp->fsp_name->base_name)))
291                 {
292                         CATIA_DEBUG_CC(10, cc, fsp);
293
294                         /*
295                          * Names changed. Setting don't expose the cache on the
296                          * fsp and ask the caller to create a temporary cache.
297                          */
298                         *make_tmp_cache = true;
299                         return NULL;
300                 }
301
302                 /*
303                  * Ok, a validated cache while in a recursion, just let the
304                  * caller detect that cc->busy is != busy and there's
305                  * nothing else to do.
306                  */
307                 CATIA_DEBUG_CC(10, cc, fsp);
308                 return cc;
309         }
310
311         /* Not in a recursion */
312
313         if ((cc->orig_fname != fsp->fsp_name->base_name)
314             ||
315             ((fsp->base_fsp != NULL) &&
316              (cc->orig_base_fname != fsp->base_fsp->fsp_name->base_name)))
317         {
318                 /*
319                  * fsp names changed, this can happen in an rename op.
320                  * Trigger recreation as a full fledged fsp extension.
321                  */
322
323                 CATIA_DEBUG_CC(10, cc, fsp);
324                 catia_free_cc(&cc, handle, fsp);
325                 return NULL;
326         }
327
328
329         /*
330          * Ok, we found a valid cache entry, no recursion. Just set translated
331          * names from the cache and mark the cc as busy.
332          */
333         fsp->fsp_name->base_name = cc->fname;
334         if (fsp->base_fsp != NULL) {
335                 fsp->base_fsp->fsp_name->base_name = cc->base_fname;
336         }
337
338         cc->busy = busy;
339         CATIA_DEBUG_CC(10, cc, fsp);
340         return cc;
341 }
342
343 #define CATIA_FETCH_FSP_PRE_NEXT(mem_ctx, handle, fsp, _cc) \
344         catia_fetch_fsp_pre_next((mem_ctx), (handle), (fsp), (_cc), __func__);
345
346 static int catia_fetch_fsp_pre_next(TALLOC_CTX *mem_ctx,
347                                     vfs_handle_struct *handle,
348                                     files_struct *fsp,
349                                     struct catia_cache **_cc,
350                                     const char *function)
351 {
352         const struct catia_cache * const *busy =
353                 (const struct catia_cache * const *)_cc;
354         struct catia_cache *cc = NULL;
355         NTSTATUS status;
356         bool make_tmp_cache = false;
357
358         *_cc = NULL;
359
360         DBG_DEBUG("Called from [%s]\n", function);
361
362         cc = catia_validate_and_apply_cc(handle,
363                                          fsp,
364                                          busy,
365                                          &make_tmp_cache);
366         if (cc != NULL) {
367                 if (cc->busy != busy) {
368                         return 0;
369                 }
370                 *_cc = cc;
371                 return 0;
372         }
373
374         if (!make_tmp_cache) {
375                 cc = VFS_ADD_FSP_EXTENSION(
376                         handle, fsp, struct catia_cache, NULL);
377                 if (cc == NULL) {
378                         return -1;
379                 }
380                 *cc = (struct catia_cache) {
381                         .is_fsp_ext = true,
382                 };
383
384                 mem_ctx = VFS_MEMCTX_FSP_EXTENSION(handle, fsp);
385                 if (mem_ctx == NULL) {
386                         DBG_ERR("VFS_MEMCTX_FSP_EXTENSION failed\n");
387                         catia_free_cc(&cc, handle, fsp);
388                         return -1;
389                 }
390         } else {
391                 cc = talloc_zero(mem_ctx, struct catia_cache);
392                 if (cc == NULL) {
393                         return -1;
394                 }
395                 mem_ctx = cc;
396         }
397
398
399         status = catia_string_replace_allocate(handle->conn,
400                                                fsp->fsp_name->base_name,
401                                                &cc->fname,
402                                                vfs_translate_to_unix);
403         if (!NT_STATUS_IS_OK(status)) {
404                 catia_free_cc(&cc, handle, fsp);
405                 errno = map_errno_from_nt_status(status);
406                 return -1;
407         }
408         talloc_steal(mem_ctx, cc->fname);
409
410         if (fsp->base_fsp != NULL) {
411                 status = catia_string_replace_allocate(
412                         handle->conn,
413                         fsp->base_fsp->fsp_name->base_name,
414                         &cc->base_fname,
415                         vfs_translate_to_unix);
416                 if (!NT_STATUS_IS_OK(status)) {
417                         catia_free_cc(&cc, handle, fsp);
418                         errno = map_errno_from_nt_status(status);
419                         return -1;
420                 }
421                 talloc_steal(mem_ctx, cc->base_fname);
422         }
423
424         cc->orig_fname = fsp->fsp_name->base_name;
425         fsp->fsp_name->base_name = cc->fname;
426
427         if (fsp->base_fsp != NULL) {
428                 cc->orig_base_fname = fsp->base_fsp->fsp_name->base_name;
429                 fsp->base_fsp->fsp_name->base_name = cc->base_fname;
430         }
431
432         cc->busy = busy;
433         CATIA_DEBUG_CC(10, cc, fsp);
434
435         *_cc = cc;
436
437         return 0;
438 }
439
440 #define CATIA_FETCH_FSP_POST_NEXT(_cc, fsp) do { \
441         int catia_saved_errno = errno; \
442         catia_fetch_fsp_post_next((_cc), (fsp), __func__); \
443         errno = catia_saved_errno; \
444 } while(0)
445
446 static void catia_fetch_fsp_post_next(struct catia_cache **_cc,
447                                       files_struct *fsp,
448                                       const char *function)
449 {
450         const struct catia_cache * const *busy =
451                 (const struct catia_cache * const *)_cc;
452         struct catia_cache *cc = *_cc;
453
454         DBG_DEBUG("Called from [%s]\n", function);
455
456         if (cc == NULL) {
457                 /*
458                  * This can happen when recursing in the VFS on the fsp when the
459                  * pre_next func noticed the recursion and set out cc pointer to
460                  * NULL.
461                  */
462                 return;
463         }
464
465         if (cc->busy != busy) {
466                 CATIA_DEBUG_CC(0, cc, fsp);
467                 smb_panic(__location__);
468                 return;
469         }
470
471         cc->busy = NULL;
472         *_cc = NULL;
473
474         fsp->fsp_name->base_name = cc->orig_fname;
475         if (fsp->base_fsp != NULL) {
476                 fsp->base_fsp->fsp_name->base_name = cc->orig_base_fname;
477         }
478
479         CATIA_DEBUG_CC(10, cc, fsp);
480
481         if (!cc->is_fsp_ext) {
482                 TALLOC_FREE(cc);
483         }
484
485         return;
486 }
487
488 static int catia_openat(vfs_handle_struct *handle,
489                         const struct files_struct *dirfsp,
490                         const struct smb_filename *smb_fname_in,
491                         files_struct *fsp,
492                         int flags,
493                         mode_t mode)
494 {
495         struct smb_filename *smb_fname = NULL;
496         struct catia_cache *cc = NULL;
497         char *mapped_name = NULL;
498         NTSTATUS status;
499         int ret;
500         int saved_errno = 0;
501
502         status = catia_string_replace_allocate(handle->conn,
503                                                smb_fname_in->base_name,
504                                                &mapped_name,
505                                                vfs_translate_to_unix);
506         if (!NT_STATUS_IS_OK(status)) {
507                 return -1;
508         }
509
510         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
511         if (ret != 0) {
512                 TALLOC_FREE(mapped_name);
513                 return ret;
514         }
515
516         smb_fname = cp_smb_filename(talloc_tos(), smb_fname_in);
517         if (smb_fname == NULL) {
518                 TALLOC_FREE(mapped_name);
519                 errno = ENOMEM;
520                 return -1;
521         }
522         smb_fname->base_name = mapped_name;
523
524         ret = SMB_VFS_NEXT_OPENAT(handle,
525                                   dirfsp,
526                                   smb_fname,
527                                   fsp,
528                                   flags,
529                                   mode);
530
531         if (ret == -1) {
532                 saved_errno = errno;
533         }
534         TALLOC_FREE(smb_fname);
535         TALLOC_FREE(mapped_name);
536         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
537         if (saved_errno != 0) {
538                 errno = saved_errno;
539         }
540         return ret;
541 }
542
543 static int catia_renameat(vfs_handle_struct *handle,
544                         files_struct *srcfsp,
545                         const struct smb_filename *smb_fname_src,
546                         files_struct *dstfsp,
547                         const struct smb_filename *smb_fname_dst)
548 {
549         TALLOC_CTX *ctx = talloc_tos();
550         struct smb_filename *smb_fname_src_tmp = NULL;
551         struct smb_filename *smb_fname_dst_tmp = NULL;
552         char *src_name_mapped = NULL;
553         char *dst_name_mapped = NULL;
554         NTSTATUS status;
555         int ret = -1;
556
557         status = catia_string_replace_allocate(handle->conn,
558                                 smb_fname_src->base_name,
559                                 &src_name_mapped, vfs_translate_to_unix);
560         if (!NT_STATUS_IS_OK(status)) {
561                 errno = map_errno_from_nt_status(status);
562                 return -1;
563         }
564
565         status = catia_string_replace_allocate(handle->conn,
566                                 smb_fname_dst->base_name,
567                                 &dst_name_mapped, vfs_translate_to_unix);
568         if (!NT_STATUS_IS_OK(status)) {
569                 errno = map_errno_from_nt_status(status);
570                 return -1;
571         }
572
573         /* Setup temporary smb_filename structs. */
574         smb_fname_src_tmp = cp_smb_filename(ctx, smb_fname_src);
575         if (smb_fname_src_tmp == NULL) {
576                 errno = ENOMEM;
577                 goto out;
578         }
579
580         smb_fname_dst_tmp = cp_smb_filename(ctx, smb_fname_dst);
581         if (smb_fname_dst_tmp == NULL) {
582                 errno = ENOMEM;
583                 goto out;
584         }
585
586         smb_fname_src_tmp->base_name = src_name_mapped;
587         smb_fname_dst_tmp->base_name = dst_name_mapped;
588         DEBUG(10, ("converted old name: %s\n",
589                                 smb_fname_str_dbg(smb_fname_src_tmp)));
590         DEBUG(10, ("converted new name: %s\n",
591                                 smb_fname_str_dbg(smb_fname_dst_tmp)));
592
593         ret = SMB_VFS_NEXT_RENAMEAT(handle,
594                         srcfsp,
595                         smb_fname_src_tmp,
596                         dstfsp,
597                         smb_fname_dst_tmp);
598
599 out:
600         TALLOC_FREE(src_name_mapped);
601         TALLOC_FREE(dst_name_mapped);
602         TALLOC_FREE(smb_fname_src_tmp);
603         TALLOC_FREE(smb_fname_dst_tmp);
604         return ret;
605 }
606
607
608 static int catia_stat(vfs_handle_struct *handle,
609                       struct smb_filename *smb_fname)
610 {
611         char *name = NULL;
612         char *tmp_base_name;
613         int ret;
614         NTSTATUS status;
615
616         status = catia_string_replace_allocate(handle->conn,
617                                 smb_fname->base_name,
618                                 &name, vfs_translate_to_unix);
619         if (!NT_STATUS_IS_OK(status)) {
620                 errno = map_errno_from_nt_status(status);
621                 return -1;
622         }
623
624         tmp_base_name = smb_fname->base_name;
625         smb_fname->base_name = name;
626
627         ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
628         smb_fname->base_name = tmp_base_name;
629
630         TALLOC_FREE(name);
631         return ret;
632 }
633
634 static int catia_lstat(vfs_handle_struct *handle,
635                        struct smb_filename *smb_fname)
636 {
637         char *name = NULL;
638         char *tmp_base_name;
639         int ret;
640         NTSTATUS status;
641
642         status = catia_string_replace_allocate(handle->conn,
643                                 smb_fname->base_name,
644                                 &name, vfs_translate_to_unix);
645         if (!NT_STATUS_IS_OK(status)) {
646                 errno = map_errno_from_nt_status(status);
647                 return -1;
648         }
649
650         tmp_base_name = smb_fname->base_name;
651         smb_fname->base_name = name;
652
653         ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
654         smb_fname->base_name = tmp_base_name;
655         TALLOC_FREE(name);
656
657         return ret;
658 }
659
660 static int catia_unlinkat(vfs_handle_struct *handle,
661                         struct files_struct *dirfsp,
662                         const struct smb_filename *smb_fname,
663                         int flags)
664 {
665         struct catia_cache *cc = NULL;
666         struct smb_filename *smb_fname_tmp = NULL;
667         char *name = NULL;
668         NTSTATUS status;
669         int ret;
670
671         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, dirfsp, &cc);
672         if (ret != 0) {
673                 return ret;
674         }
675
676         status = catia_string_replace_allocate(handle->conn,
677                                         smb_fname->base_name,
678                                         &name, vfs_translate_to_unix);
679         if (!NT_STATUS_IS_OK(status)) {
680                 errno = map_errno_from_nt_status(status);
681                 goto out;
682         }
683
684         /* Setup temporary smb_filename structs. */
685         smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
686         if (smb_fname_tmp == NULL) {
687                 errno = ENOMEM;
688                 goto out;
689         }
690
691         smb_fname_tmp->base_name = name;
692         smb_fname_tmp->fsp = smb_fname->fsp;
693
694         ret = SMB_VFS_NEXT_UNLINKAT(handle,
695                         dirfsp,
696                         smb_fname_tmp,
697                         flags);
698         TALLOC_FREE(smb_fname_tmp);
699         TALLOC_FREE(name);
700
701 out:
702         CATIA_FETCH_FSP_POST_NEXT(&cc, dirfsp);
703         return ret;
704 }
705
706 static int catia_lchown(vfs_handle_struct *handle,
707                         const struct smb_filename *smb_fname,
708                         uid_t uid,
709                         gid_t gid)
710 {
711         char *name = NULL;
712         NTSTATUS status;
713         int ret;
714         int saved_errno;
715         struct smb_filename *catia_smb_fname = NULL;
716
717         status = catia_string_replace_allocate(handle->conn,
718                                         smb_fname->base_name,
719                                         &name,
720                                         vfs_translate_to_unix);
721         if (!NT_STATUS_IS_OK(status)) {
722                 errno = map_errno_from_nt_status(status);
723                 return -1;
724         }
725         catia_smb_fname = synthetic_smb_fname(talloc_tos(),
726                                         name,
727                                         NULL,
728                                         &smb_fname->st,
729                                         smb_fname->twrp,
730                                         smb_fname->flags);
731         if (catia_smb_fname == NULL) {
732                 TALLOC_FREE(name);
733                 errno = ENOMEM;
734                 return -1;
735         }
736
737         ret = SMB_VFS_NEXT_LCHOWN(handle, catia_smb_fname, uid, gid);
738         saved_errno = errno;
739         TALLOC_FREE(name);
740         TALLOC_FREE(catia_smb_fname);
741         errno = saved_errno;
742         return ret;
743 }
744
745 static int catia_mkdirat(vfs_handle_struct *handle,
746                         struct files_struct *dirfsp,
747                         const struct smb_filename *smb_fname,
748                         mode_t mode)
749 {
750         char *name = NULL;
751         NTSTATUS status;
752         int ret;
753         struct smb_filename *catia_smb_fname = NULL;
754
755         status = catia_string_replace_allocate(handle->conn,
756                                 smb_fname->base_name,
757                                 &name,
758                                 vfs_translate_to_unix);
759         if (!NT_STATUS_IS_OK(status)) {
760                 errno = map_errno_from_nt_status(status);
761                 return -1;
762         }
763         catia_smb_fname = synthetic_smb_fname(talloc_tos(),
764                                         name,
765                                         NULL,
766                                         &smb_fname->st,
767                                         smb_fname->twrp,
768                                         smb_fname->flags);
769         if (catia_smb_fname == NULL) {
770                 TALLOC_FREE(name);
771                 errno = ENOMEM;
772                 return -1;
773         }
774
775         ret = SMB_VFS_NEXT_MKDIRAT(handle,
776                         dirfsp,
777                         catia_smb_fname,
778                         mode);
779         TALLOC_FREE(name);
780         TALLOC_FREE(catia_smb_fname);
781
782         return ret;
783 }
784
785 static int catia_chdir(vfs_handle_struct *handle,
786                         const struct smb_filename *smb_fname)
787 {
788         char *name = NULL;
789         struct smb_filename *catia_smb_fname = NULL;
790         NTSTATUS status;
791         int ret;
792
793         status = catia_string_replace_allocate(handle->conn,
794                                         smb_fname->base_name,
795                                         &name,
796                                         vfs_translate_to_unix);
797         if (!NT_STATUS_IS_OK(status)) {
798                 errno = map_errno_from_nt_status(status);
799                 return -1;
800         }
801
802         catia_smb_fname = synthetic_smb_fname(talloc_tos(),
803                                         name,
804                                         NULL,
805                                         &smb_fname->st,
806                                         smb_fname->twrp,
807                                         smb_fname->flags);
808         if (catia_smb_fname == NULL) {
809                 TALLOC_FREE(name);
810                 errno = ENOMEM;
811                 return -1;
812         }
813         ret = SMB_VFS_NEXT_CHDIR(handle, catia_smb_fname);
814         TALLOC_FREE(name);
815         TALLOC_FREE(catia_smb_fname);
816
817         return ret;
818 }
819
820 static int catia_fntimes(vfs_handle_struct *handle,
821                          files_struct *fsp,
822                          struct smb_file_time *ft)
823 {
824         struct catia_cache *cc = NULL;
825         int ret;
826
827         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
828         if (ret != 0) {
829                 return ret;
830         }
831
832         ret = SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
833
834         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
835
836         return ret;
837 }
838
839 static struct smb_filename *
840 catia_realpath(vfs_handle_struct *handle,
841                 TALLOC_CTX *ctx,
842                 const struct smb_filename *smb_fname)
843 {
844         char *mapped_name = NULL;
845         struct smb_filename *catia_smb_fname = NULL;
846         struct smb_filename *return_fname = NULL;
847         NTSTATUS status;
848
849         status = catia_string_replace_allocate(handle->conn,
850                                         smb_fname->base_name,
851                                         &mapped_name, vfs_translate_to_unix);
852         if (!NT_STATUS_IS_OK(status)) {
853                 errno = map_errno_from_nt_status(status);
854                 return NULL;
855         }
856
857         catia_smb_fname = synthetic_smb_fname(talloc_tos(),
858                                         mapped_name,
859                                         NULL,
860                                         &smb_fname->st,
861                                         smb_fname->twrp,
862                                         smb_fname->flags);
863         if (catia_smb_fname == NULL) {
864                 TALLOC_FREE(mapped_name);
865                 errno = ENOMEM;
866                 return NULL;
867         }
868         return_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, catia_smb_fname);
869         TALLOC_FREE(mapped_name);
870         TALLOC_FREE(catia_smb_fname);
871         return return_fname;
872 }
873
874 static int catia_chflags(struct vfs_handle_struct *handle,
875                         const struct smb_filename *smb_fname,
876                         unsigned int flags)
877 {
878         char *name = NULL;
879         struct smb_filename *catia_smb_fname = NULL;
880         NTSTATUS status;
881         int ret;
882
883         status = catia_string_replace_allocate(handle->conn,
884                                 smb_fname->base_name,
885                                 &name,
886                                 vfs_translate_to_unix);
887         if (!NT_STATUS_IS_OK(status)) {
888                 errno = map_errno_from_nt_status(status);
889                 return -1;
890         }
891         catia_smb_fname = synthetic_smb_fname(talloc_tos(),
892                                         name,
893                                         NULL,
894                                         &smb_fname->st,
895                                         smb_fname->twrp,
896                                         smb_fname->flags);
897         if (catia_smb_fname == NULL) {
898                 TALLOC_FREE(name);
899                 errno = ENOMEM;
900                 return -1;
901         }
902
903         ret = SMB_VFS_NEXT_CHFLAGS(handle, catia_smb_fname, flags);
904         TALLOC_FREE(name);
905         TALLOC_FREE(catia_smb_fname);
906
907         return ret;
908 }
909
910 static NTSTATUS
911 catia_fstreaminfo(struct vfs_handle_struct *handle,
912                  struct files_struct *fsp,
913                  TALLOC_CTX *mem_ctx,
914                  unsigned int *_num_streams,
915                  struct stream_struct **_streams)
916 {
917         char *mapped_name = NULL;
918         NTSTATUS status;
919         unsigned int i;
920         struct smb_filename *catia_smb_fname = NULL;
921         struct smb_filename *smb_fname = NULL;
922         unsigned int num_streams = 0;
923         struct stream_struct *streams = NULL;
924
925         smb_fname = fsp->fsp_name;
926         *_num_streams = 0;
927         *_streams = NULL;
928
929         status = catia_string_replace_allocate(handle->conn,
930                                 smb_fname->base_name,
931                                 &mapped_name,
932                                 vfs_translate_to_unix);
933         if (!NT_STATUS_IS_OK(status)) {
934                 return status;
935         }
936
937         status = synthetic_pathref(talloc_tos(),
938                                         handle->conn->cwd_fsp,
939                                         mapped_name,
940                                         NULL,
941                                         &smb_fname->st,
942                                         smb_fname->twrp,
943                                         smb_fname->flags,
944                                         &catia_smb_fname);
945
946         if (!NT_STATUS_IS_OK(status)) {
947                 TALLOC_FREE(mapped_name);
948                 return status;
949         }
950
951         status = SMB_VFS_NEXT_FSTREAMINFO(handle,
952                                           catia_smb_fname->fsp,
953                                           mem_ctx,
954                                           &num_streams,
955                                           &streams);
956         TALLOC_FREE(mapped_name);
957         TALLOC_FREE(catia_smb_fname);
958         if (!NT_STATUS_IS_OK(status)) {
959                 return status;
960         }
961
962         /*
963          * Translate stream names just like the base names
964          */
965         for (i = 0; i < num_streams; i++) {
966                 /*
967                  * Strip ":" prefix and ":$DATA" suffix to get a
968                  * "pure" stream name and only translate that.
969                  */
970                 void *old_ptr = streams[i].name;
971                 char *stream_name = streams[i].name + 1;
972                 char *stream_type = strrchr_m(stream_name, ':');
973
974                 if (stream_type != NULL) {
975                         *stream_type = '\0';
976                         stream_type += 1;
977                 }
978
979                 status = catia_string_replace_allocate(handle->conn,
980                                                 stream_name,
981                                                 &mapped_name,
982                                                 vfs_translate_to_windows);
983                 if (!NT_STATUS_IS_OK(status)) {
984                         TALLOC_FREE(streams);
985                         return status;
986                 }
987
988                 if (stream_type != NULL) {
989                         streams[i].name = talloc_asprintf(streams,
990                                                           ":%s:%s",
991                                                           mapped_name,
992                                                           stream_type);
993                 } else {
994                         streams[i].name = talloc_asprintf(streams,
995                                                           ":%s",
996                                                           mapped_name);
997                 }
998                 TALLOC_FREE(mapped_name);
999                 TALLOC_FREE(old_ptr);
1000                 if (streams[i].name == NULL) {
1001                         TALLOC_FREE(streams);
1002                         return NT_STATUS_NO_MEMORY;
1003                 }
1004         }
1005
1006         *_num_streams = num_streams;
1007         *_streams = streams;
1008         return NT_STATUS_OK;
1009 }
1010
1011 static NTSTATUS catia_get_nt_acl_at(struct vfs_handle_struct *handle,
1012                                     struct files_struct *dirfsp,
1013                                     const struct smb_filename *smb_fname,
1014                                     uint32_t security_info,
1015                                     TALLOC_CTX *mem_ctx,
1016                                     struct security_descriptor **ppdesc)
1017 {
1018         char *mapped_name = NULL;
1019         const char *path = smb_fname->base_name;
1020         struct smb_filename *mapped_smb_fname = NULL;
1021         NTSTATUS status;
1022
1023         SMB_ASSERT(dirfsp == handle->conn->cwd_fsp);
1024
1025         status = catia_string_replace_allocate(handle->conn,
1026                                 path, &mapped_name, vfs_translate_to_unix);
1027         if (!NT_STATUS_IS_OK(status)) {
1028                 errno = map_errno_from_nt_status(status);
1029                 return status;
1030         }
1031         mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1032                                         mapped_name,
1033                                         NULL,
1034                                         &smb_fname->st,
1035                                         smb_fname->twrp,
1036                                         smb_fname->flags);
1037         if (mapped_smb_fname == NULL) {
1038                 TALLOC_FREE(mapped_name);
1039                 return NT_STATUS_NO_MEMORY;
1040         }
1041
1042         status = SMB_VFS_NEXT_GET_NT_ACL_AT(handle,
1043                                         dirfsp,
1044                                         mapped_smb_fname,
1045                                         security_info,
1046                                         mem_ctx,
1047                                         ppdesc);
1048         TALLOC_FREE(mapped_name);
1049         TALLOC_FREE(mapped_smb_fname);
1050
1051         return status;
1052 }
1053
1054 static SMB_ACL_T
1055 catia_sys_acl_get_file(vfs_handle_struct *handle,
1056                         const struct smb_filename *smb_fname,
1057                         SMB_ACL_TYPE_T type,
1058                         TALLOC_CTX *mem_ctx)
1059 {
1060         char *mapped_name = NULL;
1061         struct smb_filename *mapped_smb_fname = NULL;
1062         NTSTATUS status;
1063         SMB_ACL_T ret;
1064         int saved_errno = 0;
1065
1066         status = catia_string_replace_allocate(handle->conn,
1067                                 smb_fname->base_name,
1068                                 &mapped_name,
1069                                 vfs_translate_to_unix);
1070         if (!NT_STATUS_IS_OK(status)) {
1071                 errno = map_errno_from_nt_status(status);
1072                 return (SMB_ACL_T)NULL;
1073         }
1074
1075         mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1076                                         mapped_name,
1077                                         NULL,
1078                                         &smb_fname->st,
1079                                         smb_fname->twrp,
1080                                         smb_fname->flags);
1081         if (mapped_smb_fname == NULL) {
1082                 TALLOC_FREE(mapped_name);
1083                 errno = ENOMEM;
1084                 return (SMB_ACL_T)NULL;
1085         }
1086
1087         ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, mapped_smb_fname,
1088                         type, mem_ctx);
1089         if (ret == (SMB_ACL_T)NULL) {
1090                 saved_errno = errno;
1091         }
1092         TALLOC_FREE(mapped_smb_fname);
1093         TALLOC_FREE(mapped_name);
1094         if (saved_errno != 0) {
1095                 errno = saved_errno;
1096         }
1097         return ret;
1098 }
1099
1100 static ssize_t
1101 catia_getxattr(vfs_handle_struct *handle,
1102                         const struct smb_filename *smb_fname,
1103                         const char *name,
1104                         void *value,
1105                         size_t size)
1106 {
1107         struct smb_filename *mapped_smb_fname = NULL;
1108         char *mapped_name = NULL;
1109         char *mapped_ea_name = NULL;
1110         NTSTATUS status;
1111         ssize_t ret;
1112         int saved_errno = 0;
1113
1114         status = catia_string_replace_allocate(handle->conn,
1115                                 smb_fname->base_name,
1116                                 &mapped_name,
1117                                 vfs_translate_to_unix);
1118         if (!NT_STATUS_IS_OK(status)) {
1119                 errno = map_errno_from_nt_status(status);
1120                 return -1;
1121         }
1122
1123         status = catia_string_replace_allocate(handle->conn,
1124                                 name, &mapped_ea_name, vfs_translate_to_unix);
1125         if (!NT_STATUS_IS_OK(status)) {
1126                 TALLOC_FREE(mapped_name);
1127                 errno = map_errno_from_nt_status(status);
1128                 return -1;
1129         }
1130
1131         mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1132                                         mapped_name,
1133                                         NULL,
1134                                         &smb_fname->st,
1135                                         smb_fname->twrp,
1136                                         smb_fname->flags);
1137         if (mapped_smb_fname == NULL) {
1138                 TALLOC_FREE(mapped_name);
1139                 TALLOC_FREE(mapped_ea_name);
1140                 errno = ENOMEM;
1141                 return -1;
1142         }
1143
1144         ret = SMB_VFS_NEXT_GETXATTR(handle, mapped_smb_fname,
1145                                 mapped_ea_name, value, size);
1146         if (ret == -1) {
1147                 saved_errno = errno;
1148         }
1149         TALLOC_FREE(mapped_name);
1150         TALLOC_FREE(mapped_ea_name);
1151         TALLOC_FREE(mapped_smb_fname);
1152         if (saved_errno != 0) {
1153                 errno = saved_errno;
1154         }
1155
1156         return ret;
1157 }
1158
1159 static int catia_fstat(vfs_handle_struct *handle,
1160                        files_struct *fsp,
1161                        SMB_STRUCT_STAT *sbuf)
1162 {
1163         struct catia_cache *cc = NULL;
1164         int ret;
1165
1166         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1167         if (ret != 0) {
1168                 return ret;
1169         }
1170
1171         ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1172
1173         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1174
1175         return ret;
1176 }
1177
1178 static ssize_t catia_pread(vfs_handle_struct *handle,
1179                            files_struct *fsp, void *data,
1180                            size_t n, off_t offset)
1181 {
1182         struct catia_cache *cc = NULL;
1183         ssize_t result;
1184         int ret;
1185
1186         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1187         if (ret != 0) {
1188                 return ret;
1189         }
1190
1191         result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1192
1193         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1194
1195         return result;
1196 }
1197
1198 static ssize_t catia_pwrite(vfs_handle_struct *handle,
1199                             files_struct *fsp, const void *data,
1200                             size_t n, off_t offset)
1201 {
1202         struct catia_cache *cc = NULL;
1203         ssize_t result;
1204         int ret;
1205
1206         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1207         if (ret != 0) {
1208                 return ret;
1209         }
1210
1211         result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
1212
1213         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1214
1215         return result;
1216 }
1217
1218 static int catia_ftruncate(struct vfs_handle_struct *handle,
1219                            struct files_struct *fsp,
1220                            off_t offset)
1221 {
1222         struct catia_cache *cc = NULL;
1223         int ret;
1224
1225         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1226         if (ret != 0) {
1227                 return ret;
1228         }
1229
1230         ret = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
1231
1232         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1233
1234         return ret;
1235 }
1236
1237 static int catia_fallocate(struct vfs_handle_struct *handle,
1238                            struct files_struct *fsp,
1239                            uint32_t mode,
1240                            off_t offset,
1241                            off_t len)
1242 {
1243         struct catia_cache *cc = NULL;
1244         int ret;
1245
1246         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1247         if (ret != 0) {
1248                 return ret;
1249         }
1250
1251         ret = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
1252
1253         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1254
1255         return ret;
1256 }
1257
1258 static ssize_t catia_fgetxattr(struct vfs_handle_struct *handle,
1259                                struct files_struct *fsp,
1260                                const char *name,
1261                                void *value,
1262                                size_t size)
1263 {
1264         char *mapped_xattr_name = NULL;
1265         NTSTATUS status;
1266         ssize_t result;
1267
1268         status = catia_string_replace_allocate(handle->conn,
1269                                                name, &mapped_xattr_name,
1270                                                vfs_translate_to_unix);
1271         if (!NT_STATUS_IS_OK(status)) {
1272                 errno = map_errno_from_nt_status(status);
1273                 return -1;
1274         }
1275
1276         result = SMB_VFS_NEXT_FGETXATTR(handle, fsp, mapped_xattr_name,
1277                                         value, size);
1278
1279         TALLOC_FREE(mapped_xattr_name);
1280
1281         return result;
1282 }
1283
1284 static ssize_t catia_flistxattr(struct vfs_handle_struct *handle,
1285                                 struct files_struct *fsp,
1286                                 char *list,
1287                                 size_t size)
1288 {
1289         struct catia_cache *cc = NULL;
1290         ssize_t result;
1291         int ret;
1292
1293         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1294         if (ret != 0) {
1295                 return ret;
1296         }
1297
1298         result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
1299
1300         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1301
1302         return result;
1303 }
1304
1305 static int catia_fremovexattr(struct vfs_handle_struct *handle,
1306                               struct files_struct *fsp,
1307                               const char *name)
1308 {
1309         char *mapped_name = NULL;
1310         NTSTATUS status;
1311         int ret;
1312
1313         status = catia_string_replace_allocate(handle->conn,
1314                                 name, &mapped_name, vfs_translate_to_unix);
1315         if (!NT_STATUS_IS_OK(status)) {
1316                 errno = map_errno_from_nt_status(status);
1317                 return -1;
1318         }
1319
1320         ret = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, mapped_name);
1321
1322         TALLOC_FREE(mapped_name);
1323
1324         return ret;
1325 }
1326
1327 static int catia_fsetxattr(struct vfs_handle_struct *handle,
1328                            struct files_struct *fsp,
1329                            const char *name,
1330                            const void *value,
1331                            size_t size,
1332                            int flags)
1333 {
1334         char *mapped_xattr_name = NULL;
1335         NTSTATUS status;
1336         int ret;
1337
1338         status = catia_string_replace_allocate(
1339                 handle->conn, name, &mapped_xattr_name, vfs_translate_to_unix);
1340         if (!NT_STATUS_IS_OK(status)) {
1341                 errno = map_errno_from_nt_status(status);
1342                 return -1;
1343         }
1344
1345         ret = SMB_VFS_NEXT_FSETXATTR(handle, fsp, mapped_xattr_name,
1346                                      value, size, flags);
1347
1348         TALLOC_FREE(mapped_xattr_name);
1349
1350         return ret;
1351 }
1352
1353 static SMB_ACL_T catia_sys_acl_get_fd(vfs_handle_struct *handle,
1354                                       files_struct *fsp,
1355                                       TALLOC_CTX *mem_ctx)
1356 {
1357         struct catia_cache *cc = NULL;
1358         struct smb_acl_t *result = NULL;
1359         int ret;
1360
1361         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1362         if (ret != 0) {
1363                 return NULL;
1364         }
1365
1366         result = SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
1367
1368         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1369
1370         return result;
1371 }
1372
1373 static int catia_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1374                                      files_struct *fsp,
1375                                      TALLOC_CTX *mem_ctx,
1376                                      char **blob_description,
1377                                      DATA_BLOB *blob)
1378 {
1379         struct catia_cache *cc = NULL;
1380         int ret;
1381
1382         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1383         if (ret != 0) {
1384                 return ret;
1385         }
1386
1387         ret = SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1388                                                blob_description, blob);
1389
1390         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1391
1392         return ret;
1393 }
1394
1395 static int catia_sys_acl_set_fd(vfs_handle_struct *handle,
1396                                 files_struct *fsp,
1397                                 SMB_ACL_TYPE_T type,
1398                                 SMB_ACL_T theacl)
1399 {
1400         struct catia_cache *cc = NULL;
1401         int ret;
1402
1403         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1404         if (ret != 0) {
1405                 return ret;
1406         }
1407
1408         ret = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
1409
1410         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1411
1412         return ret;
1413 }
1414
1415 static NTSTATUS catia_fget_nt_acl(vfs_handle_struct *handle,
1416                                   files_struct *fsp,
1417                                   uint32_t security_info,
1418                                   TALLOC_CTX *mem_ctx,
1419                                   struct security_descriptor **ppdesc)
1420 {
1421         struct catia_cache *cc = NULL;
1422         NTSTATUS status;
1423         int ret;
1424
1425         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1426         if (ret != 0) {
1427                 return map_nt_error_from_unix(errno);
1428         }
1429
1430         status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1431                                           mem_ctx, ppdesc);
1432
1433         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1434
1435         return status;
1436 }
1437
1438 static NTSTATUS catia_fset_nt_acl(vfs_handle_struct *handle,
1439                                   files_struct *fsp,
1440                                   uint32_t security_info_sent,
1441                                   const struct security_descriptor *psd)
1442 {
1443         struct catia_cache *cc = NULL;
1444         NTSTATUS status;
1445         int ret;
1446
1447         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1448         if (ret != 0) {
1449                 return map_nt_error_from_unix(errno);
1450         }
1451
1452         status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1453
1454         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1455
1456         return status;
1457 }
1458
1459 static NTSTATUS catia_fset_dos_attributes(struct vfs_handle_struct *handle,
1460                                           struct files_struct *fsp,
1461                                           uint32_t dosmode)
1462 {
1463         struct catia_cache *cc = NULL;
1464         NTSTATUS status;
1465         int ret;
1466
1467         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1468         if (ret != 0) {
1469                 return map_nt_error_from_unix(errno);
1470         }
1471
1472         status = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1473
1474         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1475
1476         return status;
1477 }
1478
1479 static NTSTATUS catia_fget_dos_attributes(struct vfs_handle_struct *handle,
1480                                           struct files_struct *fsp,
1481                                           uint32_t *dosmode)
1482 {
1483         struct catia_cache *cc = NULL;
1484         NTSTATUS status;
1485         int ret;
1486
1487         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1488         if (ret != 0) {
1489                 return map_nt_error_from_unix(errno);
1490         }
1491
1492         status = SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle, fsp, dosmode);
1493
1494         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1495
1496         return status;
1497 }
1498
1499 static int catia_fchown(vfs_handle_struct *handle,
1500                         files_struct *fsp,
1501                         uid_t uid,
1502                         gid_t gid)
1503 {
1504         struct catia_cache *cc = NULL;
1505         int ret;
1506
1507         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1508         if (ret != 0) {
1509                 return ret;
1510         }
1511
1512         ret = SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
1513
1514         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1515
1516         return ret;
1517 }
1518
1519 static int catia_fchmod(vfs_handle_struct *handle,
1520                         files_struct *fsp,
1521                         mode_t mode)
1522 {
1523         struct catia_cache *cc = NULL;
1524         int ret;
1525
1526         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1527         if (ret != 0) {
1528                 return ret;
1529         }
1530
1531         ret = SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1532
1533         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1534
1535         return ret;
1536 }
1537
1538 struct catia_pread_state {
1539         ssize_t ret;
1540         struct vfs_aio_state vfs_aio_state;
1541         struct files_struct *fsp;
1542         struct catia_cache *cc;
1543 };
1544
1545 static void catia_pread_done(struct tevent_req *subreq);
1546
1547 static struct tevent_req *catia_pread_send(struct vfs_handle_struct *handle,
1548                                            TALLOC_CTX *mem_ctx,
1549                                            struct tevent_context *ev,
1550                                            struct files_struct *fsp,
1551                                            void *data,
1552                                            size_t n,
1553                                            off_t offset)
1554 {
1555         struct tevent_req *req = NULL, *subreq = NULL;
1556         struct catia_pread_state *state = NULL;
1557         int ret;
1558
1559         req = tevent_req_create(mem_ctx, &state,
1560                                 struct catia_pread_state);
1561         if (req == NULL) {
1562                 return NULL;
1563         }
1564         state->fsp = fsp;
1565
1566         ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1567         if (ret != 0) {
1568                 tevent_req_error(req, errno);
1569                 return tevent_req_post(req, ev);
1570         }
1571
1572         subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1573                                          n, offset);
1574         if (tevent_req_nomem(subreq, req)) {
1575                 return tevent_req_post(req, ev);
1576         }
1577         tevent_req_set_callback(subreq, catia_pread_done, req);
1578
1579         return req;
1580 }
1581
1582 static void catia_pread_done(struct tevent_req *subreq)
1583 {
1584         struct tevent_req *req = tevent_req_callback_data(
1585                 subreq, struct tevent_req);
1586         struct catia_pread_state *state = tevent_req_data(
1587                 req, struct catia_pread_state);
1588
1589         state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
1590         TALLOC_FREE(subreq);
1591
1592         CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1593
1594         tevent_req_done(req);
1595 }
1596
1597 static ssize_t catia_pread_recv(struct tevent_req *req,
1598                                 struct vfs_aio_state *vfs_aio_state)
1599 {
1600         struct catia_pread_state *state = tevent_req_data(
1601                 req, struct catia_pread_state);
1602
1603         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1604                 return -1;
1605         }
1606
1607         *vfs_aio_state = state->vfs_aio_state;
1608         return state->ret;
1609 }
1610
1611 struct catia_pwrite_state {
1612         ssize_t ret;
1613         struct vfs_aio_state vfs_aio_state;
1614         struct files_struct *fsp;
1615         struct catia_cache *cc;
1616 };
1617
1618 static void catia_pwrite_done(struct tevent_req *subreq);
1619
1620 static struct tevent_req *catia_pwrite_send(struct vfs_handle_struct *handle,
1621                                             TALLOC_CTX *mem_ctx,
1622                                             struct tevent_context *ev,
1623                                             struct files_struct *fsp,
1624                                             const void *data,
1625                                             size_t n,
1626                                             off_t offset)
1627 {
1628         struct tevent_req *req = NULL, *subreq = NULL;
1629         struct catia_pwrite_state *state = NULL;
1630         int ret;
1631
1632         req = tevent_req_create(mem_ctx, &state,
1633                                 struct catia_pwrite_state);
1634         if (req == NULL) {
1635                 return NULL;
1636         }
1637         state->fsp = fsp;
1638
1639         ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1640         if (ret != 0) {
1641                 tevent_req_error(req, errno);
1642                 return tevent_req_post(req, ev);
1643         }
1644
1645         subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
1646                                           n, offset);
1647         if (tevent_req_nomem(subreq, req)) {
1648                 return tevent_req_post(req, ev);
1649         }
1650         tevent_req_set_callback(subreq, catia_pwrite_done, req);
1651
1652         return req;
1653 }
1654
1655 static void catia_pwrite_done(struct tevent_req *subreq)
1656 {
1657         struct tevent_req *req = tevent_req_callback_data(
1658                 subreq, struct tevent_req);
1659         struct catia_pwrite_state *state = tevent_req_data(
1660                 req, struct catia_pwrite_state);
1661
1662         state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
1663         TALLOC_FREE(subreq);
1664
1665         CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1666
1667         tevent_req_done(req);
1668 }
1669
1670 static ssize_t catia_pwrite_recv(struct tevent_req *req,
1671                                 struct vfs_aio_state *vfs_aio_state)
1672 {
1673         struct catia_pwrite_state *state = tevent_req_data(
1674                 req, struct catia_pwrite_state);
1675
1676         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1677                 return -1;
1678         }
1679
1680         *vfs_aio_state = state->vfs_aio_state;
1681         return state->ret;
1682 }
1683
1684 static off_t catia_lseek(vfs_handle_struct *handle,
1685                          files_struct *fsp,
1686                          off_t offset,
1687                          int whence)
1688 {
1689         struct catia_cache *cc = NULL;
1690         ssize_t result;
1691         int ret;
1692
1693         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1694         if (ret != 0) {
1695                 return -1;
1696         }
1697
1698         result = SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
1699
1700         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1701
1702         return result;
1703 }
1704
1705 struct catia_fsync_state {
1706         int ret;
1707         struct vfs_aio_state vfs_aio_state;
1708         struct files_struct *fsp;
1709         struct catia_cache *cc;
1710 };
1711
1712 static void catia_fsync_done(struct tevent_req *subreq);
1713
1714 static struct tevent_req *catia_fsync_send(struct vfs_handle_struct *handle,
1715                                            TALLOC_CTX *mem_ctx,
1716                                            struct tevent_context *ev,
1717                                            struct files_struct *fsp)
1718 {
1719         struct tevent_req *req = NULL, *subreq = NULL;
1720         struct catia_fsync_state *state = NULL;
1721         int ret;
1722
1723         req = tevent_req_create(mem_ctx, &state,
1724                                 struct catia_fsync_state);
1725         if (req == NULL) {
1726                 return NULL;
1727         }
1728         state->fsp = fsp;
1729
1730         ret = CATIA_FETCH_FSP_PRE_NEXT(state, handle, fsp, &state->cc);
1731         if (ret != 0) {
1732                 tevent_req_error(req, errno);
1733                 return tevent_req_post(req, ev);
1734         }
1735
1736         subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
1737         if (tevent_req_nomem(subreq, req)) {
1738                 return tevent_req_post(req, ev);
1739         }
1740         tevent_req_set_callback(subreq, catia_fsync_done, req);
1741
1742         return req;
1743 }
1744
1745 static void catia_fsync_done(struct tevent_req *subreq)
1746 {
1747         struct tevent_req *req = tevent_req_callback_data(
1748                 subreq, struct tevent_req);
1749         struct catia_fsync_state *state = tevent_req_data(
1750                 req, struct catia_fsync_state);
1751
1752         state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
1753         TALLOC_FREE(subreq);
1754
1755         CATIA_FETCH_FSP_POST_NEXT(&state->cc, state->fsp);
1756
1757         tevent_req_done(req);
1758 }
1759
1760 static int catia_fsync_recv(struct tevent_req *req,
1761                             struct vfs_aio_state *vfs_aio_state)
1762 {
1763         struct catia_fsync_state *state = tevent_req_data(
1764                 req, struct catia_fsync_state);
1765
1766         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1767                 return -1;
1768         }
1769
1770         *vfs_aio_state = state->vfs_aio_state;
1771         return state->ret;
1772 }
1773
1774 static bool catia_lock(vfs_handle_struct *handle,
1775                        files_struct *fsp,
1776                        int op,
1777                        off_t offset,
1778                        off_t count,
1779                        int type)
1780 {
1781         struct catia_cache *cc = NULL;
1782         bool ok;
1783         int ret;
1784
1785         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1786         if (ret != 0) {
1787                 return false;
1788         }
1789
1790         ok = SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
1791
1792         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1793
1794         return ok;
1795 }
1796
1797 static int catia_kernel_flock(struct vfs_handle_struct *handle,
1798                               struct files_struct *fsp,
1799                               uint32_t share_access,
1800                               uint32_t access_mask)
1801 {
1802         struct catia_cache *cc = NULL;
1803         int ret;
1804
1805         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1806         if (ret != 0) {
1807                 return -1;
1808         }
1809
1810         ret = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_access, access_mask);
1811
1812         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1813
1814         return ret;
1815 }
1816
1817 static int catia_linux_setlease(vfs_handle_struct *handle,
1818                                 files_struct *fsp,
1819                                 int leasetype)
1820 {
1821         struct catia_cache *cc = NULL;
1822         int ret;
1823
1824         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1825         if (ret != 0) {
1826                 return -1;
1827         }
1828
1829         ret = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
1830
1831         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1832
1833         return ret;
1834 }
1835
1836 static bool catia_getlock(vfs_handle_struct *handle,
1837                           files_struct *fsp,
1838                           off_t *poffset,
1839                           off_t *pcount,
1840                           int *ptype,
1841                           pid_t *ppid)
1842 {
1843         struct catia_cache *cc = NULL;
1844         int ret;
1845         bool ok;
1846
1847         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1848         if (ret != 0) {
1849                 return false;
1850         }
1851
1852         ok = SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
1853
1854         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1855
1856         return ok;
1857 }
1858
1859 static bool catia_strict_lock_check(struct vfs_handle_struct *handle,
1860                                     struct files_struct *fsp,
1861                                     struct lock_struct *plock)
1862 {
1863         struct catia_cache *cc = NULL;
1864         int ret;
1865         bool ok;
1866
1867         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1868         if (ret != 0) {
1869                 return false;
1870         }
1871
1872         ok = SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
1873
1874         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1875
1876         return ok;
1877 }
1878
1879 static NTSTATUS catia_fsctl(struct vfs_handle_struct *handle,
1880                             struct files_struct *fsp,
1881                             TALLOC_CTX *ctx,
1882                             uint32_t function,
1883                             uint16_t req_flags,
1884                             const uint8_t *_in_data,
1885                             uint32_t in_len,
1886                             uint8_t **_out_data,
1887                             uint32_t max_out_len,
1888                             uint32_t *out_len)
1889 {
1890         NTSTATUS result;
1891         struct catia_cache *cc = NULL;
1892         int ret;
1893
1894         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1895         if (ret != 0) {
1896                 return map_nt_error_from_unix(errno);
1897         }
1898
1899         result = SMB_VFS_NEXT_FSCTL(handle,
1900                                 fsp,
1901                                 ctx,
1902                                 function,
1903                                 req_flags,
1904                                 _in_data,
1905                                 in_len,
1906                                 _out_data,
1907                                 max_out_len,
1908                                 out_len);
1909
1910         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1911
1912         return result;
1913 }
1914
1915 static NTSTATUS catia_fget_compression(vfs_handle_struct *handle,
1916                                       TALLOC_CTX *mem_ctx,
1917                                       struct files_struct *fsp,
1918                                       uint16_t *_compression_fmt)
1919 {
1920         NTSTATUS result;
1921         struct catia_cache *cc = NULL;
1922         int ret;
1923
1924         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1925         if (ret != 0) {
1926                 return map_nt_error_from_unix(errno);
1927         }
1928
1929         result = SMB_VFS_NEXT_FGET_COMPRESSION(handle,
1930                                         mem_ctx,
1931                                         fsp,
1932                                         _compression_fmt);
1933
1934         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1935
1936         return result;
1937 }
1938
1939 static NTSTATUS catia_set_compression(vfs_handle_struct *handle,
1940                                       TALLOC_CTX *mem_ctx,
1941                                       struct files_struct *fsp,
1942                                       uint16_t compression_fmt)
1943 {
1944         NTSTATUS result;
1945         struct catia_cache *cc = NULL;
1946         int ret;
1947
1948         ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc);
1949         if (ret != 0) {
1950                 return map_nt_error_from_unix(errno);
1951         }
1952
1953         result = SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
1954                                               compression_fmt);
1955
1956         CATIA_FETCH_FSP_POST_NEXT(&cc, fsp);
1957
1958         return result;
1959 }
1960
1961 static NTSTATUS catia_create_dfs_pathat(struct vfs_handle_struct *handle,
1962                         struct files_struct *dirfsp,
1963                         const struct smb_filename *smb_fname,
1964                         const struct referral *reflist,
1965                         size_t referral_count)
1966 {
1967         char *mapped_name = NULL;
1968         const char *path = smb_fname->base_name;
1969         struct smb_filename *mapped_smb_fname = NULL;
1970         NTSTATUS status;
1971
1972         status = catia_string_replace_allocate(handle->conn,
1973                                         path,
1974                                         &mapped_name,
1975                                         vfs_translate_to_unix);
1976         if (!NT_STATUS_IS_OK(status)) {
1977                 errno = map_errno_from_nt_status(status);
1978                 return status;
1979         }
1980         mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
1981                                         mapped_name,
1982                                         NULL,
1983                                         &smb_fname->st,
1984                                         smb_fname->twrp,
1985                                         smb_fname->flags);
1986         if (mapped_smb_fname == NULL) {
1987                 TALLOC_FREE(mapped_name);
1988                 return NT_STATUS_NO_MEMORY;
1989         }
1990
1991         status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
1992                                         dirfsp,
1993                                         mapped_smb_fname,
1994                                         reflist,
1995                                         referral_count);
1996         TALLOC_FREE(mapped_name);
1997         TALLOC_FREE(mapped_smb_fname);
1998         return status;
1999 }
2000
2001 static NTSTATUS catia_read_dfs_pathat(struct vfs_handle_struct *handle,
2002                         TALLOC_CTX *mem_ctx,
2003                         struct files_struct *dirfsp,
2004                         struct smb_filename *smb_fname,
2005                         struct referral **ppreflist,
2006                         size_t *preferral_count)
2007 {
2008         char *mapped_name = NULL;
2009         const char *path = smb_fname->base_name;
2010         struct smb_filename *mapped_smb_fname = NULL;
2011         NTSTATUS status;
2012
2013         status = catia_string_replace_allocate(handle->conn,
2014                                         path,
2015                                         &mapped_name,
2016                                         vfs_translate_to_unix);
2017         if (!NT_STATUS_IS_OK(status)) {
2018                 errno = map_errno_from_nt_status(status);
2019                 return status;
2020         }
2021         mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
2022                                         mapped_name,
2023                                         NULL,
2024                                         &smb_fname->st,
2025                                         smb_fname->twrp,
2026                                         smb_fname->flags);
2027         if (mapped_smb_fname == NULL) {
2028                 TALLOC_FREE(mapped_name);
2029                 return NT_STATUS_NO_MEMORY;
2030         }
2031
2032         status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
2033                                         mem_ctx,
2034                                         dirfsp,
2035                                         mapped_smb_fname,
2036                                         ppreflist,
2037                                         preferral_count);
2038         if (NT_STATUS_IS_OK(status)) {
2039                 /* Return any stat(2) info. */
2040                 smb_fname->st = mapped_smb_fname->st;
2041         }
2042
2043         TALLOC_FREE(mapped_name);
2044         TALLOC_FREE(mapped_smb_fname);
2045         return status;
2046 }
2047
2048 static struct vfs_fn_pointers vfs_catia_fns = {
2049         .connect_fn = catia_connect,
2050
2051         /* Directory operations */
2052         .mkdirat_fn = catia_mkdirat,
2053
2054         /* File operations */
2055         .openat_fn = catia_openat,
2056         .pread_fn = catia_pread,
2057         .pread_send_fn = catia_pread_send,
2058         .pread_recv_fn = catia_pread_recv,
2059         .pwrite_fn = catia_pwrite,
2060         .pwrite_send_fn = catia_pwrite_send,
2061         .pwrite_recv_fn = catia_pwrite_recv,
2062         .lseek_fn = catia_lseek,
2063         .renameat_fn = catia_renameat,
2064         .fsync_send_fn = catia_fsync_send,
2065         .fsync_recv_fn = catia_fsync_recv,
2066         .stat_fn = catia_stat,
2067         .fstat_fn = catia_fstat,
2068         .lstat_fn = catia_lstat,
2069         .unlinkat_fn = catia_unlinkat,
2070         .fchmod_fn = catia_fchmod,
2071         .fchown_fn = catia_fchown,
2072         .lchown_fn = catia_lchown,
2073         .chdir_fn = catia_chdir,
2074         .fntimes_fn = catia_fntimes,
2075         .ftruncate_fn = catia_ftruncate,
2076         .fallocate_fn = catia_fallocate,
2077         .lock_fn = catia_lock,
2078         .kernel_flock_fn = catia_kernel_flock,
2079         .linux_setlease_fn = catia_linux_setlease,
2080         .getlock_fn = catia_getlock,
2081         .realpath_fn = catia_realpath,
2082         .chflags_fn = catia_chflags,
2083         .fstreaminfo_fn = catia_fstreaminfo,
2084         .strict_lock_check_fn = catia_strict_lock_check,
2085         .translate_name_fn = catia_translate_name,
2086         .fsctl_fn = catia_fsctl,
2087         .get_dos_attributes_send_fn = vfs_not_implemented_get_dos_attributes_send,
2088         .get_dos_attributes_recv_fn = vfs_not_implemented_get_dos_attributes_recv,
2089         .fset_dos_attributes_fn = catia_fset_dos_attributes,
2090         .fget_dos_attributes_fn = catia_fget_dos_attributes,
2091         .fget_compression_fn = catia_fget_compression,
2092         .set_compression_fn = catia_set_compression,
2093         .create_dfs_pathat_fn = catia_create_dfs_pathat,
2094         .read_dfs_pathat_fn = catia_read_dfs_pathat,
2095
2096         /* NT ACL operations. */
2097         .get_nt_acl_at_fn = catia_get_nt_acl_at,
2098         .fget_nt_acl_fn = catia_fget_nt_acl,
2099         .fset_nt_acl_fn = catia_fset_nt_acl,
2100
2101         /* POSIX ACL operations. */
2102         .sys_acl_get_file_fn = catia_sys_acl_get_file,
2103         .sys_acl_get_fd_fn = catia_sys_acl_get_fd,
2104         .sys_acl_blob_get_fd_fn = catia_sys_acl_blob_get_fd,
2105         .sys_acl_set_fd_fn = catia_sys_acl_set_fd,
2106
2107         /* EA operations. */
2108         .getxattr_fn = catia_getxattr,
2109         .getxattrat_send_fn = vfs_not_implemented_getxattrat_send,
2110         .getxattrat_recv_fn = vfs_not_implemented_getxattrat_recv,
2111         .fgetxattr_fn = catia_fgetxattr,
2112         .flistxattr_fn = catia_flistxattr,
2113         .fremovexattr_fn = catia_fremovexattr,
2114         .fsetxattr_fn = catia_fsetxattr,
2115 };
2116
2117 static_decl_vfs;
2118 NTSTATUS vfs_catia_init(TALLOC_CTX *ctx)
2119 {
2120         NTSTATUS ret;
2121
2122         ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
2123                                 &vfs_catia_fns);
2124         if (!NT_STATUS_IS_OK(ret))
2125                 return ret;
2126
2127         vfs_catia_debug_level = debug_add_class("catia");
2128         if (vfs_catia_debug_level == -1) {
2129                 vfs_catia_debug_level = DBGC_VFS;
2130                 DEBUG(0, ("vfs_catia: Couldn't register custom debugging "
2131                           "class!\n"));
2132         } else {
2133                 DEBUG(10, ("vfs_catia: Debug class number of "
2134                            "'catia': %d\n", vfs_catia_debug_level));
2135         }
2136
2137         return ret;
2138
2139 }