2 * CAP VFS module for Samba 3.x Version 0.3
4 * Copyright (C) Tim Potter, 1999-2000
5 * Copyright (C) Alexander Bokovoy, 2002-2003
6 * Copyright (C) Stefan (metze) Metzmacher, 2003
7 * Copyright (C) TAKAHASHI Motonobu (monyo), 2003
8 * Copyright (C) Jeremy Allison, 2007
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 #include "smbd/smbd.h"
29 static char *capencode(TALLOC_CTX
*ctx
, const char *from
);
30 static char *capdecode(TALLOC_CTX
*ctx
, const char *from
);
32 static uint64_t cap_disk_free(vfs_handle_struct
*handle
,
33 const struct smb_filename
*smb_fname
,
38 char *capname
= capencode(talloc_tos(), smb_fname
->base_name
);
39 struct smb_filename
*cap_smb_fname
= NULL
;
45 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
50 if (cap_smb_fname
== NULL
) {
55 return SMB_VFS_NEXT_DISK_FREE(handle
, cap_smb_fname
,
59 static int cap_get_quota(vfs_handle_struct
*handle
,
60 const struct smb_filename
*smb_fname
,
61 enum SMB_QUOTA_TYPE qtype
,
65 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
66 struct smb_filename
*cap_smb_fname
= NULL
;
72 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
77 if (cap_smb_fname
== NULL
) {
82 return SMB_VFS_NEXT_GET_QUOTA(handle
, cap_smb_fname
, qtype
, id
, dq
);
85 static DIR *cap_opendir(vfs_handle_struct
*handle
,
86 const struct smb_filename
*smb_fname
,
90 char *capname
= capencode(talloc_tos(), smb_fname
->base_name
);
91 struct smb_filename
*cap_smb_fname
= NULL
;
97 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
102 if (cap_smb_fname
== NULL
) {
103 TALLOC_FREE(capname
);
107 return SMB_VFS_NEXT_OPENDIR(handle
, cap_smb_fname
, mask
, attr
);
110 static struct dirent
*cap_readdir(vfs_handle_struct
*handle
,
112 SMB_STRUCT_STAT
*sbuf
)
114 struct dirent
*result
;
115 struct dirent
*newdirent
;
118 DEBUG(3,("cap: cap_readdir\n"));
120 result
= SMB_VFS_NEXT_READDIR(handle
, dirp
, NULL
);
125 newname
= capdecode(talloc_tos(), result
->d_name
);
129 DEBUG(3,("cap: cap_readdir: %s\n", newname
));
130 newnamelen
= strlen(newname
)+1;
131 newdirent
= talloc_size(
132 talloc_tos(), sizeof(struct dirent
) + newnamelen
);
136 talloc_set_name_const(newdirent
, "struct dirent");
137 memcpy(newdirent
, result
, sizeof(struct dirent
));
138 memcpy(&newdirent
->d_name
, newname
, newnamelen
);
142 static int cap_mkdir(vfs_handle_struct
*handle
,
143 const struct smb_filename
*smb_fname
,
146 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
147 struct smb_filename
*cap_smb_fname
= NULL
;
154 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
159 if (cap_smb_fname
== NULL
) {
160 TALLOC_FREE(cappath
);
165 return SMB_VFS_NEXT_MKDIR(handle
, cap_smb_fname
, mode
);
168 static int cap_rmdir(vfs_handle_struct
*handle
,
169 const struct smb_filename
*smb_fname
)
171 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
172 struct smb_filename
*cap_smb_fname
= NULL
;
179 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
184 if (cap_smb_fname
== NULL
) {
185 TALLOC_FREE(cappath
);
190 return SMB_VFS_NEXT_RMDIR(handle
, cap_smb_fname
);
193 static int cap_open(vfs_handle_struct
*handle
, struct smb_filename
*smb_fname
,
194 files_struct
*fsp
, int flags
, mode_t mode
)
197 char *tmp_base_name
= NULL
;
200 cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
207 tmp_base_name
= smb_fname
->base_name
;
208 smb_fname
->base_name
= cappath
;
210 DEBUG(3,("cap: cap_open for %s\n", smb_fname_str_dbg(smb_fname
)));
211 ret
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
213 smb_fname
->base_name
= tmp_base_name
;
214 TALLOC_FREE(cappath
);
219 static int cap_rename(vfs_handle_struct
*handle
,
220 const struct smb_filename
*smb_fname_src
,
221 const struct smb_filename
*smb_fname_dst
)
225 struct smb_filename
*smb_fname_src_tmp
= NULL
;
226 struct smb_filename
*smb_fname_dst_tmp
= NULL
;
229 capold
= capencode(talloc_tos(), smb_fname_src
->base_name
);
230 capnew
= capencode(talloc_tos(), smb_fname_dst
->base_name
);
231 if (!capold
|| !capnew
) {
236 /* Setup temporary smb_filename structs. */
237 smb_fname_src_tmp
= cp_smb_filename(talloc_tos(), smb_fname_src
);
238 if (smb_fname_src_tmp
== NULL
) {
242 smb_fname_dst_tmp
= cp_smb_filename(talloc_tos(), smb_fname_dst
);
243 if (smb_fname_dst_tmp
== NULL
) {
248 smb_fname_src_tmp
->base_name
= capold
;
249 smb_fname_dst_tmp
->base_name
= capnew
;
251 ret
= SMB_VFS_NEXT_RENAME(handle
, smb_fname_src_tmp
,
256 TALLOC_FREE(smb_fname_src_tmp
);
257 TALLOC_FREE(smb_fname_dst_tmp
);
262 static int cap_stat(vfs_handle_struct
*handle
, struct smb_filename
*smb_fname
)
265 char *tmp_base_name
= NULL
;
268 cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
275 tmp_base_name
= smb_fname
->base_name
;
276 smb_fname
->base_name
= cappath
;
278 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
280 smb_fname
->base_name
= tmp_base_name
;
281 TALLOC_FREE(cappath
);
286 static int cap_lstat(vfs_handle_struct
*handle
, struct smb_filename
*smb_fname
)
289 char *tmp_base_name
= NULL
;
292 cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
299 tmp_base_name
= smb_fname
->base_name
;
300 smb_fname
->base_name
= cappath
;
302 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
304 smb_fname
->base_name
= tmp_base_name
;
305 TALLOC_FREE(cappath
);
310 static int cap_unlink(vfs_handle_struct
*handle
,
311 const struct smb_filename
*smb_fname
)
313 struct smb_filename
*smb_fname_tmp
= NULL
;
314 char *cappath
= NULL
;
317 cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
323 /* Setup temporary smb_filename structs. */
324 smb_fname_tmp
= cp_smb_filename(talloc_tos(), smb_fname
);
325 if (smb_fname_tmp
== NULL
) {
330 smb_fname_tmp
->base_name
= cappath
;
332 ret
= SMB_VFS_NEXT_UNLINK(handle
, smb_fname_tmp
);
334 TALLOC_FREE(smb_fname_tmp
);
338 static int cap_chmod(vfs_handle_struct
*handle
,
339 const struct smb_filename
*smb_fname
,
342 struct smb_filename
*cap_smb_fname
= NULL
;
343 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
352 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
357 if (cap_smb_fname
== NULL
) {
358 TALLOC_FREE(cappath
);
363 ret
= SMB_VFS_NEXT_CHMOD(handle
, cap_smb_fname
, mode
);
365 TALLOC_FREE(cappath
);
366 TALLOC_FREE(cap_smb_fname
);
371 static int cap_chown(vfs_handle_struct
*handle
,
372 const struct smb_filename
*smb_fname
,
376 struct smb_filename
*cap_smb_fname
= NULL
;
377 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
386 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
391 if (cap_smb_fname
== NULL
) {
392 TALLOC_FREE(cappath
);
397 ret
= SMB_VFS_NEXT_CHOWN(handle
, cap_smb_fname
, uid
, gid
);
399 TALLOC_FREE(cappath
);
400 TALLOC_FREE(cap_smb_fname
);
405 static int cap_lchown(vfs_handle_struct
*handle
,
406 const struct smb_filename
*smb_fname
,
410 struct smb_filename
*cap_smb_fname
= NULL
;
411 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
420 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
425 if (cap_smb_fname
== NULL
) {
426 TALLOC_FREE(cappath
);
431 ret
= SMB_VFS_NEXT_LCHOWN(handle
, cap_smb_fname
, uid
, gid
);
433 TALLOC_FREE(cappath
);
434 TALLOC_FREE(cap_smb_fname
);
439 static int cap_chdir(vfs_handle_struct
*handle
,
440 const struct smb_filename
*smb_fname
)
442 struct smb_filename
*cap_smb_fname
= NULL
;
443 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
451 DEBUG(3,("cap: cap_chdir for %s\n", smb_fname
->base_name
));
453 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
458 if (cap_smb_fname
== NULL
) {
459 TALLOC_FREE(cappath
);
463 ret
= SMB_VFS_NEXT_CHDIR(handle
, cap_smb_fname
);
467 TALLOC_FREE(cappath
);
468 TALLOC_FREE(cap_smb_fname
);
469 if (saved_errno
!= 0) {
475 static int cap_ntimes(vfs_handle_struct
*handle
,
476 const struct smb_filename
*smb_fname
,
477 struct smb_file_time
*ft
)
479 struct smb_filename
*smb_fname_tmp
= NULL
;
480 char *cappath
= NULL
;
483 cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
490 /* Setup temporary smb_filename structs. */
491 smb_fname_tmp
= cp_smb_filename(talloc_tos(), smb_fname
);
492 if (smb_fname_tmp
== NULL
) {
497 smb_fname_tmp
->base_name
= cappath
;
499 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname_tmp
, ft
);
501 TALLOC_FREE(smb_fname_tmp
);
506 static int cap_symlink(vfs_handle_struct
*handle
,
507 const char *link_contents
,
508 const struct smb_filename
*new_smb_fname
)
510 char *capold
= capencode(talloc_tos(), link_contents
);
511 char *capnew
= capencode(talloc_tos(), new_smb_fname
->base_name
);
512 struct smb_filename
*new_cap_smb_fname
= NULL
;
516 if (!capold
|| !capnew
) {
520 new_cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
524 new_smb_fname
->flags
);
525 if (new_cap_smb_fname
== NULL
) {
531 ret
= SMB_VFS_NEXT_SYMLINK(handle
,
539 TALLOC_FREE(new_cap_smb_fname
);
540 if (saved_errno
!= 0) {
546 static int cap_readlink(vfs_handle_struct
*handle
,
547 const struct smb_filename
*smb_fname
,
551 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
552 struct smb_filename
*cap_smb_fname
= NULL
;
560 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
565 if (cap_smb_fname
== NULL
) {
566 TALLOC_FREE(cappath
);
570 ret
= SMB_VFS_NEXT_READLINK(handle
, cap_smb_fname
, buf
, bufsiz
);
574 TALLOC_FREE(cappath
);
575 TALLOC_FREE(cap_smb_fname
);
576 if (saved_errno
!= 0) {
582 static int cap_link(vfs_handle_struct
*handle
,
583 const struct smb_filename
*old_smb_fname
,
584 const struct smb_filename
*new_smb_fname
)
586 char *capold
= capencode(talloc_tos(), old_smb_fname
->base_name
);
587 char *capnew
= capencode(talloc_tos(), new_smb_fname
->base_name
);
588 struct smb_filename
*old_cap_smb_fname
= NULL
;
589 struct smb_filename
*new_cap_smb_fname
= NULL
;
593 if (!capold
|| !capnew
) {
597 old_cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
601 old_smb_fname
->flags
);
602 if (old_cap_smb_fname
== NULL
) {
608 new_cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
612 new_smb_fname
->flags
);
613 if (new_cap_smb_fname
== NULL
) {
616 TALLOC_FREE(old_cap_smb_fname
);
620 ret
= SMB_VFS_NEXT_LINK(handle
, old_cap_smb_fname
, new_cap_smb_fname
);
626 TALLOC_FREE(old_cap_smb_fname
);
627 TALLOC_FREE(new_cap_smb_fname
);
628 if (saved_errno
!= 0) {
634 static int cap_mknod(vfs_handle_struct
*handle
,
635 const struct smb_filename
*smb_fname
,
639 struct smb_filename
*cap_smb_fname
= NULL
;
640 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
648 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
653 if (cap_smb_fname
== NULL
) {
654 TALLOC_FREE(cappath
);
658 ret
= SMB_VFS_NEXT_MKNOD(handle
, cap_smb_fname
, mode
, dev
);
662 TALLOC_FREE(cappath
);
663 TALLOC_FREE(cap_smb_fname
);
664 if (saved_errno
!= 0) {
670 static struct smb_filename
*cap_realpath(vfs_handle_struct
*handle
,
672 const struct smb_filename
*smb_fname
)
674 /* monyo need capencode'ed and capdecode'ed? */
675 struct smb_filename
*cap_smb_fname
= NULL
;
676 struct smb_filename
*return_fname
= NULL
;
677 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
684 cap_smb_fname
= synthetic_smb_fname(ctx
,
689 if (cap_smb_fname
== NULL
) {
690 TALLOC_FREE(cappath
);
694 return_fname
= SMB_VFS_NEXT_REALPATH(handle
, ctx
, cap_smb_fname
);
695 if (return_fname
== NULL
) {
698 TALLOC_FREE(cappath
);
699 TALLOC_FREE(cap_smb_fname
);
700 if (saved_errno
!= 0) {
706 static SMB_ACL_T
cap_sys_acl_get_file(vfs_handle_struct
*handle
,
707 const struct smb_filename
*smb_fname
,
711 struct smb_filename
*cap_smb_fname
= NULL
;
712 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
718 return (SMB_ACL_T
)NULL
;
720 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
725 if (cap_smb_fname
== NULL
) {
726 TALLOC_FREE(cappath
);
728 return (SMB_ACL_T
)NULL
;
730 ret
= SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, cap_smb_fname
,
735 TALLOC_FREE(cappath
);
736 TALLOC_FREE(cap_smb_fname
);
737 if (saved_errno
!= 0) {
743 static int cap_sys_acl_set_file(vfs_handle_struct
*handle
,
744 const struct smb_filename
*smb_fname
,
745 SMB_ACL_TYPE_T acltype
,
748 struct smb_filename
*cap_smb_fname
= NULL
;
749 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
757 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
762 if (cap_smb_fname
== NULL
) {
763 TALLOC_FREE(cappath
);
767 ret
= SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, cap_smb_fname
,
772 TALLOC_FREE(cappath
);
773 TALLOC_FREE(cap_smb_fname
);
774 if (saved_errno
!= 0) {
780 static int cap_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
781 const struct smb_filename
*smb_fname
)
783 struct smb_filename
*cap_smb_fname
= NULL
;
784 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
792 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
797 if (cap_smb_fname
== NULL
) {
798 TALLOC_FREE(cappath
);
802 ret
= SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, cap_smb_fname
);
806 TALLOC_FREE(cappath
);
807 TALLOC_FREE(cap_smb_fname
);
814 static ssize_t
cap_getxattr(vfs_handle_struct
*handle
,
815 const struct smb_filename
*smb_fname
,
820 struct smb_filename
*cap_smb_fname
= NULL
;
821 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
822 char *capname
= capencode(talloc_tos(), name
);
826 if (!cappath
|| !capname
) {
830 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
835 if (cap_smb_fname
== NULL
) {
836 TALLOC_FREE(cappath
);
837 TALLOC_FREE(capname
);
841 ret
= SMB_VFS_NEXT_GETXATTR(handle
, cap_smb_fname
,
842 capname
, value
, size
);
846 TALLOC_FREE(cappath
);
847 TALLOC_FREE(capname
);
848 TALLOC_FREE(cap_smb_fname
);
855 static ssize_t
cap_fgetxattr(vfs_handle_struct
*handle
, struct files_struct
*fsp
, const char *path
, void *value
, size_t size
)
857 char *cappath
= capencode(talloc_tos(), path
);
863 return SMB_VFS_NEXT_FGETXATTR(handle
, fsp
, cappath
, value
, size
);
866 static ssize_t
cap_listxattr(vfs_handle_struct
*handle
,
867 const struct smb_filename
*smb_fname
,
871 struct smb_filename
*cap_smb_fname
= NULL
;
872 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
880 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
885 if (cap_smb_fname
== NULL
) {
886 TALLOC_FREE(cappath
);
890 ret
= SMB_VFS_NEXT_LISTXATTR(handle
, cap_smb_fname
, list
, size
);
894 TALLOC_FREE(cappath
);
895 TALLOC_FREE(cap_smb_fname
);
902 static int cap_removexattr(vfs_handle_struct
*handle
,
903 const struct smb_filename
*smb_fname
,
906 struct smb_filename
*cap_smb_fname
= NULL
;
907 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
908 char *capname
= capencode(talloc_tos(), name
);
912 if (!cappath
|| !capname
) {
916 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
921 if (cap_smb_fname
== NULL
) {
922 TALLOC_FREE(cappath
);
923 TALLOC_FREE(capname
);
927 ret
= SMB_VFS_NEXT_REMOVEXATTR(handle
, cap_smb_fname
, capname
);
931 TALLOC_FREE(cappath
);
932 TALLOC_FREE(capname
);
933 TALLOC_FREE(cap_smb_fname
);
940 static int cap_fremovexattr(vfs_handle_struct
*handle
, struct files_struct
*fsp
, const char *path
)
942 char *cappath
= capencode(talloc_tos(), path
);
948 return SMB_VFS_NEXT_FREMOVEXATTR(handle
, fsp
, cappath
);
951 static int cap_setxattr(vfs_handle_struct
*handle
,
952 const struct smb_filename
*smb_fname
,
958 struct smb_filename
*cap_smb_fname
= NULL
;
959 char *cappath
= capencode(talloc_tos(), smb_fname
->base_name
);
960 char *capname
= capencode(talloc_tos(), name
);
964 if (!cappath
|| !capname
) {
968 cap_smb_fname
= synthetic_smb_fname(talloc_tos(),
973 if (cap_smb_fname
== NULL
) {
974 TALLOC_FREE(cappath
);
975 TALLOC_FREE(capname
);
979 ret
= SMB_VFS_NEXT_SETXATTR(handle
, cap_smb_fname
,
980 capname
, value
, size
, flags
);
984 TALLOC_FREE(cappath
);
985 TALLOC_FREE(capname
);
986 TALLOC_FREE(cap_smb_fname
);
993 static int cap_fsetxattr(vfs_handle_struct
*handle
, struct files_struct
*fsp
, const char *path
, const void *value
, size_t size
, int flags
)
995 char *cappath
= capencode(talloc_tos(), path
);
1001 return SMB_VFS_NEXT_FSETXATTR(handle
, fsp
, cappath
, value
, size
, flags
);
1004 static struct vfs_fn_pointers vfs_cap_fns
= {
1005 .disk_free_fn
= cap_disk_free
,
1006 .get_quota_fn
= cap_get_quota
,
1007 .opendir_fn
= cap_opendir
,
1008 .readdir_fn
= cap_readdir
,
1009 .mkdir_fn
= cap_mkdir
,
1010 .rmdir_fn
= cap_rmdir
,
1011 .open_fn
= cap_open
,
1012 .rename_fn
= cap_rename
,
1013 .stat_fn
= cap_stat
,
1014 .lstat_fn
= cap_lstat
,
1015 .unlink_fn
= cap_unlink
,
1016 .chmod_fn
= cap_chmod
,
1017 .chown_fn
= cap_chown
,
1018 .lchown_fn
= cap_lchown
,
1019 .chdir_fn
= cap_chdir
,
1020 .ntimes_fn
= cap_ntimes
,
1021 .symlink_fn
= cap_symlink
,
1022 .readlink_fn
= cap_readlink
,
1023 .link_fn
= cap_link
,
1024 .mknod_fn
= cap_mknod
,
1025 .realpath_fn
= cap_realpath
,
1026 .sys_acl_get_file_fn
= cap_sys_acl_get_file
,
1027 .sys_acl_set_file_fn
= cap_sys_acl_set_file
,
1028 .sys_acl_delete_def_file_fn
= cap_sys_acl_delete_def_file
,
1029 .getxattr_fn
= cap_getxattr
,
1030 .fgetxattr_fn
= cap_fgetxattr
,
1031 .listxattr_fn
= cap_listxattr
,
1032 .removexattr_fn
= cap_removexattr
,
1033 .fremovexattr_fn
= cap_fremovexattr
,
1034 .setxattr_fn
= cap_setxattr
,
1035 .fsetxattr_fn
= cap_fsetxattr
1039 NTSTATUS
vfs_cap_init(TALLOC_CTX
*ctx
)
1041 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "cap",
1045 /* For CAP functions */
1047 #define hex2bin(c) hex2bin_table[(unsigned char)(c)]
1048 #define bin2hex(c) bin2hex_table[(unsigned char)(c)]
1049 #define is_hex(s) ((s)[0] == hex_tag)
1051 static unsigned char hex2bin_table
[256] = {
1052 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 */
1053 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 */
1054 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 */
1055 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, /* 0x30 */
1056 0000, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0000, /* 0x40 */
1057 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
1058 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 */
1059 0000, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0000, /* 0x60 */
1060 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
1061 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 */
1062 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 */
1063 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 */
1064 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0 */
1065 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0 */
1066 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xc0 */
1067 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xd0 */
1068 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xe0 */
1069 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xf0 */
1071 static unsigned char bin2hex_table
[256] = "0123456789abcdef";
1073 /*******************************************************************
1074 original code -> ":xx" - CAP format
1075 ********************************************************************/
1077 static char *capencode(TALLOC_CTX
*ctx
, const char *from
)
1084 for (p1
= from
; *p1
; p1
++) {
1085 if ((unsigned char)*p1
>= 0x80) {
1093 to
= talloc_array(ctx
, char, len
);
1098 for (out
= to
; *from
;) {
1099 /* buffer husoku error */
1100 if ((unsigned char)*from
>= 0x80) {
1102 *out
++ = bin2hex (((*from
)>>4)&0x0f);
1103 *out
++ = bin2hex ((*from
)&0x0f);
1113 /*******************************************************************
1114 CAP -> original code
1115 ********************************************************************/
1116 /* ":xx" -> a byte */
1118 static char *capdecode(TALLOC_CTX
*ctx
, const char *from
)
1125 for (p1
= from
; *p1
; len
++) {
1134 to
= talloc_array(ctx
, char, len
);
1139 for (out
= to
; *from
;) {
1141 *out
++ = (hex2bin(from
[1])<<4) | (hex2bin(from
[2]));