diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2010-10-08 13:18:34 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2010-10-18 09:58:37 +0000 |
commit | 45b641394157610188e606bfdc08f2a202313292 (patch) | |
tree | 6cae739887d54fe1f07f2848a967315c5a3bb896 | |
parent | cdd4e669c1f7cbe20abd38e3cfdea614c6f647bc (diff) | |
download | alpine_aports-45b641394157610188e606bfdc08f2a202313292.tar.bz2 alpine_aports-45b641394157610188e606bfdc08f2a202313292.tar.xz alpine_aports-45b641394157610188e606bfdc08f2a202313292.zip |
main/apk-tools: id cache should be specific to db root
fixes #434
(cherry picked from commit 8fff0d810d40bfaa29b5aa628ee4de1e387a4ab4)
-rw-r--r-- | main/apk-tools/0001-io-db-id-cache-should-be-specific-to-database-root-n.patch | 437 | ||||
-rw-r--r-- | main/apk-tools/0002-db-fix-the-previous-commit.patch | 50 | ||||
-rw-r--r-- | main/apk-tools/APKBUILD | 8 |
3 files changed, 493 insertions, 2 deletions
diff --git a/main/apk-tools/0001-io-db-id-cache-should-be-specific-to-database-root-n.patch b/main/apk-tools/0001-io-db-id-cache-should-be-specific-to-database-root-n.patch new file mode 100644 index 0000000000..228f4ffe55 --- /dev/null +++ b/main/apk-tools/0001-io-db-id-cache-should-be-specific-to-database-root-n.patch | |||
@@ -0,0 +1,437 @@ | |||
1 | From 19419f1a88285a0dee53bdf49201c4d3d4cbf19f Mon Sep 17 00:00:00 2001 | ||
2 | From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi> | ||
3 | Date: Fri, 8 Oct 2010 15:36:54 +0300 | ||
4 | Subject: [PATCH 1/2] io, db: id cache should be specific to database root, not system root | ||
5 | |||
6 | Otherwise we end up using wrong uid/gid mappings when doing install | ||
7 | to alternate system root. Fixes #434. | ||
8 | --- | ||
9 | src/apk.c | 2 - | ||
10 | src/apk_archive.h | 2 +- | ||
11 | src/apk_database.h | 2 + | ||
12 | src/apk_io.h | 18 ++++++++--- | ||
13 | src/apk_package.h | 5 ++- | ||
14 | src/archive.c | 6 ++-- | ||
15 | src/database.c | 22 ++++++++----- | ||
16 | src/io.c | 88 ++++++++++++++++++++++++++++++--------------------- | ||
17 | src/package.c | 9 +++-- | ||
18 | src/verify.c | 2 +- | ||
19 | 10 files changed, 93 insertions(+), 63 deletions(-) | ||
20 | |||
21 | diff --git a/src/apk.c b/src/apk.c | ||
22 | index 4196f74..55628c1 100644 | ||
23 | --- a/src/apk.c | ||
24 | +++ b/src/apk.c | ||
25 | @@ -248,7 +248,6 @@ int main(int argc, char **argv) | ||
26 | memset(&dbopts, 0, sizeof(dbopts)); | ||
27 | list_init(&dbopts.repository_list); | ||
28 | umask(0); | ||
29 | - apk_id_cache_init(); | ||
30 | |||
31 | applet = deduce_applet(argc, argv); | ||
32 | num_options = ARRAY_SIZE(generic_options) + 1; | ||
33 | @@ -370,7 +369,6 @@ int main(int argc, char **argv) | ||
34 | |||
35 | r = applet->main(ctx, &db, argc, argv); | ||
36 | apk_db_close(&db); | ||
37 | - apk_id_cache_free(); | ||
38 | |||
39 | if (r == -EINVAL) | ||
40 | return usage(applet); | ||
41 | diff --git a/src/apk_archive.h b/src/apk_archive.h | ||
42 | index f1b5aaf..ff4fb48 100644 | ||
43 | --- a/src/apk_archive.h | ||
44 | +++ b/src/apk_archive.h | ||
45 | @@ -22,7 +22,7 @@ typedef int (*apk_archive_entry_parser)(void *ctx, | ||
46 | |||
47 | int apk_tar_parse(struct apk_istream *, | ||
48 | apk_archive_entry_parser parser, void *ctx, | ||
49 | - int soft_checksums); | ||
50 | + int soft_checksums, struct apk_id_cache *); | ||
51 | int apk_tar_write_entry(struct apk_ostream *, const struct apk_file_info *ae, | ||
52 | const char *data); | ||
53 | int apk_tar_write_padding(struct apk_ostream *, const struct apk_file_info *ae); | ||
54 | diff --git a/src/apk_database.h b/src/apk_database.h | ||
55 | index da33289..249ddae 100644 | ||
56 | --- a/src/apk_database.h | ||
57 | +++ b/src/apk_database.h | ||
58 | @@ -16,6 +16,7 @@ | ||
59 | #include "apk_hash.h" | ||
60 | #include "apk_archive.h" | ||
61 | #include "apk_package.h" | ||
62 | +#include "apk_io.h" | ||
63 | |||
64 | #define APK_MAX_REPOS 32 | ||
65 | #define APK_CACHE_CSUM_BYTES 4 | ||
66 | @@ -109,6 +110,7 @@ struct apk_database { | ||
67 | struct apk_dependency_array *world; | ||
68 | struct apk_string_array *protected_paths; | ||
69 | struct apk_repository repos[APK_MAX_REPOS]; | ||
70 | + struct apk_id_cache id_cache; | ||
71 | |||
72 | struct { | ||
73 | struct apk_hash names; | ||
74 | diff --git a/src/apk_io.h b/src/apk_io.h | ||
75 | index 3a3abff..20051a6 100644 | ||
76 | --- a/src/apk_io.h | ||
77 | +++ b/src/apk_io.h | ||
78 | @@ -15,6 +15,14 @@ | ||
79 | |||
80 | #include "apk_defines.h" | ||
81 | #include "apk_blob.h" | ||
82 | +#include "apk_hash.h" | ||
83 | + | ||
84 | +struct apk_id_cache { | ||
85 | + int root_fd; | ||
86 | + unsigned int genid; | ||
87 | + struct apk_hash uid_cache; | ||
88 | + struct apk_hash gid_cache; | ||
89 | +}; | ||
90 | |||
91 | struct apk_file_info { | ||
92 | char *name; | ||
93 | @@ -95,10 +103,10 @@ int apk_file_get_info(int atfd, const char *filename, unsigned int flags, | ||
94 | int apk_url_download(const char *url, int atfd, const char *file); | ||
95 | const char *apk_url_local_file(const char *url); | ||
96 | |||
97 | -void apk_id_cache_init(void); | ||
98 | -void apk_id_cache_free(void); | ||
99 | -void apk_id_cache_reset(void); | ||
100 | -uid_t apk_resolve_uid(const char *username, uid_t default_uid); | ||
101 | -uid_t apk_resolve_gid(const char *groupname, uid_t default_gid); | ||
102 | +void apk_id_cache_init(struct apk_id_cache *idc, int root_fd); | ||
103 | +void apk_id_cache_free(struct apk_id_cache *idc); | ||
104 | +void apk_id_cache_reset(struct apk_id_cache *idc); | ||
105 | +uid_t apk_resolve_uid(struct apk_id_cache *idc, const char *username, uid_t default_uid); | ||
106 | +uid_t apk_resolve_gid(struct apk_id_cache *idc, const char *groupname, uid_t default_gid); | ||
107 | |||
108 | #endif | ||
109 | diff --git a/src/apk_package.h b/src/apk_package.h | ||
110 | index 7901ddb..55f6845 100644 | ||
111 | --- a/src/apk_package.h | ||
112 | +++ b/src/apk_package.h | ||
113 | @@ -143,8 +143,9 @@ void apk_pkg_uninstall(struct apk_database *db, struct apk_package *pkg); | ||
114 | int apk_ipkg_add_script(struct apk_installed_package *ipkg, | ||
115 | struct apk_istream *is, | ||
116 | unsigned int type, unsigned int size); | ||
117 | -int apk_ipkg_run_script(struct apk_installed_package *ipkg, int root_fd, | ||
118 | - unsigned int type, char **argv); | ||
119 | +int apk_ipkg_run_script(struct apk_installed_package *ipkg, | ||
120 | + struct apk_database *db, | ||
121 | + unsigned int type, char **argv); | ||
122 | |||
123 | struct apk_package *apk_pkg_parse_index_entry(struct apk_database *db, apk_blob_t entry); | ||
124 | int apk_pkg_write_index_entry(struct apk_package *pkg, struct apk_ostream *os); | ||
125 | diff --git a/src/archive.c b/src/archive.c | ||
126 | index b60b3b2..6e555b4 100644 | ||
127 | --- a/src/archive.c | ||
128 | +++ b/src/archive.c | ||
129 | @@ -117,7 +117,7 @@ static void tar_entry_close(void *stream) | ||
130 | } | ||
131 | |||
132 | int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser, | ||
133 | - void *ctx, int soft_checksums) | ||
134 | + void *ctx, int soft_checksums, struct apk_id_cache *idc) | ||
135 | { | ||
136 | struct apk_file_info entry; | ||
137 | struct apk_tar_entry_istream teis = { | ||
138 | @@ -146,8 +146,8 @@ int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser, | ||
139 | |||
140 | entry = (struct apk_file_info){ | ||
141 | .size = GET_OCTAL(buf.size), | ||
142 | - .uid = apk_resolve_uid(buf.uname, GET_OCTAL(buf.uid)), | ||
143 | - .gid = apk_resolve_gid(buf.gname, GET_OCTAL(buf.gid)), | ||
144 | + .uid = apk_resolve_uid(idc, buf.uname, GET_OCTAL(buf.uid)), | ||
145 | + .gid = apk_resolve_gid(idc, buf.gname, GET_OCTAL(buf.gid)), | ||
146 | .mode = GET_OCTAL(buf.mode) & 07777, | ||
147 | .mtime = GET_OCTAL(buf.mtime), | ||
148 | .name = entry.name, | ||
149 | diff --git a/src/database.c b/src/database.c | ||
150 | index 0054837..f0b8cb6 100644 | ||
151 | --- a/src/database.c | ||
152 | +++ b/src/database.c | ||
153 | @@ -472,7 +472,7 @@ int apk_cache_download(struct apk_database *db, const char *url, | ||
154 | apk_bstream_from_file(db->cachetmp_fd, cacheitem), | ||
155 | apk_sign_ctx_mpart_cb, &sctx); | ||
156 | |||
157 | - r = apk_tar_parse(is, apk_sign_ctx_verify_tar, &sctx, FALSE); | ||
158 | + r = apk_tar_parse(is, apk_sign_ctx_verify_tar, &sctx, FALSE, &db->id_cache); | ||
159 | is->close(is); | ||
160 | apk_sign_ctx_free(&sctx); | ||
161 | if (r != 0) { | ||
162 | @@ -916,7 +916,7 @@ static int apk_db_read_state(struct apk_database *db, int flags) | ||
163 | is = apk_istream_from_file(db->root_fd, "var/lib/apk/scripts.tar"); | ||
164 | if (is != NULL) { | ||
165 | apk_tar_parse(is, apk_read_script_archive_entry, db, | ||
166 | - FALSE); | ||
167 | + FALSE, &db->id_cache); | ||
168 | } else { | ||
169 | is = apk_istream_from_file(db->root_fd, "var/lib/apk/scripts"); | ||
170 | if (is != NULL) | ||
171 | @@ -1177,6 +1177,8 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts) | ||
172 | goto ret_r; | ||
173 | } | ||
174 | |||
175 | + apk_id_cache_init(&db->id_cache, db->root_fd); | ||
176 | + | ||
177 | return rr; | ||
178 | |||
179 | ret_errno: | ||
180 | @@ -1266,6 +1268,8 @@ void apk_db_close(struct apk_database *db) | ||
181 | struct hlist_node *dc, *dn; | ||
182 | int i; | ||
183 | |||
184 | + apk_id_cache_free(&db->id_cache); | ||
185 | + | ||
186 | list_for_each_entry(ipkg, &db->installed.packages, installed_pkgs_list) { | ||
187 | hlist_for_each_entry_safe(diri, dc, dn, &ipkg->owned_dirs, pkg_dirs_list) { | ||
188 | apk_db_diri_free(db, diri, APK_DISALLOW_RMDIR); | ||
189 | @@ -1343,7 +1347,7 @@ int apk_db_run_triggers(struct apk_database *db) | ||
190 | continue; | ||
191 | |||
192 | *apk_string_array_add(&ipkg->pending_triggers) = NULL; | ||
193 | - apk_ipkg_run_script(ipkg, db->root_fd, APK_SCRIPT_TRIGGER, | ||
194 | + apk_ipkg_run_script(ipkg, db, APK_SCRIPT_TRIGGER, | ||
195 | ipkg->pending_triggers->item); | ||
196 | apk_string_array_free(&ipkg->pending_triggers); | ||
197 | } | ||
198 | @@ -1520,7 +1524,7 @@ static int load_index(struct apk_database *db, struct apk_bstream *bs, | ||
199 | ctx.found = 0; | ||
200 | apk_sign_ctx_init(&ctx.sctx, APK_SIGN_VERIFY, NULL, db->keys_fd); | ||
201 | is = apk_bstream_gunzip_mpart(bs, apk_sign_ctx_mpart_cb, &ctx.sctx); | ||
202 | - r = apk_tar_parse(is, load_apkindex, &ctx, FALSE); | ||
203 | + r = apk_tar_parse(is, load_apkindex, &ctx, FALSE, &db->id_cache); | ||
204 | is->close(is); | ||
205 | apk_sign_ctx_free(&ctx.sctx); | ||
206 | if (ctx.found == 0) | ||
207 | @@ -1624,7 +1628,7 @@ static int apk_db_run_pending_script(struct install_ctx *ctx) | ||
208 | return 0; | ||
209 | |||
210 | ctx->script_pending = FALSE; | ||
211 | - r = apk_ipkg_run_script(ctx->ipkg, ctx->db->root_fd, ctx->script, | ||
212 | + r = apk_ipkg_run_script(ctx->ipkg, ctx->db, ctx->script, | ||
213 | ctx->script_args); | ||
214 | if (r != 0) | ||
215 | apk_error("%s-%s: Failed to execute " | ||
216 | @@ -2043,7 +2047,7 @@ static int apk_db_unpack_pkg(struct apk_database *db, | ||
217 | apk_name_array_init(&ctx.replaces); | ||
218 | apk_sign_ctx_init(&ctx.sctx, APK_SIGN_VERIFY_IDENTITY, &pkg->csum, db->keys_fd); | ||
219 | tar = apk_bstream_gunzip_mpart(bs, apk_sign_ctx_mpart_cb, &ctx.sctx); | ||
220 | - r = apk_tar_parse(tar, apk_db_install_archive_entry, &ctx, TRUE); | ||
221 | + r = apk_tar_parse(tar, apk_db_install_archive_entry, &ctx, TRUE, &db->id_cache); | ||
222 | apk_sign_ctx_free(&ctx.sctx); | ||
223 | apk_name_array_free(&ctx.replaces); | ||
224 | tar->close(tar); | ||
225 | @@ -2098,13 +2102,13 @@ int apk_db_install_pkg(struct apk_database *db, | ||
226 | if (ipkg == NULL) | ||
227 | return 0; | ||
228 | |||
229 | - r = apk_ipkg_run_script(ipkg, db->root_fd, | ||
230 | + r = apk_ipkg_run_script(ipkg, db, | ||
231 | APK_SCRIPT_PRE_DEINSTALL, script_args); | ||
232 | if (r != 0) | ||
233 | return r; | ||
234 | |||
235 | apk_db_purge_pkg(db, ipkg, NULL); | ||
236 | - r = apk_ipkg_run_script(ipkg, db->root_fd, | ||
237 | + r = apk_ipkg_run_script(ipkg, db, | ||
238 | APK_SCRIPT_POST_DEINSTALL, script_args); | ||
239 | apk_pkg_uninstall(db, oldpkg); | ||
240 | |||
241 | @@ -2135,7 +2139,7 @@ int apk_db_install_pkg(struct apk_database *db, | ||
242 | apk_pkg_uninstall(db, oldpkg); | ||
243 | } | ||
244 | |||
245 | - r = apk_ipkg_run_script(ipkg, db->root_fd, | ||
246 | + r = apk_ipkg_run_script(ipkg, db, | ||
247 | (oldpkg == NULL) ? | ||
248 | APK_SCRIPT_POST_INSTALL : APK_SCRIPT_POST_UPGRADE, | ||
249 | script_args); | ||
250 | diff --git a/src/io.c b/src/io.c | ||
251 | index 5100d41..38bc4e6 100644 | ||
252 | --- a/src/io.c | ||
253 | +++ b/src/io.c | ||
254 | @@ -766,48 +766,55 @@ static struct cache_item *resolve_cache_item(struct apk_hash *hash, apk_blob_t n | ||
255 | return ci; | ||
256 | } | ||
257 | |||
258 | -static unsigned int id_genid = 0; | ||
259 | -static struct apk_hash uid_cache, gid_cache; | ||
260 | - | ||
261 | -void apk_id_cache_init(void) | ||
262 | +void apk_id_cache_init(struct apk_id_cache *idc, int root_fd) | ||
263 | { | ||
264 | - apk_hash_init(&uid_cache, &id_hash_ops, 256); | ||
265 | - apk_hash_init(&gid_cache, &id_hash_ops, 256); | ||
266 | - id_genid = 1; | ||
267 | + idc->root_fd = root_fd; | ||
268 | + idc->genid = 1; | ||
269 | + apk_hash_init(&idc->uid_cache, &id_hash_ops, 256); | ||
270 | + apk_hash_init(&idc->gid_cache, &id_hash_ops, 256); | ||
271 | } | ||
272 | |||
273 | -void apk_id_cache_free(void) | ||
274 | +void apk_id_cache_free(struct apk_id_cache *idc) | ||
275 | { | ||
276 | - apk_hash_free(&uid_cache); | ||
277 | - apk_hash_free(&gid_cache); | ||
278 | + apk_hash_free(&idc->uid_cache); | ||
279 | + apk_hash_free(&idc->gid_cache); | ||
280 | } | ||
281 | |||
282 | -void apk_id_cache_reset(void) | ||
283 | +void apk_id_cache_reset(struct apk_id_cache *idc) | ||
284 | { | ||
285 | - id_genid++; | ||
286 | - if (id_genid == 0) | ||
287 | - id_genid = 1; | ||
288 | + idc->genid++; | ||
289 | + if (idc->genid == 0) | ||
290 | + idc->genid = 1; | ||
291 | } | ||
292 | |||
293 | -uid_t apk_resolve_uid(const char *username, uid_t default_uid) | ||
294 | +uid_t apk_resolve_uid(struct apk_id_cache *idc, const char *username, uid_t default_uid) | ||
295 | { | ||
296 | struct cache_item *ci; | ||
297 | struct passwd pwent, *pwd; | ||
298 | char buf[1024]; | ||
299 | - int r; | ||
300 | + FILE *in; | ||
301 | |||
302 | - ci = resolve_cache_item(&uid_cache, APK_BLOB_STR(username)); | ||
303 | + ci = resolve_cache_item(&idc->uid_cache, APK_BLOB_STR(username)); | ||
304 | if (ci == NULL) | ||
305 | return default_uid; | ||
306 | |||
307 | - if (ci->genid != id_genid) { | ||
308 | - r = getpwnam_r(username, &pwent, buf, sizeof(buf), &pwd); | ||
309 | - if (pwd != NULL) | ||
310 | - ci->uid = pwd->pw_uid; | ||
311 | - else | ||
312 | - ci->uid = -1; | ||
313 | - if (r == 0) | ||
314 | - ci->genid = id_genid; | ||
315 | + if (ci->genid != idc->genid) { | ||
316 | + ci->genid = idc->genid; | ||
317 | + ci->uid = -1; | ||
318 | + | ||
319 | + in = fdopen(openat(idc->root_fd, "etc/passwd", O_RDONLY|O_CLOEXEC), "r"); | ||
320 | + if (in != NULL) { | ||
321 | + do { | ||
322 | + fgetpwent_r(in, &pwent, buf, sizeof(buf), &pwd); | ||
323 | + if (pwd == NULL) | ||
324 | + break; | ||
325 | + if (strcmp(pwd->pw_name, username) == 0) { | ||
326 | + ci->uid = pwd->pw_uid; | ||
327 | + break; | ||
328 | + } | ||
329 | + } while (1); | ||
330 | + fclose(in); | ||
331 | + } | ||
332 | } | ||
333 | |||
334 | if (ci->uid != -1) | ||
335 | @@ -816,25 +823,34 @@ uid_t apk_resolve_uid(const char *username, uid_t default_uid) | ||
336 | return default_uid; | ||
337 | } | ||
338 | |||
339 | -uid_t apk_resolve_gid(const char *groupname, uid_t default_gid) | ||
340 | +uid_t apk_resolve_gid(struct apk_id_cache *idc, const char *groupname, uid_t default_gid) | ||
341 | { | ||
342 | struct cache_item *ci; | ||
343 | struct group grent, *grp; | ||
344 | char buf[1024]; | ||
345 | - int r; | ||
346 | + FILE *in; | ||
347 | |||
348 | - ci = resolve_cache_item(&gid_cache, APK_BLOB_STR(groupname)); | ||
349 | + ci = resolve_cache_item(&idc->gid_cache, APK_BLOB_STR(groupname)); | ||
350 | if (ci == NULL) | ||
351 | return default_gid; | ||
352 | |||
353 | - if (ci->genid != id_genid) { | ||
354 | - r = getgrnam_r(groupname, &grent, buf, sizeof(buf), &grp); | ||
355 | - if (grp != NULL) | ||
356 | - ci->gid = grp->gr_gid; | ||
357 | - else | ||
358 | - ci->gid = -1; | ||
359 | - if (r == 0) | ||
360 | - ci->genid = id_genid; | ||
361 | + if (ci->genid != idc->genid) { | ||
362 | + ci->genid = idc->genid; | ||
363 | + ci->gid = -1; | ||
364 | + | ||
365 | + in = fdopen(openat(idc->root_fd, "etc/passwd", O_RDONLY|O_CLOEXEC), "r"); | ||
366 | + if (in != NULL) { | ||
367 | + do { | ||
368 | + fgetgrent_r(in, &grent, buf, sizeof(buf), &grp); | ||
369 | + if (grp == NULL) | ||
370 | + break; | ||
371 | + if (strcmp(grp->gr_name, groupname) == 0) { | ||
372 | + ci->gid = grp->gr_gid; | ||
373 | + break; | ||
374 | + } | ||
375 | + } while (1); | ||
376 | + fclose(in); | ||
377 | + } | ||
378 | } | ||
379 | |||
380 | if (ci->gid != -1) | ||
381 | diff --git a/src/package.c b/src/package.c | ||
382 | index 8f15e7a..df53d93 100644 | ||
383 | --- a/src/package.c | ||
384 | +++ b/src/package.c | ||
385 | @@ -793,7 +793,7 @@ int apk_pkg_read(struct apk_database *db, const char *file, | ||
386 | ctx.pkg->size = fi.size; | ||
387 | |||
388 | tar = apk_bstream_gunzip_mpart(bs, apk_sign_ctx_mpart_cb, sctx); | ||
389 | - r = apk_tar_parse(tar, read_info_entry, &ctx, FALSE); | ||
390 | + r = apk_tar_parse(tar, read_info_entry, &ctx, FALSE, &db->id_cache); | ||
391 | tar->close(tar); | ||
392 | if (r < 0 && r != -ECANCELED) | ||
393 | goto err; | ||
394 | @@ -856,7 +856,8 @@ int apk_ipkg_add_script(struct apk_installed_package *ipkg, | ||
395 | return 0; | ||
396 | } | ||
397 | |||
398 | -int apk_ipkg_run_script(struct apk_installed_package *ipkg, int root_fd, | ||
399 | +int apk_ipkg_run_script(struct apk_installed_package *ipkg, | ||
400 | + struct apk_database *db, | ||
401 | unsigned int type, char **argv) | ||
402 | { | ||
403 | static char * const environment[] = { | ||
404 | @@ -865,7 +866,7 @@ int apk_ipkg_run_script(struct apk_installed_package *ipkg, int root_fd, | ||
405 | }; | ||
406 | struct apk_package *pkg = ipkg->pkg; | ||
407 | char fn[PATH_MAX]; | ||
408 | - int fd, status; | ||
409 | + int fd, status, root_fd = db->root_fd; | ||
410 | pid_t pid; | ||
411 | |||
412 | if (type >= APK_SCRIPT_MAX) | ||
413 | @@ -911,7 +912,7 @@ int apk_ipkg_run_script(struct apk_installed_package *ipkg, int root_fd, | ||
414 | } | ||
415 | waitpid(pid, &status, 0); | ||
416 | unlinkat(root_fd, fn, 0); | ||
417 | - apk_id_cache_reset(); | ||
418 | + apk_id_cache_reset(&db->id_cache); | ||
419 | |||
420 | if (WIFEXITED(status)) | ||
421 | return WEXITSTATUS(status); | ||
422 | diff --git a/src/verify.c b/src/verify.c | ||
423 | index 006b548..b6a5cbc 100644 | ||
424 | --- a/src/verify.c | ||
425 | +++ b/src/verify.c | ||
426 | @@ -33,7 +33,7 @@ static int verify_main(void *ctx, struct apk_database *db, int argc, char **argv | ||
427 | rc++; | ||
428 | continue; | ||
429 | } | ||
430 | - r = apk_tar_parse(is, apk_sign_ctx_verify_tar, &sctx, FALSE); | ||
431 | + r = apk_tar_parse(is, apk_sign_ctx_verify_tar, &sctx, FALSE, &db->id_cache); | ||
432 | is->close(is); | ||
433 | ok = sctx.control_verified && sctx.data_verified; | ||
434 | if (apk_verbosity >= 1) | ||
435 | -- | ||
436 | 1.7.3.1 | ||
437 | |||
diff --git a/main/apk-tools/0002-db-fix-the-previous-commit.patch b/main/apk-tools/0002-db-fix-the-previous-commit.patch new file mode 100644 index 0000000000..48f38ba072 --- /dev/null +++ b/main/apk-tools/0002-db-fix-the-previous-commit.patch | |||
@@ -0,0 +1,50 @@ | |||
1 | From 6398d338c6441f3b967a2633bbc9df4709bcb258 Mon Sep 17 00:00:00 2001 | ||
2 | From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi> | ||
3 | Date: Fri, 8 Oct 2010 16:09:03 +0300 | ||
4 | Subject: [PATCH 2/2] db: fix the previous commit | ||
5 | |||
6 | id cache needs to be initialized early. and group database filename | ||
7 | is surprisingly 'group'. | ||
8 | --- | ||
9 | src/database.c | 4 ++-- | ||
10 | src/io.c | 2 +- | ||
11 | 2 files changed, 3 insertions(+), 3 deletions(-) | ||
12 | |||
13 | diff --git a/src/database.c b/src/database.c | ||
14 | index f0b8cb6..e22289a 100644 | ||
15 | --- a/src/database.c | ||
16 | +++ b/src/database.c | ||
17 | @@ -1079,6 +1079,8 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts) | ||
18 | S_ISDIR(st.st_mode) && major(st.st_dev) != 0) | ||
19 | db->cache_dir = apk_linked_cache_dir; | ||
20 | |||
21 | + apk_id_cache_init(&db->id_cache, db->root_fd); | ||
22 | + | ||
23 | if (dbopts->open_flags & APK_OPENF_WRITE) { | ||
24 | db->lock_fd = openat(db->root_fd, "var/lib/apk/lock", | ||
25 | O_CREAT | O_RDWR | O_CLOEXEC, 0400); | ||
26 | @@ -1177,8 +1179,6 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts) | ||
27 | goto ret_r; | ||
28 | } | ||
29 | |||
30 | - apk_id_cache_init(&db->id_cache, db->root_fd); | ||
31 | - | ||
32 | return rr; | ||
33 | |||
34 | ret_errno: | ||
35 | diff --git a/src/io.c b/src/io.c | ||
36 | index 38bc4e6..0f09403 100644 | ||
37 | --- a/src/io.c | ||
38 | +++ b/src/io.c | ||
39 | @@ -838,7 +838,7 @@ uid_t apk_resolve_gid(struct apk_id_cache *idc, const char *groupname, uid_t def | ||
40 | ci->genid = idc->genid; | ||
41 | ci->gid = -1; | ||
42 | |||
43 | - in = fdopen(openat(idc->root_fd, "etc/passwd", O_RDONLY|O_CLOEXEC), "r"); | ||
44 | + in = fdopen(openat(idc->root_fd, "etc/group", O_RDONLY|O_CLOEXEC), "r"); | ||
45 | if (in != NULL) { | ||
46 | do { | ||
47 | fgetgrent_r(in, &grent, buf, sizeof(buf), &grp); | ||
48 | -- | ||
49 | 1.7.3.1 | ||
50 | |||
diff --git a/main/apk-tools/APKBUILD b/main/apk-tools/APKBUILD index f64df8a815..b18e056185 100644 --- a/main/apk-tools/APKBUILD +++ b/main/apk-tools/APKBUILD | |||
@@ -1,12 +1,14 @@ | |||
1 | # Maintainer: Natanael Copa <ncopa@alpinelinux.org> | 1 | # Maintainer: Natanael Copa <ncopa@alpinelinux.org> |
2 | pkgname=apk-tools | 2 | pkgname=apk-tools |
3 | pkgver=2.0.6 | 3 | pkgver=2.0.6 |
4 | pkgrel=0 | 4 | pkgrel=1 |
5 | pkgdesc="Alpine Package Keeper - package manager for alpine" | 5 | pkgdesc="Alpine Package Keeper - package manager for alpine" |
6 | subpackages="$pkgname-static" | 6 | subpackages="$pkgname-static" |
7 | depends= | 7 | depends= |
8 | makedepends="zlib-dev openssl-dev pkgconfig" | 8 | makedepends="zlib-dev openssl-dev pkgconfig" |
9 | source="http://git.alpinelinux.org/cgit/$pkgname/snapshot/$pkgname-$pkgver.tar.bz2 | 9 | source="http://git.alpinelinux.org/cgit/$pkgname/snapshot/$pkgname-$pkgver.tar.bz2 |
10 | 0001-io-db-id-cache-should-be-specific-to-database-root-n.patch | ||
11 | 0002-db-fix-the-previous-commit.patch | ||
10 | " | 12 | " |
11 | 13 | ||
12 | url="http://git.alpinelinux.org/cgit/apk-tools/" | 14 | url="http://git.alpinelinux.org/cgit/apk-tools/" |
@@ -47,4 +49,6 @@ static() { | |||
47 | "$subpkgdir"/sbin/apk.static | 49 | "$subpkgdir"/sbin/apk.static |
48 | } | 50 | } |
49 | 51 | ||
50 | md5sums="5933a61f91f44c5c534f8a62e6effb65 apk-tools-2.0.6.tar.bz2" | 52 | md5sums="5933a61f91f44c5c534f8a62e6effb65 apk-tools-2.0.6.tar.bz2 |
53 | 20c2f3e406984af51c7cf69b69a1d874 0001-io-db-id-cache-should-be-specific-to-database-root-n.patch | ||
54 | 01a86fb39a3d161221a57002b86b2a0d 0002-db-fix-the-previous-commit.patch" | ||