2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Major refactoring of ACL and XATTR code written by:
22 * Radosław Korzeniewski, MMXVI
23 * radoslaw@korzeniewski.net, radekk@inteos.pl
24 * Inteos Sp. z o.o. http://www.inteos.pl/
32 * Magic used in the magic field of the xattr struct.
33 * This way we can see if we encounter a valid xattr struct.
34 * Used for backward compatibility only.
36 #define XATTR_MAGIC 0x5C5884
39 * Return value status enumeration
40 * You have an error when value is less then zero.
41 * You have a positive status when value is not negative
42 * (greater or equal to zero).
45 bRC_XACL_inval = -3, // input data invalid
46 bRC_XACL_fatal = -2, // a fatal error
47 bRC_XACL_error = -1, // standard error
48 bRC_XACL_ok = 0, // success
49 bRC_XACL_skip = 1, // processing should skip current runtime
50 bRC_XACL_cont = 2 // processing should skip current element
51 // and continue with next one
55 * We support the following types of ACLs
60 XACL_TYPE_DEFAULT = 2,
61 XACL_TYPE_DEFAULT_DIR = 3,
62 XACL_TYPE_EXTENDED = 4,
68 * Flags which control what ACL/XATTR engine
69 * to use for backup/restore
71 #define XACL_FLAG_NONE 0
72 #define XACL_FLAG_NATIVE 0x01
73 #define XACL_FLAG_AFS 0x02
74 #define XACL_FLAG_PLUGIN 0x04
80 #define ACL_TYPE_NONE 0x0
84 * Extended attribute (xattr) list element.
86 * Every xattr consist of a Key=>Value pair where
87 * both could be a binary data.
97 * Basic ACL/XATTR class which is a foundation for any other OS specyfic implementation.
99 * This class cannot be used directly as it is an abstraction class with a lot of virtual
100 * methods laying around. As a basic class it has all public API available for backup and
101 * restore functionality. As a bonus it handles all ACL/XATTR generic functions and OS
102 * independent API, i.e. for AFS ACL/XATTR or Plugins ACL/XATTR (future functionality).
109 uint32_t current_dev;
111 uint32_t content_len;
112 uint32_t acl_nr_errors;
113 uint32_t xattr_nr_errors;
114 const int *acl_streams;
115 const int *default_acl_streams;
116 const int *xattr_streams;
117 const char **xattr_skiplist;
118 const char **xattr_acl_skiplist;
123 * Perform OS specyfic ACL backup.
125 * jcr - Job Control Record
126 * ff_pkt - file to backup information rector
128 * bRC_XACL_ok - backup performed without problems
129 * any other - some error ocurred
131 virtual bRC_XACL os_backup_acl (JCR *jcr, FF_PKT *ff_pkt){return bRC_XACL_fatal;};
134 * Perform OS specyfic ACL restore. Runtime is called only when stream is supported by OS.
136 * jcr - Job Control Record
137 * ff_pkt - file to backup information rector
139 * bRC_XACL_ok - backup performed without problems
140 * any other - some error ocurred
142 virtual bRC_XACL os_restore_acl (JCR *jcr, int stream, char *content, uint32_t length){return bRC_XACL_fatal;};
145 * Perform OS specyfic XATTR backup.
148 * jcr - Job Control Record
149 * ff_pkt - file to backup control package
151 * bRC_XACL_ok - xattr backup ok or no xattr to backup found
152 * bRC_XACL_error/fatal - an error or fatal error occurred
154 virtual bRC_XACL os_backup_xattr (JCR *jcr, FF_PKT *ff_pkt){return bRC_XACL_fatal;};
157 * Perform OS specyfic XATTR restore. Runtime is called only when stream is supported by OS.
160 * jcr - Job Control Record
161 * stream - backup stream number
162 * content - a buffer with data to restore
163 * length - a data restore length
165 * bRC_XACL_ok - xattr backup ok or no xattr to backup found
166 * bRC_XACL_error/fatal - an error or fatal error occurred
168 virtual bRC_XACL os_restore_xattr (JCR *jcr, int stream, char *content, uint32_t length){return bRC_XACL_fatal;};
171 * Low level OS specyfic runtime to get ACL data from file. The ACL data is set in internal content buffer.
174 * jcr - Job Control Record
175 * xacltype - the acl type to restore
178 * bRC_XACL_error/fatal - an error or fatal error occurred
180 virtual bRC_XACL os_get_acl (JCR *jcr, XACL_type xacltype){return bRC_XACL_fatal;};
183 * Low level OS specyfic runtime to set ACL data on file.
186 * jcr - Job Control Record
187 * xacltype - the acl type to restore
188 * content - a buffer with data to restore
189 * length - a data restore length
192 * bRC_XACL_error/fatal - an error or fatal error occurred
194 virtual bRC_XACL os_set_acl (JCR *jcr, XACL_type xacltype, char *content, uint32_t length){return bRC_XACL_fatal;};
197 * Returns a list of xattr names in newly allocated pool memory and a length of the allocated buffer.
198 * It allocates a memory with poolmem subroutines every time a function is called, so it must be freed
199 * when not needed. The list of xattr names is returned as an unordered array of NULL terminated
200 * character strings (attribute names are separated by NULL characters), like this:
201 * user.name1\0system.name1\0user.name2\0
202 * The format of the list is based on standard "llistxattr" function call.
203 * TODO: change the format of the list from an array of NULL terminated strings into an alist of structures.
206 * jcr - Job Control Record
207 * xlen - non NULL pointer to the uint32_t variable for storing a length of the xattr names list
208 * pxlist - non NULL pointer to the char* variable for allocating a memoty data for xattr names list
210 * bRC_XACL_ok - we've got a xattr data to backup
211 * bRC_XACL_skip - no xattr data available, no fatal error, skip rest of the runtime
212 * bRC_XACL_fatal - when required buffers are unallocated
213 * bRC_XACL_error - in case of any error
215 virtual bRC_XACL os_get_xattr_names (JCR *jcr, POOLMEM ** pxlist, uint32_t * xlen){return bRC_XACL_fatal;};
218 * Returns a value of the requested attribute name and a length of the allocated buffer.
219 * It allocates a memory with poolmem subroutines every time a function is called, so it must be freed
223 * jcr - Job Control Record
224 * name - a name of the extended attribute
225 * pvalue - the pointer for the buffer with value - it is allocated by function and should be freed when no needed
226 * plen - the pointer for the length of the allocated buffer
229 * pxlist - the atributes list
230 * bRC_XACL_ok - we've got a xattr data which could be empty when xlen=0
231 * bRC_XACL_skip - no xattr data available, no fatal error, skip rest of the runtime
232 * bRC_XACL_error - error getting an attribute
233 * bRC_XACL_fatal - required buffers are unallocated
235 virtual bRC_XACL os_get_xattr_value (JCR *jcr, char * name, char ** pvalue, uint32_t * plen){return bRC_XACL_fatal;};
238 * Low level OS specyfic runtime to set extended attribute on file
241 * jcr - Job Control Record
242 * xattr - the struct with attribute/value to set
245 * bRC_XACL_ok - setting the attribute was ok
246 * bRC_XACL_error - error during extattribute set
247 * bRC_XACL_fatal - required buffers are unallocated
249 virtual bRC_XACL os_set_xattr (JCR *jcr, XACL_xattr *xattr){return bRC_XACL_fatal;};
251 void inc_acl_errors(){ acl_nr_errors++;};
252 void inc_xattr_errors(){ xattr_nr_errors++;};
253 bRC_XACL check_dev (JCR *jcr);
254 void check_dev (JCR *jcr, uint32_t dev);
260 /* enable/disable functionality */
264 void disable_xattr();
267 * public methods used outside the class or derivatives
269 bRC_XACL backup_acl (JCR *jcr, FF_PKT *ff_pkt);
270 bRC_XACL restore_acl (JCR *jcr, int stream, char *content, uint32_t content_length);
271 bRC_XACL backup_xattr (JCR *jcr, FF_PKT *ff_pkt);
272 bRC_XACL restore_xattr (JCR *jcr, int stream, char *content, uint32_t content_length);
274 /* utility functions */
275 inline uint32_t get_acl_nr_errors(){ return acl_nr_errors;};
276 inline uint32_t get_xattr_nr_errors(){ return xattr_nr_errors;};
277 void set_acl_streams (const int *pacl, const int *pacl_def);
278 void set_xattr_streams (const int *pxattr);
279 void set_xattr_skiplists (const char **pxattr, const char **pxattr_acl);
280 inline void clear_flag (uint32_t flag){ flags &= ~flag;};
281 inline void set_flag (uint32_t flag){ flags |= flag;};
282 POOLMEM * set_content (char *text);
283 POOLMEM * set_content(char *data, int len);
284 inline POOLMEM * get_content (void){ return content;};
285 inline uint32_t get_content_size (void){ return sizeof_pool_memory(content);};
286 inline uint32_t get_content_len (void){ return content_len;};
287 bool check_xattr_skiplists (JCR *jcr, FF_PKT *ff_pkt, char * name);
289 /* sending data to the storage */
290 bRC_XACL send_acl_stream (JCR *jcr, int stream);
291 bRC_XACL send_xattr_stream (JCR *jcr, int stream);
293 /* serialize / unserialize stream */
294 bRC_XACL unserialize_xattr_stream(JCR *jcr, char *content, uint32_t length, alist *list);
295 bRC_XACL serialize_xattr_stream(JCR *jcr, uint32_t len, alist *list);
297 /* generic functions */
298 bRC_XACL generic_backup_acl (JCR *jcr, FF_PKT *ff_pkt);
299 bRC_XACL generic_restore_acl (JCR *jcr, int stream);
300 bRC_XACL afs_backup_acl (JCR *jcr, FF_PKT *ff_pkt);
301 bRC_XACL afs_restore_acl (JCR *jcr, int stream);
302 bRC_XACL generic_backup_xattr (JCR *jcr, FF_PKT *ff_pkt);
303 bRC_XACL generic_restore_xattr (JCR *jcr, int stream);
308 #endif /* __BXACL_H_ */