summaryrefslogtreecommitdiffstats
path: root/usr.bin/tar
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2008-03-15 03:06:46 +0000
committerkientzle <kientzle@FreeBSD.org>2008-03-15 03:06:46 +0000
commite3d8bdbf5590edf7776ca1213dbcfc2634d98bb0 (patch)
treeb71d9b5155e2b02073080b764627ba88dde1d40a /usr.bin/tar
parent0d1e934945c730a93df2007db901e3c2d434a2f3 (diff)
downloadFreeBSD-src-e3d8bdbf5590edf7776ca1213dbcfc2634d98bb0.zip
FreeBSD-src-e3d8bdbf5590edf7776ca1213dbcfc2634d98bb0.tar.gz
--chroot implementation thanks to Joerg Sonnenberger.
Diffstat (limited to 'usr.bin/tar')
-rw-r--r--usr.bin/tar/bsdtar.c5
-rw-r--r--usr.bin/tar/bsdtar.h1
-rw-r--r--usr.bin/tar/config_freebsd.h1
-rw-r--r--usr.bin/tar/read.c11
4 files changed, 18 insertions, 0 deletions
diff --git a/usr.bin/tar/bsdtar.c b/usr.bin/tar/bsdtar.c
index bf98d68..d37aa4c 100644
--- a/usr.bin/tar/bsdtar.c
+++ b/usr.bin/tar/bsdtar.c
@@ -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,
diff --git a/usr.bin/tar/bsdtar.h b/usr.bin/tar/bsdtar.h
index 2dfa7e7..6748560 100644
--- a/usr.bin/tar/bsdtar.h
+++ b/usr.bin/tar/bsdtar.h
@@ -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 */
diff --git a/usr.bin/tar/config_freebsd.h b/usr.bin/tar/config_freebsd.h
index e24f437..e118ef1 100644
--- a/usr.bin/tar/config_freebsd.h
+++ b/usr.bin/tar/config_freebsd.h
@@ -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
diff --git a/usr.bin/tar/read.c b/usr.bin/tar/read.c
index de08fd1..a0267a3 100644
--- a/usr.bin/tar/read.c
+++ b/usr.bin/tar/read.c
@@ -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 &&
OpenPOWER on IntegriCloud