packaging(RHEL-CTDB): move the idmap and nss_info modules to the common package
[Samba/ekacnet.git] / source3 / modules / vfs_catia.c
blob14e404f9f5c09678adfb2e768778fab61c7ebb16
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"
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))
38 struct char_mappings {
39 smb_ucs2_t entry[MAP_SIZE][2];
42 struct share_mapping_entry {
43 int snum;
44 struct share_mapping_entry *next;
45 struct char_mappings **mappings;
48 struct share_mapping_entry *srt_head = NULL;
50 static bool build_table(struct char_mappings **cmaps, int value)
52 int i;
53 int start = T_START(value);
55 (*cmaps) = talloc_zero(NULL, struct char_mappings);
57 if (!*cmaps)
58 return False;
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;
65 return True;
68 static void set_tables(struct char_mappings **cmaps,
69 long unix_map,
70 long windows_map)
72 int i;
74 /* set unix -> windows */
75 i = T_OFFSET(unix_map);
76 cmaps[T_PICK(unix_map)]->entry[i][vfs_translate_to_windows] = windows_map;
78 /* set windows -> unix */
79 i = T_OFFSET(windows_map);
80 cmaps[T_PICK(windows_map)]->entry[i][vfs_translate_to_unix] = unix_map;
83 static bool build_ranges(struct char_mappings **cmaps,
84 long unix_map,
85 long windows_map)
88 if (!cmaps[T_PICK(unix_map)]) {
89 if (!build_table(&cmaps[T_PICK(unix_map)], unix_map))
90 return False;
93 if (!cmaps[T_PICK(windows_map)]) {
94 if (!build_table(&cmaps[T_PICK(windows_map)], windows_map))
95 return False;
98 set_tables(cmaps, unix_map, windows_map);
100 return True;
103 static struct share_mapping_entry *get_srt(connection_struct *conn,
104 struct share_mapping_entry **global)
106 struct share_mapping_entry *share;
108 for (share = srt_head; share != NULL; share = share->next) {
109 if (share->snum == GLOBAL_SNUM)
110 (*global) = share;
112 if (share->snum == SNUM(conn))
113 return share;
116 return share;
119 static struct share_mapping_entry *add_srt(int snum, const char **mappings)
122 char *tmp;
123 fstring mapping;
124 int i;
125 long unix_map, windows_map;
126 struct share_mapping_entry *ret = NULL;
128 ret = (struct share_mapping_entry *)
129 TALLOC_ZERO(NULL, sizeof(struct share_mapping_entry) +
130 (mappings ? (MAP_NUM * sizeof(struct char_mappings *)) : 0));
132 if (!ret)
133 return ret;
135 ret->snum = snum;
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;
148 * catia mappings are of the form :
149 * UNIX char (in 0xnn hex) : WINDOWS char (in 0xnn hex)
151 * multiple mappings are comma seperated in smb.conf
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;
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;
166 if (!build_ranges(ret->mappings, unix_map, windows_map)) {
167 DEBUG(0, ("TABLE ERROR - CATIA MAPPINGS - %s\n", mapping));
168 continue;
172 ret->next = srt_head;
173 srt_head = ret;
175 return ret;
178 static bool init_mappings(connection_struct *conn,
179 struct share_mapping_entry **selected_out)
181 const char **mappings = NULL;
182 struct share_mapping_entry *share_level = NULL;
183 struct share_mapping_entry *global = NULL;
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);
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);
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);
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;
212 return False;
215 static NTSTATUS catia_string_replace_allocate(connection_struct *conn,
216 const char *name_in,
217 char **mapped_name,
218 int direction)
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();
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;
234 return NT_STATUS_OK;
237 if ((push_ucs2_talloc(ctx, &tmpbuf, name_in,
238 &converted_size)) == -1) {
239 return map_nt_error_from_unix(errno);
241 ptr = tmpbuf;
242 for(;*ptr;ptr++) {
243 if (*ptr == 0)
244 break;
245 map = selected->mappings[T_PICK((*ptr))];
247 /* nothing to do */
248 if (!map)
249 continue;
251 *ptr = map->entry[T_OFFSET((*ptr))][direction];
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);
259 TALLOC_FREE(tmpbuf);
260 return NT_STATUS_OK;
263 static SMB_STRUCT_DIR *catia_opendir(vfs_handle_struct *handle,
264 const char *fname,
265 const char *mask,
266 uint32 attr)
268 char *name_mapped = NULL;
269 NTSTATUS status;
270 SMB_STRUCT_DIR *ret;
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;
279 ret = SMB_VFS_NEXT_OPENDIR(handle, name_mapped, mask, attr);
280 TALLOC_FREE(name_mapped);
282 return ret;
286 * TRANSLATE_NAME call which converts the given name to
287 * "WINDOWS displayable" name
289 static NTSTATUS catia_translate_name(vfs_handle_struct *handle,
290 char **mapped_name,
291 enum vfs_translate_direction direction)
293 char *name = NULL;
294 NTSTATUS ret;
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
302 name = talloc_strdup(talloc_tos(), *mapped_name);
303 if (!name) {
304 errno = ENOMEM;
305 return NT_STATUS_NO_MEMORY;
307 TALLOC_FREE(*mapped_name);
308 ret = catia_string_replace_allocate(handle->conn, name,
309 mapped_name, direction);
311 TALLOC_FREE(name);
312 if (!NT_STATUS_IS_OK(ret)) {
313 return ret;
316 ret = SMB_VFS_NEXT_TRANSLATE_NAME(handle, mapped_name, direction);
318 return ret;
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)
327 char *name_mapped = NULL;
328 char *tmp_base_name;
329 int ret;
330 NTSTATUS status;
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;
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);
346 return ret;
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)
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;
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;
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;
377 /* Setup temporary smb_filename structs. */
378 status = copy_smb_filename(ctx, smb_fname_src, &smb_fname_src_tmp);
380 if (!NT_STATUS_IS_OK(status)) {
381 errno = map_errno_from_nt_status(status);
382 goto out;
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;
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)));
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;
408 static int catia_stat(vfs_handle_struct *handle,
409 struct smb_filename *smb_fname)
411 char *name = NULL;
412 char *tmp_base_name;
413 int ret;
414 NTSTATUS status;
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;
424 tmp_base_name = smb_fname->base_name;
425 smb_fname->base_name = name;
427 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
428 smb_fname->base_name = tmp_base_name;
430 TALLOC_FREE(name);
431 return ret;
434 static int catia_lstat(vfs_handle_struct *handle,
435 struct smb_filename *smb_fname)
437 char *name = NULL;
438 char *tmp_base_name;
439 int ret;
440 NTSTATUS status;
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;
450 tmp_base_name = smb_fname->base_name;
451 smb_fname->base_name = name;
453 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
454 smb_fname->base_name = tmp_base_name;
455 TALLOC_FREE(name);
457 return ret;
460 static int catia_unlink(vfs_handle_struct *handle,
461 const struct smb_filename *smb_fname)
463 struct smb_filename *smb_fname_tmp = NULL;
464 char *name = NULL;
465 NTSTATUS status;
466 int ret;
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;
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;
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);
488 return ret;
491 static int catia_chown(vfs_handle_struct *handle,
492 const char *path,
493 uid_t uid,
494 gid_t gid)
496 char *name = NULL;
497 NTSTATUS status;
498 int ret;
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;
507 ret = SMB_VFS_NEXT_CHOWN(handle, name, uid, gid);
508 TALLOC_FREE(name);
510 return ret;
513 static int catia_lchown(vfs_handle_struct *handle,
514 const char *path,
515 uid_t uid,
516 gid_t gid)
518 char *name = NULL;
519 NTSTATUS status;
520 int ret;
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;
529 ret = SMB_VFS_NEXT_LCHOWN(handle, name, uid, gid);
530 TALLOC_FREE(name);
532 return ret;
535 static int catia_rmdir(vfs_handle_struct *handle,
536 const char *path)
538 char *name = NULL;
539 NTSTATUS status;
540 int ret;
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;
549 ret = SMB_VFS_NEXT_RMDIR(handle, name);
550 TALLOC_FREE(name);
552 return ret;
555 static int catia_mkdir(vfs_handle_struct *handle,
556 const char *path,
557 mode_t mode)
559 char *name = NULL;
560 NTSTATUS status;
561 int ret;
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;
570 ret = SMB_VFS_NEXT_MKDIR(handle, name, mode);
571 TALLOC_FREE(name);
573 return ret;
576 static int catia_chdir(vfs_handle_struct *handle,
577 const char *path)
579 char *name = NULL;
580 NTSTATUS status;
581 int ret;
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;
590 ret = SMB_VFS_NEXT_CHDIR(handle, name);
591 TALLOC_FREE(name);
593 return ret;
596 static int catia_ntimes(vfs_handle_struct *handle,
597 const struct smb_filename *smb_fname,
598 struct smb_file_time *ft)
600 struct smb_filename *smb_fname_tmp = NULL;
601 char *name = NULL;
602 NTSTATUS status;
603 int ret;
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;
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;
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);
624 return ret;
627 static char *
628 catia_realpath(vfs_handle_struct *handle, const char *path,
629 char *resolved_path)
631 char *mapped_name = NULL;
632 NTSTATUS status;
633 char *ret = NULL;
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;
642 ret = SMB_VFS_NEXT_REALPATH(handle, mapped_name, resolved_path);
643 TALLOC_FREE(mapped_name);
645 return ret;
648 static int catia_chflags(struct vfs_handle_struct *handle,
649 const char *path, unsigned int flags)
651 char *mapped_name = NULL;
652 NTSTATUS status;
653 int ret;
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;
662 ret = SMB_VFS_NEXT_CHFLAGS(handle, mapped_name, flags);
663 TALLOC_FREE(mapped_name);
665 return ret;
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)
676 char *mapped_name = NULL;
677 NTSTATUS status;
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;
686 status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, mapped_name,
687 mem_ctx, num_streams,streams);
688 TALLOC_FREE(mapped_name);
690 return status;
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)
699 char *mapped_name = NULL;
700 NTSTATUS status;
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;
708 status = SMB_VFS_NEXT_GET_NT_ACL(handle, mapped_name,
709 security_info, ppdesc);
710 TALLOC_FREE(mapped_name);
712 return status;
715 static int
716 catia_chmod_acl(vfs_handle_struct *handle,
717 const char *path,
718 mode_t mode)
720 char *mapped_name = NULL;
721 NTSTATUS status;
722 int ret;
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;
731 ret = SMB_VFS_NEXT_CHMOD_ACL(handle, mapped_name, mode);
732 TALLOC_FREE(mapped_name);
733 return ret;
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)
741 char *mapped_name = NULL;
742 NTSTATUS status;
743 SMB_ACL_T ret;
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;
752 ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, mapped_name, type);
753 TALLOC_FREE(mapped_name);
755 return ret;
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)
764 char *mapped_name = NULL;
765 NTSTATUS status;
766 int ret;
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;
775 ret = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, mapped_name, type, theacl);
776 TALLOC_FREE(mapped_name);
778 return ret;
781 static int
782 catia_sys_acl_delete_def_file(vfs_handle_struct *handle,
783 const char *path)
785 char *mapped_name = NULL;
786 NTSTATUS status;
787 int ret;
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;
796 ret = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, mapped_name);
797 TALLOC_FREE(mapped_name);
799 return ret;
802 static ssize_t
803 catia_getxattr(vfs_handle_struct *handle, const char *path,
804 const char *name, void *value, size_t size)
806 char *mapped_name = NULL;
807 NTSTATUS status;
808 ssize_t ret;
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;
818 ret = SMB_VFS_NEXT_GETXATTR(handle, path, mapped_name, value, size);
819 TALLOC_FREE(mapped_name);
821 return ret;
824 static ssize_t
825 catia_lgetxattr(vfs_handle_struct *handle, const char *path,
826 const char *name, void *value, size_t size)
828 char *mapped_name = NULL;
829 NTSTATUS status;
830 ssize_t ret;
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;
840 ret = SMB_VFS_NEXT_LGETXATTR(handle, path, mapped_name, value, size);
841 TALLOC_FREE(mapped_name);
843 return ret;
846 static ssize_t
847 catia_listxattr(vfs_handle_struct *handle, const char *path,
848 char *list, size_t size)
850 char *mapped_name = NULL;
851 NTSTATUS status;
852 ssize_t ret;
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;
862 ret = SMB_VFS_NEXT_LISTXATTR(handle, mapped_name, list, size);
863 TALLOC_FREE(mapped_name);
865 return ret;
868 static ssize_t
869 catia_llistxattr(vfs_handle_struct *handle, const char *path,
870 char *list, size_t size)
872 char *mapped_name = NULL;
873 NTSTATUS status;
874 ssize_t ret;
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;
884 ret = SMB_VFS_NEXT_LLISTXATTR(handle, mapped_name, list, size);
885 TALLOC_FREE(mapped_name);
887 return ret;
890 static int
891 catia_removexattr(vfs_handle_struct *handle, const char *path,
892 const char *name)
894 char *mapped_name = NULL;
895 NTSTATUS status;
896 ssize_t ret;
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;
906 ret = SMB_VFS_NEXT_REMOVEXATTR(handle, path, mapped_name);
907 TALLOC_FREE(mapped_name);
909 return ret;
912 static int
913 catia_lremovexattr(vfs_handle_struct *handle, const char *path,
914 const char *name)
916 char *mapped_name = NULL;
917 NTSTATUS status;
918 ssize_t ret;
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;
928 ret = SMB_VFS_NEXT_LREMOVEXATTR(handle, path, mapped_name);
929 TALLOC_FREE(mapped_name);
931 return ret;
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)
939 char *mapped_name = NULL;
940 NTSTATUS status;
941 ssize_t ret;
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;
951 ret = SMB_VFS_NEXT_SETXATTR(handle, path, mapped_name, value, size, flags);
952 TALLOC_FREE(mapped_name);
954 return ret;
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)
962 char *mapped_name = NULL;
963 NTSTATUS status;
964 ssize_t ret;
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;
974 ret = SMB_VFS_NEXT_LSETXATTR(handle, path, mapped_name, value, size, flags);
975 TALLOC_FREE(mapped_name);
977 return ret;
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,
1012 NTSTATUS vfs_catia_init(void)
1014 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia",
1015 &vfs_catia_fns);