]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Port the --gname, --uname, --uid, --gid options from libarchive/trunk.
authorTim Kientzle <kientzle@gmail.com>
Sat, 22 Oct 2011 16:39:25 +0000 (12:39 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sat, 22 Oct 2011 16:39:25 +0000 (12:39 -0400)
SVN-Revision: 3738

tar/bsdtar.1
tar/bsdtar.c
tar/bsdtar.h
tar/cmdline.c
tar/read.c
tar/write.c

index 74fa1eac8abba34b4039df35e71d0062a92e5db3..dd2a7ddda836e2e841304c762c1692532f72203f 100644 (file)
@@ -182,6 +182,27 @@ If not specified, the default tape device will be used.
 .Fx ,
 the default tape device is
 .Pa /dev/sa0 . )
+.It Fl Fl gid Ar id
+Use the provided group id number.
+On extract, this overrides the group id in the archive;
+the group name in the archive will be ignored.
+On create, this overrides the group id read from disk;
+if
+.Fl Fl gname
+is not also specified, the group name will be set to
+match the group id.
+.It Fl Fl gname Ar name
+Use the provided group name.
+On extract, this overrides the group name in the archive;
+if the provided group name does not exist on the system,
+the group id
+(from the archive or from the
+.Fl Fl gid
+option)
+will be used instead.
+On create, this sets the group name that will be stored
+in the archive;
+the name will not be verified against the system group database.
 .It Fl H
 (c and r mode only)
 Symbolic links named on the command line will be followed; the
@@ -282,6 +303,33 @@ option to
 (x mode only)
 Ignore symbolic user and group names when restoring archives to disk,
 only numeric uid and gid values will be obeyed.
+.It Fl Fl no-same-owner
+(x mode only)
+Do not extract owner and group IDs.
+This is the reverse of
+.Fl Fl same-owner
+and the default behavior if
+.Nm
+is run as non-root.
+.It Fl Fl no-same-permissions
+(x mode only)
+Do not extract full permissions (SGID, SUID, sticky bit, ACLs,
+extended attributes or extended file flags).
+This is the reverse of
+.Fl p
+and the default behavior if
+.Nm
+is run as non-root.
+.It Fl Fl numeric-owner
+This is equivalent to
+.Fl Fl uname
+.Qq
+.Fl Fl gname
+.Qq .
+On extract, it causes user and group names in the archive
+to be ignored in favor of the numeric user and group ids.
+On create, it causes user and group names to not be stored
+in the archive.
 .It Fl O
 (x, t modes only)
 In extract (-x) mode, files will be written to standard out rather than
@@ -476,7 +524,26 @@ Without this option,
 overwrites existing files, which preserves existing hardlinks.
 With this option, existing hardlinks will be broken, as will any
 symlink that would affect the location of an extracted file.
-.It Fl -use-compress-program Ar program
+.It Fl Fl uid Ar id
+Use the provided user id number and ignore the user
+name from the archive.
+On create, if
+.Fl Fl uname
+is not also specified, the user name will be set to
+match the user id.
+.It Fl Fl uname Ar name
+Use the provided user name.
+On extract, this overrides the user name in the archive;
+if the provided user name does not exist on the system,
+it will be ignored and the user id
+(from the archive or from the
+.Fl Fl uid
+option)
+will be used instead.
+On create, this sets the user name that will be stored
+in the archive;
+the name is not verified against the system user database.
+.It Fl Fl use-compress-program Ar program
 Pipe the input (in x or t mode) or the output (in c mode) through
 .Pa program
 instead of using the builtin compression support.
index d8f8286842e9cb4aa996a4471295b35e4695783e..3b227bcce81ee5b8a047ec6ae34ee5b5730faf73 100644 (file)
@@ -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))
@@ -263,14 +265,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;
@@ -398,7 +407,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;
@@ -409,6 +419,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
@@ -474,6 +487,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;
index 5e8dc7f89ec57b57f1a3911533d9c9434ee8259e..893ebca5d4a59094ab8b28bc31202c2403dffb41 100644 (file)
@@ -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
 };
index ba3e8a1b2a88b3c472292e2f4c91b39d29d88bf9..f0431554c521320d8426f06ede082a331e383d01 100644 (file)
@@ -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' },
index aaaacac0dcaa2c82567d31dd8dbd6f3f2f513ef9..278921ef8f201c9323ce3d81e9d397029b27f839 100644 (file)
@@ -204,10 +204,18 @@ read_archive(struct bsdtar *bsdtar, char mode)
                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.
index 163611490db322dea1ef99930b8b1fc60a0f5d98..32ee2b6d83bca1a7c917d048185ca7f554675471 100644 (file)
@@ -824,6 +824,24 @@ write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path)
 #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));