2011-12-20 22:47:56 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003-2007 Tim Kientzle
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD: src/usr.bin/tar/bsdtar.h,v 1.37 2008/12/06 07:37:14 kientzle Exp $
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bsdtar_platform.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define DEFAULT_BYTES_PER_BLOCK (20*512)
|
2013-03-21 18:59:02 +00:00
|
|
|
#define ENV_READER_OPTIONS "TAR_READER_OPTIONS"
|
|
|
|
#define ENV_WRITER_OPTIONS "TAR_WRITER_OPTIONS"
|
|
|
|
#define IGNORE_WRONG_MODULE_NAME "__ignore_wrong_module_name__,"
|
2011-12-20 22:47:56 +00:00
|
|
|
|
2013-03-21 18:59:02 +00:00
|
|
|
struct creation_set;
|
2011-12-20 22:47:56 +00:00
|
|
|
/*
|
|
|
|
* The internal state for the "bsdtar" program.
|
|
|
|
*
|
|
|
|
* Keeping all of the state in a structure like this simplifies memory
|
|
|
|
* leak testing (at exit, anything left on the heap is suspect). A
|
|
|
|
* pointer to this structure is passed to most bsdtar internal
|
|
|
|
* functions.
|
|
|
|
*/
|
|
|
|
struct bsdtar {
|
|
|
|
/* Options */
|
|
|
|
const char *filename; /* -f filename */
|
|
|
|
char *pending_chdir; /* -C dir */
|
|
|
|
const char *names_from_file; /* -T file */
|
|
|
|
int bytes_per_block; /* -b block_size */
|
2012-02-08 12:53:14 +00:00
|
|
|
int bytes_in_last_block; /* See -b handling. */
|
2011-12-20 22:47:56 +00:00
|
|
|
int verbose; /* -v */
|
2017-03-02 21:02:17 +00:00
|
|
|
unsigned int flags; /* Bitfield of boolean options */
|
2011-12-20 22:47:56 +00:00
|
|
|
int extract_flags; /* Flags for extract operation */
|
2012-07-27 08:24:12 +00:00
|
|
|
int readdisk_flags; /* Flags for read disk operation */
|
2011-12-20 22:47:56 +00:00
|
|
|
int strip_components; /* Remove this many leading dirs */
|
|
|
|
int gid; /* --gid */
|
|
|
|
const char *gname; /* --gname */
|
|
|
|
int uid; /* --uid */
|
|
|
|
const char *uname; /* --uname */
|
2016-05-11 10:19:44 +00:00
|
|
|
const char *passphrase; /* --passphrase */
|
2011-12-20 22:47:56 +00:00
|
|
|
char mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */
|
|
|
|
char symlink_mode; /* H or L, per BSD conventions */
|
|
|
|
const char *option_options; /* --options */
|
|
|
|
char day_first; /* show day before month in -tv output */
|
2013-03-21 18:59:02 +00:00
|
|
|
struct creation_set *cset;
|
2012-02-08 12:53:14 +00:00
|
|
|
|
|
|
|
/* Option parser state */
|
|
|
|
int getopt_state;
|
|
|
|
char *getopt_word;
|
2011-12-20 22:47:56 +00:00
|
|
|
|
|
|
|
/* If >= 0, then close this when done. */
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/* Miscellaneous state information */
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
2012-02-08 12:53:14 +00:00
|
|
|
const char *argument;
|
2011-12-20 22:47:56 +00:00
|
|
|
size_t gs_width; /* For 'list_item' in read.c */
|
|
|
|
size_t u_width; /* for 'list_item' in read.c */
|
|
|
|
uid_t user_uid; /* UID running this program */
|
|
|
|
int return_value; /* Value returned by main() */
|
|
|
|
char warned_lead_slash; /* Already displayed warning */
|
|
|
|
char next_line_is_dir; /* Used for -C parsing in -cT */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Data for various subsystems. Full definitions are located in
|
|
|
|
* the file where they are used.
|
|
|
|
*/
|
|
|
|
struct archive *diskreader; /* for write.c */
|
|
|
|
struct archive_entry_linkresolver *resolver; /* for write.c */
|
|
|
|
struct archive_dir *archive_dir; /* for write.c */
|
|
|
|
struct name_cache *gname_cache; /* for write.c */
|
|
|
|
char *buff; /* for write.c */
|
2012-02-08 12:53:14 +00:00
|
|
|
size_t buff_size; /* for write.c */
|
2012-07-27 08:24:12 +00:00
|
|
|
int first_fs; /* for write.c */
|
|
|
|
struct archive *matching; /* for matching.c */
|
2011-12-20 22:47:56 +00:00
|
|
|
struct security *security; /* for read.c */
|
|
|
|
struct name_cache *uname_cache; /* for write.c */
|
|
|
|
struct siginfo_data *siginfo; /* for siginfo.c */
|
|
|
|
struct substitution *substitution; /* for subst.c */
|
2016-05-11 10:19:44 +00:00
|
|
|
char *ppbuff; /* for util.c */
|
2011-12-20 22:47:56 +00:00
|
|
|
};
|
|
|
|
|
2017-03-02 21:02:17 +00:00
|
|
|
/* Options for flags bitfield */
|
|
|
|
#define OPTFLAG_AUTO_COMPRESS (0x00000001) /* -a */
|
|
|
|
#define OPTFLAG_ABSOLUTE_PATHS (0x00000002) /* -P */
|
|
|
|
#define OPTFLAG_CHROOT (0x00000004) /* --chroot */
|
|
|
|
#define OPTFLAG_FAST_READ (0x00000008) /* --fast-read */
|
|
|
|
#define OPTFLAG_IGNORE_ZEROS (0x00000010) /* --ignore-zeros */
|
|
|
|
#define OPTFLAG_INTERACTIVE (0x00000020) /* -w */
|
|
|
|
#define OPTFLAG_NO_OWNER (0x00000040) /* -o */
|
|
|
|
#define OPTFLAG_NO_SUBDIRS (0x00000080) /* -n */
|
|
|
|
#define OPTFLAG_NULL (0x00000100) /* --null */
|
|
|
|
#define OPTFLAG_NUMERIC_OWNER (0x00000200) /* --numeric-owner */
|
|
|
|
#define OPTFLAG_O (0x00000400) /* -o */
|
|
|
|
#define OPTFLAG_STDOUT (0x00000800) /* -O */
|
|
|
|
#define OPTFLAG_TOTALS (0x00001000) /* --totals */
|
|
|
|
#define OPTFLAG_UNLINK_FIRST (0x00002000) /* -U */
|
|
|
|
#define OPTFLAG_WARN_LINKS (0x00004000) /* --check-links */
|
|
|
|
#define OPTFLAG_NO_XATTRS (0x00008000) /* --no-xattrs */
|
|
|
|
#define OPTFLAG_XATTRS (0x00010000) /* --xattrs */
|
|
|
|
#define OPTFLAG_NO_ACLS (0x00020000) /* --no-acls */
|
|
|
|
#define OPTFLAG_ACLS (0x00040000) /* --acls */
|
|
|
|
#define OPTFLAG_NO_FFLAGS (0x00080000) /* --no-fflags */
|
|
|
|
#define OPTFLAG_FFLAGS (0x00100000) /* --fflags */
|
|
|
|
#define OPTFLAG_NO_MAC_METADATA (0x00200000) /* --no-mac-metadata */
|
|
|
|
#define OPTFLAG_MAC_METADATA (0x00400000) /* --mac-metadata */
|
|
|
|
|
2011-12-20 22:47:56 +00:00
|
|
|
/* Fake short equivalents for long options that otherwise lack them. */
|
|
|
|
enum {
|
2017-03-02 21:02:17 +00:00
|
|
|
OPTION_ACLS = 1,
|
|
|
|
OPTION_B64ENCODE,
|
2013-03-21 18:59:02 +00:00
|
|
|
OPTION_CHECK_LINKS,
|
2011-12-20 22:47:56 +00:00
|
|
|
OPTION_CHROOT,
|
2016-05-11 10:19:44 +00:00
|
|
|
OPTION_CLEAR_NOCHANGE_FFLAGS,
|
2011-12-20 22:47:56 +00:00
|
|
|
OPTION_EXCLUDE,
|
2017-03-02 21:02:17 +00:00
|
|
|
OPTION_FFLAGS,
|
2011-12-20 22:47:56 +00:00
|
|
|
OPTION_FORMAT,
|
|
|
|
OPTION_GID,
|
|
|
|
OPTION_GNAME,
|
2013-03-21 18:59:02 +00:00
|
|
|
OPTION_GRZIP,
|
2011-12-20 22:47:56 +00:00
|
|
|
OPTION_HELP,
|
2013-03-21 18:59:02 +00:00
|
|
|
OPTION_HFS_COMPRESSION,
|
2016-05-11 10:19:44 +00:00
|
|
|
OPTION_IGNORE_ZEROS,
|
2011-12-20 22:47:56 +00:00
|
|
|
OPTION_INCLUDE,
|
|
|
|
OPTION_KEEP_NEWER_FILES,
|
2013-03-21 18:59:02 +00:00
|
|
|
OPTION_LRZIP,
|
2016-05-11 10:19:44 +00:00
|
|
|
OPTION_LZ4,
|
2012-02-08 12:53:14 +00:00
|
|
|
OPTION_LZIP,
|
2011-12-20 22:47:56 +00:00
|
|
|
OPTION_LZMA,
|
2013-03-21 18:59:02 +00:00
|
|
|
OPTION_LZOP,
|
2017-03-02 21:02:17 +00:00
|
|
|
OPTION_MAC_METADATA,
|
2011-12-20 22:47:56 +00:00
|
|
|
OPTION_NEWER_CTIME,
|
|
|
|
OPTION_NEWER_CTIME_THAN,
|
|
|
|
OPTION_NEWER_MTIME,
|
|
|
|
OPTION_NEWER_MTIME_THAN,
|
|
|
|
OPTION_NODUMP,
|
2013-03-21 18:59:02 +00:00
|
|
|
OPTION_NOPRESERVE_HFS_COMPRESSION,
|
2017-03-02 21:02:17 +00:00
|
|
|
OPTION_NO_ACLS,
|
|
|
|
OPTION_NO_FFLAGS,
|
|
|
|
OPTION_NO_MAC_METADATA,
|
2011-12-20 22:47:56 +00:00
|
|
|
OPTION_NO_SAME_OWNER,
|
|
|
|
OPTION_NO_SAME_PERMISSIONS,
|
2017-03-02 21:02:17 +00:00
|
|
|
OPTION_NO_XATTRS,
|
2011-12-20 22:47:56 +00:00
|
|
|
OPTION_NULL,
|
|
|
|
OPTION_NUMERIC_OWNER,
|
2013-03-21 18:59:02 +00:00
|
|
|
OPTION_OLDER_CTIME,
|
|
|
|
OPTION_OLDER_CTIME_THAN,
|
|
|
|
OPTION_OLDER_MTIME,
|
|
|
|
OPTION_OLDER_MTIME_THAN,
|
2011-12-20 22:47:56 +00:00
|
|
|
OPTION_ONE_FILE_SYSTEM,
|
|
|
|
OPTION_OPTIONS,
|
2016-05-11 10:19:44 +00:00
|
|
|
OPTION_PASSPHRASE,
|
2011-12-20 22:47:56 +00:00
|
|
|
OPTION_POSIX,
|
|
|
|
OPTION_SAME_OWNER,
|
|
|
|
OPTION_STRIP_COMPONENTS,
|
|
|
|
OPTION_TOTALS,
|
|
|
|
OPTION_UID,
|
|
|
|
OPTION_UNAME,
|
|
|
|
OPTION_USE_COMPRESS_PROGRAM,
|
2013-03-21 18:59:02 +00:00
|
|
|
OPTION_UUENCODE,
|
2017-03-02 21:02:17 +00:00
|
|
|
OPTION_VERSION,
|
|
|
|
OPTION_XATTRS
|
2011-12-20 22:47:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int bsdtar_getopt(struct bsdtar *);
|
|
|
|
void do_chdir(struct bsdtar *);
|
|
|
|
int edit_pathname(struct bsdtar *, struct archive_entry *);
|
|
|
|
int need_report(void);
|
|
|
|
int pathcmp(const char *a, const char *b);
|
2017-03-02 21:13:25 +00:00
|
|
|
void safe_fprintf(FILE *, const char *fmt, ...) __LA_PRINTF(2, 3);
|
2011-12-20 22:47:56 +00:00
|
|
|
void set_chdir(struct bsdtar *, const char *newdir);
|
|
|
|
const char *tar_i64toa(int64_t);
|
|
|
|
void tar_mode_c(struct bsdtar *bsdtar);
|
|
|
|
void tar_mode_r(struct bsdtar *bsdtar);
|
|
|
|
void tar_mode_t(struct bsdtar *bsdtar);
|
|
|
|
void tar_mode_u(struct bsdtar *bsdtar);
|
|
|
|
void tar_mode_x(struct bsdtar *bsdtar);
|
2017-03-02 21:13:25 +00:00
|
|
|
void usage(void) __LA_DEAD;
|
|
|
|
int yes(const char *fmt, ...) __LA_PRINTF(1, 2);
|
2011-12-20 22:47:56 +00:00
|
|
|
|
2013-03-21 18:59:02 +00:00
|
|
|
#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
|
2011-12-20 22:47:56 +00:00
|
|
|
void add_substitution(struct bsdtar *, const char *);
|
2012-02-08 12:53:14 +00:00
|
|
|
int apply_substitution(struct bsdtar *, const char *, char **, int, int);
|
2011-12-20 22:47:56 +00:00
|
|
|
void cleanup_substitution(struct bsdtar *);
|
|
|
|
#endif
|
2013-03-21 18:59:02 +00:00
|
|
|
|
|
|
|
void cset_add_filter(struct creation_set *, const char *);
|
|
|
|
void cset_add_filter_program(struct creation_set *, const char *);
|
|
|
|
int cset_auto_compress(struct creation_set *, const char *);
|
|
|
|
void cset_free(struct creation_set *);
|
|
|
|
const char * cset_get_format(struct creation_set *);
|
|
|
|
struct creation_set *cset_new(void);
|
|
|
|
int cset_read_support_filter_program(struct creation_set *,
|
|
|
|
struct archive *);
|
|
|
|
void cset_set_format(struct creation_set *, const char *);
|
|
|
|
int cset_write_add_filters(struct creation_set *,
|
|
|
|
struct archive *, const void **);
|
|
|
|
|
2016-05-11 10:19:44 +00:00
|
|
|
const char * passphrase_callback(struct archive *, void *);
|
|
|
|
void passphrase_free(char *);
|
|
|
|
void list_item_verbose(struct bsdtar *, FILE *,
|
|
|
|
struct archive_entry *);
|