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 {
32   kErrorFatal,
33   kError,
34   kWarning,
35   kSuccess
36 };
37 
38 #if defined(HAVE_LINUX_OS)
39 #define BXATTR_ENOTSUP EOPNOTSUPP
40 #elif defined(HAVE_DARWIN_OS)
41 #define BXATTR_ENOTSUP ENOTSUP
42 #elif defined(HAVE_HURD_OS)
43 #define BXATTR_ENOTSUP ENOTSUP
44 #endif
45 
46 /*
47  * Magic used in the magic field of the xattr struct.
48  * This way we can see we encounter a valid xattr struct.
49  */
50 #define XATTR_MAGIC 0x5C5884
51 
52 /*
53  * Internal representation of an extended attribute.
54  */
55 struct xattr_t {
56   uint32_t magic;
57   uint32_t name_length;
58   char* name;
59   uint32_t value_length;
60   char* value;
61 };
62 
63 /*
64  * Internal representation of an extended attribute hardlinked file.
65  */
66 struct xattr_link_cache_entry_t {
67   uint32_t inum;
68   char* target;
69 };
70 
71 #define BXATTR_FLAG_SAVE_NATIVE 0x01
72 #define BXATTR_FLAG_RESTORE_NATIVE 0x02
73 
74 struct xattr_build_data_t {
75   uint32_t nr_errors;
76   uint32_t nr_saved;
77   POOLMEM* content;
78   uint32_t content_length;
79   alist* link_cache;
80 };
81 
82 struct xattr_parse_data_t {
83   uint32_t nr_errors;
84 };
85 
86 /*
87  * Internal tracking data.
88  */
89 struct XattrData {
90   POOLMEM* last_fname;
91   uint32_t flags{0}; /* See BXATTR_FLAG_* */
92   uint32_t current_dev{0};
93   bool first_dev{true};
94   union {
95     struct xattr_build_data_t* build;
96     struct xattr_parse_data_t* parse;
97   } u;
98 };
99 
100 /*
101  * Maximum size of the XATTR stream this prevents us from blowing up the filed.
102  */
103 #define MAX_XATTR_STREAM (1 * 1024 * 1024) /* 1 Mb */
104 
105 /*
106  * Upperlimit on a xattr internal buffer
107  */
108 #define XATTR_BUFSIZ 1024
109 class alist;
110 
111 BxattrExitCode SendXattrStream(JobControlRecord* jcr,
112                                XattrData* xattr_data,
113                                int stream);
114 void XattrDropInternalTable(alist* xattr_value_list);
115 uint32_t SerializeXattrStream(JobControlRecord* jcr,
116                               XattrData* xattr_data,
117                               uint32_t expected_serialize_len,
118                               alist* xattr_value_list);
119 BxattrExitCode UnSerializeXattrStream(JobControlRecord* jcr,
120                                       XattrData* xattr_data,
121                                       char* content,
122                                       uint32_t content_length,
123                                       alist* xattr_value_list);
124 BxattrExitCode BuildXattrStreams(JobControlRecord* jcr,
125                                  struct XattrData* xattr_data,
126                                  FindFilesPacket* ff_pkt);
127 BxattrExitCode ParseXattrStreams(JobControlRecord* jcr,
128                                  struct XattrData* xattr_data,
129                                  int stream,
130                                  char* content,
131                                  uint32_t content_length);
132 
133 
134 #endif
135