From owner-svn-src-all@FreeBSD.ORG Sat Oct 22 16:52:05 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 49C7D106564A; Sat, 22 Oct 2011 16:52:05 +0000 (UTC) (envelope-from kientzle@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 393058FC14; Sat, 22 Oct 2011 16:52:05 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p9MGq5HQ087749; Sat, 22 Oct 2011 16:52:05 GMT (envelope-from kientzle@svn.freebsd.org) Received: (from kientzle@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p9MGq57j087743; Sat, 22 Oct 2011 16:52:05 GMT (envelope-from kientzle@svn.freebsd.org) Message-Id: <201110221652.p9MGq57j087743@svn.freebsd.org> From: Tim Kientzle Date: Sat, 22 Oct 2011 16:52:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226635 - head/usr.bin/tar X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 Oct 2011 16:52:05 -0000 Author: kientzle Date: Sat Oct 22 16:52:04 2011 New Revision: 226635 URL: http://svn.freebsd.org/changeset/base/226635 Log: Bring in the --gid --gname --uid and --uname implementation from libarchive.googlecode.com. MFC after: 3 days Modified: head/usr.bin/tar/bsdtar.c head/usr.bin/tar/bsdtar.h head/usr.bin/tar/cmdline.c head/usr.bin/tar/read.c head/usr.bin/tar/write.c Modified: head/usr.bin/tar/bsdtar.c ============================================================================== --- head/usr.bin/tar/bsdtar.c Sat Oct 22 16:03:45 2011 (r226634) +++ head/usr.bin/tar/bsdtar.c Sat Oct 22 16:52:04 2011 (r226635) @@ -147,6 +147,8 @@ main(int argc, char **argv) _bsdtar = bsdtar = &bsdtar_storage; memset(bsdtar, 0, sizeof(*bsdtar)); bsdtar->fd = -1; /* Mark as "unused" */ + bsdtar->gid = -1; + bsdtar->uid = -1; option_o = 0; #if defined(HAVE_SIGACTION) && (defined(SIGINFO) || defined(SIGUSR1)) @@ -262,14 +264,21 @@ main(int argc, char **argv) case OPTION_FORMAT: /* GNU tar, others */ bsdtar->create_format = bsdtar->optarg; break; - case OPTION_OPTIONS: - bsdtar->option_options = bsdtar->optarg; - break; case 'f': /* SUSv2 */ bsdtar->filename = bsdtar->optarg; if (strcmp(bsdtar->filename, "-") == 0) bsdtar->filename = NULL; break; + case OPTION_GID: /* cpio */ + t = atoi(bsdtar->optarg); + if (t < 0) + lafe_errc(1, 0, + "Argument to --gid must be positive"); + bsdtar->gid = t; + break; + case OPTION_GNAME: /* cpio */ + bsdtar->gname = bsdtar->optarg; + break; case 'H': /* BSD convention */ bsdtar->symlink_mode = 'H'; break; @@ -397,7 +406,8 @@ main(int argc, char **argv) bsdtar->option_null++; break; case OPTION_NUMERIC_OWNER: /* GNU tar */ - bsdtar->option_numeric_owner++; + bsdtar->uname = ""; + bsdtar->gname = ""; break; case 'O': /* GNU tar */ bsdtar->option_stdout = 1; @@ -408,6 +418,9 @@ main(int argc, char **argv) case OPTION_ONE_FILE_SYSTEM: /* GNU tar */ bsdtar->option_dont_traverse_mounts = 1; break; + case OPTION_OPTIONS: + bsdtar->option_options = bsdtar->optarg; + break; #if 0 /* * The common BSD -P option is not necessary, since @@ -473,6 +486,16 @@ main(int argc, char **argv) case 'u': /* SUSv2 */ set_mode(bsdtar, opt); break; + case OPTION_UID: /* cpio */ + t = atoi(bsdtar->optarg); + if (t < 0) + lafe_errc(1, 0, + "Argument to --uid must be positive"); + bsdtar->uid = t; + break; + case OPTION_UNAME: /* cpio */ + bsdtar->uname = bsdtar->optarg; + break; case 'v': /* SUSv2 */ bsdtar->verbose++; break; Modified: head/usr.bin/tar/bsdtar.h ============================================================================== --- head/usr.bin/tar/bsdtar.h Sat Oct 22 16:03:45 2011 (r226634) +++ head/usr.bin/tar/bsdtar.h Sat Oct 22 16:52:04 2011 (r226635) @@ -54,6 +54,10 @@ struct bsdtar { int verbose; /* -v */ int extract_flags; /* Flags for extract operation */ int strip_components; /* Remove this many leading dirs */ + int gid; /* --gid */ + const char *gname; /* --gname */ + int uid; /* --uid */ + const char *uname; /* --uname */ char mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */ char symlink_mode; /* H or L, per BSD conventions */ char create_compression; /* j, y, or z */ @@ -68,7 +72,6 @@ struct bsdtar { char option_no_owner; /* -o */ char option_no_subdirs; /* -n */ char option_null; /* --null */ - char option_numeric_owner; /* --numeric-owner */ char option_stdout; /* -O */ char option_totals; /* --totals */ char option_unlink_first; /* -U */ @@ -111,7 +114,8 @@ enum { OPTION_CHROOT, OPTION_EXCLUDE, OPTION_FORMAT, - OPTION_OPTIONS, + OPTION_GID, + OPTION_GNAME, OPTION_HELP, OPTION_INCLUDE, OPTION_KEEP_NEWER_FILES, @@ -126,10 +130,13 @@ enum { OPTION_NULL, OPTION_NUMERIC_OWNER, OPTION_ONE_FILE_SYSTEM, + OPTION_OPTIONS, OPTION_POSIX, OPTION_SAME_OWNER, OPTION_STRIP_COMPONENTS, OPTION_TOTALS, + OPTION_UID, + OPTION_UNAME, OPTION_USE_COMPRESS_PROGRAM, OPTION_VERSION }; Modified: head/usr.bin/tar/cmdline.c ============================================================================== --- head/usr.bin/tar/cmdline.c Sat Oct 22 16:03:45 2011 (r226634) +++ head/usr.bin/tar/cmdline.c Sat Oct 22 16:52:04 2011 (r226635) @@ -84,7 +84,8 @@ static struct option { { "file", 1, 'f' }, { "files-from", 1, 'T' }, { "format", 1, OPTION_FORMAT }, - { "options", 1, OPTION_OPTIONS }, + { "gid", 1, OPTION_GID }, + { "gname", 1, OPTION_GNAME }, { "gunzip", 0, 'z' }, { "gzip", 0, 'z' }, { "help", 0, OPTION_HELP }, @@ -110,6 +111,7 @@ static struct option { { "null", 0, OPTION_NULL }, { "numeric-owner", 0, OPTION_NUMERIC_OWNER }, { "one-file-system", 0, OPTION_ONE_FILE_SYSTEM }, + { "options", 1, OPTION_OPTIONS }, { "posix", 0, OPTION_POSIX }, { "preserve-permissions", 0, 'p' }, { "read-full-blocks", 0, 'B' }, @@ -118,6 +120,8 @@ static struct option { { "strip-components", 1, OPTION_STRIP_COMPONENTS }, { "to-stdout", 0, 'O' }, { "totals", 0, OPTION_TOTALS }, + { "uid", 1, OPTION_UID }, + { "uname", 1, OPTION_UNAME }, { "uncompress", 0, 'Z' }, { "unlink", 0, 'U' }, { "unlink-first", 0, 'U' }, Modified: head/usr.bin/tar/read.c ============================================================================== --- head/usr.bin/tar/read.c Sat Oct 22 16:03:45 2011 (r226634) +++ head/usr.bin/tar/read.c Sat Oct 22 16:52:04 2011 (r226635) @@ -209,10 +209,18 @@ read_archive(struct bsdtar *bsdtar, char if (r == ARCHIVE_FATAL) break; - if (bsdtar->option_numeric_owner) { + if (bsdtar->uid >= 0) { + archive_entry_set_uid(entry, bsdtar->uid); archive_entry_set_uname(entry, NULL); + } + if (bsdtar->gid >= 0) { + archive_entry_set_gid(entry, bsdtar->gid); archive_entry_set_gname(entry, NULL); } + if (bsdtar->uname) + archive_entry_set_uname(entry, bsdtar->uname); + if (bsdtar->gname >= 0) + archive_entry_set_gname(entry, bsdtar->gname); /* * Exclude entries that are too old. Modified: head/usr.bin/tar/write.c ============================================================================== --- head/usr.bin/tar/write.c Sat Oct 22 16:03:45 2011 (r226634) +++ head/usr.bin/tar/write.c Sat Oct 22 16:52:04 2011 (r226635) @@ -833,6 +833,24 @@ write_hierarchy(struct bsdtar *bsdtar, s #endif r = archive_read_disk_entry_from_file(bsdtar->diskreader, entry, -1, st); + if (bsdtar->uid >= 0) { + archive_entry_set_uid(entry, bsdtar->uid); + if (!bsdtar->uname) + archive_entry_set_uname(entry, + archive_read_disk_uname(bsdtar->diskreader, + bsdtar->uid)); + } + if (bsdtar->gid >= 0) { + archive_entry_set_gid(entry, bsdtar->gid); + if (!bsdtar->gname) + archive_entry_set_gname(entry, + archive_read_disk_gname(bsdtar->diskreader, + bsdtar->gid)); + } + if (bsdtar->uname) + archive_entry_set_uname(entry, bsdtar->uname); + if (bsdtar->gname) + archive_entry_set_gname(entry, bsdtar->gname); if (r != ARCHIVE_OK) lafe_warnc(archive_errno(bsdtar->diskreader), "%s", archive_error_string(bsdtar->diskreader));