diff options
-rw-r--r-- | archival/rpm.c | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/archival/rpm.c b/archival/rpm.c index 6757a6ceb..793701652 100644 --- a/archival/rpm.c +++ b/archival/rpm.c | |||
@@ -14,10 +14,10 @@ | |||
14 | //usage: "\nCommands:" | 14 | //usage: "\nCommands:" |
15 | //usage: "\n -i Install package" | 15 | //usage: "\n -i Install package" |
16 | //usage: "\n -qp Query package" | 16 | //usage: "\n -qp Query package" |
17 | //usage: "\n -i Show information" | 17 | //usage: "\n -qpi Show information" |
18 | //usage: "\n -l List contents" | 18 | //usage: "\n -qpl List contents" |
19 | //usage: "\n -d List documents" | 19 | //usage: "\n -qpd List documents" |
20 | //usage: "\n -c List config files" | 20 | //usage: "\n -qpc List config files" |
21 | 21 | ||
22 | #include "libbb.h" | 22 | #include "libbb.h" |
23 | #include "bb_archive.h" | 23 | #include "bb_archive.h" |
@@ -96,8 +96,8 @@ static void loop_through_files(int filetag, void (*fileaction)(char *filename, i | |||
96 | int rpm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 96 | int rpm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
97 | int rpm_main(int argc, char **argv) | 97 | int rpm_main(int argc, char **argv) |
98 | { | 98 | { |
99 | int opt = 0, func = 0, rpm_fd, offset; | 99 | int opt, func = 0; |
100 | const int pagesize = getpagesize(); | 100 | const unsigned pagesize = getpagesize(); |
101 | 101 | ||
102 | while ((opt = getopt(argc, argv, "iqpldc")) != -1) { | 102 | while ((opt = getopt(argc, argv, "iqpldc")) != -1) { |
103 | switch (opt) { | 103 | switch (opt) { |
@@ -134,6 +134,8 @@ int rpm_main(int argc, char **argv) | |||
134 | } | 134 | } |
135 | 135 | ||
136 | while (*argv) { | 136 | while (*argv) { |
137 | int rpm_fd; | ||
138 | unsigned offset; | ||
137 | const char *source_rpm; | 139 | const char *source_rpm; |
138 | 140 | ||
139 | rpm_fd = xopen(*argv++, O_RDONLY); | 141 | rpm_fd = xopen(*argv++, O_RDONLY); |
@@ -141,8 +143,8 @@ int rpm_main(int argc, char **argv) | |||
141 | if (!mytags) | 143 | if (!mytags) |
142 | bb_error_msg_and_die("error reading rpm header"); | 144 | bb_error_msg_and_die("error reading rpm header"); |
143 | offset = xlseek(rpm_fd, 0, SEEK_CUR); | 145 | offset = xlseek(rpm_fd, 0, SEEK_CUR); |
144 | /* Mimimum is one page */ | 146 | /* Some NOMMU systems prefer MAP_PRIVATE over MAP_SHARED */ |
145 | map = mmap(0, offset > pagesize ? (offset + offset % pagesize) : pagesize, PROT_READ, MAP_PRIVATE, rpm_fd, 0); | 147 | map = mmap(0, (offset + pagesize) & (-(int)pagesize), PROT_READ, MAP_PRIVATE, rpm_fd, 0); |
146 | 148 | ||
147 | source_rpm = rpm_getstr(TAG_SOURCERPM, 0); | 149 | source_rpm = rpm_getstr(TAG_SOURCERPM, 0); |
148 | 150 | ||
@@ -166,21 +168,29 @@ int rpm_main(int argc, char **argv) | |||
166 | char bdatestring[50]; | 168 | char bdatestring[50]; |
167 | const char *p; | 169 | const char *p; |
168 | 170 | ||
169 | p = rpm_getstr(TAG_PREFIXS, 0); | 171 | printf("%-12s: %s\n", "Name" , rpm_getstr(TAG_NAME, 0)); |
170 | if (!p) p = "(not relocateable)"; | 172 | /* TODO compat: add "Epoch" here */ |
171 | printf("Name : %-29sRelocations: %s\n", rpm_getstr(TAG_NAME, 0), p); | 173 | printf("%-12s: %s\n", "Version" , rpm_getstr(TAG_VERSION, 0)); |
172 | p = rpm_getstr(TAG_VENDOR, 0); | 174 | printf("%-12s: %s\n", "Release" , rpm_getstr(TAG_RELEASE, 0)); |
173 | if (!p) p = "(none)"; | 175 | /* add "Architecture" */ |
174 | printf("Version : %-34sVendor: %s\n", rpm_getstr(TAG_VERSION, 0), p); | 176 | printf("%-12s: %s\n", "Install Date", "(not installed)"); |
177 | printf("%-12s: %s\n", "Group" , rpm_getstr(TAG_GROUP, 0)); | ||
178 | printf("%-12s: %d\n", "Size" , rpm_getint(TAG_SIZE, 0)); | ||
179 | printf("%-12s: %s\n", "License" , rpm_getstr(TAG_LICENSE, 0)); | ||
180 | /* add "Signature" */ | ||
181 | printf("%-12s: %s\n", "Source RPM" , source_rpm ? source_rpm : "(none)"); | ||
175 | bdate_time = rpm_getint(TAG_BUILDTIME, 0); | 182 | bdate_time = rpm_getint(TAG_BUILDTIME, 0); |
176 | bdate_ptm = localtime(&bdate_time); | 183 | bdate_ptm = localtime(&bdate_time); |
177 | strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate_ptm); | 184 | strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate_ptm); |
178 | printf("Release : %-30sBuild Date: %s\n", rpm_getstr(TAG_RELEASE, 0), bdatestring); | 185 | printf("%-12s: %s\n", "Build Date" , bdatestring); |
179 | printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstr(TAG_BUILDHOST, 0)); | 186 | printf("%-12s: %s\n", "Build Host" , rpm_getstr(TAG_BUILDHOST, 0)); |
180 | printf("Group : %-30sSource RPM: %s\n", rpm_getstr(TAG_GROUP, 0), source_rpm); | 187 | p = rpm_getstr(TAG_PREFIXS, 0); |
181 | printf("Size : %-33dLicense: %s\n", rpm_getint(TAG_SIZE, 0), rpm_getstr(TAG_LICENSE, 0)); | 188 | printf("%-12s: %s\n", "Relocations" , p ? p : "(not relocatable)"); |
182 | printf("URL : %s\n", rpm_getstr(TAG_URL, 0)); | 189 | /* add "Packager" */ |
183 | printf("Summary : %s\n", rpm_getstr(TAG_SUMMARY, 0)); | 190 | p = rpm_getstr(TAG_VENDOR, 0); |
191 | printf("%-12s: %s\n", "Vendor" , p ? p : "(none)"); | ||
192 | printf("%-12s: %s\n", "URL" , rpm_getstr(TAG_URL, 0)); | ||
193 | printf("%-12s: %s\n", "Summary" , rpm_getstr(TAG_SUMMARY, 0)); | ||
184 | printf("Description :\n%s\n", rpm_getstr(TAG_DESCRIPTION, 0)); | 194 | printf("Description :\n%s\n", rpm_getstr(TAG_DESCRIPTION, 0)); |
185 | } | 195 | } |
186 | if (func & rpm_query_list) { | 196 | if (func & rpm_query_list) { |
@@ -206,6 +216,7 @@ int rpm_main(int argc, char **argv) | |||
206 | } | 216 | } |
207 | } | 217 | } |
208 | free(mytags); | 218 | free(mytags); |
219 | close(rpm_fd); | ||
209 | } | 220 | } |
210 | return 0; | 221 | return 0; |
211 | } | 222 | } |
@@ -322,7 +333,7 @@ static char *rpm_getstr(int tag, int itemindex) | |||
322 | static int rpm_getint(int tag, int itemindex) | 333 | static int rpm_getint(int tag, int itemindex) |
323 | { | 334 | { |
324 | rpm_index **found; | 335 | rpm_index **found; |
325 | int *tmpint; /* NB: using int8_t* would be easier to code */ | 336 | char *tmpint; |
326 | 337 | ||
327 | /* gcc throws warnings here when sizeof(void*)!=sizeof(int) ... | 338 | /* gcc throws warnings here when sizeof(void*)!=sizeof(int) ... |
328 | * it's ok to ignore it because tag won't be used as a pointer */ | 339 | * it's ok to ignore it because tag won't be used as a pointer */ |
@@ -330,24 +341,17 @@ static int rpm_getint(int tag, int itemindex) | |||
330 | if (!found || itemindex >= found[0]->count) | 341 | if (!found || itemindex >= found[0]->count) |
331 | return -1; | 342 | return -1; |
332 | 343 | ||
333 | tmpint = (int *) ((char *) map + found[0]->offset); | 344 | tmpint = (char *) map + found[0]->offset; |
334 | |||
335 | if (found[0]->type == RPM_INT32_TYPE) { | 345 | if (found[0]->type == RPM_INT32_TYPE) { |
336 | tmpint = (int *) ((char *) tmpint + itemindex*4); | 346 | tmpint += itemindex*4; |
337 | /*return ntohl(*tmpint);*/ | ||
338 | /* int can be != int32_t */ | ||
339 | return ntohl(*(int32_t*)tmpint); | 347 | return ntohl(*(int32_t*)tmpint); |
340 | } | 348 | } |
341 | if (found[0]->type == RPM_INT16_TYPE) { | 349 | if (found[0]->type == RPM_INT16_TYPE) { |
342 | tmpint = (int *) ((char *) tmpint + itemindex*2); | 350 | tmpint += itemindex*2; |
343 | /* ??? read int, and THEN ntohs() it?? */ | ||
344 | /*return ntohs(*tmpint);*/ | ||
345 | return ntohs(*(int16_t*)tmpint); | 351 | return ntohs(*(int16_t*)tmpint); |
346 | } | 352 | } |
347 | if (found[0]->type == RPM_INT8_TYPE) { | 353 | if (found[0]->type == RPM_INT8_TYPE) { |
348 | tmpint = (int *) ((char *) tmpint + itemindex); | 354 | tmpint += itemindex; |
349 | /* ??? why we don't read byte here??? */ | ||
350 | /*return ntohs(*tmpint);*/ | ||
351 | return *(int8_t*)tmpint; | 355 | return *(int8_t*)tmpint; |
352 | } | 356 | } |
353 | return -1; | 357 | return -1; |