Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Mini rpm applet for busybox |
| 4 | * |
| 5 | * Copyright (C) 2001,2002 by Laurence Anderson |
| 6 | * |
Bernhard Reutner-Fischer | 20f4000 | 2006-01-30 17:17:14 +0000 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Glenn L McGrath | 38386d7 | 2002-12-10 02:09:12 +0000 | [diff] [blame] | 10 | #include "busybox.h" |
| 11 | #include "unarchive.h" |
| 12 | |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 13 | #define RPM_HEADER_MAGIC "\216\255\350" |
| 14 | #define RPM_CHAR_TYPE 1 |
| 15 | #define RPM_INT8_TYPE 2 |
| 16 | #define RPM_INT16_TYPE 3 |
| 17 | #define RPM_INT32_TYPE 4 |
| 18 | /* #define RPM_INT64_TYPE 5 ---- These aren't supported (yet) */ |
| 19 | #define RPM_STRING_TYPE 6 |
| 20 | #define RPM_BIN_TYPE 7 |
| 21 | #define RPM_STRING_ARRAY_TYPE 8 |
| 22 | #define RPM_I18NSTRING_TYPE 9 |
| 23 | |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 24 | #define RPMTAG_NAME 1000 |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 25 | #define RPMTAG_VERSION 1001 |
| 26 | #define RPMTAG_RELEASE 1002 |
| 27 | #define RPMTAG_SUMMARY 1004 |
| 28 | #define RPMTAG_DESCRIPTION 1005 |
| 29 | #define RPMTAG_BUILDTIME 1006 |
| 30 | #define RPMTAG_BUILDHOST 1007 |
| 31 | #define RPMTAG_SIZE 1009 |
| 32 | #define RPMTAG_VENDOR 1011 |
| 33 | #define RPMTAG_LICENSE 1014 |
| 34 | #define RPMTAG_PACKAGER 1015 |
| 35 | #define RPMTAG_GROUP 1016 |
| 36 | #define RPMTAG_URL 1020 |
| 37 | #define RPMTAG_PREIN 1023 |
| 38 | #define RPMTAG_POSTIN 1024 |
| 39 | #define RPMTAG_FILEFLAGS 1037 |
| 40 | #define RPMTAG_FILEUSERNAME 1039 |
| 41 | #define RPMTAG_FILEGROUPNAME 1040 |
| 42 | #define RPMTAG_SOURCERPM 1044 |
| 43 | #define RPMTAG_PREINPROG 1085 |
| 44 | #define RPMTAG_POSTINPROG 1086 |
| 45 | #define RPMTAG_PREFIXS 1098 |
| 46 | #define RPMTAG_DIRINDEXES 1116 |
| 47 | #define RPMTAG_BASENAMES 1117 |
| 48 | #define RPMTAG_DIRNAMES 1118 |
| 49 | #define RPMFILE_CONFIG (1 << 0) |
| 50 | #define RPMFILE_DOC (1 << 1) |
| 51 | |
| 52 | enum rpm_functions_e { |
| 53 | rpm_query = 1, |
| 54 | rpm_install = 2, |
| 55 | rpm_query_info = 4, |
| 56 | rpm_query_package = 8, |
| 57 | rpm_query_list = 16, |
| 58 | rpm_query_list_doc = 32, |
| 59 | rpm_query_list_config = 64 |
| 60 | }; |
| 61 | |
| 62 | typedef struct { |
Eric Andersen | dfcb5b0 | 2004-01-30 22:54:20 +0000 | [diff] [blame] | 63 | uint32_t tag; /* 4 byte tag */ |
| 64 | uint32_t type; /* 4 byte type */ |
| 65 | uint32_t offset; /* 4 byte offset */ |
| 66 | uint32_t count; /* 4 byte count */ |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 67 | } rpm_index; |
| 68 | |
| 69 | static void *map; |
| 70 | static rpm_index **mytags; |
| 71 | static int tagcount; |
| 72 | |
Bernhard Reutner-Fischer | d591a36 | 2006-08-20 17:35:13 +0000 | [diff] [blame] | 73 | static void extract_cpio_gz(int fd); |
| 74 | static rpm_index **rpm_gettags(int fd, int *num_tags); |
| 75 | static int bsearch_rpmtag(const void *key, const void *item); |
| 76 | static char *rpm_getstring(int tag, int itemindex); |
| 77 | static int rpm_getint(int tag, int itemindex); |
| 78 | static int rpm_getcount(int tag); |
| 79 | static void fileaction_dobackup(char *filename, int fileref); |
| 80 | static void fileaction_setowngrp(char *filename, int fileref); |
| 81 | static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref)); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 82 | |
| 83 | int rpm_main(int argc, char **argv) |
| 84 | { |
| 85 | int opt = 0, func = 0, rpm_fd, offset; |
| 86 | |
| 87 | while ((opt = getopt(argc, argv, "iqpldc")) != -1) { |
| 88 | switch (opt) { |
| 89 | case 'i': // First arg: Install mode, with q: Information |
| 90 | if (!func) func |= rpm_install; |
| 91 | else func |= rpm_query_info; |
| 92 | break; |
| 93 | case 'q': // First arg: Query mode |
| 94 | if (!func) func |= rpm_query; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 95 | else bb_show_usage(); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 96 | break; |
| 97 | case 'p': // Query a package |
| 98 | func |= rpm_query_package; |
| 99 | break; |
| 100 | case 'l': // List files in a package |
| 101 | func |= rpm_query_list; |
| 102 | break; |
| 103 | case 'd': // List doc files in a package (implies list) |
| 104 | func |= rpm_query_list; |
| 105 | func |= rpm_query_list_doc; |
| 106 | break; |
| 107 | case 'c': // List config files in a package (implies list) |
| 108 | func |= rpm_query_list; |
| 109 | func |= rpm_query_list_config; |
| 110 | break; |
| 111 | default: |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 112 | bb_show_usage(); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 116 | if (optind == argc) bb_show_usage(); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 117 | while (optind < argc) { |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 118 | rpm_fd = xopen(argv[optind], O_RDONLY); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 119 | mytags = rpm_gettags(rpm_fd, (int *) &tagcount); |
| 120 | offset = lseek(rpm_fd, 0, SEEK_CUR); |
| 121 | if (!mytags) { printf("Error reading rpm header\n"); exit(-1); } |
Mike Frysinger | 5990efb | 2006-01-04 07:31:19 +0000 | [diff] [blame] | 122 | map = mmap(0, offset > getpagesize() ? (offset + offset % getpagesize()) : getpagesize(), PROT_READ, MAP_PRIVATE, rpm_fd, 0); // Mimimum is one page |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 123 | if (func & rpm_install) { |
| 124 | loop_through_files(RPMTAG_BASENAMES, fileaction_dobackup); /* Backup any config files */ |
| 125 | extract_cpio_gz(rpm_fd); // Extact the archive |
| 126 | loop_through_files(RPMTAG_BASENAMES, fileaction_setowngrp); /* Set the correct file uid/gid's */ |
| 127 | } else if (func & rpm_query && func & rpm_query_package) { |
| 128 | if (!((func & rpm_query_info) || (func & rpm_query_list))) { // If just a straight query, just give package name |
| 129 | printf("%s-%s-%s\n", rpm_getstring(RPMTAG_NAME, 0), rpm_getstring(RPMTAG_VERSION, 0), rpm_getstring(RPMTAG_RELEASE, 0)); |
| 130 | } |
| 131 | if (func & rpm_query_info) { |
| 132 | /* Do the nice printout */ |
| 133 | time_t bdate_time; |
| 134 | struct tm *bdate; |
| 135 | char bdatestring[50]; |
| 136 | printf("Name : %-29sRelocations: %s\n", rpm_getstring(RPMTAG_NAME, 0), rpm_getstring(RPMTAG_PREFIXS, 0) ? rpm_getstring(RPMTAG_PREFIXS, 0) : "(not relocateable)"); |
| 137 | printf("Version : %-34sVendor: %s\n", rpm_getstring(RPMTAG_VERSION, 0), rpm_getstring(RPMTAG_VENDOR, 0) ? rpm_getstring(RPMTAG_VENDOR, 0) : "(none)"); |
| 138 | bdate_time = rpm_getint(RPMTAG_BUILDTIME, 0); |
| 139 | bdate = localtime((time_t *) &bdate_time); |
| 140 | strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate); |
| 141 | printf("Release : %-30sBuild Date: %s\n", rpm_getstring(RPMTAG_RELEASE, 0), bdatestring); |
| 142 | printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstring(RPMTAG_BUILDHOST, 0)); |
| 143 | printf("Group : %-30sSource RPM: %s\n", rpm_getstring(RPMTAG_GROUP, 0), rpm_getstring(RPMTAG_SOURCERPM, 0)); |
| 144 | printf("Size : %-33dLicense: %s\n", rpm_getint(RPMTAG_SIZE, 0), rpm_getstring(RPMTAG_LICENSE, 0)); |
| 145 | printf("URL : %s\n", rpm_getstring(RPMTAG_URL, 0)); |
| 146 | printf("Summary : %s\n", rpm_getstring(RPMTAG_SUMMARY, 0)); |
| 147 | printf("Description :\n%s\n", rpm_getstring(RPMTAG_DESCRIPTION, 0)); |
| 148 | } |
| 149 | if (func & rpm_query_list) { |
| 150 | int count, it, flags; |
| 151 | count = rpm_getcount(RPMTAG_BASENAMES); |
| 152 | for (it = 0; it < count; it++) { |
| 153 | flags = rpm_getint(RPMTAG_FILEFLAGS, it); |
| 154 | switch ((func & rpm_query_list_doc) + (func & rpm_query_list_config)) |
| 155 | { |
| 156 | case rpm_query_list_doc: if (!(flags & RPMFILE_DOC)) continue; break; |
| 157 | case rpm_query_list_config: if (!(flags & RPMFILE_CONFIG)) continue; break; |
| 158 | case rpm_query_list_doc + rpm_query_list_config: if (!((flags & RPMFILE_CONFIG) || (flags & RPMFILE_DOC))) continue; break; |
| 159 | } |
| 160 | printf("%s%s\n", rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES, it)), rpm_getstring(RPMTAG_BASENAMES, it)); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | optind++; |
| 165 | free (mytags); |
| 166 | } |
| 167 | return 0; |
| 168 | } |
| 169 | |
Bernhard Reutner-Fischer | d591a36 | 2006-08-20 17:35:13 +0000 | [diff] [blame] | 170 | static void extract_cpio_gz(int fd) { |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 171 | archive_handle_t *archive_handle; |
| 172 | unsigned char magic[2]; |
| 173 | |
| 174 | /* Initialise */ |
| 175 | archive_handle = init_handle(); |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame^] | 176 | archive_handle->seek = seek_by_read; |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 177 | //archive_handle->action_header = header_list; |
| 178 | archive_handle->action_data = data_extract_all; |
| 179 | archive_handle->flags |= ARCHIVE_PRESERVE_DATE; |
| 180 | archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS; |
| 181 | archive_handle->src_fd = fd; |
| 182 | archive_handle->offset = 0; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 183 | |
Rob Landley | 5343747 | 2006-07-16 08:14:35 +0000 | [diff] [blame] | 184 | xread(archive_handle->src_fd, &magic, 2); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 185 | if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 186 | bb_error_msg_and_die("Invalid gzip magic"); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 187 | } |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 188 | check_header_gzip(archive_handle->src_fd); |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 189 | xchdir("/"); // Install RPM's to root |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 190 | |
Glenn L McGrath | 5699b85 | 2003-11-15 23:19:05 +0000 | [diff] [blame] | 191 | archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip); |
| 192 | archive_handle->offset = 0; |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 193 | while (get_header_cpio(archive_handle) == EXIT_SUCCESS); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | |
Bernhard Reutner-Fischer | d591a36 | 2006-08-20 17:35:13 +0000 | [diff] [blame] | 197 | static rpm_index **rpm_gettags(int fd, int *num_tags) |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 198 | { |
Rob Landley | 1ec5b29 | 2006-05-29 07:42:02 +0000 | [diff] [blame] | 199 | rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */ |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 200 | int pass, tagindex = 0; |
| 201 | lseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */ |
| 202 | |
| 203 | for (pass = 0; pass < 2; pass++) { /* 1st pass is the signature headers, 2nd is the main stuff */ |
| 204 | struct { |
| 205 | char magic[3]; /* 3 byte magic: 0x8e 0xad 0xe8 */ |
Eric Andersen | dfcb5b0 | 2004-01-30 22:54:20 +0000 | [diff] [blame] | 206 | uint8_t version; /* 1 byte version number */ |
| 207 | uint32_t reserved; /* 4 bytes reserved */ |
| 208 | uint32_t entries; /* Number of entries in header (4 bytes) */ |
| 209 | uint32_t size; /* Size of store (4 bytes) */ |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 210 | } header; |
| 211 | rpm_index *tmpindex; |
| 212 | int storepos; |
| 213 | |
| 214 | read(fd, &header, sizeof(header)); |
| 215 | if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) return NULL; /* Invalid magic */ |
| 216 | if (header.version != 1) return NULL; /* This program only supports v1 headers */ |
| 217 | header.size = ntohl(header.size); |
| 218 | header.entries = ntohl(header.entries); |
| 219 | storepos = lseek(fd,0,SEEK_CUR) + header.entries * 16; |
| 220 | |
| 221 | while (header.entries--) { |
Mike Frysinger | 1eef0c4 | 2005-08-16 05:32:42 +0000 | [diff] [blame] | 222 | tmpindex = tags[tagindex++] = xmalloc(sizeof(rpm_index)); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 223 | read(fd, tmpindex, sizeof(rpm_index)); |
| 224 | tmpindex->tag = ntohl(tmpindex->tag); tmpindex->type = ntohl(tmpindex->type); tmpindex->count = ntohl(tmpindex->count); |
| 225 | tmpindex->offset = storepos + ntohl(tmpindex->offset); |
| 226 | if (pass==0) tmpindex->tag -= 743; |
| 227 | } |
| 228 | lseek(fd, header.size, SEEK_CUR); /* Seek past store */ |
| 229 | if (pass==0) lseek(fd, (8 - (lseek(fd,0,SEEK_CUR) % 8)) % 8, SEEK_CUR); /* Skip padding to 8 byte boundary after reading signature headers */ |
| 230 | } |
| 231 | tags = realloc(tags, tagindex * sizeof(struct rpmtag *)); /* realloc tags to save space */ |
| 232 | *num_tags = tagindex; |
| 233 | return tags; /* All done, leave the file at the start of the gzipped cpio archive */ |
| 234 | } |
| 235 | |
Bernhard Reutner-Fischer | d591a36 | 2006-08-20 17:35:13 +0000 | [diff] [blame] | 236 | static int bsearch_rpmtag(const void *key, const void *item) |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 237 | { |
Eric Andersen | 2cdd4d5 | 2006-01-30 18:33:12 +0000 | [diff] [blame] | 238 | int *tag = (int *)key; |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 239 | rpm_index **tmp = (rpm_index **) item; |
Eric Andersen | 2cdd4d5 | 2006-01-30 18:33:12 +0000 | [diff] [blame] | 240 | return (*tag - tmp[0]->tag); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Bernhard Reutner-Fischer | d591a36 | 2006-08-20 17:35:13 +0000 | [diff] [blame] | 243 | static int rpm_getcount(int tag) |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 244 | { |
| 245 | rpm_index **found; |
Eric Andersen | 2cdd4d5 | 2006-01-30 18:33:12 +0000 | [diff] [blame] | 246 | found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 247 | if (!found) return 0; |
| 248 | else return found[0]->count; |
| 249 | } |
| 250 | |
Bernhard Reutner-Fischer | d591a36 | 2006-08-20 17:35:13 +0000 | [diff] [blame] | 251 | static char *rpm_getstring(int tag, int itemindex) |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 252 | { |
| 253 | rpm_index **found; |
Eric Andersen | 2cdd4d5 | 2006-01-30 18:33:12 +0000 | [diff] [blame] | 254 | found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 255 | if (!found || itemindex >= found[0]->count) return NULL; |
| 256 | if (found[0]->type == RPM_STRING_TYPE || found[0]->type == RPM_I18NSTRING_TYPE || found[0]->type == RPM_STRING_ARRAY_TYPE) { |
| 257 | int n; |
| 258 | char *tmpstr = (char *) (map + found[0]->offset); |
| 259 | for (n=0; n < itemindex; n++) tmpstr = tmpstr + strlen(tmpstr) + 1; |
| 260 | return tmpstr; |
| 261 | } else return NULL; |
| 262 | } |
| 263 | |
Bernhard Reutner-Fischer | d591a36 | 2006-08-20 17:35:13 +0000 | [diff] [blame] | 264 | static int rpm_getint(int tag, int itemindex) |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 265 | { |
| 266 | rpm_index **found; |
| 267 | int n, *tmpint; |
Mike Frysinger | 19d7021 | 2005-04-23 01:43:07 +0000 | [diff] [blame] | 268 | /* gcc throws warnings here when sizeof(void*)!=sizeof(int) ... |
| 269 | * it's ok to ignore it because tag won't be used as a pointer */ |
Eric Andersen | 2cdd4d5 | 2006-01-30 18:33:12 +0000 | [diff] [blame] | 270 | found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 271 | if (!found || itemindex >= found[0]->count) return -1; |
| 272 | tmpint = (int *) (map + found[0]->offset); |
| 273 | if (found[0]->type == RPM_INT32_TYPE) { |
| 274 | for (n=0; n<itemindex; n++) tmpint = (int *) ((void *) tmpint + 4); |
| 275 | return ntohl(*tmpint); |
| 276 | } else if (found[0]->type == RPM_INT16_TYPE) { |
| 277 | for (n=0; n<itemindex; n++) tmpint = (int *) ((void *) tmpint + 2); |
| 278 | return ntohs(*tmpint); |
| 279 | } else if (found[0]->type == RPM_INT8_TYPE) { |
| 280 | for (n=0; n<itemindex; n++) tmpint = (int *) ((void *) tmpint + 1); |
| 281 | return ntohs(*tmpint); |
| 282 | } else return -1; |
| 283 | } |
| 284 | |
Bernhard Reutner-Fischer | d591a36 | 2006-08-20 17:35:13 +0000 | [diff] [blame] | 285 | static void fileaction_dobackup(char *filename, int fileref) |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 286 | { |
| 287 | struct stat oldfile; |
| 288 | int stat_res; |
| 289 | char *newname; |
| 290 | if (rpm_getint(RPMTAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) { /* Only need to backup config files */ |
| 291 | stat_res = lstat (filename, &oldfile); |
| 292 | if (stat_res == 0 && S_ISREG(oldfile.st_mode)) { /* File already exists - really should check MD5's etc to see if different */ |
Denis Vlasenko | 9cac521 | 2006-09-09 12:24:19 +0000 | [diff] [blame] | 293 | newname = xasprintf("%s.rpmorig", filename); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 294 | copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS); |
| 295 | remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE); |
| 296 | free(newname); |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
Bernhard Reutner-Fischer | d591a36 | 2006-08-20 17:35:13 +0000 | [diff] [blame] | 301 | static void fileaction_setowngrp(char *filename, int fileref) |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 302 | { |
| 303 | int uid, gid; |
Bernhard Reutner-Fischer | d5bd137 | 2005-09-20 21:06:17 +0000 | [diff] [blame] | 304 | uid = bb_xgetpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref)); |
| 305 | gid = bb_xgetgrnam(rpm_getstring(RPMTAG_FILEGROUPNAME, fileref)); |
Denis Vlasenko | cf94446 | 2006-10-03 19:02:20 +0000 | [diff] [blame] | 306 | chown(filename, uid, gid); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Bernhard Reutner-Fischer | d591a36 | 2006-08-20 17:35:13 +0000 | [diff] [blame] | 309 | static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref)) |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 310 | { |
| 311 | int count = 0; |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 312 | while (rpm_getstring(filetag, count)) { |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 313 | char * filename = xasprintf("%s%s", |
Rob Landley | 1ec5b29 | 2006-05-29 07:42:02 +0000 | [diff] [blame] | 314 | rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES, |
| 315 | count)), rpm_getstring(RPMTAG_BASENAMES, count)); |
Glenn L McGrath | b72a735 | 2002-12-10 00:17:22 +0000 | [diff] [blame] | 316 | fileaction(filename, count++); |
| 317 | free(filename); |
| 318 | } |
| 319 | } |