The branch, master has been updated via 36b48aa7837 s3:net: add 'net vfs getntacl' command via bb37a88e636 s4/torture: add a vfs_fruit unconversion test via 17496a39b1c s3:net: add 'vfs' hierarchy with 'stream2adouble' command via a331b15e2b4 adouble: add ad_unconvert() via 145c54e4de7 s3: move fruit catia string replace mappings to s3/lib/ via cd3b4187266 s3:{modules => lib}/string_replace.[c|h] via 1acdca75193 vfs_fruit: remove duplicate catia mappings via 2bd926accd7 s3:modules: pass a TALLOC_CTX to string_replace_init_map() via f820647fa1b adouble: ensure stat info is marked invalid on new path via a2a30e63d50 adouble: remove xattrs after successfull conversion via 0f5fde7bed4 adouble: add some ASCII art via 1c464232f88 adouble: use runtime size when writing out AppleDouble header via 5e52d9ebf06 adouble: pass VFS handle and fsp to ad_pack() via 79e0110e461 adouble: remove redundant calls to ad_pack() via 3093c374f2f s3:lib: move Mac streams util functions to s3/lib via dbc840e740a vfs_fruit: move AppleDouble functionality to a dedicated subsystem via f9df2b67ced vfs_fruit: pass catia mappings as argument to ad_convert() via 1bf4175a23d vfs_fruit: add flags to ad_convert() via c7bb524438a vfs_fruit: convert adouble accessor macros to functions from 9f6b87d3f6c ldap_server: Regression in 0559430ab6e5c48d6e853fda0d8b63f2e149015c
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 36b48aa783743c86da21f8a896eac0f774fed27a Author: Ralph Boehme <s...@samba.org> Date: Thu Jul 11 16:23:53 2019 +0200 s3:net: add 'net vfs getntacl' command Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> Autobuild-User(master): Jeremy Allison <j...@samba.org> Autobuild-Date(master): Fri Jul 12 22:59:58 UTC 2019 on sn-devel-184 commit bb37a88e63660f885121703419f183f9c3e85827 Author: Ralph Boehme <s...@samba.org> Date: Fri Jul 5 17:35:50 2019 +0200 s4/torture: add a vfs_fruit unconversion test Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 17496a39b1c6f6c703219d559254e894a40d0117 Author: Ralph Boehme <s...@samba.org> Date: Wed Jul 10 16:03:17 2019 +0200 s3:net: add 'vfs' hierarchy with 'stream2adouble' command This adds a new top-level command hierarchy 'vfs' that can be used to add commands that access the smbd VFS stack. The first command to be implemented is 'stream2adouble' which can be used to convert stream metadata to AppleDouble files. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit a331b15e2b4eeda7b206f70ddad04bcac4243e4f Author: Ralph Boehme <s...@samba.org> Date: Thu Jul 4 11:43:34 2019 +0200 adouble: add ad_unconvert() This collects a file's stream data and packs it into a AppleDouble file. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 145c54e4de7435810eb82c9299aaccaedd9898f0 Author: Ralph Boehme <s...@samba.org> Date: Tue Jul 9 19:26:01 2019 +0200 s3: move fruit catia string replace mappings to s3/lib/ This will be needed by another component soonish. Signed-off-by: Ralph Boehme <s...@samba.org> commit cd3b4187266a49ceaf5ce176abfdd17c741d4caf Author: Ralph Boehme <s...@samba.org> Date: Tue Jul 9 19:10:14 2019 +0200 s3:{modules => lib}/string_replace.[c|h] This is now also consumed by something outside source3/modules/. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 1acdca751937186b9b114961bd045b9a022e39b5 Author: Ralph Boehme <s...@samba.org> Date: Tue Jul 9 19:07:30 2019 +0200 vfs_fruit: remove duplicate catia mappings 0x0d:0xf00d is already given a few lines above. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 2bd926accd7a4649fb83eb2a262f962277566b45 Author: Ralph Boehme <s...@samba.org> Date: Tue Jul 9 18:05:09 2019 +0200 s3:modules: pass a TALLOC_CTX to string_replace_init_map() Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit f820647fa1be39c700b6989418e379114ec7ea3b Author: Ralph Boehme <s...@samba.org> Date: Sun Jul 7 13:50:49 2019 +0200 adouble: ensure stat info is marked invalid on new path Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit a2a30e63d509ac3bca0ae56c9babb63942450699 Author: Ralph Boehme <s...@samba.org> Date: Fri Jul 5 11:42:11 2019 +0200 adouble: remove xattrs after successfull conversion This ensure the subsequent ad_fset() does not attempt to put back the xattrs on disk in the AppleDouble file. It's not yet a problem as we don't have the code that would do that, but that will be added in the next commit... Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 0f5fde7bed4dbf01736ee583fe790db99c7d4561 Author: Ralph Boehme <s...@samba.org> Date: Thu Jul 4 11:43:01 2019 +0200 adouble: add some ASCII art Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 1c464232f8848e6d3a28f49f7721f4ac076c5645 Author: Ralph Boehme <s...@samba.org> Date: Thu Jul 4 11:37:10 2019 +0200 adouble: use runtime size when writing out AppleDouble header We're calling SMB_VFS_NEXT_PWRITE() to write out the AppleDouble header data. Until now this header always had a fixed sizeof AD_DATASZ_DOT_UND bytes, but a subsequent commit will change that. Use the correct size which is the offset of the begining of the resource fork data. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 5e52d9ebf0638ce40130dc72c8225c5b7e25ee22 Author: Ralph Boehme <s...@samba.org> Date: Thu Jul 4 11:35:19 2019 +0200 adouble: pass VFS handle and fsp to ad_pack() Unused for now, that comes next. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 79e0110e461e56750ab4683900737f1712798575 Author: Ralph Boehme <s...@samba.org> Date: Thu Jul 4 10:46:46 2019 +0200 adouble: remove redundant calls to ad_pack() ad_fset() calls ad_pack() anyway... Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 3093c374f2fe16efd765b485bf86599feff1f6a7 Author: Ralph Boehme <s...@samba.org> Date: Mon Jul 1 15:53:36 2019 +0200 s3:lib: move Mac streams util functions to s3/lib While at it, change the functions to work on the stream name directly instead of struct smb_filename. A later commit wants to use the function on the resulting stream names coming from vfs_streaminfo(). Also use the simple string compare version, not the multibyte ones, as the afp* stream names are simple ASCII string, so there's no need to become fancy. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit dbc840e740a447b3e7771bbe0c607a4623518e98 Author: Ralph Boehme <s...@samba.org> Date: Tue Jul 9 13:10:00 2019 +0200 vfs_fruit: move AppleDouble functionality to a dedicated subsystem It's still tied to the VFS, therefor it lives in source3/modules/. Reduces code bloat in vfs_fruit and makes it possible to use it from other parts of the codebase in future. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit f9df2b67ced95bfad4bdac925dc200ca7daf111e Author: Ralph Boehme <s...@samba.org> Date: Mon May 27 17:55:07 2019 +0200 vfs_fruit: pass catia mappings as argument to ad_convert() This removes the direct use of fruit_catia_maps from ad_convert(), to make it possible to move the whole AppleDouble functionality to a dedicated subsystem. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 1bf4175a23db4e8a91b64bff73f43e325ee6a517 Author: Ralph Boehme <s...@samba.org> Date: Mon May 27 16:57:51 2019 +0200 vfs_fruit: add flags to ad_convert() A subsequent commmit will move all AppleDouble related functionality, including ad_convert(), to a different compilation unit. We must therefor remove the dependency on struct fruit_config_data. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit c7bb524438afd08ed25e121ef2a8afd70777f2d4 Author: Ralph Boehme <s...@samba.org> Date: Fri May 24 17:50:52 2019 +0200 vfs_fruit: convert adouble accessor macros to functions The functions will be moved to a different compilation unit in a subsequent commit and struct adouble will become a private struct so callers can't access it directly. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> ----------------------------------------------------------------------- Summary of changes: docs-xml/manpages/net.8.xml | 86 + source3/lib/adouble.c | 2675 ++++++++++++++++++++ source3/lib/adouble.h | 187 ++ source3/{modules => lib}/string_replace.c | 17 +- source3/{modules => lib}/string_replace.h | 5 +- source3/lib/util_macstreams.c | 73 + .../unix_match.h => source3/lib/util_macstreams.h | 12 +- source3/modules/vfs_catia.c | 2 +- source3/modules/vfs_fruit.c | 2234 +--------------- source3/modules/wscript_build | 5 +- source3/selftest/tests.py | 10 + source3/utils/net.c | 27 + source3/utils/net.h | 3 + source3/utils/net_proto.h | 2 + source3/utils/net_vfs.c | 450 ++++ source3/utils/wscript_build | 3 + source3/wscript_build | 8 + source4/torture/vfs/fruit.c | 251 ++ source4/torture/vfs/vfs.c | 1 + 19 files changed, 3913 insertions(+), 2138 deletions(-) create mode 100644 source3/lib/adouble.c create mode 100644 source3/lib/adouble.h rename source3/{modules => lib}/string_replace.c (85%) rename source3/{modules => lib}/string_replace.h (87%) create mode 100644 source3/lib/util_macstreams.c copy lib/util/unix_match.h => source3/lib/util_macstreams.h (73%) create mode 100644 source3/utils/net_vfs.c Changeset truncated at 500 lines: diff --git a/docs-xml/manpages/net.8.xml b/docs-xml/manpages/net.8.xml index df423a3df06..94ea5fd9727 100644 --- a/docs-xml/manpages/net.8.xml +++ b/docs-xml/manpages/net.8.xml @@ -392,6 +392,26 @@ </para></listitem> </varlistentry> + <!-- Options for net vfs stream2abouble --> + + <varlistentry> + <term>--recursive</term> + <listitem><para>Traverse a directory + hierarchy.</para></listitem> + </varlistentry> + + <varlistentry> + <term>--continue</term> + <listitem><para>Continue traversing a directory hierarchy in + case conversion of one file fails.</para></listitem> + </varlistentry> + + <varlistentry> + <term>--follow-symlinks</term> + <listitem><para>Follow symlinks encountered while traversing a + directory.</para></listitem> + </varlistentry> + &stdarg.encrypt; &popt.common.samba.client; @@ -2889,6 +2909,72 @@ Dump the locking table of a certain global lock. </refsect3> </refsect2> +<refsect2> + <title>vfs</title> + <para>Access shared filesystem through the VFS.</para> + + <refsect3> + <title>vfs stream2abouble [--recursive] [--verbose] [--continue] [--follow-symlinks] <replaceable>share</replaceable> <replaceable>path</replaceable></title> + + <para>Convert file streams to AppleDouble files.</para> + <itemizedlist> + <listitem> + <para><replaceable>share</replaceable> + A Samba share.</para> + </listitem> + </itemizedlist> + <itemizedlist> + <listitem> + <para><replaceable>path</replaceable> A relative path of something in + the Samba share. "." can be used for the root directory of the + share.</para> + </listitem> + </itemizedlist> + + <para>Options:</para> + <variablelist> + <varlistentry> + <term>--recursive</term> + <listitem><para>Traverse a directory hierarchy.</para></listitem> + </varlistentry> + <varlistentry> + <term>--verbose</term> + <listitem><para>Verbose output.</para></listitem> + </varlistentry> + <varlistentry> + <term>--continue</term> + <listitem><para>Continue traversing a directory hierarchy if a single + conversion fails.</para></listitem> + </varlistentry> + <varlistentry> + <term>--follow-symlinks</term> + <listitem><para>Follow symlinks encountered while traversing a + directory.</para></listitem> + </varlistentry> + </variablelist> + </refsect3> + + <refsect3> + <title>vfs getntacl <replaceable>share</replaceable> <replaceable>path</replaceable></title> + + <para>Display the security descriptor of a file or directory.</para> + <itemizedlist> + <listitem> + <para><replaceable>share</replaceable> + A Samba share.</para> + </listitem> + </itemizedlist> + <itemizedlist> + <listitem> + <para><replaceable>path</replaceable> A relative path of something in + the Samba share. "." can be used for the root directory of the + share.</para> + </listitem> + </itemizedlist> + </refsect3> + +</refsect2> + <refsect2> <title>HELP [COMMAND]</title> diff --git a/source3/lib/adouble.c b/source3/lib/adouble.c new file mode 100644 index 00000000000..4e2d9e01b48 --- /dev/null +++ b/source3/lib/adouble.c @@ -0,0 +1,2675 @@ +/* + * Samba AppleDouble helpers + * + * Copyright (C) Ralph Boehme, 2019 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "includes.h" +#include "adouble.h" +#include "MacExtensions.h" +#include "string_replace.h" +#include "smbd/smbd.h" +#include "system/filesys.h" +#include "libcli/security/security.h" +#include "lib/util_macstreams.h" +#include "auth.h" + +/* + "._" AppleDouble Header File Layout: + + MAGIC 0x00051607 + VERSION 0x00020000 + FILLER 0 + COUNT 2 + .-- AD ENTRY[0] Finder Info Entry (must be first) + .--+-- AD ENTRY[1] Resource Fork Entry (must be last) + | | ///////////// + | '-> FINDER INFO Fixed Size Data (32 Bytes) + | ~~~~~~~~~~~~~ 2 Bytes Padding + | EXT ATTR HDR Fixed Size Data (36 Bytes) + | ///////////// + | ATTR ENTRY[0] --. + | ATTR ENTRY[1] --+--. + | ATTR ENTRY[2] --+--+--. + | ... | | | + | ATTR ENTRY[N] --+--+--+--. + | ATTR DATA 0 <-' | | | + | //////////// | | | + | ATTR DATA 1 <----' | | + | ///////////// | | + | ATTR DATA 2 <-------' | + | ///////////// | + | ... | + | ATTR DATA N <----------' + | ///////////// + | ... Attribute Free Space + | + '----> RESOURCE FORK + ... Variable Sized Data + ... +*/ + +/* Number of actually used entries */ +#define ADEID_NUM_XATTR 8 +#define ADEID_NUM_DOT_UND 2 +#define ADEID_NUM_RSRC_XATTR 1 + +/* Sizes of relevant entry bits */ +#define ADEDLEN_MAGIC 4 +#define ADEDLEN_VERSION 4 +#define ADEDLEN_FILLER 16 +#define AD_FILLER_TAG "Netatalk " /* should be 16 bytes */ +#define AD_FILLER_TAG_OSX "Mac OS X " /* should be 16 bytes */ +#define ADEDLEN_NENTRIES 2 +#define AD_HEADER_LEN (ADEDLEN_MAGIC + ADEDLEN_VERSION + \ + ADEDLEN_FILLER + ADEDLEN_NENTRIES) /* 26 */ +#define AD_ENTRY_LEN_EID 4 +#define AD_ENTRY_LEN_OFF 4 +#define AD_ENTRY_LEN_LEN 4 +#define AD_ENTRY_LEN (AD_ENTRY_LEN_EID + AD_ENTRY_LEN_OFF + AD_ENTRY_LEN_LEN) + +/* Offsets */ +#define ADEDOFF_MAGIC 0 +#define ADEDOFF_VERSION (ADEDOFF_MAGIC + ADEDLEN_MAGIC) +#define ADEDOFF_FILLER (ADEDOFF_VERSION + ADEDLEN_VERSION) +#define ADEDOFF_NENTRIES (ADEDOFF_FILLER + ADEDLEN_FILLER) + +#define ADEDOFF_FINDERI_XATTR (AD_HEADER_LEN + \ + (ADEID_NUM_XATTR * AD_ENTRY_LEN)) +#define ADEDOFF_COMMENT_XATTR (ADEDOFF_FINDERI_XATTR + ADEDLEN_FINDERI) +#define ADEDOFF_FILEDATESI_XATTR (ADEDOFF_COMMENT_XATTR + ADEDLEN_COMMENT) +#define ADEDOFF_AFPFILEI_XATTR (ADEDOFF_FILEDATESI_XATTR + \ + ADEDLEN_FILEDATESI) +#define ADEDOFF_PRIVDEV_XATTR (ADEDOFF_AFPFILEI_XATTR + ADEDLEN_AFPFILEI) +#define ADEDOFF_PRIVINO_XATTR (ADEDOFF_PRIVDEV_XATTR + ADEDLEN_PRIVDEV) +#define ADEDOFF_PRIVSYN_XATTR (ADEDOFF_PRIVINO_XATTR + ADEDLEN_PRIVINO) +#define ADEDOFF_PRIVID_XATTR (ADEDOFF_PRIVSYN_XATTR + ADEDLEN_PRIVSYN) + +#define ADEDOFF_FINDERI_DOT_UND (AD_HEADER_LEN + \ + (ADEID_NUM_DOT_UND * AD_ENTRY_LEN)) +#define ADEDOFF_RFORK_DOT_UND (ADEDOFF_FINDERI_DOT_UND + ADEDLEN_FINDERI) + +#define AD_DATASZ_XATTR (AD_HEADER_LEN + \ + (ADEID_NUM_XATTR * AD_ENTRY_LEN) + \ + ADEDLEN_FINDERI + ADEDLEN_COMMENT + \ + ADEDLEN_FILEDATESI + ADEDLEN_AFPFILEI + \ + ADEDLEN_PRIVDEV + ADEDLEN_PRIVINO + \ + ADEDLEN_PRIVSYN + ADEDLEN_PRIVID) + +#if AD_DATASZ_XATTR != 402 +#error bad size for AD_DATASZ_XATTR +#endif + +#define AD_DATASZ_DOT_UND (AD_HEADER_LEN + \ + (ADEID_NUM_DOT_UND * AD_ENTRY_LEN) + \ + ADEDLEN_FINDERI) +#if AD_DATASZ_DOT_UND != 82 +#error bad size for AD_DATASZ_DOT_UND +#endif + +#define AD_XATTR_HDR_MAGIC 0x41545452 /* 'ATTR' */ +#define AD_XATTR_MAX_ENTRIES 1024 /* Some arbitrarily enforced limit */ +#define AD_XATTR_HDR_SIZE 36 +#define AD_XATTR_MAX_HDR_SIZE 65536 +#define ADX_ENTRY_FIXED_SIZE (4+4+2+1) + +/* + * Both struct ad_xattr_header and struct ad_xattr_entry describe the in memory + * representation as well as the on-disk format. + * + * The ad_xattr_header follows the FinderInfo data in the FinderInfo entry if + * the length of the FinderInfo entry is larger then 32 bytes. It is then + * preceeded with 2 bytes padding. + * + * Cf: https://opensource.apple.com/source/xnu/xnu-4570.1.46/bsd/vfs/vfs_xattr.c + */ + +struct ad_xattr_header { + uint32_t adx_magic; /* ATTR_HDR_MAGIC */ + uint32_t adx_debug_tag; /* for debugging == file id of owning file */ + uint32_t adx_total_size; /* file offset of end of attribute header + entries + data */ + uint32_t adx_data_start; /* file offset to attribute data area */ + uint32_t adx_data_length; /* length of attribute data area */ + uint32_t adx_reserved[3]; + uint16_t adx_flags; + uint16_t adx_num_attrs; +}; + +/* On-disk entries are aligned on 4 byte boundaries */ +struct ad_xattr_entry { + uint32_t adx_offset; /* file offset to data */ + uint32_t adx_length; /* size of attribute data */ + uint16_t adx_flags; + uint8_t adx_namelen; /* included the NULL terminator */ + char *adx_name; /* NULL-terminated UTF-8 name */ +}; + +struct ad_entry { + size_t ade_off; + size_t ade_len; +}; + +struct adouble { + files_struct *ad_fsp; + bool ad_opened; + adouble_type_t ad_type; + uint32_t ad_magic; + uint32_t ad_version; + uint8_t ad_filler[ADEDLEN_FILLER]; + struct ad_entry ad_eid[ADEID_MAX]; + char *ad_data; + char *ad_rsrc_data; + struct ad_xattr_header adx_header; + struct ad_xattr_entry *adx_entries; + char *adx_data; +}; + +struct ad_entry_order { + uint32_t id, offset, len; +}; + +/* Netatalk AppleDouble metadata xattr */ +static const +struct ad_entry_order entry_order_meta_xattr[ADEID_NUM_XATTR + 1] = { + {ADEID_FINDERI, ADEDOFF_FINDERI_XATTR, ADEDLEN_FINDERI}, + {ADEID_COMMENT, ADEDOFF_COMMENT_XATTR, 0}, + {ADEID_FILEDATESI, ADEDOFF_FILEDATESI_XATTR, ADEDLEN_FILEDATESI}, + {ADEID_AFPFILEI, ADEDOFF_AFPFILEI_XATTR, ADEDLEN_AFPFILEI}, + {ADEID_PRIVDEV, ADEDOFF_PRIVDEV_XATTR, 0}, + {ADEID_PRIVINO, ADEDOFF_PRIVINO_XATTR, 0}, + {ADEID_PRIVSYN, ADEDOFF_PRIVSYN_XATTR, 0}, + {ADEID_PRIVID, ADEDOFF_PRIVID_XATTR, 0}, + {0, 0, 0} +}; + +/* AppleDouble resource fork file (the ones prefixed by "._") */ +static const +struct ad_entry_order entry_order_dot_und[ADEID_NUM_DOT_UND + 1] = { + {ADEID_FINDERI, ADEDOFF_FINDERI_DOT_UND, ADEDLEN_FINDERI}, + {ADEID_RFORK, ADEDOFF_RFORK_DOT_UND, 0}, + {0, 0, 0} +}; + +/* Conversion from enumerated id to on-disk AppleDouble id */ +#define AD_EID_DISK(a) (set_eid[a]) +static const uint32_t set_eid[] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + AD_DEV, AD_INO, AD_SYN, AD_ID +}; + +static char empty_resourcefork[] = { + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, + 0x54, 0x68, 0x69, 0x73, 0x20, 0x72, 0x65, 0x73, + 0x6F, 0x75, 0x72, 0x63, 0x65, 0x20, 0x66, 0x6F, + 0x72, 0x6B, 0x20, 0x69, 0x6E, 0x74, 0x65, 0x6E, + 0x74, 0x69, 0x6F, 0x6E, 0x61, 0x6C, 0x6C, 0x79, + 0x20, 0x6C, 0x65, 0x66, 0x74, 0x20, 0x62, 0x6C, + 0x61, 0x6E, 0x6B, 0x20, 0x20, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1C, 0x00, 0x1E, 0xFF, 0xFF +}; + +size_t ad_getentrylen(const struct adouble *ad, int eid) +{ + return ad->ad_eid[eid].ade_len; +} + +size_t ad_getentryoff(const struct adouble *ad, int eid) +{ + return ad->ad_eid[eid].ade_off; +} + +size_t ad_setentrylen(struct adouble *ad, int eid, size_t len) +{ + return ad->ad_eid[eid].ade_len = len; +} + +size_t ad_setentryoff(struct adouble *ad, int eid, size_t off) +{ + return ad->ad_eid[eid].ade_off = off; +} + +/** + * Return a pointer to an AppleDouble entry + * + * Returns NULL if the entry is not present + **/ +char *ad_get_entry(const struct adouble *ad, int eid) +{ + off_t off = ad_getentryoff(ad, eid); + size_t len = ad_getentrylen(ad, eid); + + if (off == 0 || len == 0) { + return NULL; + } + + return ad->ad_data + off; +} + +/** + * Get a date + **/ +int ad_getdate(const struct adouble *ad, unsigned int dateoff, uint32_t *date) +{ + bool xlate = (dateoff & AD_DATE_UNIX); + char *p = NULL; + + dateoff &= AD_DATE_MASK; + p = ad_get_entry(ad, ADEID_FILEDATESI); + if (p == NULL) { + return -1; + } + + if (dateoff > AD_DATE_ACCESS) { + return -1; + } + + memcpy(date, p + dateoff, sizeof(uint32_t)); + + if (xlate) { + *date = AD_DATE_TO_UNIX(*date); + } + return 0; +} + +/** + * Set a date + **/ +int ad_setdate(struct adouble *ad, unsigned int dateoff, uint32_t date) +{ + bool xlate = (dateoff & AD_DATE_UNIX); + char *p = NULL; + + p = ad_get_entry(ad, ADEID_FILEDATESI); + if (p == NULL) { + return -1; + } + + dateoff &= AD_DATE_MASK; + if (xlate) { + date = AD_DATE_FROM_UNIX(date); + } + + if (dateoff > AD_DATE_ACCESS) { + return -1; + } + + memcpy(p + dateoff, &date, sizeof(date)); + + return 0; +} + + +/** + * Map on-disk AppleDouble id to enumerated id + **/ +static uint32_t get_eid(uint32_t eid) +{ + if (eid <= 15) { + return eid; + } + + switch (eid) { + case AD_DEV: + return ADEID_PRIVDEV; + case AD_INO: + return ADEID_PRIVINO; + case AD_SYN: + return ADEID_PRIVSYN; + case AD_ID: + return ADEID_PRIVID; + default: + break; + } + + return 0; +} + +/* + * Move resourcefork data in an AppleDouble file + * + * This is supposed to make room in an AppleDouble file by moving the + * resourcefork data behind the space required for packing additional xattr data + * in the extended FinderInfo entry. + * + * When we're called we're expecting an AppleDouble file with just two entries + * (FinderInfo an Resourcefork) and the resourcefork is expected at a fixed + * offset of ADEDOFF_RFORK_DOT_UND. + */ +static bool ad_pack_move_reso(struct vfs_handle_struct *handle, + struct adouble *ad, + files_struct *fsp) +{ + size_t reso_len; + size_t reso_off; + size_t n; + bool ok; + + reso_len = ad_getentrylen(ad, ADEID_RFORK); + reso_off = ad_getentryoff(ad, ADEID_RFORK); + -- Samba Shared Repository