Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/cmlibarchive/libarchive/archive_entry.h
3153 views
1
/*-
2
* Copyright (c) 2003-2008 Tim Kientzle
3
* Copyright (c) 2016 Martin Matuska
4
* All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
8
* are met:
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
*/
26
27
#ifndef ARCHIVE_ENTRY_H_INCLUDED
28
#define ARCHIVE_ENTRY_H_INCLUDED
29
30
/* Note: Compiler will complain if this does not match archive.h! */
31
#define ARCHIVE_VERSION_NUMBER 3007009
32
33
/*
34
* Note: archive_entry.h is for use outside of libarchive; the
35
* configuration headers (config.h, archive_platform.h, etc.) are
36
* purely internal. Do NOT use HAVE_XXX configuration macros to
37
* control the behavior of this header! If you must conditionalize,
38
* use predefined compiler and/or platform macros.
39
*/
40
41
#include <sys/types.h>
42
#include <stddef.h> /* for wchar_t */
43
#include <stdint.h>
44
#include <time.h>
45
46
#if defined(_WIN32) && !defined(__CYGWIN__)
47
#include <windows.h>
48
#endif
49
50
/* Get a suitable 64-bit integer type. */
51
#if !defined(__LA_INT64_T_DEFINED)
52
# if ARCHIVE_VERSION_NUMBER < 4000000
53
#define __LA_INT64_T la_int64_t
54
# endif
55
#define __LA_INT64_T_DEFINED
56
# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
57
typedef __int64 la_int64_t;
58
# else
59
#include <unistd.h>
60
# if defined(_SCO_DS) || defined(__osf__)
61
typedef long long la_int64_t;
62
# else
63
typedef int64_t la_int64_t;
64
# endif
65
# endif
66
#endif
67
68
/* The la_ssize_t should match the type used in 'struct stat' */
69
#if !defined(__LA_SSIZE_T_DEFINED)
70
/* Older code relied on the __LA_SSIZE_T macro; after 4.0 we'll switch to the typedef exclusively. */
71
# if ARCHIVE_VERSION_NUMBER < 4000000
72
#define __LA_SSIZE_T la_ssize_t
73
# endif
74
#define __LA_SSIZE_T_DEFINED
75
# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
76
# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_)
77
typedef ssize_t la_ssize_t;
78
# elif defined(_WIN64)
79
typedef __int64 la_ssize_t;
80
# else
81
typedef long la_ssize_t;
82
# endif
83
# else
84
# include <unistd.h> /* ssize_t */
85
typedef ssize_t la_ssize_t;
86
# endif
87
#endif
88
89
/* Get a suitable definition for mode_t */
90
#if ARCHIVE_VERSION_NUMBER >= 3999000
91
/* Switch to plain 'int' for libarchive 4.0. It's less broken than 'mode_t' */
92
# define __LA_MODE_T int
93
#elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
94
# define __LA_MODE_T unsigned short
95
#else
96
# define __LA_MODE_T mode_t
97
#endif
98
99
/* Large file support for Android */
100
#if defined(__LIBARCHIVE_BUILD) && defined(__ANDROID__)
101
#include "android_lf.h"
102
#endif
103
104
/*
105
* On Windows, define LIBARCHIVE_STATIC if you're building or using a
106
* .lib. The default here assumes you're building a DLL. Only
107
* libarchive source should ever define __LIBARCHIVE_BUILD.
108
*/
109
#if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC)
110
# ifdef __LIBARCHIVE_BUILD
111
# ifdef __GNUC__
112
# define __LA_DECL __attribute__((dllexport)) extern
113
# else
114
# define __LA_DECL __declspec(dllexport)
115
# endif
116
# else
117
# ifdef __GNUC__
118
# define __LA_DECL
119
# else
120
# define __LA_DECL __declspec(dllimport)
121
# endif
122
# endif
123
#elif defined __LIBARCHIVE_ENABLE_VISIBILITY
124
# define __LA_DECL __attribute__((visibility("default")))
125
#else
126
/* Static libraries on all platforms and shared libraries on non-Windows. */
127
# define __LA_DECL
128
#endif
129
130
/* CMake uses some deprecated APIs to build with old libarchive versions. */
131
#define __LA_DEPRECATED
132
133
#ifdef __cplusplus
134
extern "C" {
135
#endif
136
137
/*
138
* Description of an archive entry.
139
*
140
* You can think of this as "struct stat" with some text fields added in.
141
*
142
* TODO: Add "comment", "charset", and possibly other entries that are
143
* supported by "pax interchange" format. However, GNU, ustar, cpio,
144
* and other variants don't support these features, so they're not an
145
* excruciatingly high priority right now.
146
*
147
* TODO: "pax interchange" format allows essentially arbitrary
148
* key/value attributes to be attached to any entry. Supporting
149
* such extensions may make this library useful for special
150
* applications (e.g., a package manager could attach special
151
* package-management attributes to each entry).
152
*/
153
struct archive;
154
struct archive_entry;
155
156
/*
157
* File-type constants. These are returned from archive_entry_filetype()
158
* and passed to archive_entry_set_filetype().
159
*
160
* These values match S_XXX defines on every platform I've checked,
161
* including Windows, AIX, Linux, Solaris, and BSD. They're
162
* (re)defined here because platforms generally don't define the ones
163
* they don't support. For example, Windows doesn't define S_IFLNK or
164
* S_IFBLK. Instead of having a mass of conditional logic and system
165
* checks to define any S_XXX values that aren't supported locally,
166
* I've just defined a new set of such constants so that
167
* libarchive-based applications can manipulate and identify archive
168
* entries properly even if the hosting platform can't store them on
169
* disk.
170
*
171
* These values are also used directly within some portable formats,
172
* such as cpio. If you find a platform that varies from these, the
173
* correct solution is to leave these alone and translate from these
174
* portable values to platform-native values when entries are read from
175
* or written to disk.
176
*/
177
/*
178
* In libarchive 4.0, we can drop the casts here.
179
* They're needed to work around Borland C's broken mode_t.
180
*/
181
#define AE_IFMT ((__LA_MODE_T)0170000)
182
#define AE_IFREG ((__LA_MODE_T)0100000)
183
#define AE_IFLNK ((__LA_MODE_T)0120000)
184
#define AE_IFSOCK ((__LA_MODE_T)0140000)
185
#define AE_IFCHR ((__LA_MODE_T)0020000)
186
#define AE_IFBLK ((__LA_MODE_T)0060000)
187
#define AE_IFDIR ((__LA_MODE_T)0040000)
188
#define AE_IFIFO ((__LA_MODE_T)0010000)
189
190
/*
191
* Symlink types
192
*/
193
#define AE_SYMLINK_TYPE_UNDEFINED 0
194
#define AE_SYMLINK_TYPE_FILE 1
195
#define AE_SYMLINK_TYPE_DIRECTORY 2
196
197
/*
198
* Basic object manipulation
199
*/
200
201
__LA_DECL struct archive_entry *archive_entry_clear(struct archive_entry *);
202
/* The 'clone' function does a deep copy; all of the strings are copied too. */
203
__LA_DECL struct archive_entry *archive_entry_clone(struct archive_entry *);
204
__LA_DECL void archive_entry_free(struct archive_entry *);
205
__LA_DECL struct archive_entry *archive_entry_new(void);
206
207
/*
208
* This form of archive_entry_new2() will pull character-set
209
* conversion information from the specified archive handle. The
210
* older archive_entry_new(void) form is equivalent to calling
211
* archive_entry_new2(NULL) and will result in the use of an internal
212
* default character-set conversion.
213
*/
214
__LA_DECL struct archive_entry *archive_entry_new2(struct archive *);
215
216
/*
217
* Retrieve fields from an archive_entry.
218
*
219
* There are a number of implicit conversions among these fields. For
220
* example, if a regular string field is set and you read the _w wide
221
* character field, the entry will implicitly convert narrow-to-wide
222
* using the current locale. Similarly, dev values are automatically
223
* updated when you write devmajor or devminor and vice versa.
224
*
225
* In addition, fields can be "set" or "unset." Unset string fields
226
* return NULL, non-string fields have _is_set() functions to test
227
* whether they've been set. You can "unset" a string field by
228
* assigning NULL; non-string fields have _unset() functions to
229
* unset them.
230
*
231
* Note: There is one ambiguity in the above; string fields will
232
* also return NULL when implicit character set conversions fail.
233
* This is usually what you want.
234
*/
235
__LA_DECL time_t archive_entry_atime(struct archive_entry *);
236
__LA_DECL long archive_entry_atime_nsec(struct archive_entry *);
237
__LA_DECL int archive_entry_atime_is_set(struct archive_entry *);
238
__LA_DECL time_t archive_entry_birthtime(struct archive_entry *);
239
__LA_DECL long archive_entry_birthtime_nsec(struct archive_entry *);
240
__LA_DECL int archive_entry_birthtime_is_set(struct archive_entry *);
241
__LA_DECL time_t archive_entry_ctime(struct archive_entry *);
242
__LA_DECL long archive_entry_ctime_nsec(struct archive_entry *);
243
__LA_DECL int archive_entry_ctime_is_set(struct archive_entry *);
244
__LA_DECL dev_t archive_entry_dev(struct archive_entry *);
245
__LA_DECL int archive_entry_dev_is_set(struct archive_entry *);
246
__LA_DECL dev_t archive_entry_devmajor(struct archive_entry *);
247
__LA_DECL dev_t archive_entry_devminor(struct archive_entry *);
248
__LA_DECL __LA_MODE_T archive_entry_filetype(struct archive_entry *);
249
__LA_DECL int archive_entry_filetype_is_set(struct archive_entry *);
250
__LA_DECL void archive_entry_fflags(struct archive_entry *,
251
unsigned long * /* set */,
252
unsigned long * /* clear */);
253
__LA_DECL const char *archive_entry_fflags_text(struct archive_entry *);
254
__LA_DECL la_int64_t archive_entry_gid(struct archive_entry *);
255
__LA_DECL int archive_entry_gid_is_set(struct archive_entry *);
256
__LA_DECL const char *archive_entry_gname(struct archive_entry *);
257
__LA_DECL const char *archive_entry_gname_utf8(struct archive_entry *);
258
__LA_DECL const wchar_t *archive_entry_gname_w(struct archive_entry *);
259
__LA_DECL void archive_entry_set_link_to_hardlink(struct archive_entry *);
260
__LA_DECL const char *archive_entry_hardlink(struct archive_entry *);
261
__LA_DECL const char *archive_entry_hardlink_utf8(struct archive_entry *);
262
__LA_DECL const wchar_t *archive_entry_hardlink_w(struct archive_entry *);
263
__LA_DECL int archive_entry_hardlink_is_set(struct archive_entry *);
264
__LA_DECL la_int64_t archive_entry_ino(struct archive_entry *);
265
__LA_DECL la_int64_t archive_entry_ino64(struct archive_entry *);
266
__LA_DECL int archive_entry_ino_is_set(struct archive_entry *);
267
__LA_DECL __LA_MODE_T archive_entry_mode(struct archive_entry *);
268
__LA_DECL time_t archive_entry_mtime(struct archive_entry *);
269
__LA_DECL long archive_entry_mtime_nsec(struct archive_entry *);
270
__LA_DECL int archive_entry_mtime_is_set(struct archive_entry *);
271
__LA_DECL unsigned int archive_entry_nlink(struct archive_entry *);
272
__LA_DECL const char *archive_entry_pathname(struct archive_entry *);
273
__LA_DECL const char *archive_entry_pathname_utf8(struct archive_entry *);
274
__LA_DECL const wchar_t *archive_entry_pathname_w(struct archive_entry *);
275
__LA_DECL __LA_MODE_T archive_entry_perm(struct archive_entry *);
276
__LA_DECL int archive_entry_perm_is_set(struct archive_entry *);
277
__LA_DECL int archive_entry_rdev_is_set(struct archive_entry *);
278
__LA_DECL dev_t archive_entry_rdev(struct archive_entry *);
279
__LA_DECL dev_t archive_entry_rdevmajor(struct archive_entry *);
280
__LA_DECL dev_t archive_entry_rdevminor(struct archive_entry *);
281
__LA_DECL const char *archive_entry_sourcepath(struct archive_entry *);
282
__LA_DECL const wchar_t *archive_entry_sourcepath_w(struct archive_entry *);
283
__LA_DECL la_int64_t archive_entry_size(struct archive_entry *);
284
__LA_DECL int archive_entry_size_is_set(struct archive_entry *);
285
__LA_DECL const char *archive_entry_strmode(struct archive_entry *);
286
__LA_DECL void archive_entry_set_link_to_symlink(struct archive_entry *);
287
__LA_DECL const char *archive_entry_symlink(struct archive_entry *);
288
__LA_DECL const char *archive_entry_symlink_utf8(struct archive_entry *);
289
__LA_DECL int archive_entry_symlink_type(struct archive_entry *);
290
__LA_DECL const wchar_t *archive_entry_symlink_w(struct archive_entry *);
291
__LA_DECL la_int64_t archive_entry_uid(struct archive_entry *);
292
__LA_DECL int archive_entry_uid_is_set(struct archive_entry *);
293
__LA_DECL const char *archive_entry_uname(struct archive_entry *);
294
__LA_DECL const char *archive_entry_uname_utf8(struct archive_entry *);
295
__LA_DECL const wchar_t *archive_entry_uname_w(struct archive_entry *);
296
__LA_DECL int archive_entry_is_data_encrypted(struct archive_entry *);
297
__LA_DECL int archive_entry_is_metadata_encrypted(struct archive_entry *);
298
__LA_DECL int archive_entry_is_encrypted(struct archive_entry *);
299
300
/*
301
* Set fields in an archive_entry.
302
*
303
* Note: Before libarchive 2.4, there were 'set' and 'copy' versions
304
* of the string setters. 'copy' copied the actual string, 'set' just
305
* stored the pointer. In libarchive 2.4 and later, strings are
306
* always copied.
307
*/
308
309
__LA_DECL void archive_entry_set_atime(struct archive_entry *, time_t, long);
310
__LA_DECL void archive_entry_unset_atime(struct archive_entry *);
311
#if defined(_WIN32) && !defined(__CYGWIN__)
312
__LA_DECL void archive_entry_copy_bhfi(struct archive_entry *, struct _BY_HANDLE_FILE_INFORMATION *);
313
#endif
314
__LA_DECL void archive_entry_set_birthtime(struct archive_entry *, time_t, long);
315
__LA_DECL void archive_entry_unset_birthtime(struct archive_entry *);
316
__LA_DECL void archive_entry_set_ctime(struct archive_entry *, time_t, long);
317
__LA_DECL void archive_entry_unset_ctime(struct archive_entry *);
318
__LA_DECL void archive_entry_set_dev(struct archive_entry *, dev_t);
319
__LA_DECL void archive_entry_set_devmajor(struct archive_entry *, dev_t);
320
__LA_DECL void archive_entry_set_devminor(struct archive_entry *, dev_t);
321
__LA_DECL void archive_entry_set_filetype(struct archive_entry *, unsigned int);
322
__LA_DECL void archive_entry_set_fflags(struct archive_entry *,
323
unsigned long /* set */, unsigned long /* clear */);
324
/* Returns pointer to start of first invalid token, or NULL if none. */
325
/* Note that all recognized tokens are processed, regardless. */
326
__LA_DECL const char *archive_entry_copy_fflags_text(struct archive_entry *,
327
const char *);
328
__LA_DECL const char *archive_entry_copy_fflags_text_len(struct archive_entry *,
329
const char *, size_t);
330
__LA_DECL const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *,
331
const wchar_t *);
332
__LA_DECL void archive_entry_set_gid(struct archive_entry *, la_int64_t);
333
__LA_DECL void archive_entry_set_gname(struct archive_entry *, const char *);
334
__LA_DECL void archive_entry_set_gname_utf8(struct archive_entry *, const char *);
335
__LA_DECL void archive_entry_copy_gname(struct archive_entry *, const char *);
336
__LA_DECL void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *);
337
__LA_DECL int archive_entry_update_gname_utf8(struct archive_entry *, const char *);
338
__LA_DECL void archive_entry_set_hardlink(struct archive_entry *, const char *);
339
__LA_DECL void archive_entry_set_hardlink_utf8(struct archive_entry *, const char *);
340
__LA_DECL void archive_entry_copy_hardlink(struct archive_entry *, const char *);
341
__LA_DECL void archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *);
342
__LA_DECL int archive_entry_update_hardlink_utf8(struct archive_entry *, const char *);
343
__LA_DECL void archive_entry_set_ino(struct archive_entry *, la_int64_t);
344
__LA_DECL void archive_entry_set_ino64(struct archive_entry *, la_int64_t);
345
__LA_DECL void archive_entry_set_link(struct archive_entry *, const char *);
346
__LA_DECL void archive_entry_set_link_utf8(struct archive_entry *, const char *);
347
__LA_DECL void archive_entry_copy_link(struct archive_entry *, const char *);
348
__LA_DECL void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *);
349
__LA_DECL int archive_entry_update_link_utf8(struct archive_entry *, const char *);
350
__LA_DECL void archive_entry_set_mode(struct archive_entry *, __LA_MODE_T);
351
__LA_DECL void archive_entry_set_mtime(struct archive_entry *, time_t, long);
352
__LA_DECL void archive_entry_unset_mtime(struct archive_entry *);
353
__LA_DECL void archive_entry_set_nlink(struct archive_entry *, unsigned int);
354
__LA_DECL void archive_entry_set_pathname(struct archive_entry *, const char *);
355
__LA_DECL void archive_entry_set_pathname_utf8(struct archive_entry *, const char *);
356
__LA_DECL void archive_entry_copy_pathname(struct archive_entry *, const char *);
357
__LA_DECL void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *);
358
__LA_DECL int archive_entry_update_pathname_utf8(struct archive_entry *, const char *);
359
__LA_DECL void archive_entry_set_perm(struct archive_entry *, __LA_MODE_T);
360
__LA_DECL void archive_entry_set_rdev(struct archive_entry *, dev_t);
361
__LA_DECL void archive_entry_set_rdevmajor(struct archive_entry *, dev_t);
362
__LA_DECL void archive_entry_set_rdevminor(struct archive_entry *, dev_t);
363
__LA_DECL void archive_entry_set_size(struct archive_entry *, la_int64_t);
364
__LA_DECL void archive_entry_unset_size(struct archive_entry *);
365
__LA_DECL void archive_entry_copy_sourcepath(struct archive_entry *, const char *);
366
__LA_DECL void archive_entry_copy_sourcepath_w(struct archive_entry *, const wchar_t *);
367
__LA_DECL void archive_entry_set_symlink(struct archive_entry *, const char *);
368
__LA_DECL void archive_entry_set_symlink_type(struct archive_entry *, int);
369
__LA_DECL void archive_entry_set_symlink_utf8(struct archive_entry *, const char *);
370
__LA_DECL void archive_entry_copy_symlink(struct archive_entry *, const char *);
371
__LA_DECL void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *);
372
__LA_DECL int archive_entry_update_symlink_utf8(struct archive_entry *, const char *);
373
__LA_DECL void archive_entry_set_uid(struct archive_entry *, la_int64_t);
374
__LA_DECL void archive_entry_set_uname(struct archive_entry *, const char *);
375
__LA_DECL void archive_entry_set_uname_utf8(struct archive_entry *, const char *);
376
__LA_DECL void archive_entry_copy_uname(struct archive_entry *, const char *);
377
__LA_DECL void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *);
378
__LA_DECL int archive_entry_update_uname_utf8(struct archive_entry *, const char *);
379
__LA_DECL void archive_entry_set_is_data_encrypted(struct archive_entry *, char is_encrypted);
380
__LA_DECL void archive_entry_set_is_metadata_encrypted(struct archive_entry *, char is_encrypted);
381
/*
382
* Routines to bulk copy fields to/from a platform-native "struct
383
* stat." Libarchive used to just store a struct stat inside of each
384
* archive_entry object, but this created issues when trying to
385
* manipulate archives on systems different than the ones they were
386
* created on.
387
*
388
* TODO: On Linux and other LFS systems, provide both stat32 and
389
* stat64 versions of these functions and all of the macro glue so
390
* that archive_entry_stat is magically defined to
391
* archive_entry_stat32 or archive_entry_stat64 as appropriate.
392
*/
393
__LA_DECL const struct stat *archive_entry_stat(struct archive_entry *);
394
__LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct stat *);
395
396
/*
397
* Storage for Mac OS-specific AppleDouble metadata information.
398
* Apple-format tar files store a separate binary blob containing
399
* encoded metadata with ACL, extended attributes, etc.
400
* This provides a place to store that blob.
401
*/
402
403
__LA_DECL const void * archive_entry_mac_metadata(struct archive_entry *, size_t *);
404
__LA_DECL void archive_entry_copy_mac_metadata(struct archive_entry *, const void *, size_t);
405
406
/*
407
* Digest routine. This is used to query the raw hex digest for the
408
* given entry. The type of digest is provided as an argument.
409
*/
410
#define ARCHIVE_ENTRY_DIGEST_MD5 0x00000001
411
#define ARCHIVE_ENTRY_DIGEST_RMD160 0x00000002
412
#define ARCHIVE_ENTRY_DIGEST_SHA1 0x00000003
413
#define ARCHIVE_ENTRY_DIGEST_SHA256 0x00000004
414
#define ARCHIVE_ENTRY_DIGEST_SHA384 0x00000005
415
#define ARCHIVE_ENTRY_DIGEST_SHA512 0x00000006
416
417
__LA_DECL const unsigned char * archive_entry_digest(struct archive_entry *, int /* type */);
418
419
/*
420
* ACL routines. This used to simply store and return text-format ACL
421
* strings, but that proved insufficient for a number of reasons:
422
* = clients need control over uname/uid and gname/gid mappings
423
* = there are many different ACL text formats
424
* = would like to be able to read/convert archives containing ACLs
425
* on platforms that lack ACL libraries
426
*
427
* This last point, in particular, forces me to implement a reasonably
428
* complete set of ACL support routines.
429
*/
430
431
/*
432
* Permission bits.
433
*/
434
#define ARCHIVE_ENTRY_ACL_EXECUTE 0x00000001
435
#define ARCHIVE_ENTRY_ACL_WRITE 0x00000002
436
#define ARCHIVE_ENTRY_ACL_READ 0x00000004
437
#define ARCHIVE_ENTRY_ACL_READ_DATA 0x00000008
438
#define ARCHIVE_ENTRY_ACL_LIST_DIRECTORY 0x00000008
439
#define ARCHIVE_ENTRY_ACL_WRITE_DATA 0x00000010
440
#define ARCHIVE_ENTRY_ACL_ADD_FILE 0x00000010
441
#define ARCHIVE_ENTRY_ACL_APPEND_DATA 0x00000020
442
#define ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY 0x00000020
443
#define ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS 0x00000040
444
#define ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS 0x00000080
445
#define ARCHIVE_ENTRY_ACL_DELETE_CHILD 0x00000100
446
#define ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES 0x00000200
447
#define ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES 0x00000400
448
#define ARCHIVE_ENTRY_ACL_DELETE 0x00000800
449
#define ARCHIVE_ENTRY_ACL_READ_ACL 0x00001000
450
#define ARCHIVE_ENTRY_ACL_WRITE_ACL 0x00002000
451
#define ARCHIVE_ENTRY_ACL_WRITE_OWNER 0x00004000
452
#define ARCHIVE_ENTRY_ACL_SYNCHRONIZE 0x00008000
453
454
#define ARCHIVE_ENTRY_ACL_PERMS_POSIX1E \
455
(ARCHIVE_ENTRY_ACL_EXECUTE \
456
| ARCHIVE_ENTRY_ACL_WRITE \
457
| ARCHIVE_ENTRY_ACL_READ)
458
459
#define ARCHIVE_ENTRY_ACL_PERMS_NFS4 \
460
(ARCHIVE_ENTRY_ACL_EXECUTE \
461
| ARCHIVE_ENTRY_ACL_READ_DATA \
462
| ARCHIVE_ENTRY_ACL_LIST_DIRECTORY \
463
| ARCHIVE_ENTRY_ACL_WRITE_DATA \
464
| ARCHIVE_ENTRY_ACL_ADD_FILE \
465
| ARCHIVE_ENTRY_ACL_APPEND_DATA \
466
| ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY \
467
| ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS \
468
| ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS \
469
| ARCHIVE_ENTRY_ACL_DELETE_CHILD \
470
| ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES \
471
| ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES \
472
| ARCHIVE_ENTRY_ACL_DELETE \
473
| ARCHIVE_ENTRY_ACL_READ_ACL \
474
| ARCHIVE_ENTRY_ACL_WRITE_ACL \
475
| ARCHIVE_ENTRY_ACL_WRITE_OWNER \
476
| ARCHIVE_ENTRY_ACL_SYNCHRONIZE)
477
478
/*
479
* Inheritance values (NFS4 ACLs only); included in permset.
480
*/
481
#define ARCHIVE_ENTRY_ACL_ENTRY_INHERITED 0x01000000
482
#define ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT 0x02000000
483
#define ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT 0x04000000
484
#define ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT 0x08000000
485
#define ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY 0x10000000
486
#define ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS 0x20000000
487
#define ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS 0x40000000
488
489
#define ARCHIVE_ENTRY_ACL_INHERITANCE_NFS4 \
490
(ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT \
491
| ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT \
492
| ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT \
493
| ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY \
494
| ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS \
495
| ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS \
496
| ARCHIVE_ENTRY_ACL_ENTRY_INHERITED)
497
498
/* We need to be able to specify combinations of these. */
499
#define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 0x00000100 /* POSIX.1e only */
500
#define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 0x00000200 /* POSIX.1e only */
501
#define ARCHIVE_ENTRY_ACL_TYPE_ALLOW 0x00000400 /* NFS4 only */
502
#define ARCHIVE_ENTRY_ACL_TYPE_DENY 0x00000800 /* NFS4 only */
503
#define ARCHIVE_ENTRY_ACL_TYPE_AUDIT 0x00001000 /* NFS4 only */
504
#define ARCHIVE_ENTRY_ACL_TYPE_ALARM 0x00002000 /* NFS4 only */
505
#define ARCHIVE_ENTRY_ACL_TYPE_POSIX1E (ARCHIVE_ENTRY_ACL_TYPE_ACCESS \
506
| ARCHIVE_ENTRY_ACL_TYPE_DEFAULT)
507
#define ARCHIVE_ENTRY_ACL_TYPE_NFS4 (ARCHIVE_ENTRY_ACL_TYPE_ALLOW \
508
| ARCHIVE_ENTRY_ACL_TYPE_DENY \
509
| ARCHIVE_ENTRY_ACL_TYPE_AUDIT \
510
| ARCHIVE_ENTRY_ACL_TYPE_ALARM)
511
512
/* Tag values mimic POSIX.1e */
513
#define ARCHIVE_ENTRY_ACL_USER 10001 /* Specified user. */
514
#define ARCHIVE_ENTRY_ACL_USER_OBJ 10002 /* User who owns the file. */
515
#define ARCHIVE_ENTRY_ACL_GROUP 10003 /* Specified group. */
516
#define ARCHIVE_ENTRY_ACL_GROUP_OBJ 10004 /* Group who owns the file. */
517
#define ARCHIVE_ENTRY_ACL_MASK 10005 /* Modify group access (POSIX.1e only) */
518
#define ARCHIVE_ENTRY_ACL_OTHER 10006 /* Public (POSIX.1e only) */
519
#define ARCHIVE_ENTRY_ACL_EVERYONE 10107 /* Everyone (NFS4 only) */
520
521
/*
522
* Set the ACL by clearing it and adding entries one at a time.
523
* Unlike the POSIX.1e ACL routines, you must specify the type
524
* (access/default) for each entry. Internally, the ACL data is just
525
* a soup of entries. API calls here allow you to retrieve just the
526
* entries of interest. This design (which goes against the spirit of
527
* POSIX.1e) is useful for handling archive formats that combine
528
* default and access information in a single ACL list.
529
*/
530
__LA_DECL void archive_entry_acl_clear(struct archive_entry *);
531
__LA_DECL int archive_entry_acl_add_entry(struct archive_entry *,
532
int /* type */, int /* permset */, int /* tag */,
533
int /* qual */, const char * /* name */);
534
__LA_DECL int archive_entry_acl_add_entry_w(struct archive_entry *,
535
int /* type */, int /* permset */, int /* tag */,
536
int /* qual */, const wchar_t * /* name */);
537
538
/*
539
* To retrieve the ACL, first "reset", then repeatedly ask for the
540
* "next" entry. The want_type parameter allows you to request only
541
* certain types of entries.
542
*/
543
__LA_DECL int archive_entry_acl_reset(struct archive_entry *, int /* want_type */);
544
__LA_DECL int archive_entry_acl_next(struct archive_entry *, int /* want_type */,
545
int * /* type */, int * /* permset */, int * /* tag */,
546
int * /* qual */, const char ** /* name */);
547
548
/*
549
* Construct a text-format ACL. The flags argument is a bitmask that
550
* can include any of the following:
551
*
552
* Flags only for archive entries with POSIX.1e ACL:
553
* ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include POSIX.1e "access" entries.
554
* ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include POSIX.1e "default" entries.
555
* ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each
556
* default ACL entry.
557
* ARCHIVE_ENTRY_ACL_STYLE_SOLARIS - Output only one colon after "other" and
558
* "mask" entries.
559
*
560
* Flags only for archive entries with NFSv4 ACL:
561
* ARCHIVE_ENTRY_ACL_STYLE_COMPACT - Do not output the minus character for
562
* unset permissions and flags in NFSv4 ACL permission and flag fields
563
*
564
* Flags for for archive entries with POSIX.1e ACL or NFSv4 ACL:
565
* ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in
566
* each ACL entry.
567
* ARCHIVE_ENTRY_ACL_STYLE_SEPARATOR_COMMA - Separate entries with comma
568
* instead of newline.
569
*/
570
#define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 0x00000001
571
#define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 0x00000002
572
#define ARCHIVE_ENTRY_ACL_STYLE_SOLARIS 0x00000004
573
#define ARCHIVE_ENTRY_ACL_STYLE_SEPARATOR_COMMA 0x00000008
574
#define ARCHIVE_ENTRY_ACL_STYLE_COMPACT 0x00000010
575
576
__LA_DECL wchar_t *archive_entry_acl_to_text_w(struct archive_entry *,
577
la_ssize_t * /* len */, int /* flags */);
578
__LA_DECL char *archive_entry_acl_to_text(struct archive_entry *,
579
la_ssize_t * /* len */, int /* flags */);
580
__LA_DECL int archive_entry_acl_from_text_w(struct archive_entry *,
581
const wchar_t * /* wtext */, int /* type */);
582
__LA_DECL int archive_entry_acl_from_text(struct archive_entry *,
583
const char * /* text */, int /* type */);
584
585
/* Deprecated constants */
586
#define OLD_ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024
587
#define OLD_ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048
588
589
/* Deprecated functions */
590
__LA_DECL const wchar_t *archive_entry_acl_text_w(struct archive_entry *,
591
int /* flags */) __LA_DEPRECATED;
592
__LA_DECL const char *archive_entry_acl_text(struct archive_entry *,
593
int /* flags */) __LA_DEPRECATED;
594
595
/* Return bitmask of ACL types in an archive entry */
596
__LA_DECL int archive_entry_acl_types(struct archive_entry *);
597
598
/* Return a count of entries matching 'want_type' */
599
__LA_DECL int archive_entry_acl_count(struct archive_entry *, int /* want_type */);
600
601
/* Return an opaque ACL object. */
602
/* There's not yet anything clients can actually do with this... */
603
struct archive_acl;
604
__LA_DECL struct archive_acl *archive_entry_acl(struct archive_entry *);
605
606
/*
607
* extended attributes
608
*/
609
610
__LA_DECL void archive_entry_xattr_clear(struct archive_entry *);
611
__LA_DECL void archive_entry_xattr_add_entry(struct archive_entry *,
612
const char * /* name */, const void * /* value */,
613
size_t /* size */);
614
615
/*
616
* To retrieve the xattr list, first "reset", then repeatedly ask for the
617
* "next" entry.
618
*/
619
620
__LA_DECL int archive_entry_xattr_count(struct archive_entry *);
621
__LA_DECL int archive_entry_xattr_reset(struct archive_entry *);
622
__LA_DECL int archive_entry_xattr_next(struct archive_entry *,
623
const char ** /* name */, const void ** /* value */, size_t *);
624
625
/*
626
* sparse
627
*/
628
629
__LA_DECL void archive_entry_sparse_clear(struct archive_entry *);
630
__LA_DECL void archive_entry_sparse_add_entry(struct archive_entry *,
631
la_int64_t /* offset */, la_int64_t /* length */);
632
633
/*
634
* To retrieve the xattr list, first "reset", then repeatedly ask for the
635
* "next" entry.
636
*/
637
638
__LA_DECL int archive_entry_sparse_count(struct archive_entry *);
639
__LA_DECL int archive_entry_sparse_reset(struct archive_entry *);
640
__LA_DECL int archive_entry_sparse_next(struct archive_entry *,
641
la_int64_t * /* offset */, la_int64_t * /* length */);
642
643
/*
644
* Utility to match up hardlinks.
645
*
646
* The 'struct archive_entry_linkresolver' is a cache of archive entries
647
* for files with multiple links. Here's how to use it:
648
* 1. Create a lookup object with archive_entry_linkresolver_new()
649
* 2. Tell it the archive format you're using.
650
* 3. Hand each archive_entry to archive_entry_linkify().
651
* That function will return 0, 1, or 2 entries that should
652
* be written.
653
* 4. Call archive_entry_linkify(resolver, NULL) until
654
* no more entries are returned.
655
* 5. Call archive_entry_linkresolver_free(resolver) to free resources.
656
*
657
* The entries returned have their hardlink and size fields updated
658
* appropriately. If an entry is passed in that does not refer to
659
* a file with multiple links, it is returned unchanged. The intention
660
* is that you should be able to simply filter all entries through
661
* this machine.
662
*
663
* To make things more efficient, be sure that each entry has a valid
664
* nlinks value. The hardlink cache uses this to track when all links
665
* have been found. If the nlinks value is zero, it will keep every
666
* name in the cache indefinitely, which can use a lot of memory.
667
*
668
* Note that archive_entry_size() is reset to zero if the file
669
* body should not be written to the archive. Pay attention!
670
*/
671
struct archive_entry_linkresolver;
672
673
/*
674
* There are three different strategies for marking hardlinks.
675
* The descriptions below name them after the best-known
676
* formats that rely on each strategy:
677
*
678
* "Old cpio" is the simplest, it always returns any entry unmodified.
679
* As far as I know, only cpio formats use this. Old cpio archives
680
* store every link with the full body; the onus is on the dearchiver
681
* to detect and properly link the files as they are restored.
682
* "tar" is also pretty simple; it caches a copy the first time it sees
683
* any link. Subsequent appearances are modified to be hardlink
684
* references to the first one without any body. Used by all tar
685
* formats, although the newest tar formats permit the "old cpio" strategy
686
* as well. This strategy is very simple for the dearchiver,
687
* and reasonably straightforward for the archiver.
688
* "new cpio" is trickier. It stores the body only with the last
689
* occurrence. The complication is that we might not
690
* see every link to a particular file in a single session, so
691
* there's no easy way to know when we've seen the last occurrence.
692
* The solution here is to queue one link until we see the next.
693
* At the end of the session, you can enumerate any remaining
694
* entries by calling archive_entry_linkify(NULL) and store those
695
* bodies. If you have a file with three links l1, l2, and l3,
696
* you'll get the following behavior if you see all three links:
697
* linkify(l1) => NULL (the resolver stores l1 internally)
698
* linkify(l2) => l1 (resolver stores l2, you write l1)
699
* linkify(l3) => l2, l3 (all links seen, you can write both).
700
* If you only see l1 and l2, you'll get this behavior:
701
* linkify(l1) => NULL
702
* linkify(l2) => l1
703
* linkify(NULL) => l2 (at end, you retrieve remaining links)
704
* As the name suggests, this strategy is used by newer cpio variants.
705
* It's noticeably more complex for the archiver, slightly more complex
706
* for the dearchiver than the tar strategy, but makes it straightforward
707
* to restore a file using any link by simply continuing to scan until
708
* you see a link that is stored with a body. In contrast, the tar
709
* strategy requires you to rescan the archive from the beginning to
710
* correctly extract an arbitrary link.
711
*/
712
713
__LA_DECL struct archive_entry_linkresolver *archive_entry_linkresolver_new(void);
714
__LA_DECL void archive_entry_linkresolver_set_strategy(
715
struct archive_entry_linkresolver *, int /* format_code */);
716
__LA_DECL void archive_entry_linkresolver_free(struct archive_entry_linkresolver *);
717
__LA_DECL void archive_entry_linkify(struct archive_entry_linkresolver *,
718
struct archive_entry **, struct archive_entry **);
719
__LA_DECL struct archive_entry *archive_entry_partial_links(
720
struct archive_entry_linkresolver *res, unsigned int *links);
721
#ifdef __cplusplus
722
}
723
#endif
724
725
/* This is meaningless outside of this header. */
726
#undef __LA_DECL
727
728
#endif /* !ARCHIVE_ENTRY_H_INCLUDED */
729
730