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