summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/opkg/opkg/0002-Ensure-we-use-the-uname-gname-fields-when-extracting.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/opkg/opkg/0002-Ensure-we-use-the-uname-gname-fields-when-extracting.patch')
-rw-r--r--meta/recipes-devtools/opkg/opkg/0002-Ensure-we-use-the-uname-gname-fields-when-extracting.patch101
1 files changed, 101 insertions, 0 deletions
diff --git a/meta/recipes-devtools/opkg/opkg/0002-Ensure-we-use-the-uname-gname-fields-when-extracting.patch b/meta/recipes-devtools/opkg/opkg/0002-Ensure-we-use-the-uname-gname-fields-when-extracting.patch
new file mode 100644
index 0000000000..f51cf587ca
--- /dev/null
+++ b/meta/recipes-devtools/opkg/opkg/0002-Ensure-we-use-the-uname-gname-fields-when-extracting.patch
@@ -0,0 +1,101 @@
1From 254780ab3b0db398447150251332916598d3b9f4 Mon Sep 17 00:00:00 2001
2From: Richard Purdie <richard.purdie@linuxfoundation.org>
3Date: Fri, 11 Nov 2011 17:17:01 +0000
4Subject: [PATCH 2/7] Ensure we use the uname/gname fields when extracting
5 tarballs
6
7When updating packages on the target device we ideally want to match
8user and group numbers from the existing file system. This patch encourages
9opkg to lookup the uname/gname fields first and only use the hardcoded
10numerical values if that fails.
11
12Upstream-Status: Submitted
13http://code.google.com/p/opkg/issues/detail?id=93
14
15Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
16Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
17---
18 libbb/unarchive.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++--
19 1 file changed, 47 insertions(+), 2 deletions(-)
20
21diff --git a/libbb/unarchive.c b/libbb/unarchive.c
22index 5d4464f..d583767 100644
23--- a/libbb/unarchive.c
24+++ b/libbb/unarchive.c
25@@ -22,10 +22,13 @@
26 #include <stdio.h>
27 #include <errno.h>
28 #include <stdlib.h>
29+#include <stdbool.h>
30 #include <string.h>
31 #include <unistd.h>
32 #include <utime.h>
33 #include <libgen.h>
34+#include <grp.h>
35+#include <pwd.h>
36
37 #include "libbb.h"
38
39@@ -436,6 +439,42 @@ free_header_ar(file_header_t *ar_entry)
40 free(ar_entry);
41 }
42
43+static char uname_cache[32] = "";
44+static uid_t uid_cache;
45+
46+static bool update_unamecache(char *uname) {
47+ struct passwd *passwd;
48+ if (!uname)
49+ return FALSE;
50+ if (!uname_cache[0] && strcmp(uname_cache, uname) == 0)
51+ return TRUE;
52+ passwd = getpwnam(uname);
53+ if (passwd) {
54+ uid_cache = passwd->pw_uid;
55+ strncpy(uname, uname_cache, 32);
56+ return TRUE;
57+ }
58+ return FALSE;
59+}
60+
61+static char gname_cache[32] = "";
62+static gid_t gid_cache;
63+
64+static bool update_gnamecache(char *gname) {
65+ struct group *group;
66+ if (!gname)
67+ return FALSE;
68+ if (!gname_cache[0] && strcmp(gname_cache, gname) == 0)
69+ return TRUE;
70+ group = getgrnam(gname);
71+ if (group) {
72+ gid_cache = group->gr_gid;
73+ strncpy(gname, gname_cache, 32);
74+ return TRUE;
75+ }
76+ return FALSE;
77+}
78+
79
80 static file_header_t *
81 get_header_tar(FILE *tar_stream)
82@@ -515,8 +554,14 @@ get_header_tar(FILE *tar_stream)
83 */
84 tar_entry->mode = 07777 & strtol(tar.formated.mode, NULL, 8);
85
86- tar_entry->uid = strtol(tar.formated.uid, NULL, 8);
87- tar_entry->gid = strtol(tar.formated.gid, NULL, 8);
88+ if (update_unamecache(tar.formated.uname))
89+ tar_entry->uid = uid_cache;
90+ else
91+ tar_entry->uid = strtol(tar.formated.uid, NULL, 8);
92+ if (update_gnamecache(tar.formated.gname))
93+ tar_entry->gid = gid_cache;
94+ else
95+ tar_entry->gid = strtol(tar.formated.gid, NULL, 8);
96 tar_entry->size = strtol(tar.formated.size, NULL, 8);
97 tar_entry->mtime = strtol(tar.formated.mtime, NULL, 8);
98
99--
1001.7.12
101