1228753Smm/*- 2228753Smm * Copyright (c) 2003-2007 Tim Kientzle 3228753Smm * All rights reserved. 4228753Smm * 5228753Smm * Redistribution and use in source and binary forms, with or without 6228753Smm * modification, are permitted provided that the following conditions 7228753Smm * are met: 8228753Smm * 1. Redistributions of source code must retain the above copyright 9228753Smm * notice, this list of conditions and the following disclaimer. 10228753Smm * 2. Redistributions in binary form must reproduce the above copyright 11228753Smm * notice, this list of conditions and the following disclaimer in the 12228753Smm * documentation and/or other materials provided with the distribution. 13228753Smm * 14228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24228753Smm * 25228763Smm * $FreeBSD: releng/11.0/contrib/libarchive/tar/bsdtar.h 299529 2016-05-12 10:16:16Z mm $ 26228753Smm */ 27228753Smm 28228753Smm#include "bsdtar_platform.h" 29228753Smm#include <stdio.h> 30228753Smm 31228753Smm#define DEFAULT_BYTES_PER_BLOCK (20*512) 32248616Smm#define ENV_READER_OPTIONS "TAR_READER_OPTIONS" 33248616Smm#define ENV_WRITER_OPTIONS "TAR_WRITER_OPTIONS" 34248616Smm#define IGNORE_WRONG_MODULE_NAME "__ignore_wrong_module_name__," 35228753Smm 36248616Smmstruct creation_set; 37228753Smm/* 38228753Smm * The internal state for the "bsdtar" program. 39228753Smm * 40228753Smm * Keeping all of the state in a structure like this simplifies memory 41228753Smm * leak testing (at exit, anything left on the heap is suspect). A 42228753Smm * pointer to this structure is passed to most bsdtar internal 43228753Smm * functions. 44228753Smm */ 45228753Smmstruct bsdtar { 46228753Smm /* Options */ 47228753Smm const char *filename; /* -f filename */ 48228753Smm char *pending_chdir; /* -C dir */ 49228753Smm const char *names_from_file; /* -T file */ 50228753Smm int bytes_per_block; /* -b block_size */ 51232153Smm int bytes_in_last_block; /* See -b handling. */ 52228753Smm int verbose; /* -v */ 53228753Smm int extract_flags; /* Flags for extract operation */ 54238856Smm int readdisk_flags; /* Flags for read disk operation */ 55228753Smm int strip_components; /* Remove this many leading dirs */ 56228753Smm int gid; /* --gid */ 57228753Smm const char *gname; /* --gname */ 58228753Smm int uid; /* --uid */ 59228753Smm const char *uname; /* --uname */ 60299529Smm const char *passphrase; /* --passphrase */ 61228753Smm char mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */ 62228753Smm char symlink_mode; /* H or L, per BSD conventions */ 63228753Smm char option_absolute_paths; /* -P */ 64228753Smm char option_chroot; /* --chroot */ 65228753Smm char option_fast_read; /* --fast-read */ 66228753Smm const char *option_options; /* --options */ 67299529Smm char option_ignore_zeros; /* --ignore-zeros */ 68228753Smm char option_interactive; /* -w */ 69228753Smm char option_no_owner; /* -o */ 70228753Smm char option_no_subdirs; /* -n */ 71232153Smm char option_numeric_owner; /* --numeric-owner */ 72228753Smm char option_null; /* --null */ 73228753Smm char option_stdout; /* -O */ 74228753Smm char option_totals; /* --totals */ 75228753Smm char option_unlink_first; /* -U */ 76228753Smm char option_warn_links; /* --check-links */ 77228753Smm char day_first; /* show day before month in -tv output */ 78248616Smm struct creation_set *cset; 79228753Smm 80232153Smm /* Option parser state */ 81232153Smm int getopt_state; 82232153Smm char *getopt_word; 83232153Smm 84228753Smm /* If >= 0, then close this when done. */ 85228753Smm int fd; 86228753Smm 87228753Smm /* Miscellaneous state information */ 88228753Smm int argc; 89228753Smm char **argv; 90232153Smm const char *argument; 91228753Smm size_t gs_width; /* For 'list_item' in read.c */ 92228753Smm size_t u_width; /* for 'list_item' in read.c */ 93228753Smm uid_t user_uid; /* UID running this program */ 94228753Smm int return_value; /* Value returned by main() */ 95228753Smm char warned_lead_slash; /* Already displayed warning */ 96228753Smm char next_line_is_dir; /* Used for -C parsing in -cT */ 97228753Smm 98228753Smm /* 99228753Smm * Data for various subsystems. Full definitions are located in 100228753Smm * the file where they are used. 101228753Smm */ 102228753Smm struct archive *diskreader; /* for write.c */ 103228753Smm struct archive_entry_linkresolver *resolver; /* for write.c */ 104228753Smm struct archive_dir *archive_dir; /* for write.c */ 105228753Smm struct name_cache *gname_cache; /* for write.c */ 106228753Smm char *buff; /* for write.c */ 107232153Smm size_t buff_size; /* for write.c */ 108238856Smm int first_fs; /* for write.c */ 109238856Smm struct archive *matching; /* for matching.c */ 110228753Smm struct security *security; /* for read.c */ 111228753Smm struct name_cache *uname_cache; /* for write.c */ 112228753Smm struct siginfo_data *siginfo; /* for siginfo.c */ 113228753Smm struct substitution *substitution; /* for subst.c */ 114299529Smm char *ppbuff; /* for util.c */ 115228753Smm}; 116228753Smm 117228753Smm/* Fake short equivalents for long options that otherwise lack them. */ 118228753Smmenum { 119248616Smm OPTION_B64ENCODE = 1, 120248616Smm OPTION_CHECK_LINKS, 121228753Smm OPTION_CHROOT, 122299529Smm OPTION_CLEAR_NOCHANGE_FFLAGS, 123232153Smm OPTION_DISABLE_COPYFILE, 124228753Smm OPTION_EXCLUDE, 125228753Smm OPTION_FORMAT, 126228753Smm OPTION_GID, 127228753Smm OPTION_GNAME, 128248616Smm OPTION_GRZIP, 129228753Smm OPTION_HELP, 130248616Smm OPTION_HFS_COMPRESSION, 131299529Smm OPTION_IGNORE_ZEROS, 132228753Smm OPTION_INCLUDE, 133228753Smm OPTION_KEEP_NEWER_FILES, 134248616Smm OPTION_LRZIP, 135299529Smm OPTION_LZ4, 136232153Smm OPTION_LZIP, 137228753Smm OPTION_LZMA, 138248616Smm OPTION_LZOP, 139228753Smm OPTION_NEWER_CTIME, 140228753Smm OPTION_NEWER_CTIME_THAN, 141228753Smm OPTION_NEWER_MTIME, 142228753Smm OPTION_NEWER_MTIME_THAN, 143228753Smm OPTION_NODUMP, 144248616Smm OPTION_NOPRESERVE_HFS_COMPRESSION, 145228753Smm OPTION_NO_SAME_OWNER, 146228753Smm OPTION_NO_SAME_PERMISSIONS, 147299529Smm OPTION_NO_XATTR, 148228753Smm OPTION_NULL, 149228753Smm OPTION_NUMERIC_OWNER, 150248616Smm OPTION_OLDER_CTIME, 151248616Smm OPTION_OLDER_CTIME_THAN, 152248616Smm OPTION_OLDER_MTIME, 153248616Smm OPTION_OLDER_MTIME_THAN, 154228753Smm OPTION_ONE_FILE_SYSTEM, 155228753Smm OPTION_OPTIONS, 156299529Smm OPTION_PASSPHRASE, 157228753Smm OPTION_POSIX, 158228753Smm OPTION_SAME_OWNER, 159228753Smm OPTION_STRIP_COMPONENTS, 160228753Smm OPTION_TOTALS, 161228753Smm OPTION_UID, 162228753Smm OPTION_UNAME, 163228753Smm OPTION_USE_COMPRESS_PROGRAM, 164248616Smm OPTION_UUENCODE, 165228753Smm OPTION_VERSION 166228753Smm}; 167228753Smm 168228753Smmint bsdtar_getopt(struct bsdtar *); 169228753Smmvoid do_chdir(struct bsdtar *); 170228753Smmint edit_pathname(struct bsdtar *, struct archive_entry *); 171228753Smmint need_report(void); 172228753Smmint pathcmp(const char *a, const char *b); 173228753Smmvoid safe_fprintf(FILE *, const char *fmt, ...); 174228753Smmvoid set_chdir(struct bsdtar *, const char *newdir); 175228753Smmconst char *tar_i64toa(int64_t); 176228753Smmvoid tar_mode_c(struct bsdtar *bsdtar); 177228753Smmvoid tar_mode_r(struct bsdtar *bsdtar); 178228753Smmvoid tar_mode_t(struct bsdtar *bsdtar); 179228753Smmvoid tar_mode_u(struct bsdtar *bsdtar); 180228753Smmvoid tar_mode_x(struct bsdtar *bsdtar); 181228753Smmvoid usage(void); 182228753Smmint yes(const char *fmt, ...); 183228753Smm 184248616Smm#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) 185228753Smmvoid add_substitution(struct bsdtar *, const char *); 186232153Smmint apply_substitution(struct bsdtar *, const char *, char **, int, int); 187228753Smmvoid cleanup_substitution(struct bsdtar *); 188228753Smm#endif 189248616Smm 190248616Smmvoid cset_add_filter(struct creation_set *, const char *); 191248616Smmvoid cset_add_filter_program(struct creation_set *, const char *); 192248616Smmint cset_auto_compress(struct creation_set *, const char *); 193248616Smmvoid cset_free(struct creation_set *); 194248616Smmconst char * cset_get_format(struct creation_set *); 195248616Smmstruct creation_set *cset_new(void); 196248616Smmint cset_read_support_filter_program(struct creation_set *, 197248616Smm struct archive *); 198248616Smmvoid cset_set_format(struct creation_set *, const char *); 199248616Smmint cset_write_add_filters(struct creation_set *, 200248616Smm struct archive *, const void **); 201248616Smm 202299529Smmconst char * passphrase_callback(struct archive *, void *); 203299529Smmvoid passphrase_free(char *); 204299529Smmvoid list_item_verbose(struct bsdtar *, FILE *, 205299529Smm struct archive_entry *); 206