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