--chroot implementation thanks to Joerg Sonnenberger.

This commit is contained in:
kientzle 2008-03-15 03:06:46 +00:00
parent 0d1e934945
commit e3d8bdbf55
4 changed files with 18 additions and 0 deletions

View File

@ -137,6 +137,7 @@ static const char *tar_opts = "+Bb:C:cf:HhI:jkLlmnOoPprtT:UuvW:wX:xyZz";
/* Fake short equivalents for long options that otherwise lack them. */
enum {
OPTION_CHECK_LINKS=1,
OPTION_CHROOT,
OPTION_EXCLUDE,
OPTION_FAST_READ,
OPTION_FORMAT,
@ -171,6 +172,7 @@ static const struct option tar_longopts[] = {
{ "bzip2", no_argument, NULL, 'j' },
{ "cd", required_argument, NULL, 'C' },
{ "check-links", no_argument, NULL, OPTION_CHECK_LINKS },
{ "chroot", no_argument, NULL, OPTION_CHROOT },
{ "compress", no_argument, NULL, 'Z' },
{ "confirmation", no_argument, NULL, 'w' },
{ "create", no_argument, NULL, 'c' },
@ -322,6 +324,9 @@ main(int argc, char **argv)
case OPTION_CHECK_LINKS: /* GNU tar */
bsdtar->option_warn_links = 1;
break;
case OPTION_CHROOT: /* NetBSD */
bsdtar->option_chroot = 1;
break;
case OPTION_EXCLUDE: /* GNU tar */
if (exclude(bsdtar, optarg))
bsdtar_errc(bsdtar, 1, 0,

View File

@ -57,6 +57,7 @@ struct bsdtar {
char create_compression; /* j, y, or z */
const char *compress_program;
char option_absolute_paths; /* -P */
char option_chroot; /* --chroot */
char option_dont_traverse_mounts; /* --one-file-system */
char option_fast_read; /* --fast-read */
char option_honor_nodump; /* --nodump */

View File

@ -38,6 +38,7 @@
#undef HAVE_ATTR_XATTR_H
#define HAVE_BZLIB_H 1
#define HAVE_CHFLAGS 1
#define HAVE_CHROOT 1
#define HAVE_DECL_OPTARG 1
#define HAVE_DECL_OPTIND 1
#define HAVE_DIRENT_D_NAMLEN 1

View File

@ -118,6 +118,17 @@ read_archive(struct bsdtar *bsdtar, char mode)
archive_error_string(a));
do_chdir(bsdtar);
if (mode == 'x' && bsdtar->option_chroot) {
#if HAVE_CHROOT
if (chroot(".") != 0)
bsdtar_errc(bsdtar, 1, errno, "Can't chroot to \".\"");
#else
bsdtar_errc(bsdtar, 1, 0,
"chroot isn't supported on this platform");
#endif
}
for (;;) {
/* Support --fast-read option */
if (bsdtar->option_fast_read &&