vfs catia: Fix a NULL dereference when CATIA is loaded with no mappings specified.
[kamenim/samba-autobuild/.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  * Yes, this a BAD BAD UGLY INCOMPLETE hack, but it helps quite some people
8  * out there. Catia V4 on AIX uses characters like "<*$ a *lot*, all forbidden
9  * under Windows...
10  *
11  * Copyright (C) Volker Lendecke, 2005
12  * Copyright (C) Aravind Srinivasan, 2009
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, see <http://www.gnu.org/licenses/>.
26  */
27
28
29 #include "includes.h"
30
31 #define GLOBAL_SNUM     0xFFFFFFF
32 #define MAP_SIZE        0xFF
33 #define MAP_NUM         0x101 /* max unicode charval / MAP_SIZE */
34 #define T_OFFSET(_v_)   ((_v_ % MAP_SIZE))
35 #define T_START(_v_)    (((_v_ / MAP_SIZE) * MAP_SIZE))
36 #define T_PICK(_v_)     ((_v_ / MAP_SIZE))
37
38 struct char_mappings {
39         smb_ucs2_t entry[MAP_SIZE][2];
40 };
41
42 struct share_mapping_entry {
43         int snum;
44         struct share_mapping_entry *next;
45         struct char_mappings **mappings;
46 };
47
48 struct share_mapping_entry *srt_head = NULL;
49
50 static bool build_table(struct char_mappings **cmaps, int value)
51 {
52         int i;
53         int start = T_START(value);
54
55         (*cmaps) = talloc_zero(NULL, struct char_mappings);
56
57         if (!*cmaps)
58                 return False;
59
60         for (i = 0; i < MAP_SIZE;i++) {
61                 (*cmaps)->entry[i][vfs_translate_to_unix] = start + i;
62                 (*cmaps)->entry[i][vfs_translate_to_windows] = start + i;
63         }
64
65         return True;
66 }
67
68 static void set_tables(struct char_mappings **cmaps,
69                        long unix_map,
70                        long windows_map)
71 {
72         int i;
73
74         /* set unix -> windows */
75         i = T_OFFSET(unix_map);
76         cmaps[T_PICK(unix_map)]->entry[i][vfs_translate_to_windows] = windows_map;
77
78         /* set windows -> unix */
79         i = T_OFFSET(windows_map);
80         cmaps[T_PICK(windows_map)]->entry[i][vfs_translate_to_unix] = unix_map;
81 }
82
83 static bool build_ranges(struct char_mappings **cmaps,
84                          long unix_map,
85                          long windows_map)
86 {
87
88         if (!cmaps[T_PICK(unix_map)]) {
89                 if (!build_table(&cmaps[T_PICK(unix_map)], unix_map))
90                         return False;
91         }
92
93         if (!cmaps[T_PICK(windows_map)]) {
94                 if (!build_table(&cmaps[T_PICK(windows_map)], windows_map))
95                         return False;
96         }
97
98         set_tables(cmaps, unix_map, windows_map);
99
100         return True;
101 }
102
103 static struct share_mapping_entry *get_srt(connection_struct *conn,
104                                            struct share_mapping_entry **global)
105 {
106         struct share_mapping_entry *share;
107
108         for (share = srt_head; share != NULL; share = share->next) {
109                 if (share->snum == GLOBAL_SNUM)
110                         (*global) = share;
111
112                 if (share->snum == SNUM(conn))
113                         return share;
114         }
115
116         return share;
117 }
118
119 static struct share_mapping_entry *add_srt(int snum, const char **mappings)
120 {
121
122         char *tmp;
123         fstring mapping;
124         int i;
125         long unix_map, windows_map;
126         struct share_mapping_entry *ret = NULL;
127
128         ret = (struct share_mapping_entry *)
129                 TALLOC_ZERO(NULL, sizeof(struct share_mapping_entry) +
130                 (mappings ? (MAP_NUM * sizeof(struct char_mappings *)) : 0));
131
132         if (!ret)
133                 return ret;
134
135         ret->snum = snum;
136
137         if (mappings) {
138                 ret->mappings = (struct char_mappings**) ((unsigned char*) ret +
139                     sizeof(struct share_mapping_entry));
140                 memset(ret->mappings, 0,
141                     MAP_NUM * sizeof(struct char_mappings *));
142         } else {
143                 ret->mappings = NULL;
144                 return ret;
145         }
146
147         /*
148          * catia mappings are of the form :
149          * UNIX char (in 0xnn hex) : WINDOWS char (in 0xnn hex)
150          *
151          * multiple mappings are comma seperated in smb.conf
152          */
153         for (i=0;mappings[i];i++) {
154                 fstrcpy(mapping, mappings[i]);
155                 unix_map = strtol(mapping, &tmp, 16);
156                 if (unix_map == 0 && errno == EINVAL) {
157                         DEBUG(0, ("INVALID CATIA MAPPINGS - %s\n", mapping));
158                         continue;
159                 }
160                 windows_map = strtol(++tmp, NULL, 16);
161                 if (windows_map == 0 && errno == EINVAL) {
162                         DEBUG(0, ("INVALID CATIA MAPPINGS - %s\n", mapping));
163                         continue;
164                 }
165
166                 if (!build_ranges(ret->mappings, unix_map, windows_map)) {
167                         DEBUG(0, ("TABLE ERROR - CATIA MAPPINGS - %s\n", mapping));
168                         continue;
169                 }
170         }
171
172         ret->next = srt_head;
173         srt_head = ret;
174
175         return ret;
176 }
177
178 static bool init_mappings(connection_struct *conn,
179                           struct share_mapping_entry **selected_out)
180 {
181         const char **mappings = NULL;
182         struct share_mapping_entry *share_level = NULL;
183         struct share_mapping_entry *global = NULL;
184
185         /* check srt cache */
186         share_level = get_srt(conn, &global);
187         if (share_level) {
188                 *selected_out = share_level;
189                 return (share_level->mappings != NULL);
190         }
191
192         /* see if we have a global setting */
193         if (!global) {
194                 /* global setting */
195                 mappings = lp_parm_string_list(-1, "catia", "mappings", NULL);
196                 global = add_srt(GLOBAL_SNUM, mappings);
197         }
198
199         /* no global setting - what about share level ? */
200         mappings = lp_parm_string_list(SNUM(conn), "catia", "mappings", NULL);
201         share_level = add_srt(SNUM(conn), mappings);
202
203         if (share_level->mappings) {
204                 (*selected_out) = share_level;
205                 return True;
206         } else if (global->mappings) {
207                 share_level->mappings = global->mappings;
208                 (*selected_out) = share_level;
209                 return True;
210         }
211
212         return False;
213 }
214
215 static NTSTATUS catia_string_replace_allocate(connection_struct *conn,
216                                               const char *name_in,
217                                               char **mapped_name,
218                                               int direction)
219 {
220         static smb_ucs2_t *tmpbuf = NULL;
221         smb_ucs2_t *ptr;
222         struct share_mapping_entry *selected;
223         struct char_mappings *map = NULL;
224         size_t converted_size;
225         TALLOC_CTX *ctx = talloc_tos();
226
227         if (!init_mappings(conn, &selected)) {
228                 /* No mappings found. Just use the old name */
229                 *mapped_name = talloc_strdup(NULL, name_in);
230                 if (!*mapped_name) {
231                         errno = ENOMEM;
232                         return NT_STATUS_NO_MEMORY;
233                 }
234                 return NT_STATUS_OK;
235         }
236
237         if ((push_ucs2_talloc(ctx, &tmpbuf, name_in,
238                               &converted_size)) == -1) {
239                 return map_nt_error_from_unix(errno);
240         }
241         ptr = tmpbuf;
242         for(;*ptr;ptr++) {
243                 if (*ptr == 0)
244                         break;
245                 map = selected->mappings[T_PICK((*ptr))];
246
247                 /* nothing to do */
248                 if (!map)
249                         continue;
250
251                 *ptr = map->entry[T_OFFSET((*ptr))][direction];
252         }
253
254         if ((pull_ucs2_talloc(ctx, mapped_name, tmpbuf,
255                               &converted_size)) == -1) {
256                 TALLOC_FREE(tmpbuf);
257                 return map_nt_error_from_unix(errno);
258         }
259         TALLOC_FREE(tmpbuf);
260         return NT_STATUS_OK;
261 }
262
263 static SMB_STRUCT_DIR *catia_opendir(vfs_handle_struct *handle,
264                                      const char *fname,
265                                      const char *mask,
266                                      uint32 attr)
267 {
268         char *name_mapped = NULL;
269         NTSTATUS status;
270         SMB_STRUCT_DIR *ret;
271
272         status = catia_string_replace_allocate(handle->conn, fname,
273                                         &name_mapped, vfs_translate_to_unix);
274         if (!NT_STATUS_IS_OK(status)) {
275                 errno = map_errno_from_nt_status(status);
276                 return NULL;
277         }
278
279         ret = SMB_VFS_NEXT_OPENDIR(handle, name_mapped, mask, attr);
280         TALLOC_FREE(name_mapped);
281
282         return ret;
283 }
284
285 /*
286  * TRANSLATE_NAME call which converts the given name to
287  * "WINDOWS displayable" name
288  */
289 static NTSTATUS catia_translate_name(vfs_handle_struct *handle,
290                                      char **mapped_name,
291                                      enum vfs_translate_direction direction)
292 {
293         char *name = NULL;
294         NTSTATUS ret;
295
296         /*
297          * Copy the supplied name and free the memory for mapped_name,
298          * already allocated by the caller.
299          * We will be allocating new memory for mapped_name in
300          * catia_string_replace_allocate
301          */
302         name = talloc_strdup(talloc_tos(), *mapped_name);
303         if (!name) {
304                 errno = ENOMEM;
305                 return NT_STATUS_NO_MEMORY;
306         }
307         TALLOC_FREE(*mapped_name);
308         ret = catia_string_replace_allocate(handle->conn, name,
309                         mapped_name, direction);
310
311         TALLOC_FREE(name);
312         if (!NT_STATUS_IS_OK(ret)) {
313                 return ret;
314         }
315
316         ret = SMB_VFS_NEXT_TRANSLATE_NAME(handle, mapped_name, direction);
317
318         return ret;
319 }
320
321 static int catia_open(vfs_handle_struct *handle,
322                       struct smb_filename *smb_fname,
323                       files_struct *fsp,
324                       int flags,
325                       mode_t mode)
326 {
327         char *name_mapped = NULL;
328         char *tmp_base_name;
329         int ret;
330         NTSTATUS status;
331
332         tmp_base_name = smb_fname->base_name;
333         status = catia_string_replace_allocate(handle->conn,
334                                         smb_fname->base_name,
335                                         &name_mapped, vfs_translate_to_unix);
336         if (!NT_STATUS_IS_OK(status)) {
337                 errno = map_errno_from_nt_status(status);
338                 return -1;
339         }
340
341         smb_fname->base_name = name_mapped;
342         ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
343         smb_fname->base_name = tmp_base_name;
344         TALLOC_FREE(name_mapped);
345
346         return ret;
347 }
348
349 static int catia_rename(vfs_handle_struct *handle,
350                         const struct smb_filename *smb_fname_src,
351                         const struct smb_filename *smb_fname_dst)
352 {
353         TALLOC_CTX *ctx = talloc_tos();
354         struct smb_filename *smb_fname_src_tmp = NULL;
355         struct smb_filename *smb_fname_dst_tmp = NULL;
356         char *src_name_mapped = NULL;
357         char *dst_name_mapped = NULL;
358         NTSTATUS status;
359         int ret = -1;
360
361         status = catia_string_replace_allocate(handle->conn,
362                                 smb_fname_src->base_name,
363                                 &src_name_mapped, vfs_translate_to_unix);
364         if (!NT_STATUS_IS_OK(status)) {
365                 errno = map_errno_from_nt_status(status);
366                 return -1;
367         }
368
369         status = catia_string_replace_allocate(handle->conn,
370                                 smb_fname_dst->base_name,
371                                 &dst_name_mapped, vfs_translate_to_unix);
372         if (!NT_STATUS_IS_OK(status)) {
373                 errno = map_errno_from_nt_status(status);
374                 return -1;
375         }
376
377         /* Setup temporary smb_filename structs. */
378         status = copy_smb_filename(ctx, smb_fname_src, &smb_fname_src_tmp);
379
380         if (!NT_STATUS_IS_OK(status)) {
381                 errno = map_errno_from_nt_status(status);
382                 goto out;
383         }
384
385         status = copy_smb_filename(ctx, smb_fname_dst, &smb_fname_dst_tmp);
386         if (!NT_STATUS_IS_OK(status)) {
387                 errno = map_errno_from_nt_status(status);
388                 goto out;
389         }
390
391         smb_fname_src_tmp->base_name = src_name_mapped;
392         smb_fname_dst_tmp->base_name = dst_name_mapped; 
393         DEBUG(10, ("converted old name: %s\n",
394                                 smb_fname_str_dbg(smb_fname_src_tmp)));
395         DEBUG(10, ("converted new name: %s\n",
396                                 smb_fname_str_dbg(smb_fname_dst_tmp)));
397
398         ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src_tmp,
399                         smb_fname_dst_tmp);
400 out:
401         TALLOC_FREE(src_name_mapped);
402         TALLOC_FREE(dst_name_mapped);
403         TALLOC_FREE(smb_fname_src_tmp);
404         TALLOC_FREE(smb_fname_dst_tmp);
405         return ret;
406 }
407
408 static int catia_stat(vfs_handle_struct *handle,
409                       struct smb_filename *smb_fname)
410 {
411         char *name = NULL;
412         char *tmp_base_name;
413         int ret;
414         NTSTATUS status;
415
416         status = catia_string_replace_allocate(handle->conn,
417                                 smb_fname->base_name,
418                                 &name, vfs_translate_to_unix);
419         if (!NT_STATUS_IS_OK(status)) {
420                 errno = map_errno_from_nt_status(status);
421                 return -1;
422         }
423
424         tmp_base_name = smb_fname->base_name;
425         smb_fname->base_name = name;
426
427         ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
428         smb_fname->base_name = tmp_base_name;
429
430         TALLOC_FREE(name);
431         return ret;
432 }
433
434 static int catia_lstat(vfs_handle_struct *handle,
435                        struct smb_filename *smb_fname)
436 {
437         char *name = NULL;
438         char *tmp_base_name;
439         int ret;
440         NTSTATUS status;
441
442         status = catia_string_replace_allocate(handle->conn,
443                                 smb_fname->base_name,
444                                 &name, vfs_translate_to_unix);
445         if (!NT_STATUS_IS_OK(status)) {
446                 errno = map_errno_from_nt_status(status);
447                 return -1;
448         }
449
450         tmp_base_name = smb_fname->base_name;
451         smb_fname->base_name = name;
452
453         ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
454         smb_fname->base_name = tmp_base_name;
455         TALLOC_FREE(name);
456
457         return ret;
458 }
459
460 static int catia_unlink(vfs_handle_struct *handle,
461                         const struct smb_filename *smb_fname)
462 {
463         struct smb_filename *smb_fname_tmp = NULL;
464         char *name = NULL;
465         NTSTATUS status;
466         int ret;
467
468         status = catia_string_replace_allocate(handle->conn,
469                                         smb_fname->base_name,
470                                         &name, vfs_translate_to_unix);
471         if (!NT_STATUS_IS_OK(status)) {
472                 errno = map_errno_from_nt_status(status);
473                 return -1;
474         }
475
476         /* Setup temporary smb_filename structs. */
477         status = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);
478         if (!NT_STATUS_IS_OK(status)) {
479                 errno = map_errno_from_nt_status(status);
480                 return -1;
481         }
482
483         smb_fname_tmp->base_name = name;
484         ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_tmp);
485         TALLOC_FREE(smb_fname_tmp);
486         TALLOC_FREE(name);
487
488         return ret;
489 }
490
491 static int catia_chown(vfs_handle_struct *handle,
492                        const char *path,
493                        uid_t uid,
494                        gid_t gid)
495 {
496         char *name = NULL;
497         NTSTATUS status;
498         int ret;
499
500         status = catia_string_replace_allocate(handle->conn, path,
501                                         &name, vfs_translate_to_unix);
502         if (!NT_STATUS_IS_OK(status)) {
503                 errno = map_errno_from_nt_status(status);
504                 return -1;
505         }
506
507         ret = SMB_VFS_NEXT_CHOWN(handle, name, uid, gid);
508         TALLOC_FREE(name);
509
510         return ret;
511 }
512
513 static int catia_lchown(vfs_handle_struct *handle,
514                         const char *path,
515                         uid_t uid,
516                         gid_t gid)
517 {
518         char *name = NULL;
519         NTSTATUS status;
520         int ret;
521
522         status = catia_string_replace_allocate(handle->conn, path,
523                                         &name, vfs_translate_to_unix);
524         if (!NT_STATUS_IS_OK(status)) {
525                 errno = map_errno_from_nt_status(status);
526                 return -1;
527         }
528
529         ret = SMB_VFS_NEXT_LCHOWN(handle, name, uid, gid);
530         TALLOC_FREE(name);
531
532         return ret;
533 }
534
535 static int catia_rmdir(vfs_handle_struct *handle,
536                        const char *path)
537 {
538         char *name = NULL;
539         NTSTATUS status;
540         int ret;
541
542         status = catia_string_replace_allocate(handle->conn, path,
543                                         &name, vfs_translate_to_unix);
544         if (!NT_STATUS_IS_OK(status)) {
545                 errno = map_errno_from_nt_status(status);
546                 return -1;
547         }
548
549         ret = SMB_VFS_NEXT_RMDIR(handle, name);
550         TALLOC_FREE(name);
551
552         return ret;
553 }
554
555 static int catia_mkdir(vfs_handle_struct *handle,
556                        const char *path,
557                        mode_t mode)
558 {
559         char *name = NULL;
560         NTSTATUS status;
561         int ret;
562
563         status = catia_string_replace_allocate(handle->conn, path,
564                                          &name, vfs_translate_to_unix);
565         if (!NT_STATUS_IS_OK(status)) {
566                 errno = map_errno_from_nt_status(status);
567                 return -1;
568         }
569
570         ret = SMB_VFS_NEXT_MKDIR(handle, name, mode);
571         TALLOC_FREE(name);
572
573         return ret;
574 }
575
576 static int catia_chdir(vfs_handle_struct *handle,
577                        const char *path)
578 {
579         char *name = NULL;
580         NTSTATUS status;
581         int ret;
582
583         status = catia_string_replace_allocate(handle->conn, path,
584                                         &name, vfs_translate_to_unix);
585         if (!NT_STATUS_IS_OK(status)) {
586                 errno = map_errno_from_nt_status(status);
587                 return -1;
588         }
589
590         ret = SMB_VFS_NEXT_CHDIR(handle, name);
591         TALLOC_FREE(name);
592
593         return ret;
594 }
595
596 static int catia_ntimes(vfs_handle_struct *handle,
597                         const struct smb_filename *smb_fname,
598                         struct smb_file_time *ft)
599 {
600         struct smb_filename *smb_fname_tmp = NULL;
601         char *name = NULL;
602         NTSTATUS status;
603         int ret;
604
605         status = catia_string_replace_allocate(handle->conn,
606                                 smb_fname->base_name,
607                                 &name, vfs_translate_to_unix);
608         if (!NT_STATUS_IS_OK(status)) {
609                 errno = map_errno_from_nt_status(status);
610                 return -1;
611         }
612
613         status = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);
614         if (!NT_STATUS_IS_OK(status)) {
615                 errno = map_errno_from_nt_status(status);
616                 return -1;
617         }
618
619         smb_fname_tmp->base_name = name;
620         ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname_tmp, ft);
621         TALLOC_FREE(name);
622         TALLOC_FREE(smb_fname_tmp);
623
624         return ret;
625 }
626
627 static char *
628 catia_realpath(vfs_handle_struct *handle, const char *path,
629                char *resolved_path)
630 {
631         char *mapped_name = NULL;
632         NTSTATUS status;
633         char *ret = NULL;
634
635         status = catia_string_replace_allocate(handle->conn, path,
636                                         &mapped_name, vfs_translate_to_unix);
637         if (!NT_STATUS_IS_OK(status)) {
638                 errno = map_errno_from_nt_status(status);
639                 return NULL;
640         }
641
642         ret = SMB_VFS_NEXT_REALPATH(handle, mapped_name, resolved_path);
643         TALLOC_FREE(mapped_name);
644
645         return ret;
646 }
647
648 static int catia_chflags(struct vfs_handle_struct *handle,
649                          const char *path, unsigned int flags)
650 {
651         char *mapped_name = NULL;
652         NTSTATUS status;
653         int ret;
654
655         status = catia_string_replace_allocate(handle->conn, path,
656                                         &mapped_name, vfs_translate_to_unix);
657         if (!NT_STATUS_IS_OK(status)) {
658                 errno = map_errno_from_nt_status(status);
659                 return -1;
660         }
661
662         ret = SMB_VFS_NEXT_CHFLAGS(handle, mapped_name, flags);
663         TALLOC_FREE(mapped_name);
664
665         return ret;
666 }
667
668 static NTSTATUS
669 catia_streaminfo(struct vfs_handle_struct *handle,
670                  struct files_struct *fsp,
671                  const char *path,
672                  TALLOC_CTX *mem_ctx,
673                  unsigned int *num_streams,
674                  struct stream_struct **streams)
675 {
676         char *mapped_name = NULL;
677         NTSTATUS status;
678
679         status = catia_string_replace_allocate(handle->conn, path,
680                                         &mapped_name, vfs_translate_to_unix);
681         if (!NT_STATUS_IS_OK(status)) {
682                 errno = map_errno_from_nt_status(status);
683                 return status;
684         }
685
686         status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, mapped_name,
687                                          mem_ctx, num_streams,streams);
688         TALLOC_FREE(mapped_name);
689
690         return status;
691 }
692
693 static NTSTATUS
694 catia_get_nt_acl(struct vfs_handle_struct *handle,
695                  const char *path,
696                  uint32 security_info,
697                  struct security_descriptor **ppdesc)
698 {
699         char *mapped_name = NULL;
700         NTSTATUS status;
701
702         status = catia_string_replace_allocate(handle->conn,
703                                 path, &mapped_name, vfs_translate_to_unix);
704         if (!NT_STATUS_IS_OK(status)) {
705                 errno = map_errno_from_nt_status(status);
706                 return status;
707         }
708         status = SMB_VFS_NEXT_GET_NT_ACL(handle, mapped_name,
709                                          security_info, ppdesc);
710         TALLOC_FREE(mapped_name);
711
712         return status;
713 }
714
715 static int
716 catia_chmod_acl(vfs_handle_struct *handle,
717                 const char *path,
718                 mode_t mode)
719 {
720         char *mapped_name = NULL;
721         NTSTATUS status;
722         int ret;
723
724         status = catia_string_replace_allocate(handle->conn,
725                                 path, &mapped_name, vfs_translate_to_unix);
726         if (!NT_STATUS_IS_OK(status)) {
727                 errno = map_errno_from_nt_status(status);
728                 return -1;
729         }
730
731         ret = SMB_VFS_NEXT_CHMOD_ACL(handle, mapped_name, mode);
732         TALLOC_FREE(mapped_name);
733         return ret;
734 }
735
736 static SMB_ACL_T
737 catia_sys_acl_get_file(vfs_handle_struct *handle,
738                        const char *path,
739                        SMB_ACL_TYPE_T type)
740 {
741         char *mapped_name = NULL;
742         NTSTATUS status;
743         SMB_ACL_T ret;
744
745         status = catia_string_replace_allocate(handle->conn,
746                                 path, &mapped_name, vfs_translate_to_unix);
747         if (!NT_STATUS_IS_OK(status)) {
748                 errno = map_errno_from_nt_status(status);
749                 return NULL;
750         }
751
752         ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, mapped_name, type);
753         TALLOC_FREE(mapped_name);
754
755         return ret;
756 }
757
758 static int
759 catia_sys_acl_set_file(vfs_handle_struct *handle,
760                        const char *path,
761                        SMB_ACL_TYPE_T type,
762                        SMB_ACL_T theacl)
763 {
764         char *mapped_name = NULL;
765         NTSTATUS status;
766         int ret;
767
768         status = catia_string_replace_allocate(handle->conn,
769                                 path, &mapped_name, vfs_translate_to_unix);
770         if (!NT_STATUS_IS_OK(status)) {
771                 errno = map_errno_from_nt_status(status);
772                 return -1;
773         }
774
775         ret = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, mapped_name, type, theacl);
776         TALLOC_FREE(mapped_name);
777
778         return ret;
779 }
780
781 static int
782 catia_sys_acl_delete_def_file(vfs_handle_struct *handle,
783                               const char *path)
784 {
785         char *mapped_name = NULL;
786         NTSTATUS status;
787         int ret;
788
789         status = catia_string_replace_allocate(handle->conn,
790                                 path, &mapped_name, vfs_translate_to_unix);
791         if (!NT_STATUS_IS_OK(status)) {
792                 errno = map_errno_from_nt_status(status);
793                 return -1;
794         }
795
796         ret = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, mapped_name);
797         TALLOC_FREE(mapped_name);
798
799         return ret;
800 }
801
802 static ssize_t
803 catia_getxattr(vfs_handle_struct *handle, const char *path,
804                const char *name, void *value, size_t size)
805 {
806         char *mapped_name = NULL;
807         NTSTATUS status;
808         ssize_t ret;
809
810         status = catia_string_replace_allocate(handle->conn,
811                                 name, &mapped_name, vfs_translate_to_unix);
812         if (!NT_STATUS_IS_OK(status)) {
813                 errno = map_errno_from_nt_status(status);
814                 return -1;
815         }
816
817
818         ret = SMB_VFS_NEXT_GETXATTR(handle, path, mapped_name, value, size);
819         TALLOC_FREE(mapped_name);
820
821         return ret;
822 }
823
824 static ssize_t
825 catia_lgetxattr(vfs_handle_struct *handle, const char *path,
826                 const char *name, void *value, size_t size)
827 {
828         char *mapped_name = NULL;
829         NTSTATUS status;
830         ssize_t ret;
831
832         status = catia_string_replace_allocate(handle->conn,
833                                 name, &mapped_name, vfs_translate_to_unix);
834         if (!NT_STATUS_IS_OK(status)) {
835                 errno = map_errno_from_nt_status(status);
836                 return -1;
837         }
838
839
840         ret = SMB_VFS_NEXT_LGETXATTR(handle, path, mapped_name, value, size);
841         TALLOC_FREE(mapped_name);
842
843         return ret;
844 }
845
846 static ssize_t
847 catia_listxattr(vfs_handle_struct *handle, const char *path,
848                 char *list, size_t size)
849 {
850         char *mapped_name = NULL;
851         NTSTATUS status;
852         ssize_t ret;
853
854         status = catia_string_replace_allocate(handle->conn,
855                                 path, &mapped_name, vfs_translate_to_unix);
856         if (!NT_STATUS_IS_OK(status)) {
857                 errno = map_errno_from_nt_status(status);
858                 return -1;
859         }
860
861
862         ret = SMB_VFS_NEXT_LISTXATTR(handle, mapped_name, list, size);
863         TALLOC_FREE(mapped_name);
864
865         return ret;
866 }
867
868 static ssize_t
869 catia_llistxattr(vfs_handle_struct *handle, const char *path,
870                  char *list, size_t size)
871 {
872         char *mapped_name = NULL;
873         NTSTATUS status;
874         ssize_t ret;
875
876         status = catia_string_replace_allocate(handle->conn,
877                                 path, &mapped_name, vfs_translate_to_unix);
878         if (!NT_STATUS_IS_OK(status)) {
879                 errno = map_errno_from_nt_status(status);
880                 return -1;
881         }
882
883
884         ret = SMB_VFS_NEXT_LLISTXATTR(handle, mapped_name, list, size);
885         TALLOC_FREE(mapped_name);
886
887         return ret;
888 }
889
890 static int
891 catia_removexattr(vfs_handle_struct *handle, const char *path,
892                   const char *name)
893 {
894         char *mapped_name = NULL;
895         NTSTATUS status;
896         ssize_t ret;
897
898         status = catia_string_replace_allocate(handle->conn,
899                                 name, &mapped_name, vfs_translate_to_unix);
900         if (!NT_STATUS_IS_OK(status)) {
901                 errno = map_errno_from_nt_status(status);
902                 return -1;
903         }
904
905
906         ret = SMB_VFS_NEXT_REMOVEXATTR(handle, path, mapped_name);
907         TALLOC_FREE(mapped_name);
908
909         return ret;
910 }
911
912 static int
913 catia_lremovexattr(vfs_handle_struct *handle, const char *path,
914                    const char *name)
915 {
916         char *mapped_name = NULL;
917         NTSTATUS status;
918         ssize_t ret;
919
920         status = catia_string_replace_allocate(handle->conn,
921                                 name, &mapped_name, vfs_translate_to_unix);
922         if (!NT_STATUS_IS_OK(status)) {
923                 errno = map_errno_from_nt_status(status);
924                 return -1;
925         }
926
927
928         ret = SMB_VFS_NEXT_LREMOVEXATTR(handle, path, mapped_name);
929         TALLOC_FREE(mapped_name);
930
931         return ret;
932 }
933
934 static int
935 catia_setxattr(vfs_handle_struct *handle, const char *path,
936                const char *name, const void *value, size_t size,
937                int flags)
938 {
939         char *mapped_name = NULL;
940         NTSTATUS status;
941         ssize_t ret;
942
943         status = catia_string_replace_allocate(handle->conn,
944                                 name, &mapped_name, vfs_translate_to_unix);
945         if (!NT_STATUS_IS_OK(status)) {
946                 errno = map_errno_from_nt_status(status);
947                 return -1;
948         }
949
950
951         ret = SMB_VFS_NEXT_SETXATTR(handle, path, mapped_name, value, size, flags);
952         TALLOC_FREE(mapped_name);
953
954         return ret;
955 }
956
957 static int
958 catia_lsetxattr(vfs_handle_struct *handle, const char *path,
959                 const char *name, const void *value, size_t size,
960                 int flags)
961 {
962         char *mapped_name = NULL;
963         NTSTATUS status;
964         ssize_t ret;
965
966         status = catia_string_replace_allocate(handle->conn,
967                                 name, &mapped_name, vfs_translate_to_unix);
968         if (!NT_STATUS_IS_OK(status)) {
969                 errno = map_errno_from_nt_status(status);
970                 return -1;
971         }
972
973
974         ret = SMB_VFS_NEXT_LSETXATTR(handle, path, mapped_name, value, size, flags);
975         TALLOC_FREE(mapped_name);
976
977         return ret;
978 }
979
980 static struct vfs_fn_pointers vfs_catia_fns = {
981         .mkdir = catia_mkdir,
982         .rmdir = catia_rmdir,
983         .opendir = catia_opendir,
984         .open = catia_open,
985         .rename = catia_rename,
986         .stat = catia_stat,
987         .lstat = catia_lstat,
988         .unlink = catia_unlink,
989         .chown = catia_chown,
990         .lchown = catia_lchown,
991         .chdir = catia_chdir,
992         .ntimes = catia_ntimes,
993         .realpath = catia_realpath,
994         .chflags = catia_chflags,
995         .streaminfo = catia_streaminfo,
996         .translate_name = catia_translate_name,
997         .get_nt_acl = catia_get_nt_acl,
998         .chmod_acl = catia_chmod_acl,
999         .sys_acl_get_file = catia_sys_acl_get_file,
1000         .sys_acl_set_file = catia_sys_acl_set_file,
1001         .sys_acl_delete_def_file = catia_sys_acl_delete_def_file,
1002         .getxattr = catia_getxattr,
1003         .lgetxattr = catia_lgetxattr,
1004         .listxattr = catia_listxattr,
1005         .llistxattr = catia_llistxattr,
1006         .removexattr = catia_removexattr,
1007         .lremovexattr = catia_lremovexattr,
1008         .setxattr = catia_setxattr,
1009         .lsetxattr = catia_lsetxattr,
1010 };
1011
1012 NTSTATUS vfs_catia_init(void)
1013 {
1014         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
1015                                 &vfs_catia_fns);
1016 }