vfs_catia: fix the translation to "vfs_translate_to_windows"
[Samba.git] / source3 / modules / vfs_catia.c
blobc0063be05f437144060399c9c1d8b20ebf4f2fd6
1 /*
2 * Catia VFS module
4 * Implement a fixed mapping of forbidden NT characters in filenames that are
5 * used a lot by the CAD package Catia.
7 * 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...
11 * Copyright (C) Volker Lendecke, 2005
12 * Copyright (C) Aravind Srinivasan, 2009
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.
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.
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/>.
29 #include "includes.h"
30 #include "smbd/smbd.h"
32 static int vfs_catia_debug_level = DBGC_VFS;
34 #undef DBGC_CLASS
35 #define DBGC_CLASS vfs_catia_debug_level
37 #define GLOBAL_SNUM 0xFFFFFFF
38 #define MAP_SIZE 0xFF
39 #define MAP_NUM 0x101 /* max unicode charval / MAP_SIZE */
40 #define T_OFFSET(_v_) ((_v_ % MAP_SIZE))
41 #define T_START(_v_) (((_v_ / MAP_SIZE) * MAP_SIZE))
42 #define T_PICK(_v_) ((_v_ / MAP_SIZE))
44 struct char_mappings {
45 smb_ucs2_t entry[MAP_SIZE][2];
48 struct share_mapping_entry {
49 int snum;
50 struct share_mapping_entry *next;
51 struct char_mappings **mappings;
54 struct share_mapping_entry *srt_head = NULL;
56 static bool build_table(struct char_mappings **cmaps, int value)
58 int i;
59 int start = T_START(value);
61 (*cmaps) = talloc_zero(NULL, struct char_mappings);
63 if (!*cmaps)
64 return False;
66 for (i = 0; i < MAP_SIZE;i++) {
67 (*cmaps)->entry[i][vfs_translate_to_unix] = start + i;
68 (*cmaps)->entry[i][vfs_translate_to_windows] = start + i;
71 return True;
74 static void set_tables(struct char_mappings **cmaps,
75 long unix_map,
76 long windows_map)
78 int i;
80 /* set unix -> windows */
81 i = T_OFFSET(unix_map);
82 cmaps[T_PICK(unix_map)]->entry[i][vfs_translate_to_windows] = windows_map;
84 /* set windows -> unix */
85 i = T_OFFSET(windows_map);
86 cmaps[T_PICK(windows_map)]->entry[i][vfs_translate_to_unix] = unix_map;
89 static bool build_ranges(struct char_mappings **cmaps,
90 long unix_map,
91 long windows_map)
94 if (!cmaps[T_PICK(unix_map)]) {
95 if (!build_table(&cmaps[T_PICK(unix_map)], unix_map))
96 return False;
99 if (!cmaps[T_PICK(windows_map)]) {
100 if (!build_table(&cmaps[T_PICK(windows_map)], windows_map))
101 return False;
104 set_tables(cmaps, unix_map, windows_map);
106 return True;
109 static struct share_mapping_entry *get_srt(connection_struct *conn,
110 struct share_mapping_entry **global)
112 struct share_mapping_entry *share;
114 for (share = srt_head; share != NULL; share = share->next) {
115 if (share->snum == GLOBAL_SNUM)
116 (*global) = share;
118 if (share->snum == SNUM(conn))
119 return share;
122 return share;
125 static struct share_mapping_entry *add_srt(int snum, const char **mappings)
128 char *tmp;
129 fstring mapping;
130 int i;
131 long unix_map, windows_map;
132 struct share_mapping_entry *ret = NULL;
134 ret = (struct share_mapping_entry *)
135 TALLOC_ZERO(NULL, sizeof(struct share_mapping_entry) +
136 (mappings ? (MAP_NUM * sizeof(struct char_mappings *)) : 0));
138 if (!ret)
139 return ret;
141 ret->snum = snum;
143 if (mappings) {
144 ret->mappings = (struct char_mappings**) ((unsigned char*) ret +
145 sizeof(struct share_mapping_entry));
146 memset(ret->mappings, 0,
147 MAP_NUM * sizeof(struct char_mappings *));
148 } else {
149 ret->mappings = NULL;
150 return ret;
154 * catia mappings are of the form :
155 * UNIX char (in 0xnn hex) : WINDOWS char (in 0xnn hex)
157 * multiple mappings are comma seperated in smb.conf
159 for (i=0;mappings[i];i++) {
160 fstrcpy(mapping, mappings[i]);
161 unix_map = strtol(mapping, &tmp, 16);
162 if (unix_map == 0 && errno == EINVAL) {
163 DEBUG(0, ("INVALID CATIA MAPPINGS - %s\n", mapping));
164 continue;
166 windows_map = strtol(++tmp, NULL, 16);
167 if (windows_map == 0 && errno == EINVAL) {
168 DEBUG(0, ("INVALID CATIA MAPPINGS - %s\n", mapping));
169 continue;
172 if (!build_ranges(ret->mappings, unix_map, windows_map)) {
173 DEBUG(0, ("TABLE ERROR - CATIA MAPPINGS - %s\n", mapping));
174 continue;
178 ret->next = srt_head;
179 srt_head = ret;
181 return ret;
184 static bool init_mappings(connection_struct *conn,
185 struct share_mapping_entry **selected_out)
187 const char **mappings = NULL;
188 struct share_mapping_entry *share_level = NULL;
189 struct share_mapping_entry *global = NULL;
191 /* check srt cache */
192 share_level = get_srt(conn, &global);
193 if (share_level) {
194 *selected_out = share_level;
195 return (share_level->mappings != NULL);
198 /* see if we have a global setting */
199 if (!global) {
200 /* global setting */
201 mappings = lp_parm_string_list(-1, "catia", "mappings", NULL);
202 global = add_srt(GLOBAL_SNUM, mappings);
205 /* no global setting - what about share level ? */
206 mappings = lp_parm_string_list(SNUM(conn), "catia", "mappings", NULL);
207 share_level = add_srt(SNUM(conn), mappings);
209 if (share_level->mappings) {
210 (*selected_out) = share_level;
211 return True;
212 } else if (global->mappings) {
213 share_level->mappings = global->mappings;
214 (*selected_out) = share_level;
215 return True;
218 return False;
221 static NTSTATUS catia_string_replace_allocate(connection_struct *conn,
222 const char *name_in,
223 char **mapped_name,
224 int direction)
226 static smb_ucs2_t *tmpbuf = NULL;
227 smb_ucs2_t *ptr;
228 struct share_mapping_entry *selected;
229 struct char_mappings *map = NULL;
230 size_t converted_size;
231 TALLOC_CTX *ctx = talloc_tos();
233 if (!init_mappings(conn, &selected)) {
234 /* No mappings found. Just use the old name */
235 *mapped_name = talloc_strdup(NULL, name_in);
236 if (!*mapped_name) {
237 errno = ENOMEM;
238 return NT_STATUS_NO_MEMORY;
240 return NT_STATUS_OK;
243 if ((push_ucs2_talloc(ctx, &tmpbuf, name_in,
244 &converted_size)) == false) {
245 return map_nt_error_from_unix(errno);
247 ptr = tmpbuf;
248 for(;*ptr;ptr++) {
249 if (*ptr == 0)
250 break;
251 map = selected->mappings[T_PICK((*ptr))];
253 /* nothing to do */
254 if (!map)
255 continue;
257 *ptr = map->entry[T_OFFSET((*ptr))][direction];
260 if ((pull_ucs2_talloc(ctx, mapped_name, tmpbuf,
261 &converted_size)) == false) {
262 TALLOC_FREE(tmpbuf);
263 return map_nt_error_from_unix(errno);
265 TALLOC_FREE(tmpbuf);
266 return NT_STATUS_OK;
269 static SMB_STRUCT_DIR *catia_opendir(vfs_handle_struct *handle,
270 const char *fname,
271 const char *mask,
272 uint32 attr)
274 char *name_mapped = NULL;
275 NTSTATUS status;
276 SMB_STRUCT_DIR *ret;
278 status = catia_string_replace_allocate(handle->conn, fname,
279 &name_mapped, vfs_translate_to_unix);
280 if (!NT_STATUS_IS_OK(status)) {
281 errno = map_errno_from_nt_status(status);
282 return NULL;
285 ret = SMB_VFS_NEXT_OPENDIR(handle, name_mapped, mask, attr);
286 TALLOC_FREE(name_mapped);
288 return ret;
292 * TRANSLATE_NAME call which converts the given name to
293 * "WINDOWS displayable" name
295 static NTSTATUS catia_translate_name(struct vfs_handle_struct *handle,
296 const char *orig_name,
297 enum vfs_translate_direction direction,
298 TALLOC_CTX *mem_ctx,
299 char **pmapped_name)
301 char *name = NULL;
302 char *mapped_name;
303 NTSTATUS status, ret;
306 * Copy the supplied name and free the memory for mapped_name,
307 * already allocated by the caller.
308 * We will be allocating new memory for mapped_name in
309 * catia_string_replace_allocate
311 name = talloc_strdup(talloc_tos(), orig_name);
312 if (!name) {
313 errno = ENOMEM;
314 return NT_STATUS_NO_MEMORY;
316 status = catia_string_replace_allocate(handle->conn, name,
317 &mapped_name, direction);
319 TALLOC_FREE(name);
320 if (!NT_STATUS_IS_OK(status)) {
321 return status;
324 ret = SMB_VFS_NEXT_TRANSLATE_NAME(handle, mapped_name, direction,
325 mem_ctx, pmapped_name);
327 if (NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED)) {
328 *pmapped_name = talloc_move(mem_ctx, &mapped_name);
329 /* we need to return the former translation result here */
330 ret = status;
331 } else {
332 TALLOC_FREE(mapped_name);
335 return ret;
338 static int catia_open(vfs_handle_struct *handle,
339 struct smb_filename *smb_fname,
340 files_struct *fsp,
341 int flags,
342 mode_t mode)
344 char *name_mapped = NULL;
345 char *tmp_base_name;
346 int ret;
347 NTSTATUS status;
349 tmp_base_name = smb_fname->base_name;
350 status = catia_string_replace_allocate(handle->conn,
351 smb_fname->base_name,
352 &name_mapped, vfs_translate_to_unix);
353 if (!NT_STATUS_IS_OK(status)) {
354 errno = map_errno_from_nt_status(status);
355 return -1;
358 smb_fname->base_name = name_mapped;
359 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
360 smb_fname->base_name = tmp_base_name;
361 TALLOC_FREE(name_mapped);
363 return ret;
366 static int catia_rename(vfs_handle_struct *handle,
367 const struct smb_filename *smb_fname_src,
368 const struct smb_filename *smb_fname_dst)
370 TALLOC_CTX *ctx = talloc_tos();
371 struct smb_filename *smb_fname_src_tmp = NULL;
372 struct smb_filename *smb_fname_dst_tmp = NULL;
373 char *src_name_mapped = NULL;
374 char *dst_name_mapped = NULL;
375 NTSTATUS status;
376 int ret = -1;
378 status = catia_string_replace_allocate(handle->conn,
379 smb_fname_src->base_name,
380 &src_name_mapped, vfs_translate_to_unix);
381 if (!NT_STATUS_IS_OK(status)) {
382 errno = map_errno_from_nt_status(status);
383 return -1;
386 status = catia_string_replace_allocate(handle->conn,
387 smb_fname_dst->base_name,
388 &dst_name_mapped, vfs_translate_to_unix);
389 if (!NT_STATUS_IS_OK(status)) {
390 errno = map_errno_from_nt_status(status);
391 return -1;
394 /* Setup temporary smb_filename structs. */
395 status = copy_smb_filename(ctx, smb_fname_src, &smb_fname_src_tmp);
397 if (!NT_STATUS_IS_OK(status)) {
398 errno = map_errno_from_nt_status(status);
399 goto out;
402 status = copy_smb_filename(ctx, smb_fname_dst, &smb_fname_dst_tmp);
403 if (!NT_STATUS_IS_OK(status)) {
404 errno = map_errno_from_nt_status(status);
405 goto out;
408 smb_fname_src_tmp->base_name = src_name_mapped;
409 smb_fname_dst_tmp->base_name = dst_name_mapped;
410 DEBUG(10, ("converted old name: %s\n",
411 smb_fname_str_dbg(smb_fname_src_tmp)));
412 DEBUG(10, ("converted new name: %s\n",
413 smb_fname_str_dbg(smb_fname_dst_tmp)));
415 ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src_tmp,
416 smb_fname_dst_tmp);
417 out:
418 TALLOC_FREE(src_name_mapped);
419 TALLOC_FREE(dst_name_mapped);
420 TALLOC_FREE(smb_fname_src_tmp);
421 TALLOC_FREE(smb_fname_dst_tmp);
422 return ret;
425 static int catia_stat(vfs_handle_struct *handle,
426 struct smb_filename *smb_fname)
428 char *name = NULL;
429 char *tmp_base_name;
430 int ret;
431 NTSTATUS status;
433 status = catia_string_replace_allocate(handle->conn,
434 smb_fname->base_name,
435 &name, vfs_translate_to_unix);
436 if (!NT_STATUS_IS_OK(status)) {
437 errno = map_errno_from_nt_status(status);
438 return -1;
441 tmp_base_name = smb_fname->base_name;
442 smb_fname->base_name = name;
444 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
445 smb_fname->base_name = tmp_base_name;
447 TALLOC_FREE(name);
448 return ret;
451 static int catia_lstat(vfs_handle_struct *handle,
452 struct smb_filename *smb_fname)
454 char *name = NULL;
455 char *tmp_base_name;
456 int ret;
457 NTSTATUS status;
459 status = catia_string_replace_allocate(handle->conn,
460 smb_fname->base_name,
461 &name, vfs_translate_to_unix);
462 if (!NT_STATUS_IS_OK(status)) {
463 errno = map_errno_from_nt_status(status);
464 return -1;
467 tmp_base_name = smb_fname->base_name;
468 smb_fname->base_name = name;
470 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
471 smb_fname->base_name = tmp_base_name;
472 TALLOC_FREE(name);
474 return ret;
477 static int catia_unlink(vfs_handle_struct *handle,
478 const struct smb_filename *smb_fname)
480 struct smb_filename *smb_fname_tmp = NULL;
481 char *name = NULL;
482 NTSTATUS status;
483 int ret;
485 status = catia_string_replace_allocate(handle->conn,
486 smb_fname->base_name,
487 &name, vfs_translate_to_unix);
488 if (!NT_STATUS_IS_OK(status)) {
489 errno = map_errno_from_nt_status(status);
490 return -1;
493 /* Setup temporary smb_filename structs. */
494 status = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);
495 if (!NT_STATUS_IS_OK(status)) {
496 errno = map_errno_from_nt_status(status);
497 return -1;
500 smb_fname_tmp->base_name = name;
501 ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_tmp);
502 TALLOC_FREE(smb_fname_tmp);
503 TALLOC_FREE(name);
505 return ret;
508 static int catia_chown(vfs_handle_struct *handle,
509 const char *path,
510 uid_t uid,
511 gid_t gid)
513 char *name = NULL;
514 NTSTATUS status;
515 int ret;
517 status = catia_string_replace_allocate(handle->conn, path,
518 &name, vfs_translate_to_unix);
519 if (!NT_STATUS_IS_OK(status)) {
520 errno = map_errno_from_nt_status(status);
521 return -1;
524 ret = SMB_VFS_NEXT_CHOWN(handle, name, uid, gid);
525 TALLOC_FREE(name);
527 return ret;
530 static int catia_lchown(vfs_handle_struct *handle,
531 const char *path,
532 uid_t uid,
533 gid_t gid)
535 char *name = NULL;
536 NTSTATUS status;
537 int ret;
539 status = catia_string_replace_allocate(handle->conn, path,
540 &name, vfs_translate_to_unix);
541 if (!NT_STATUS_IS_OK(status)) {
542 errno = map_errno_from_nt_status(status);
543 return -1;
546 ret = SMB_VFS_NEXT_LCHOWN(handle, name, uid, gid);
547 TALLOC_FREE(name);
549 return ret;
552 static int catia_rmdir(vfs_handle_struct *handle,
553 const char *path)
555 char *name = NULL;
556 NTSTATUS status;
557 int ret;
559 status = catia_string_replace_allocate(handle->conn, path,
560 &name, vfs_translate_to_unix);
561 if (!NT_STATUS_IS_OK(status)) {
562 errno = map_errno_from_nt_status(status);
563 return -1;
566 ret = SMB_VFS_NEXT_RMDIR(handle, name);
567 TALLOC_FREE(name);
569 return ret;
572 static int catia_mkdir(vfs_handle_struct *handle,
573 const char *path,
574 mode_t mode)
576 char *name = NULL;
577 NTSTATUS status;
578 int ret;
580 status = catia_string_replace_allocate(handle->conn, path,
581 &name, vfs_translate_to_unix);
582 if (!NT_STATUS_IS_OK(status)) {
583 errno = map_errno_from_nt_status(status);
584 return -1;
587 ret = SMB_VFS_NEXT_MKDIR(handle, name, mode);
588 TALLOC_FREE(name);
590 return ret;
593 static int catia_chdir(vfs_handle_struct *handle,
594 const char *path)
596 char *name = NULL;
597 NTSTATUS status;
598 int ret;
600 status = catia_string_replace_allocate(handle->conn, path,
601 &name, vfs_translate_to_unix);
602 if (!NT_STATUS_IS_OK(status)) {
603 errno = map_errno_from_nt_status(status);
604 return -1;
607 ret = SMB_VFS_NEXT_CHDIR(handle, name);
608 TALLOC_FREE(name);
610 return ret;
613 static int catia_ntimes(vfs_handle_struct *handle,
614 const struct smb_filename *smb_fname,
615 struct smb_file_time *ft)
617 struct smb_filename *smb_fname_tmp = NULL;
618 char *name = NULL;
619 NTSTATUS status;
620 int ret;
622 status = catia_string_replace_allocate(handle->conn,
623 smb_fname->base_name,
624 &name, vfs_translate_to_unix);
625 if (!NT_STATUS_IS_OK(status)) {
626 errno = map_errno_from_nt_status(status);
627 return -1;
630 status = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);
631 if (!NT_STATUS_IS_OK(status)) {
632 errno = map_errno_from_nt_status(status);
633 return -1;
636 smb_fname_tmp->base_name = name;
637 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname_tmp, ft);
638 TALLOC_FREE(name);
639 TALLOC_FREE(smb_fname_tmp);
641 return ret;
644 static char *
645 catia_realpath(vfs_handle_struct *handle, const char *path)
647 char *mapped_name = NULL;
648 NTSTATUS status;
649 char *ret = NULL;
651 status = catia_string_replace_allocate(handle->conn, path,
652 &mapped_name, vfs_translate_to_unix);
653 if (!NT_STATUS_IS_OK(status)) {
654 errno = map_errno_from_nt_status(status);
655 return NULL;
658 ret = SMB_VFS_NEXT_REALPATH(handle, mapped_name);
659 TALLOC_FREE(mapped_name);
661 return ret;
664 static int catia_chflags(struct vfs_handle_struct *handle,
665 const char *path, unsigned int flags)
667 char *mapped_name = NULL;
668 NTSTATUS status;
669 int ret;
671 status = catia_string_replace_allocate(handle->conn, path,
672 &mapped_name, vfs_translate_to_unix);
673 if (!NT_STATUS_IS_OK(status)) {
674 errno = map_errno_from_nt_status(status);
675 return -1;
678 ret = SMB_VFS_NEXT_CHFLAGS(handle, mapped_name, flags);
679 TALLOC_FREE(mapped_name);
681 return ret;
684 static NTSTATUS
685 catia_streaminfo(struct vfs_handle_struct *handle,
686 struct files_struct *fsp,
687 const char *path,
688 TALLOC_CTX *mem_ctx,
689 unsigned int *num_streams,
690 struct stream_struct **streams)
692 char *mapped_name = NULL;
693 NTSTATUS status;
695 status = catia_string_replace_allocate(handle->conn, path,
696 &mapped_name, vfs_translate_to_unix);
697 if (!NT_STATUS_IS_OK(status)) {
698 errno = map_errno_from_nt_status(status);
699 return status;
702 status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, mapped_name,
703 mem_ctx, num_streams,streams);
704 TALLOC_FREE(mapped_name);
706 return status;
709 static NTSTATUS
710 catia_get_nt_acl(struct vfs_handle_struct *handle,
711 const char *path,
712 uint32 security_info,
713 struct security_descriptor **ppdesc)
715 char *mapped_name = NULL;
716 NTSTATUS status;
718 status = catia_string_replace_allocate(handle->conn,
719 path, &mapped_name, vfs_translate_to_unix);
720 if (!NT_STATUS_IS_OK(status)) {
721 errno = map_errno_from_nt_status(status);
722 return status;
724 status = SMB_VFS_NEXT_GET_NT_ACL(handle, mapped_name,
725 security_info, ppdesc);
726 TALLOC_FREE(mapped_name);
728 return status;
731 static int
732 catia_chmod_acl(vfs_handle_struct *handle,
733 const char *path,
734 mode_t mode)
736 char *mapped_name = NULL;
737 NTSTATUS status;
738 int ret;
740 status = catia_string_replace_allocate(handle->conn,
741 path, &mapped_name, vfs_translate_to_unix);
742 if (!NT_STATUS_IS_OK(status)) {
743 errno = map_errno_from_nt_status(status);
744 return -1;
747 ret = SMB_VFS_NEXT_CHMOD_ACL(handle, mapped_name, mode);
748 TALLOC_FREE(mapped_name);
749 return ret;
752 static SMB_ACL_T
753 catia_sys_acl_get_file(vfs_handle_struct *handle,
754 const char *path,
755 SMB_ACL_TYPE_T type)
757 char *mapped_name = NULL;
758 NTSTATUS status;
759 SMB_ACL_T ret;
761 status = catia_string_replace_allocate(handle->conn,
762 path, &mapped_name, vfs_translate_to_unix);
763 if (!NT_STATUS_IS_OK(status)) {
764 errno = map_errno_from_nt_status(status);
765 return NULL;
768 ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, mapped_name, type);
769 TALLOC_FREE(mapped_name);
771 return ret;
774 static int
775 catia_sys_acl_set_file(vfs_handle_struct *handle,
776 const char *path,
777 SMB_ACL_TYPE_T type,
778 SMB_ACL_T theacl)
780 char *mapped_name = NULL;
781 NTSTATUS status;
782 int ret;
784 status = catia_string_replace_allocate(handle->conn,
785 path, &mapped_name, vfs_translate_to_unix);
786 if (!NT_STATUS_IS_OK(status)) {
787 errno = map_errno_from_nt_status(status);
788 return -1;
791 ret = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, mapped_name, type, theacl);
792 TALLOC_FREE(mapped_name);
794 return ret;
797 static int
798 catia_sys_acl_delete_def_file(vfs_handle_struct *handle,
799 const char *path)
801 char *mapped_name = NULL;
802 NTSTATUS status;
803 int ret;
805 status = catia_string_replace_allocate(handle->conn,
806 path, &mapped_name, vfs_translate_to_unix);
807 if (!NT_STATUS_IS_OK(status)) {
808 errno = map_errno_from_nt_status(status);
809 return -1;
812 ret = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, mapped_name);
813 TALLOC_FREE(mapped_name);
815 return ret;
818 static ssize_t
819 catia_getxattr(vfs_handle_struct *handle, const char *path,
820 const char *name, void *value, size_t size)
822 char *mapped_name = NULL;
823 NTSTATUS status;
824 ssize_t ret;
826 status = catia_string_replace_allocate(handle->conn,
827 name, &mapped_name, vfs_translate_to_unix);
828 if (!NT_STATUS_IS_OK(status)) {
829 errno = map_errno_from_nt_status(status);
830 return -1;
834 ret = SMB_VFS_NEXT_GETXATTR(handle, path, mapped_name, value, size);
835 TALLOC_FREE(mapped_name);
837 return ret;
840 static ssize_t
841 catia_lgetxattr(vfs_handle_struct *handle, const char *path,
842 const char *name, void *value, size_t size)
844 char *mapped_name = NULL;
845 NTSTATUS status;
846 ssize_t ret;
848 status = catia_string_replace_allocate(handle->conn,
849 name, &mapped_name, vfs_translate_to_unix);
850 if (!NT_STATUS_IS_OK(status)) {
851 errno = map_errno_from_nt_status(status);
852 return -1;
856 ret = SMB_VFS_NEXT_LGETXATTR(handle, path, mapped_name, value, size);
857 TALLOC_FREE(mapped_name);
859 return ret;
862 static ssize_t
863 catia_listxattr(vfs_handle_struct *handle, const char *path,
864 char *list, size_t size)
866 char *mapped_name = NULL;
867 NTSTATUS status;
868 ssize_t ret;
870 status = catia_string_replace_allocate(handle->conn,
871 path, &mapped_name, vfs_translate_to_unix);
872 if (!NT_STATUS_IS_OK(status)) {
873 errno = map_errno_from_nt_status(status);
874 return -1;
878 ret = SMB_VFS_NEXT_LISTXATTR(handle, mapped_name, list, size);
879 TALLOC_FREE(mapped_name);
881 return ret;
884 static ssize_t
885 catia_llistxattr(vfs_handle_struct *handle, const char *path,
886 char *list, size_t size)
888 char *mapped_name = NULL;
889 NTSTATUS status;
890 ssize_t ret;
892 status = catia_string_replace_allocate(handle->conn,
893 path, &mapped_name, vfs_translate_to_unix);
894 if (!NT_STATUS_IS_OK(status)) {
895 errno = map_errno_from_nt_status(status);
896 return -1;
900 ret = SMB_VFS_NEXT_LLISTXATTR(handle, mapped_name, list, size);
901 TALLOC_FREE(mapped_name);
903 return ret;
906 static int
907 catia_removexattr(vfs_handle_struct *handle, const char *path,
908 const char *name)
910 char *mapped_name = NULL;
911 NTSTATUS status;
912 ssize_t ret;
914 status = catia_string_replace_allocate(handle->conn,
915 name, &mapped_name, vfs_translate_to_unix);
916 if (!NT_STATUS_IS_OK(status)) {
917 errno = map_errno_from_nt_status(status);
918 return -1;
922 ret = SMB_VFS_NEXT_REMOVEXATTR(handle, path, mapped_name);
923 TALLOC_FREE(mapped_name);
925 return ret;
928 static int
929 catia_lremovexattr(vfs_handle_struct *handle, const char *path,
930 const char *name)
932 char *mapped_name = NULL;
933 NTSTATUS status;
934 ssize_t ret;
936 status = catia_string_replace_allocate(handle->conn,
937 name, &mapped_name, vfs_translate_to_unix);
938 if (!NT_STATUS_IS_OK(status)) {
939 errno = map_errno_from_nt_status(status);
940 return -1;
944 ret = SMB_VFS_NEXT_LREMOVEXATTR(handle, path, mapped_name);
945 TALLOC_FREE(mapped_name);
947 return ret;
950 static int
951 catia_setxattr(vfs_handle_struct *handle, const char *path,
952 const char *name, const void *value, size_t size,
953 int flags)
955 char *mapped_name = NULL;
956 NTSTATUS status;
957 ssize_t ret;
959 status = catia_string_replace_allocate(handle->conn,
960 name, &mapped_name, vfs_translate_to_unix);
961 if (!NT_STATUS_IS_OK(status)) {
962 errno = map_errno_from_nt_status(status);
963 return -1;
967 ret = SMB_VFS_NEXT_SETXATTR(handle, path, mapped_name, value, size, flags);
968 TALLOC_FREE(mapped_name);
970 return ret;
973 static int
974 catia_lsetxattr(vfs_handle_struct *handle, const char *path,
975 const char *name, const void *value, size_t size,
976 int flags)
978 char *mapped_name = NULL;
979 NTSTATUS status;
980 ssize_t ret;
982 status = catia_string_replace_allocate(handle->conn,
983 name, &mapped_name, vfs_translate_to_unix);
984 if (!NT_STATUS_IS_OK(status)) {
985 errno = map_errno_from_nt_status(status);
986 return -1;
990 ret = SMB_VFS_NEXT_LSETXATTR(handle, path, mapped_name, value, size, flags);
991 TALLOC_FREE(mapped_name);
993 return ret;
996 static struct vfs_fn_pointers vfs_catia_fns = {
997 .mkdir = catia_mkdir,
998 .rmdir = catia_rmdir,
999 .opendir = catia_opendir,
1000 .open_fn = catia_open,
1001 .rename = catia_rename,
1002 .stat = catia_stat,
1003 .lstat = catia_lstat,
1004 .unlink = catia_unlink,
1005 .chown = catia_chown,
1006 .lchown = catia_lchown,
1007 .chdir = catia_chdir,
1008 .ntimes = catia_ntimes,
1009 .realpath = catia_realpath,
1010 .chflags = catia_chflags,
1011 .streaminfo = catia_streaminfo,
1012 .translate_name = catia_translate_name,
1013 .get_nt_acl = catia_get_nt_acl,
1014 .chmod_acl = catia_chmod_acl,
1015 .sys_acl_get_file = catia_sys_acl_get_file,
1016 .sys_acl_set_file = catia_sys_acl_set_file,
1017 .sys_acl_delete_def_file = catia_sys_acl_delete_def_file,
1018 .getxattr = catia_getxattr,
1019 .lgetxattr = catia_lgetxattr,
1020 .listxattr = catia_listxattr,
1021 .llistxattr = catia_llistxattr,
1022 .removexattr = catia_removexattr,
1023 .lremovexattr = catia_lremovexattr,
1024 .setxattr = catia_setxattr,
1025 .lsetxattr = catia_lsetxattr,
1028 NTSTATUS vfs_catia_init(void)
1030 NTSTATUS ret;
1032 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
1033 &vfs_catia_fns);
1034 if (!NT_STATUS_IS_OK(ret))
1035 return ret;
1037 vfs_catia_debug_level = debug_add_class("catia");
1038 if (vfs_catia_debug_level == -1) {
1039 vfs_catia_debug_level = DBGC_VFS;
1040 DEBUG(0, ("vfs_catia: Couldn't register custom debugging "
1041 "class!\n"));
1042 } else {
1043 DEBUG(10, ("vfs_catia: Debug class number of "
1044 "'catia': %d\n", vfs_catia_debug_level));
1047 return ret;