aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-04-21 00:52:21 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-04-21 00:52:21 +0000
commit8b814b4a349e2262c0ad25793b05206a14651ebb (patch)
treed58a9a4b05e6c662d1ccdcca8da82173d52c1e4b
parent76478b8091d4c3472fb0c7e572c350d150ecd459 (diff)
downloadbusybox-w32-8b814b4a349e2262c0ad25793b05206a14651ebb.tar.gz
busybox-w32-8b814b4a349e2262c0ad25793b05206a14651ebb.tar.bz2
busybox-w32-8b814b4a349e2262c0ad25793b05206a14651ebb.zip
tar: support for tar --numeric-owner. By Natanael Copa.
function old new delta tar_longopts 221 237 +16 data_extract_all 692 705 +13 tar_main 690 702 +12
-rw-r--r--archival/libunarchive/data_extract_all.c30
-rw-r--r--archival/tar.c6
-rw-r--r--include/unarchive.h1
3 files changed, 23 insertions, 14 deletions
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c
index 8b1ee2a6e..a2dfcb9e1 100644
--- a/archival/libunarchive/data_extract_all.c
+++ b/archival/libunarchive/data_extract_all.c
@@ -114,22 +114,24 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
114 } 114 }
115 115
116 if (!(archive_handle->ah_flags & ARCHIVE_NOPRESERVE_OWN)) { 116 if (!(archive_handle->ah_flags & ARCHIVE_NOPRESERVE_OWN)) {
117#if ENABLE_FEATURE_TAR_UNAME_GNAME 117 if (ENABLE_FEATURE_TAR_UNAME_GNAME
118 uid_t uid = file_header->uid; 118 && !(archive_handle->ah_flags & ARCHIVE_NUMERIC_OWNER)
119 gid_t gid = file_header->gid; 119 ) {
120 uid_t uid = file_header->uid;
121 gid_t gid = file_header->gid;
120 122
121 if (file_header->uname) { 123 if (file_header->uname) {
122 struct passwd *pwd = getpwnam(file_header->uname); 124 struct passwd *pwd = getpwnam(file_header->uname);
123 if (pwd) uid = pwd->pw_uid; 125 if (pwd) uid = pwd->pw_uid;
124 } 126 }
125 if (file_header->gname) { 127 if (file_header->gname) {
126 struct group *grp = getgrnam(file_header->gname); 128 struct group *grp = getgrnam(file_header->gname);
127 if (grp) gid = grp->gr_gid; 129 if (grp) gid = grp->gr_gid;
130 }
131 lchown(file_header->name, uid, gid);
132 } else {
133 lchown(file_header->name, file_header->uid, file_header->gid);
128 } 134 }
129 lchown(file_header->name, uid, gid);
130#else
131 lchown(file_header->name, file_header->uid, file_header->gid);
132#endif
133 } 135 }
134 if ((file_header->mode & S_IFMT) != S_IFLNK) { 136 if ((file_header->mode & S_IFMT) != S_IFLNK) {
135 /* uclibc has no lchmod, glibc is even stranger - 137 /* uclibc has no lchmod, glibc is even stranger -
diff --git a/archival/tar.c b/archival/tar.c
index eeaf3586b..03d66a692 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -738,6 +738,7 @@ enum {
738 USE_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) 738 USE_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,)
739 OPTBIT_NOPRESERVE_OWN, 739 OPTBIT_NOPRESERVE_OWN,
740 OPTBIT_NOPRESERVE_PERM, 740 OPTBIT_NOPRESERVE_PERM,
741 OPTBIT_NUMERIC_OWNER,
741 OPT_TEST = 1 << 0, // t 742 OPT_TEST = 1 << 0, // t
742 OPT_EXTRACT = 1 << 1, // x 743 OPT_EXTRACT = 1 << 1, // x
743 OPT_BASEDIR = 1 << 2, // C 744 OPT_BASEDIR = 1 << 2, // C
@@ -756,6 +757,7 @@ enum {
756 OPT_COMPRESS = USE_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z 757 OPT_COMPRESS = USE_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
757 OPT_NOPRESERVE_OWN = 1 << OPTBIT_NOPRESERVE_OWN , // no-same-owner 758 OPT_NOPRESERVE_OWN = 1 << OPTBIT_NOPRESERVE_OWN , // no-same-owner
758 OPT_NOPRESERVE_PERM = 1 << OPTBIT_NOPRESERVE_PERM, // no-same-permissions 759 OPT_NOPRESERVE_PERM = 1 << OPTBIT_NOPRESERVE_PERM, // no-same-permissions
760 OPT_NUMERIC_OWNER = 1 << OPTBIT_NUMERIC_OWNER,
759}; 761};
760#if ENABLE_FEATURE_TAR_LONG_OPTIONS 762#if ENABLE_FEATURE_TAR_LONG_OPTIONS
761static const char tar_longopts[] ALIGN1 = 763static const char tar_longopts[] ALIGN1 =
@@ -787,6 +789,7 @@ static const char tar_longopts[] ALIGN1 =
787# if ENABLE_FEATURE_SEAMLESS_Z 789# if ENABLE_FEATURE_SEAMLESS_Z
788 "compress\0" No_argument "Z" 790 "compress\0" No_argument "Z"
789# endif 791# endif
792 "numeric-owner\0" No_argument "\xfc"
790 "no-same-owner\0" No_argument "\xfd" 793 "no-same-owner\0" No_argument "\xfd"
791 "no-same-permissions\0" No_argument "\xfe" 794 "no-same-permissions\0" No_argument "\xfe"
792 /* --exclude takes next bit position in option mask, */ 795 /* --exclude takes next bit position in option mask, */
@@ -873,6 +876,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
873 if (opt & OPT_NOPRESERVE_PERM) 876 if (opt & OPT_NOPRESERVE_PERM)
874 tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_PERM; 877 tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_PERM;
875 878
879 if (opt & OPT_NUMERIC_OWNER)
880 tar_handle->ah_flags |= ARCHIVE_NUMERIC_OWNER;
881
876 if (opt & OPT_GZIP) 882 if (opt & OPT_GZIP)
877 get_header_ptr = get_header_tar_gz; 883 get_header_ptr = get_header_tar_gz;
878 884
diff --git a/include/unarchive.h b/include/unarchive.h
index beb962c8f..9d4f1fa40 100644
--- a/include/unarchive.h
+++ b/include/unarchive.h
@@ -11,6 +11,7 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
11#define ARCHIVE_EXTRACT_NEWER 16 11#define ARCHIVE_EXTRACT_NEWER 16
12#define ARCHIVE_NOPRESERVE_OWN 32 12#define ARCHIVE_NOPRESERVE_OWN 32
13#define ARCHIVE_NOPRESERVE_PERM 64 13#define ARCHIVE_NOPRESERVE_PERM 64
14#define ARCHIVE_NUMERIC_OWNER 128
14 15
15typedef struct file_header_t { 16typedef struct file_header_t {
16 char *name; 17 char *name;