summaryrefslogtreecommitdiffstats
path: root/usr.bin/cpio
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2010-08-08 01:25:33 +0000
committerkientzle <kientzle@FreeBSD.org>2010-08-08 01:25:33 +0000
commit53521b51507eb171400e2c3246d016fc637d03e2 (patch)
tree1f09d3a85cae92398260269902fb5dff7722a3d8 /usr.bin/cpio
parent08ccc1c1b2d4b08f092d43dcd5d8135cd00a1582 (diff)
downloadFreeBSD-src-53521b51507eb171400e2c3246d016fc637d03e2.zip
FreeBSD-src-53521b51507eb171400e2c3246d016fc637d03e2.tar.gz
Fix -R when used with -p. Previously, the
uname and gname weren't overwritten, so the disk restore would use those to lookup the original uid/gid again. Clearing the uname and gname prevents this. Reported by: swell.k MFC after: 7 days
Diffstat (limited to 'usr.bin/cpio')
-rw-r--r--usr.bin/cpio/cmdline.c2
-rw-r--r--usr.bin/cpio/cpio.c18
-rw-r--r--usr.bin/cpio/cpio.h2
3 files changed, 18 insertions, 4 deletions
diff --git a/usr.bin/cpio/cmdline.c b/usr.bin/cpio/cmdline.c
index ca50ed2..f0e8ba20 100644
--- a/usr.bin/cpio/cmdline.c
+++ b/usr.bin/cpio/cmdline.c
@@ -285,6 +285,8 @@ cpio_getopt(struct cpio *cpio)
* A period can be used instead of the colon.
*
* Sets uid/gid return as appropriate, -1 indicates uid/gid not specified.
+ * TODO: If the spec uses uname/gname, then return those to the caller
+ * as well. If the spec provides uid/gid, just return names as NULL.
*
* Returns NULL if no error, otherwise returns error string for display.
*
diff --git a/usr.bin/cpio/cpio.c b/usr.bin/cpio/cpio.c
index 9b76fe8..ab32224 100644
--- a/usr.bin/cpio/cpio.c
+++ b/usr.bin/cpio/cpio.c
@@ -273,15 +273,21 @@ main(int argc, char *argv[])
cpio->quiet = 1;
break;
case 'R': /* GNU cpio, also --owner */
+ /* TODO: owner_parse should return uname/gname
+ * also; use that to set [ug]name_override. */
errmsg = owner_parse(cpio->optarg, &uid, &gid);
if (errmsg) {
warnc(-1, "%s", errmsg);
usage();
}
- if (uid != -1)
+ if (uid != -1) {
cpio->uid_override = uid;
- if (gid != -1)
+ cpio->uname_override = NULL;
+ }
+ if (gid != -1) {
cpio->gid_override = gid;
+ cpio->gname_override = NULL;
+ }
break;
case 'r': /* POSIX 1997 */
cpio->option_rename = 1;
@@ -575,10 +581,14 @@ file_to_archive(struct cpio *cpio, const char *srcpath)
return (r);
}
- if (cpio->uid_override >= 0)
+ if (cpio->uid_override >= 0) {
archive_entry_set_uid(entry, cpio->uid_override);
- if (cpio->gid_override >= 0)
+ archive_entry_set_uname(entry, cpio->uname_override);
+ }
+ if (cpio->gid_override >= 0) {
archive_entry_set_gid(entry, cpio->gid_override);
+ archive_entry_set_gname(entry, cpio->gname_override);
+ }
/*
* Generate a destination path for this entry.
diff --git a/usr.bin/cpio/cpio.h b/usr.bin/cpio/cpio.h
index 36dab55..2afa8f2 100644
--- a/usr.bin/cpio/cpio.h
+++ b/usr.bin/cpio/cpio.h
@@ -68,7 +68,9 @@ struct cpio {
size_t pass_destpath_alloc;
char *pass_destpath;
int uid_override;
+ char *uname_override;
int gid_override;
+ char *gname_override;
int day_first; /* true if locale prefers day/mon */
/* If >= 0, then close this when done. */
OpenPOWER on IntegriCloud