1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2004-2009 Free Software Foundation Europe e.V.
5    Copyright (C) 2011-2012 Planets Communications B.V.
6    Copyright (C) 2013-2016 Bareos GmbH & Co. KG
7 
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12 
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    Affero General Public License for more details.
17 
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22 */
23 
24 #ifndef BAREOS_FINDLIB_XATTR_H_
25 #define BAREOS_FINDLIB_XATTR_H_
26 
27 /*
28  * Return codes from xattr subroutines.
29  */
30 enum class BxattrExitCode {
31    kErrorFatal,
32    kError,
33    kWarning,
34    kSuccess
35 };
36 
37 #if defined(HAVE_LINUX_OS)
38 #define BXATTR_ENOTSUP EOPNOTSUPP
39 #elif defined(HAVE_DARWIN_OS)
40 #define BXATTR_ENOTSUP ENOTSUP
41 #elif defined(HAVE_HURD_OS)
42 #define BXATTR_ENOTSUP ENOTSUP
43 #endif
44 
45 /*
46  * Magic used in the magic field of the xattr struct.
47  * This way we can see we encounter a valid xattr struct.
48  */
49 #define XATTR_MAGIC 0x5C5884
50 
51 /*
52  * Internal representation of an extended attribute.
53  */
54 struct xattr_t {
55    uint32_t magic;
56    uint32_t name_length;
57    char *name;
58    uint32_t value_length;
59    char *value;
60 };
61 
62 /*
63  * Internal representation of an extended attribute hardlinked file.
64  */
65 struct xattr_link_cache_entry_t {
66    uint32_t inum;
67    char *target;
68 };
69 
70 #define BXATTR_FLAG_SAVE_NATIVE    0x01
71 #define BXATTR_FLAG_RESTORE_NATIVE 0x02
72 
73 struct xattr_build_data_t {
74    uint32_t nr_errors;
75    uint32_t nr_saved;
76    POOLMEM *content;
77    uint32_t content_length;
78    alist *link_cache;
79 };
80 
81 struct xattr_parse_data_t {
82    uint32_t nr_errors;
83 };
84 
85 /*
86  * Internal tracking data.
87  */
88 struct xattr_data_t {
89    POOLMEM *last_fname;
90    uint32_t flags;              /* See BXATTR_FLAG_* */
91    uint32_t current_dev;
92    union {
93       struct xattr_build_data_t *build;
94       struct xattr_parse_data_t *parse;
95    } u;
96 };
97 
98 /*
99  * Maximum size of the XATTR stream this prevents us from blowing up the filed.
100  */
101 #define MAX_XATTR_STREAM  (1 * 1024 * 1024) /* 1 Mb */
102 
103 /*
104  * Upperlimit on a xattr internal buffer
105  */
106 #define XATTR_BUFSIZ	1024
107 
108 BxattrExitCode SendXattrStream(JobControlRecord *jcr, xattr_data_t *xattr_data, int stream);
109 void XattrDropInternalTable(alist *xattr_value_list);
110 uint32_t SerializeXattrStream(JobControlRecord *jcr, xattr_data_t *xattr_data,
111                                 uint32_t expected_serialize_len, alist *xattr_value_list);
112 BxattrExitCode UnSerializeXattrStream(JobControlRecord *jcr, xattr_data_t *xattr_data, char *content,
113                                           uint32_t content_length, alist *xattr_value_list);
114 BxattrExitCode BuildXattrStreams(JobControlRecord *jcr, struct xattr_data_t *xattr_data, FindFilesPacket *ff_pkt);
115 BxattrExitCode ParseXattrStreams(JobControlRecord *jcr, struct xattr_data_t *xattr_data,
116                                      int stream, char *content, uint32_t content_length);
117 
118 
119 #endif
120