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