aboutsummaryrefslogtreecommitdiffstats
path: root/core/busybox/bb-tar-numeric-owner.patch
blob: ad6481ffe4c9d8e3dba90f2167e2b4c1cdd7a319 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Index: archival/tar.c
===================================================================
--- a/archival/tar.c	(revision 26114)
+++ b/archival/tar.c	(working copy)
@@ -738,6 +738,7 @@
 	USE_FEATURE_SEAMLESS_Z(   OPTBIT_COMPRESS    ,)
 	OPTBIT_NOPRESERVE_OWN,
 	OPTBIT_NOPRESERVE_PERM,
+	OPTBIT_NUMERIC_OWNER,
 	OPT_TEST         = 1 << 0, // t
 	OPT_EXTRACT      = 1 << 1, // x
 	OPT_BASEDIR      = 1 << 2, // C
@@ -754,6 +755,7 @@
 	OPT_EXCLUDE_FROM = USE_FEATURE_TAR_FROM(     (1 << OPTBIT_EXCLUDE_FROM)) + 0, // X
 	OPT_GZIP         = USE_FEATURE_SEAMLESS_GZ(  (1 << OPTBIT_GZIP        )) + 0, // z
 	OPT_COMPRESS     = USE_FEATURE_SEAMLESS_Z(   (1 << OPTBIT_COMPRESS    )) + 0, // Z
+	OPT_NUMERIC_OWNER = 1 << OPTBIT_NUMERIC_OWNER,
 	OPT_NOPRESERVE_OWN  = 1 << OPTBIT_NOPRESERVE_OWN , // no-same-owner
 	OPT_NOPRESERVE_PERM = 1 << OPTBIT_NOPRESERVE_PERM, // no-same-permissions
 };
@@ -787,6 +789,7 @@
 # if ENABLE_FEATURE_SEAMLESS_Z
 	"compress\0"            No_argument       "Z"
 # endif
+	"numeric-owner\0"       No_argument       "\xfc"
 	"no-same-owner\0"       No_argument       "\xfd"
 	"no-same-permissions\0" No_argument       "\xfe"
 	/* --exclude takes next bit position in option mask, */
@@ -873,6 +876,9 @@
 	if (opt & OPT_NOPRESERVE_PERM)
 		tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_PERM;
 
+	if (opt & OPT_NUMERIC_OWNER)
+		tar_handle->ah_flags |= ARCHIVE_NUMERIC_OWNER;
+
 	if (opt & OPT_GZIP)
 		get_header_ptr = get_header_tar_gz;
 
Index: archival/libunarchive/data_extract_all.c
===================================================================
--- a/archival/libunarchive/data_extract_all.c	(revision 26114)
+++ b/archival/libunarchive/data_extract_all.c	(working copy)
@@ -114,22 +114,23 @@
 	}
 
 	if (!(archive_handle->ah_flags & ARCHIVE_NOPRESERVE_OWN)) {
-#if ENABLE_FEATURE_TAR_UNAME_GNAME
-		uid_t uid = file_header->uid;
-		gid_t gid = file_header->gid;
+		if (ENABLE_FEATURE_TAR_UNAME_GNAME && 
+		    !(archive_handle->ah_flags & ARCHIVE_NUMERIC_OWNER)) {
+			uid_t uid = file_header->uid;
+			gid_t gid = file_header->gid;
 
-		if (file_header->uname) {
-			struct passwd *pwd = getpwnam(file_header->uname);
-			if (pwd) uid = pwd->pw_uid;
+			if (file_header->uname) {
+				struct passwd *pwd = getpwnam(file_header->uname);
+				if (pwd) uid = pwd->pw_uid;
+			}
+			if (file_header->gname) {
+				struct group *grp = getgrnam(file_header->gname);
+				if (grp) gid = grp->gr_gid;
+			}
+			lchown(file_header->name, uid, gid);
+		} else {
+			lchown(file_header->name, file_header->uid, file_header->gid);
 		}
-		if (file_header->gname) {
-			struct group *grp = getgrnam(file_header->gname);
-			if (grp) gid = grp->gr_gid;
-		}
-		lchown(file_header->name, uid, gid);
-#else
-		lchown(file_header->name, file_header->uid, file_header->gid);
-#endif
 	}
 	if ((file_header->mode & S_IFMT) != S_IFLNK) {
 		/* uclibc has no lchmod, glibc is even stranger -
Index: include/unarchive.h
===================================================================
--- a/include/unarchive.h	(revision 26114)
+++ b/include/unarchive.h	(working copy)
@@ -11,6 +11,7 @@
 #define ARCHIVE_EXTRACT_NEWER           16
 #define ARCHIVE_NOPRESERVE_OWN          32
 #define ARCHIVE_NOPRESERVE_PERM         64
+#define ARCHIVE_NUMERIC_OWNER           128
 
 typedef struct file_header_t {
 	char *name;