librazor/rpm.c
author J. Ali Harlow <ali@juiblex.co.uk>
Thu Apr 14 11:59:56 2016 +0100 (2016-04-14)
changeset 466 bad1547191dc
parent 458 3f841a46eab5
child 475 008c75a5e08d
permissions -rw-r--r--
Release 0.6.1
rhughes@241
     1
/*
rhughes@241
     2
 * Copyright (C) 2008  Kristian Høgsberg <krh@redhat.com>
rhughes@241
     3
 * Copyright (C) 2008  Red Hat, Inc
ali@460
     4
 * Copyright (C) 2009, 2011, 2012, 2014  J. Ali Harlow <ali@juiblex.co.uk>
rhughes@241
     5
 *
rhughes@241
     6
 * This program is free software; you can redistribute it and/or modify
rhughes@241
     7
 * it under the terms of the GNU General Public License as published by
rhughes@241
     8
 * the Free Software Foundation; either version 2 of the License, or
rhughes@241
     9
 * (at your option) any later version.
rhughes@241
    10
 *
rhughes@241
    11
 * This program is distributed in the hope that it will be useful,
rhughes@241
    12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rhughes@241
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
rhughes@241
    14
 * GNU General Public License for more details.
rhughes@241
    15
 *
rhughes@241
    16
 * You should have received a copy of the GNU General Public License along
rhughes@241
    17
 * with this program; if not, write to the Free Software Foundation, Inc.,
rhughes@241
    18
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
rhughes@241
    19
 */
rhughes@241
    20
ali@327
    21
#include "config.h"
ali@327
    22
rhughes@241
    23
#include <stdio.h>
rhughes@241
    24
#include <stddef.h>
rhughes@241
    25
#include <stdlib.h>
rhughes@241
    26
#include <string.h>
rhughes@241
    27
#include <errno.h>
rhughes@241
    28
#include <sys/stat.h>
rhughes@241
    29
#include <sys/types.h>
ali@330
    30
#if HAVE_SYS_WAIT_H
rhughes@241
    31
#include <sys/wait.h>
ali@330
    32
#endif
rhughes@241
    33
#include <fcntl.h>
rhughes@241
    34
#include <dirent.h>
rhughes@241
    35
#include <unistd.h>
ali@329
    36
#if MSWIN_API
ali@335
    37
#include <winsock2.h>	/* For ntohl() */
ali@329
    38
#else
rhughes@241
    39
#include <arpa/inet.h>
ali@329
    40
#endif
ali@325
    41
#include <limits.h>
rhughes@241
    42
#include <zlib.h>
richard@301
    43
#include <assert.h>
rhughes@241
    44
rhughes@241
    45
#include "razor.h"
rhughes@241
    46
#include "razor-internal.h"
rhughes@241
    47
ali@345
    48
#ifndef O_BINARY
ali@345
    49
#define O_BINARY	0
ali@345
    50
#endif
ali@345
    51
ali@460
    52
struct rpm_lead {
ali@460
    53
	unsigned char magic[4];
ali@460
    54
	unsigned char major, minor;
ali@460
    55
	short type;
ali@460
    56
	short archnum;
ali@460
    57
	char name[66];
ali@460
    58
	short osnum;
ali@460
    59
	short signature_type;
ali@460
    60
	char reserved[16];
ali@460
    61
};
ali@460
    62
ali@460
    63
#define	RPM_LEAD_SIZE sizeof(struct rpm_lead)
ali@460
    64
#define	RPM_LEAD_MAGIC "\xED\xAB\xEE\xDB"
rhughes@241
    65
rhughes@241
    66
enum {
rhughes@241
    67
    PIPE	=  1,	/*!< pipe/fifo */
rhughes@241
    68
    CDEV	=  2,	/*!< character device */
rhughes@241
    69
    XDIR	=  4,	/*!< directory */
rhughes@241
    70
    BDEV	=  6,	/*!< block device */
rhughes@241
    71
    REG		=  8,	/*!< regular file */
rhughes@241
    72
    LINK	= 10,	/*!< hard link */
rhughes@241
    73
    SOCK	= 12	/*!< socket */
rhughes@241
    74
};
rhughes@241
    75
rhughes@241
    76
enum {
krh@247
    77
    RPMSENSE_LESS		= 1 << 1,
krh@247
    78
    RPMSENSE_GREATER		= 1 << 2,
krh@247
    79
    RPMSENSE_EQUAL		= 1 << 3,
krh@247
    80
    RPMSENSE_PREREQ		= 1 << 6,
krh@247
    81
    RPMSENSE_SCRIPT_PRE		= 1 << 9,
krh@247
    82
    RPMSENSE_SCRIPT_POST	= 1 << 10,
krh@247
    83
    RPMSENSE_SCRIPT_PREUN	= 1 << 11,
krh@247
    84
    RPMSENSE_SCRIPT_POSTUN	= 1 << 12,
rhughes@241
    85
};
rhughes@241
    86
rhughes@241
    87
enum {
rhughes@241
    88
    RPMTAG_NAME  		= 1000,	/* s */
rhughes@241
    89
    RPMTAG_VERSION		= 1001,	/* s */
rhughes@241
    90
    RPMTAG_RELEASE		= 1002,	/* s */
rhughes@241
    91
    RPMTAG_EPOCH   		= 1003,	/* i */
rhughes@241
    92
    RPMTAG_SUMMARY		= 1004,	/* s{} */
rhughes@241
    93
    RPMTAG_DESCRIPTION		= 1005,	/* s{} */
rhughes@241
    94
    RPMTAG_BUILDTIME		= 1006,	/* i */
rhughes@241
    95
    RPMTAG_BUILDHOST		= 1007,	/* s */
rhughes@241
    96
    RPMTAG_INSTALLTIME		= 1008,	/* i */
rhughes@241
    97
    RPMTAG_SIZE			= 1009,	/* i */
rhughes@241
    98
    RPMTAG_DISTRIBUTION		= 1010,	/* s */
rhughes@241
    99
    RPMTAG_VENDOR		= 1011,	/* s */
rhughes@241
   100
    RPMTAG_GIF			= 1012,	/* x */
rhughes@241
   101
    RPMTAG_XPM			= 1013,	/* x */
rhughes@241
   102
    RPMTAG_LICENSE		= 1014,	/* s */
rhughes@241
   103
    RPMTAG_PACKAGER		= 1015,	/* s */
rhughes@241
   104
    RPMTAG_GROUP		= 1016,	/* s{} */
rhughes@241
   105
    RPMTAG_CHANGELOG		= 1017, /*!< s[] internal */
rhughes@241
   106
    RPMTAG_SOURCE		= 1018,	/* s[] */
rhughes@241
   107
    RPMTAG_PATCH		= 1019,	/* s[] */
rhughes@241
   108
    RPMTAG_URL			= 1020,	/* s */
rhughes@241
   109
    RPMTAG_OS			= 1021,	/* s legacy used int */
rhughes@241
   110
    RPMTAG_ARCH			= 1022,	/* s legacy used int */
rhughes@241
   111
    RPMTAG_PREIN		= 1023,	/* s */
rhughes@241
   112
    RPMTAG_POSTIN		= 1024,	/* s */
rhughes@241
   113
    RPMTAG_PREUN		= 1025,	/* s */
rhughes@241
   114
    RPMTAG_POSTUN		= 1026,	/* s */
rhughes@241
   115
    RPMTAG_OLDFILENAMES		= 1027, /* s[] obsolete */
rhughes@241
   116
    RPMTAG_FILESIZES		= 1028,	/* i */
rhughes@241
   117
    RPMTAG_FILESTATES		= 1029, /* c */
rhughes@241
   118
    RPMTAG_FILEMODES		= 1030,	/* h */
rhughes@241
   119
    RPMTAG_FILEUIDS		= 1031, /*!< internal */
rhughes@241
   120
    RPMTAG_FILEGIDS		= 1032, /*!< internal */
rhughes@241
   121
    RPMTAG_FILERDEVS		= 1033,	/* h */
rhughes@241
   122
    RPMTAG_FILEMTIMES		= 1034, /* i */
rhughes@241
   123
    RPMTAG_FILEMD5S		= 1035,	/* s[] */
rhughes@241
   124
    RPMTAG_FILELINKTOS		= 1036,	/* s[] */
rhughes@241
   125
    RPMTAG_FILEFLAGS		= 1037,	/* i */
rhughes@241
   126
    RPMTAG_ROOT			= 1038, /*!< internal - obsolete */
rhughes@241
   127
    RPMTAG_FILEUSERNAME		= 1039,	/* s[] */
rhughes@241
   128
    RPMTAG_FILEGROUPNAME	= 1040,	/* s[] */
rhughes@241
   129
    RPMTAG_EXCLUDE		= 1041, /*!< internal - obsolete */
rhughes@241
   130
    RPMTAG_EXCLUSIVE		= 1042, /*!< internal - obsolete */
rhughes@241
   131
    RPMTAG_ICON			= 1043,
rhughes@241
   132
    RPMTAG_SOURCERPM		= 1044,	/* s */
rhughes@241
   133
    RPMTAG_FILEVERIFYFLAGS	= 1045,	/* i */
rhughes@241
   134
    RPMTAG_ARCHIVESIZE		= 1046,	/* i */
rhughes@241
   135
    RPMTAG_PROVIDENAME		= 1047,	/* s[] */
rhughes@241
   136
    RPMTAG_REQUIREFLAGS		= 1048,	/* i */
rhughes@241
   137
    RPMTAG_REQUIRENAME		= 1049,	/* s[] */
rhughes@241
   138
    RPMTAG_REQUIREVERSION	= 1050,	/* s[] */
rhughes@241
   139
    RPMTAG_NOSOURCE		= 1051, /*!< internal */
rhughes@241
   140
    RPMTAG_NOPATCH		= 1052, /*!< internal */
rhughes@241
   141
    RPMTAG_CONFLICTFLAGS	= 1053, /* i */
rhughes@241
   142
    RPMTAG_CONFLICTNAME		= 1054,	/* s[] */
rhughes@241
   143
    RPMTAG_CONFLICTVERSION	= 1055,	/* s[] */
rhughes@241
   144
    RPMTAG_DEFAULTPREFIX	= 1056, /*!< internal - deprecated */
rhughes@241
   145
    RPMTAG_BUILDROOT		= 1057, /*!< internal */
rhughes@241
   146
    RPMTAG_INSTALLPREFIX	= 1058, /*!< internal - deprecated */
rhughes@241
   147
    RPMTAG_EXCLUDEARCH		= 1059,
rhughes@241
   148
    RPMTAG_EXCLUDEOS		= 1060,
rhughes@241
   149
    RPMTAG_EXCLUSIVEARCH	= 1061,
rhughes@241
   150
    RPMTAG_EXCLUSIVEOS		= 1062,
rhughes@241
   151
    RPMTAG_AUTOREQPROV		= 1063, /*!< internal */
rhughes@241
   152
    RPMTAG_RPMVERSION		= 1064,	/* s */
rhughes@241
   153
    RPMTAG_TRIGGERSCRIPTS	= 1065,	/* s[] */
rhughes@241
   154
    RPMTAG_TRIGGERNAME		= 1066,	/* s[] */
rhughes@241
   155
    RPMTAG_TRIGGERVERSION	= 1067,	/* s[] */
rhughes@241
   156
    RPMTAG_TRIGGERFLAGS		= 1068,	/* i */
rhughes@241
   157
    RPMTAG_TRIGGERINDEX		= 1069,	/* i */
rhughes@241
   158
    RPMTAG_VERIFYSCRIPT		= 1079,	/* s */
rhughes@241
   159
    RPMTAG_CHANGELOGTIME	= 1080,	/* i */
rhughes@241
   160
    RPMTAG_CHANGELOGNAME	= 1081,	/* s[] */
rhughes@241
   161
    RPMTAG_CHANGELOGTEXT	= 1082,	/* s[] */
rhughes@241
   162
    RPMTAG_BROKENMD5		= 1083, /*!< internal - obsolete */
rhughes@241
   163
    RPMTAG_PREREQ		= 1084, /*!< internal */
rhughes@241
   164
    RPMTAG_PREINPROG		= 1085,	/* s */
rhughes@241
   165
    RPMTAG_POSTINPROG		= 1086,	/* s */
rhughes@241
   166
    RPMTAG_PREUNPROG		= 1087,	/* s */
rhughes@241
   167
    RPMTAG_POSTUNPROG		= 1088,	/* s */
rhughes@241
   168
    RPMTAG_BUILDARCHS		= 1089,
rhughes@241
   169
    RPMTAG_OBSOLETENAME		= 1090,	/* s[] */
rhughes@241
   170
    RPMTAG_VERIFYSCRIPTPROG	= 1091,	/* s */
rhughes@241
   171
    RPMTAG_TRIGGERSCRIPTPROG	= 1092,	/* s */
rhughes@241
   172
    RPMTAG_DOCDIR		= 1093, /*!< internal */
rhughes@241
   173
    RPMTAG_COOKIE		= 1094,	/* s */
rhughes@241
   174
    RPMTAG_FILEDEVICES		= 1095,	/* i */
rhughes@241
   175
    RPMTAG_FILEINODES		= 1096,	/* i */
rhughes@241
   176
    RPMTAG_FILELANGS		= 1097,	/* s[] */
rhughes@241
   177
    RPMTAG_PREFIXES		= 1098,	/* s[] */
rhughes@241
   178
    RPMTAG_INSTPREFIXES		= 1099,	/* s[] */
rhughes@241
   179
    RPMTAG_TRIGGERIN		= 1100, /*!< internal */
rhughes@241
   180
    RPMTAG_TRIGGERUN		= 1101, /*!< internal */
rhughes@241
   181
    RPMTAG_TRIGGERPOSTUN	= 1102, /*!< internal */
rhughes@241
   182
    RPMTAG_AUTOREQ		= 1103, /*!< internal */
rhughes@241
   183
    RPMTAG_AUTOPROV		= 1104, /*!< internal */
rhughes@241
   184
    RPMTAG_CAPABILITY		= 1105, /*!< internal - obsolete */
rhughes@241
   185
    RPMTAG_SOURCEPACKAGE	= 1106, /*!< i src.rpm header marker */
rhughes@241
   186
    RPMTAG_OLDORIGFILENAMES	= 1107, /*!< internal - obsolete */
rhughes@241
   187
    RPMTAG_BUILDPREREQ		= 1108, /*!< internal */
rhughes@241
   188
    RPMTAG_BUILDREQUIRES	= 1109, /*!< internal */
rhughes@241
   189
    RPMTAG_BUILDCONFLICTS	= 1110, /*!< internal */
rhughes@241
   190
    RPMTAG_BUILDMACROS		= 1111, /*!< internal - unused */
rhughes@241
   191
    RPMTAG_PROVIDEFLAGS		= 1112,	/* i */
rhughes@241
   192
    RPMTAG_PROVIDEVERSION	= 1113,	/* s[] */
rhughes@241
   193
    RPMTAG_OBSOLETEFLAGS	= 1114,	/* i */
rhughes@241
   194
    RPMTAG_OBSOLETEVERSION	= 1115,	/* s[] */
rhughes@241
   195
    RPMTAG_DIRINDEXES		= 1116,	/* i */
rhughes@241
   196
    RPMTAG_BASENAMES		= 1117,	/* s[] */
rhughes@241
   197
    RPMTAG_DIRNAMES		= 1118,	/* s[] */
rhughes@241
   198
    RPMTAG_ORIGDIRINDEXES	= 1119, /*!< internal */
rhughes@241
   199
    RPMTAG_ORIGBASENAMES	= 1120, /*!< internal */
rhughes@241
   200
    RPMTAG_ORIGDIRNAMES		= 1121, /*!< internal */
rhughes@241
   201
    RPMTAG_OPTFLAGS		= 1122,	/* s */
rhughes@241
   202
    RPMTAG_DISTURL		= 1123,	/* s */
rhughes@241
   203
    RPMTAG_PAYLOADFORMAT	= 1124,	/* s */
rhughes@241
   204
    RPMTAG_PAYLOADCOMPRESSOR	= 1125,	/* s */
rhughes@241
   205
    RPMTAG_PAYLOADFLAGS		= 1126,	/* s */
rhughes@241
   206
    RPMTAG_INSTALLCOLOR		= 1127, /*!< i transaction color when installed */
rhughes@241
   207
    RPMTAG_INSTALLTID		= 1128,	/* i */
rhughes@241
   208
    RPMTAG_REMOVETID		= 1129,	/* i */
rhughes@241
   209
    RPMTAG_SHA1RHN		= 1130, /*!< internal - obsolete */
rhughes@241
   210
    RPMTAG_RHNPLATFORM		= 1131,	/* s */
rhughes@241
   211
    RPMTAG_PLATFORM		= 1132,	/* s */
rhughes@241
   212
    RPMTAG_PATCHESNAME		= 1133, /*!< placeholder (SuSE) */
rhughes@241
   213
    RPMTAG_PATCHESFLAGS		= 1134, /*!< placeholder (SuSE) */
rhughes@241
   214
    RPMTAG_PATCHESVERSION	= 1135, /*!< placeholder (SuSE) */
rhughes@241
   215
    RPMTAG_CACHECTIME		= 1136,	/* i */
rhughes@241
   216
    RPMTAG_CACHEPKGPATH		= 1137,	/* s */
rhughes@241
   217
    RPMTAG_CACHEPKGSIZE		= 1138,	/* i */
rhughes@241
   218
    RPMTAG_CACHEPKGMTIME	= 1139,	/* i */
rhughes@241
   219
    RPMTAG_FILECOLORS		= 1140,	/* i */
rhughes@241
   220
    RPMTAG_FILECLASS		= 1141,	/* i */
rhughes@241
   221
    RPMTAG_CLASSDICT		= 1142,	/* s[] */
rhughes@241
   222
    RPMTAG_FILEDEPENDSX		= 1143,	/* i */
rhughes@241
   223
    RPMTAG_FILEDEPENDSN		= 1144,	/* i */
rhughes@241
   224
    RPMTAG_DEPENDSDICT		= 1145,	/* i */
rhughes@241
   225
    RPMTAG_SOURCEPKGID		= 1146,	/* x */
rhughes@241
   226
    RPMTAG_FILECONTEXTS		= 1147,	/* s[] */
rhughes@241
   227
    RPMTAG_FSCONTEXTS		= 1148,	/*!< s[] extension */
rhughes@241
   228
    RPMTAG_RECONTEXTS		= 1149,	/*!< s[] extension */
rhughes@241
   229
    RPMTAG_POLICIES		= 1150,	/*!< s[] selinux *.te policy file. */
rhughes@241
   230
    RPMTAG_PRETRANS		= 1151,	/* s */
rhughes@241
   231
    RPMTAG_POSTTRANS		= 1152,	/* s */
rhughes@241
   232
    RPMTAG_PRETRANSPROG		= 1153,	/* s */
rhughes@241
   233
    RPMTAG_POSTTRANSPROG	= 1154,	/* s */
rhughes@241
   234
    RPMTAG_DISTTAG		= 1155,	/* s */
rhughes@241
   235
    RPMTAG_SUGGESTSNAME		= 1156,	/* s[] extension placeholder */
rhughes@241
   236
    RPMTAG_SUGGESTSVERSION	= 1157,	/* s[] extension placeholder */
rhughes@241
   237
    RPMTAG_SUGGESTSFLAGS	= 1158,	/* i   extension placeholder */
rhughes@241
   238
    RPMTAG_ENHANCESNAME		= 1159,	/* s[] extension placeholder */
rhughes@241
   239
    RPMTAG_ENHANCESVERSION	= 1160,	/* s[] extension placeholder */
rhughes@241
   240
    RPMTAG_ENHANCESFLAGS	= 1161,	/* i   extension placeholder */
rhughes@241
   241
    RPMTAG_PRIORITY		= 1162, /* i   extension placeholder */
rhughes@241
   242
    RPMTAG_CVSID		= 1163, /* s */
rhughes@241
   243
    RPMTAG_TRIGGERPREIN		= 1171, /*!< internal */
rhughes@241
   244
};
rhughes@241
   245
rhughes@241
   246
struct rpm_header {
rhughes@241
   247
	unsigned char magic[4];
rhughes@241
   248
	unsigned char reserved[4];
rhughes@241
   249
	int nindex;
rhughes@241
   250
	int hsize;
rhughes@241
   251
};
rhughes@241
   252
rhughes@241
   253
struct rpm_header_index {
rhughes@241
   254
	int tag;
rhughes@241
   255
	int type;
rhughes@241
   256
	int offset;
rhughes@241
   257
	int count;
rhughes@241
   258
};
rhughes@241
   259
rhughes@241
   260
struct razor_rpm {
rhughes@241
   261
	struct rpm_header *signature;
rhughes@241
   262
	struct rpm_header *header;
rhughes@241
   263
	const char **dirs;
ali@351
   264
	unsigned int n_prefixes;
ali@351
   265
	const char **prefixes;
rhughes@241
   266
	const char *pool;
rhughes@241
   267
	void *map;
rhughes@241
   268
	size_t size;
rhughes@241
   269
	void *payload;
ali@351
   270
	struct razor_relocations *relocations;
ali@369
   271
	char *evr;
rhughes@241
   272
};
rhughes@241
   273
ali@351
   274
enum razor_relocation_flags {
ali@351
   275
	RAZOR_RELOCATION_ACTIVE		= 1 << 0,
ali@351
   276
};
ali@351
   277
ali@351
   278
struct razor_relocation {
ali@351
   279
	enum razor_relocation_flags flags;
ali@351
   280
	size_t oldlen;
ali@351
   281
	size_t newlen;
ali@351
   282
	char *oldpath;
ali@351
   283
	char *newpath;
ali@351
   284
};
ali@351
   285
ali@351
   286
struct razor_relocations {
ali@351
   287
	/* Ordered such that if oldpath 1 starts with oldpath 2, then
ali@351
   288
	 * oldpath 1 is listed first (ie., /usr/bin comes before /usr)
ali@351
   289
	 * and terminated with a NULL oldpath.
ali@351
   290
	 */
ali@351
   291
	struct razor_relocation *relocations;
ali@351
   292
	int n_relocations;
ali@351
   293
	char *path;
ali@351
   294
};
ali@351
   295
ali@351
   296
RAZOR_EXPORT struct razor_relocations *razor_relocations_create(void)
ali@351
   297
{
ali@351
   298
	return calloc(1, sizeof(struct razor_relocations));
ali@351
   299
}
ali@351
   300
ali@351
   301
RAZOR_EXPORT void razor_relocations_add(struct razor_relocations *rr,
ali@351
   302
			   const char *oldpath, const char *newpath)
ali@351
   303
{
ali@351
   304
	int i, found = 0;
ali@351
   305
	size_t len;
ali@351
   306
ali@351
   307
	if (newpath && !strcmp(oldpath, newpath))
ali@351
   308
		newpath = NULL;
ali@351
   309
ali@351
   310
	for (i = 0; i < rr->n_relocations; i++) {
ali@351
   311
		len = rr->relocations[i].oldlen;
ali@351
   312
		if (!strncmp(rr->relocations[i].oldpath, oldpath, len)) {
ali@351
   313
			found = !strcmp(rr->relocations[i].oldpath, oldpath);
ali@351
   314
			break;
ali@351
   315
		}
ali@351
   316
	}
ali@351
   317
ali@351
   318
	if (!newpath) {
ali@351
   319
		if (found) {
ali@351
   320
			free(rr->relocations[i].oldpath);
ali@351
   321
			free(rr->relocations[i].newpath);
ali@351
   322
			do {
ali@351
   323
				rr->relocations[i] = rr->relocations[i + 1];
ali@351
   324
			} while (rr->relocations[++i].oldpath);
ali@351
   325
		}
ali@351
   326
		return;
ali@351
   327
	}
ali@351
   328
ali@351
   329
	if (found) {
ali@351
   330
		free(rr->relocations[i].newpath);
ali@351
   331
		rr->relocations[i].newpath = strdup(newpath);
ali@351
   332
		rr->relocations[i].newlen = strlen(newpath);
ali@351
   333
		return;
ali@351
   334
	}
ali@351
   335
ali@351
   336
	if (!rr->n_relocations++)
ali@351
   337
		rr->relocations = calloc(1, sizeof *rr->relocations);
ali@351
   338
	else {
ali@351
   339
		rr->relocations = realloc(rr->relocations,
ali@351
   340
					  rr->n_relocations * sizeof *rr->relocations);
ali@351
   341
		memmove(rr->relocations + i + 1, rr->relocations + i,
ali@351
   342
			(rr->n_relocations - i - 1) * sizeof *rr->relocations);
ali@351
   343
	}
ali@351
   344
ali@351
   345
	rr->relocations[i].flags = 0;
ali@351
   346
	rr->relocations[i].oldpath = strdup(oldpath);
ali@351
   347
	rr->relocations[i].newpath = strdup(newpath);
ali@351
   348
	rr->relocations[i].oldlen = strlen(oldpath);
ali@351
   349
	rr->relocations[i].newlen = strlen(newpath);
ali@351
   350
}
ali@351
   351
ali@351
   352
RAZOR_EXPORT void
ali@351
   353
razor_relocations_set_rpm(struct razor_relocations *rr, struct razor_rpm *rpm)
ali@351
   354
{
ali@351
   355
	int i, j;
ali@351
   356
ali@351
   357
	for (i = 0; i < rr->n_relocations; i++) {
ali@351
   358
		rr->relocations[i].flags &= ~RAZOR_RELOCATION_ACTIVE;
ali@351
   359
		for (j = 0; j < rpm->n_prefixes; j++)
ali@351
   360
			if (!strcmp(rpm->prefixes[j],
ali@351
   361
				    rr->relocations[i].oldpath)) {
ali@351
   362
				rr->relocations[i].flags |= RAZOR_RELOCATION_ACTIVE;
ali@351
   363
				break;
ali@351
   364
			}
ali@351
   365
	}
ali@351
   366
}
ali@351
   367
ali@351
   368
RAZOR_EXPORT const char *
ali@351
   369
razor_relocations_apply(struct razor_relocations *rr, const char *path)
ali@351
   370
{
ali@351
   371
	int i;
ali@351
   372
	size_t len;
ali@351
   373
ali@351
   374
	for (i = 0; i < rr->n_relocations; i++)
ali@351
   375
		if (rr->relocations[i].flags & RAZOR_RELOCATION_ACTIVE &&
ali@351
   376
		    !strncmp(path, rr->relocations[i].oldpath,
ali@351
   377
			     rr->relocations[i].oldlen))
ali@351
   378
			break;
ali@351
   379
ali@351
   380
	if (i < rr->n_relocations) {
ali@351
   381
		free(rr->path);
ali@351
   382
		len = strlen(path + rr->relocations[i].oldlen) +
ali@351
   383
		      rr->relocations[i].newlen;
ali@351
   384
		rr->path = malloc(len + 1);
ali@351
   385
		memcpy(rr->path, rr->relocations[i].newpath,
ali@351
   386
		       rr->relocations[i].newlen);
ali@351
   387
		strcpy(rr->path + rr->relocations[i].newlen,
ali@351
   388
		       path + rr->relocations[i].oldlen);
ali@351
   389
		return rr->path;
ali@351
   390
	} else
ali@351
   391
		return path;
ali@351
   392
}
ali@351
   393
ali@351
   394
RAZOR_EXPORT void razor_relocations_destroy(struct razor_relocations *rr)
ali@351
   395
{
ali@458
   396
	int i;
ali@458
   397
ali@458
   398
	for (i = 0; i < rr->n_relocations; i++) {
ali@458
   399
	    free(rr->relocations[i].oldpath);
ali@458
   400
	    free(rr->relocations[i].newpath);
ali@458
   401
	}
ali@351
   402
	free(rr->path);
ali@351
   403
	free(rr->relocations);
ali@351
   404
	free(rr);
ali@351
   405
}
ali@351
   406
rhughes@241
   407
static struct rpm_header_index *
rhughes@241
   408
razor_rpm_get_header(struct razor_rpm *rpm, unsigned int tag)
rhughes@241
   409
{
rhughes@241
   410
	struct rpm_header_index *index, *end;
rhughes@241
   411
rhughes@241
   412
	index = (struct rpm_header_index *) (rpm->header + 1);
rhughes@241
   413
	end = index + ntohl(rpm->header->nindex);
rhughes@241
   414
	while (index < end) {
rhughes@241
   415
		if (ntohl(index->tag) == tag)
rhughes@241
   416
			return index;
rhughes@241
   417
		index++;
rhughes@241
   418
	}
rhughes@241
   419
rhughes@241
   420
	return NULL;
rhughes@241
   421
}
rhughes@241
   422
rhughes@241
   423
static const void *
rhughes@241
   424
razor_rpm_get_indirect(struct razor_rpm *rpm,
rhughes@241
   425
		       unsigned int tag, unsigned int *count)
rhughes@241
   426
{
rhughes@241
   427
	struct rpm_header_index *index;
rhughes@241
   428
rhughes@241
   429
	index = razor_rpm_get_header(rpm, tag);
rhughes@241
   430
	if (index != NULL) {
rhughes@241
   431
		if (count)
rhughes@241
   432
			*count = ntohl(index->count);
rhughes@241
   433
rhughes@241
   434
		return rpm->pool + ntohl(index->offset);
rhughes@241
   435
	}
rhughes@241
   436
rhughes@241
   437
	return NULL;
rhughes@241
   438
}
rhughes@241
   439
krh@247
   440
static uint32_t
rhughes@241
   441
rpm_to_razor_flags(uint32_t flags)
rhughes@241
   442
{
krh@247
   443
	uint32_t razor_flags;
rhughes@241
   444
krh@247
   445
	razor_flags = 0;
krh@247
   446
	if (flags & RPMSENSE_LESS)
krh@247
   447
		razor_flags |= RAZOR_PROPERTY_LESS;
krh@247
   448
	if (flags & RPMSENSE_EQUAL)
krh@247
   449
		razor_flags |= RAZOR_PROPERTY_EQUAL;
krh@247
   450
	if (flags & RPMSENSE_GREATER)
krh@247
   451
		razor_flags |= RAZOR_PROPERTY_GREATER;
krh@247
   452
krh@247
   453
	if (flags & RPMSENSE_SCRIPT_PRE)
krh@247
   454
		razor_flags |= RAZOR_PROPERTY_PRE;
krh@247
   455
	if (flags & RPMSENSE_SCRIPT_POST)
krh@247
   456
		razor_flags |= RAZOR_PROPERTY_POST;
krh@247
   457
	if (flags & RPMSENSE_SCRIPT_PREUN)
krh@247
   458
		razor_flags |= RAZOR_PROPERTY_PREUN;
krh@247
   459
	if (flags & RPMSENSE_SCRIPT_POSTUN)
krh@247
   460
		razor_flags |= RAZOR_PROPERTY_POSTUN;
krh@247
   461
	
krh@247
   462
	return razor_flags;
rhughes@241
   463
}
rhughes@241
   464
rhughes@241
   465
static void
krh@247
   466
import_properties(struct razor_importer *importer, uint32_t type,
rhughes@241
   467
		  struct razor_rpm *rpm,
rhughes@241
   468
		  int name_tag, int version_tag, int flags_tag)
rhughes@241
   469
{
rhughes@241
   470
	const char *name, *version;
rhughes@241
   471
	const uint32_t *flags;
rhughes@241
   472
	uint32_t f;
rhughes@241
   473
	unsigned int i, count;
rhughes@241
   474
rhughes@241
   475
	name = razor_rpm_get_indirect(rpm, name_tag, &count);
rhughes@241
   476
	if (name == NULL)
rhughes@241
   477
		return;
rhughes@241
   478
rhughes@241
   479
	flags = razor_rpm_get_indirect(rpm, flags_tag, &count);
rhughes@241
   480
rhughes@241
   481
	version = razor_rpm_get_indirect(rpm, version_tag, &count);
rhughes@241
   482
	for (i = 0; i < count; i++) {
rhughes@241
   483
		f = rpm_to_razor_flags(ntohl(flags[i]));
krh@247
   484
		razor_importer_add_property(importer, name, f | type, version);
rhughes@241
   485
		name += strlen(name) + 1;
rhughes@241
   486
		version += strlen(version) + 1;
rhughes@241
   487
	}
rhughes@241
   488
}
rhughes@241
   489
rhughes@241
   490
static void
rhughes@241
   491
import_files(struct razor_importer *importer, struct razor_rpm *rpm)
rhughes@241
   492
{
rhughes@241
   493
	const char *name;
rhughes@241
   494
	const uint32_t *index;
rhughes@241
   495
	unsigned int i, count;
rhughes@241
   496
	char buffer[256];
rhughes@241
   497
krh@246
   498
	if (rpm->dirs == NULL)
krh@246
   499
		return;
krh@246
   500
rhughes@241
   501
	/* assert: count is the same for all arrays */
rhughes@241
   502
	index = razor_rpm_get_indirect(rpm, RPMTAG_DIRINDEXES, &count);
rhughes@241
   503
	name = razor_rpm_get_indirect(rpm, RPMTAG_BASENAMES, &count);
rhughes@241
   504
	for (i = 0; i < count; i++) {
rhughes@241
   505
		snprintf(buffer, sizeof buffer,
rhughes@241
   506
			 "%s%s", rpm->dirs[ntohl(*index)], name);
rhughes@241
   507
		razor_importer_add_file(importer, buffer);
rhughes@241
   508
		name += strlen(name) + 1;
rhughes@241
   509
		index++;
rhughes@241
   510
	}
rhughes@241
   511
}
rhughes@241
   512
ali@369
   513
static void
ali@369
   514
razor_rpm_build_evr(struct razor_rpm *rpm)
ali@369
   515
{
ali@369
   516
	const char *version, *release;
ali@369
   517
	const uint32_t *epoch;
ali@369
   518
	char evr[128], buf[16];
ali@369
   519
ali@369
   520
	epoch = razor_rpm_get_indirect(rpm, RPMTAG_EPOCH, NULL);
ali@369
   521
	version = razor_rpm_get_indirect(rpm, RPMTAG_VERSION, NULL);
ali@369
   522
	release = razor_rpm_get_indirect(rpm, RPMTAG_RELEASE, NULL);
ali@369
   523
	if (epoch)
ali@369
   524
		snprintf(buf, sizeof buf, "%lu", (unsigned long)ntohl(*epoch));
ali@369
   525
	razor_build_evr(evr, sizeof evr, epoch ? buf : NULL, version, release);
ali@369
   526
	rpm->evr = strdup(evr);
ali@369
   527
}
ali@369
   528
ali@369
   529
static const char *
ali@372
   530
razor_rpm_get_details_string(struct razor_rpm *rpm, enum razor_detail_type type)
ali@369
   531
{
ali@369
   532
	switch(type) {
ali@369
   533
	case RAZOR_DETAIL_NAME:
ali@369
   534
		return razor_rpm_get_indirect(rpm, RPMTAG_NAME, NULL);
ali@369
   535
ali@369
   536
	case RAZOR_DETAIL_VERSION:
ali@369
   537
		if (!rpm->evr)
ali@369
   538
			razor_rpm_build_evr(rpm);
ali@369
   539
		return rpm->evr;
ali@369
   540
ali@369
   541
	case RAZOR_DETAIL_ARCH:
ali@369
   542
		return razor_rpm_get_indirect(rpm, RPMTAG_ARCH, NULL);
ali@369
   543
ali@369
   544
	case RAZOR_DETAIL_SUMMARY:
ali@369
   545
		return razor_rpm_get_indirect(rpm, RPMTAG_SUMMARY, NULL);
ali@369
   546
ali@369
   547
	case RAZOR_DETAIL_DESCRIPTION:
ali@369
   548
		return razor_rpm_get_indirect(rpm, RPMTAG_DESCRIPTION, NULL);
ali@369
   549
ali@369
   550
	case RAZOR_DETAIL_URL:
ali@369
   551
		return razor_rpm_get_indirect(rpm, RPMTAG_URL, NULL);
ali@369
   552
ali@369
   553
	case RAZOR_DETAIL_LICENSE:
ali@369
   554
		return razor_rpm_get_indirect(rpm, RPMTAG_LICENSE, NULL);
ali@369
   555
ali@369
   556
	case RAZOR_DETAIL_PREUNPROG:
ali@369
   557
		return razor_rpm_get_indirect(rpm, RPMTAG_PREUNPROG, NULL);
ali@369
   558
ali@369
   559
	case RAZOR_DETAIL_PREUN:
ali@369
   560
		return razor_rpm_get_indirect(rpm, RPMTAG_PREUN, NULL);
ali@369
   561
ali@369
   562
	case RAZOR_DETAIL_POSTUNPROG:
ali@369
   563
		return razor_rpm_get_indirect(rpm, RPMTAG_POSTUNPROG, NULL);
ali@369
   564
ali@369
   565
	case RAZOR_DETAIL_POSTUN:
ali@369
   566
		return razor_rpm_get_indirect(rpm, RPMTAG_POSTUN, NULL);
ali@369
   567
ali@369
   568
	default:
ali@369
   569
		fprintf(stderr, "type %u not found\n", type);
ali@369
   570
		return NULL;
ali@369
   571
	}
ali@369
   572
}
ali@369
   573
ali@372
   574
static const char *const *
ali@372
   575
razor_rpm_get_details_array(struct razor_rpm *rpm, enum razor_detail_type type)
ali@372
   576
{
ali@372
   577
	switch(type) {
ali@372
   578
	case RAZOR_DETAIL_PREFIXES:
ali@372
   579
		return rpm->prefixes;
ali@372
   580
ali@372
   581
	default:
ali@372
   582
		/* Impossible */
ali@372
   583
		fprintf(stderr, "type %u not found\n", type);
ali@372
   584
		return NULL;
ali@372
   585
	}
ali@372
   586
}
ali@372
   587
ali@369
   588
void
ali@369
   589
razor_rpm_get_details_varg(struct razor_rpm *rpm, va_list args)
ali@369
   590
{
ali@369
   591
	int i;
ali@369
   592
	enum razor_detail_type type;
ali@372
   593
	const char **string;
ali@372
   594
	const char *const **array;
ali@369
   595
ali@369
   596
	for (i = 0;; i += 2) {
ali@369
   597
		type = va_arg(args, enum razor_detail_type);
ali@369
   598
		if (type == RAZOR_DETAIL_LAST)
ali@369
   599
			break;
ali@372
   600
		if (type == RAZOR_DETAIL_PREFIXES) {
ali@372
   601
			array = va_arg(args, const char *const **);
ali@372
   602
			*array = razor_rpm_get_details_array(rpm, type);
ali@372
   603
		} else {
ali@372
   604
			string = va_arg(args, const char **);
ali@372
   605
			*string = razor_rpm_get_details_string(rpm, type);
ali@372
   606
		}
ali@369
   607
        }
ali@369
   608
}
ali@369
   609
ali@369
   610
RAZOR_EXPORT void
ali@369
   611
razor_rpm_get_details(struct razor_rpm *rpm, ...)
ali@369
   612
{
ali@369
   613
	va_list args;
ali@369
   614
ali@369
   615
	assert(rpm != NULL);
ali@369
   616
ali@369
   617
	va_start(args, rpm);
ali@369
   618
	razor_rpm_get_details_varg(rpm, args);
ali@369
   619
	va_end(args);
ali@369
   620
}
ali@369
   621
krh@269
   622
RAZOR_EXPORT struct razor_rpm *
ali@426
   623
razor_rpm_open(const char *filename, struct razor_error **error)
rhughes@241
   624
{
ali@460
   625
	struct rpm_lead *lead;
rhughes@241
   626
	struct razor_rpm *rpm;
rhughes@241
   627
	struct rpm_header_index *base, *index;
rhughes@241
   628
	unsigned int count, i, nindex, hsize;
ali@351
   629
	const char *name, *prefix;
rhughes@241
   630
richard@301
   631
	assert (filename != NULL);
richard@301
   632
ali@403
   633
	rpm = zalloc(sizeof *rpm);
ali@403
   634
	if (rpm == NULL) {
ali@447
   635
		razor_set_error(error, RAZOR_POSIX_ERROR, ENOMEM, NULL,
ali@447
   636
				"Not enough memory");
krh@246
   637
		return NULL;
ali@403
   638
	}
rhughes@241
   639
	memset(rpm, 0, sizeof *rpm);
rhughes@241
   640
ali@426
   641
	rpm->map = razor_file_get_contents(filename, &rpm->size, 0, error);
ali@322
   642
	if (!rpm->map) {
ali@403
   643
		free(rpm);
rhughes@241
   644
		return NULL;
rhughes@241
   645
	}
rhughes@241
   646
ali@460
   647
	lead = rpm->map;
ali@460
   648
	if (rpm->size < RPM_LEAD_SIZE ||
ali@460
   649
	    strncmp(lead->magic,RPM_LEAD_MAGIC,4) || lead->major != 3) {
ali@460
   650
		razor_rpm_close(rpm);
ali@460
   651
		razor_set_error(error, RAZOR_GENERAL_ERROR,
ali@460
   652
				RAZOR_GENERAL_ERROR_RPM_UNSUPPORTED,
ali@460
   653
				filename, "Not a recognized RPM format file");
ali@460
   654
		return NULL;
ali@460
   655
	}
ali@460
   656
rhughes@241
   657
	rpm->signature = rpm->map + RPM_LEAD_SIZE;
rhughes@241
   658
	nindex = ntohl(rpm->signature->nindex);
rhughes@241
   659
	hsize = ntohl(rpm->signature->hsize);
rhughes@241
   660
	rpm->header = (void *) (rpm->signature + 1) +
rhughes@241
   661
		ALIGN(nindex * sizeof *index + hsize, 8);
rhughes@241
   662
	nindex = ntohl(rpm->header->nindex);
rhughes@241
   663
	hsize = ntohl(rpm->header->hsize);
rhughes@241
   664
	rpm->payload = (void *) (rpm->header + 1) +
rhughes@241
   665
		nindex * sizeof *index + hsize;
rhughes@241
   666
rhughes@241
   667
	base = (struct rpm_header_index *) (rpm->header + 1);
rhughes@241
   668
	rpm->pool = (void *) base + nindex * sizeof *index;
rhughes@241
   669
rhughes@241
   670
	/* Look up dir names now so we can index them directly. */
rhughes@241
   671
	name = razor_rpm_get_indirect(rpm, RPMTAG_DIRNAMES, &count);
rhughes@241
   672
	if (name) {
rhughes@241
   673
		rpm->dirs = calloc(count, sizeof *rpm->dirs);
rhughes@241
   674
		for (i = 0; i < count; i++) {
rhughes@241
   675
			rpm->dirs[i] = name;
rhughes@241
   676
			name += strlen(name) + 1;
rhughes@241
   677
		}
rhughes@241
   678
	} else {
rhughes@241
   679
		name = razor_rpm_get_indirect(rpm, RPMTAG_OLDFILENAMES,
rhughes@241
   680
					      &count);
rhughes@241
   681
		if (name) {
ali@403
   682
			razor_rpm_close(rpm);
ali@447
   683
			razor_set_error(error, RAZOR_GENERAL_ERROR,
ali@447
   684
					RAZOR_GENERAL_ERROR_RPM_UNSUPPORTED,
ali@447
   685
					filename,
ali@426
   686
					"Old filenames not supported");
rhughes@241
   687
			return NULL;
rhughes@241
   688
		}
rhughes@241
   689
	}
rhughes@241
   690
ali@351
   691
	prefix = razor_rpm_get_indirect(rpm, RPMTAG_PREFIXES, &count);
ali@351
   692
	if (prefix) {
ali@372
   693
		rpm->prefixes = calloc(count + 1, sizeof *rpm->prefixes);
ali@351
   694
		for (i = 0; i < count; i++) {
ali@351
   695
			rpm->prefixes[i] = prefix;
ali@351
   696
			prefix += strlen(prefix) + 1;
ali@351
   697
		}
ali@372
   698
		rpm->prefixes[i] = NULL;
ali@351
   699
		rpm->n_prefixes = count;
ali@351
   700
	} else {
ali@351
   701
		prefix = razor_rpm_get_indirect(rpm, RPMTAG_DEFAULTPREFIX,
ali@351
   702
						&count);
ali@351
   703
		if (prefix) {
ali@403
   704
			razor_rpm_close(rpm);
ali@447
   705
			razor_set_error(error, RAZOR_GENERAL_ERROR,
ali@447
   706
					RAZOR_GENERAL_ERROR_RPM_UNSUPPORTED,
ali@447
   707
					filename,
ali@426
   708
					"Default prefix not supported");
ali@351
   709
			return NULL;
ali@351
   710
		}
ali@351
   711
	}
ali@351
   712
rhughes@241
   713
	return rpm;
rhughes@241
   714
}
rhughes@241
   715
ali@351
   716
RAZOR_EXPORT void razor_rpm_set_relocations(struct razor_rpm *rpm,
ali@351
   717
					    struct razor_relocations *rr)
ali@351
   718
{
ali@351
   719
	assert (rpm != NULL);
ali@351
   720
ali@351
   721
	rpm->relocations = rr;
ali@351
   722
}
ali@351
   723
rhughes@241
   724
struct cpio_file_header {
rhughes@241
   725
	char magic[6];
rhughes@241
   726
	char inode[8];
rhughes@241
   727
	char mode[8];
rhughes@241
   728
	char uid[8];
rhughes@241
   729
	char gid[8];
rhughes@241
   730
	char nlink[8];
rhughes@241
   731
	char mtime[8];
rhughes@241
   732
	char filesize[8];
rhughes@241
   733
	char devmajor[8];
rhughes@241
   734
	char devminor[8];
rhughes@241
   735
	char rdevmajor[8];
rhughes@241
   736
	char rdevminor[8];
rhughes@241
   737
	char namesize[8];
rhughes@241
   738
	char checksum[8];
rhughes@241
   739
	char filename[0];
rhughes@241
   740
};
rhughes@241
   741
rhughes@241
   742
/* gzip flags */
rhughes@241
   743
#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
rhughes@241
   744
#define HEAD_CRC     0x02 /* bit 1 set: header CRC present */
rhughes@241
   745
#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
rhughes@241
   746
#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
rhughes@241
   747
#define COMMENT      0x10 /* bit 4 set: file comment present */
rhughes@241
   748
#define RESERVED     0xE0 /* bits 5..7: reserved */
rhughes@241
   749
rhughes@241
   750
struct installer {
rhughes@241
   751
	const char *root;
rhughes@241
   752
	struct razor_rpm *rpm;
ali@403
   753
	struct razor_atomic *atomic;
rhughes@241
   754
	z_stream stream;
rhughes@241
   755
	unsigned char buffer[32768];
rhughes@241
   756
	size_t rest, length;
rhughes@241
   757
};
rhughes@241
   758
rhughes@241
   759
static int
rhughes@241
   760
installer_inflate(struct installer *installer)
rhughes@241
   761
{
rhughes@241
   762
	size_t length;
rhughes@241
   763
	int err;
rhughes@241
   764
rhughes@241
   765
	if (installer->rest > sizeof installer->buffer)
rhughes@241
   766
		length = sizeof installer->buffer;
rhughes@241
   767
	else
rhughes@241
   768
		length = installer->rest;
rhughes@241
   769
rhughes@241
   770
	installer->stream.next_out = installer->buffer;
rhughes@241
   771
	installer->stream.avail_out = length;
rhughes@241
   772
	err = inflate(&installer->stream, Z_SYNC_FLUSH);
rhughes@241
   773
	if (err != Z_OK && err != Z_STREAM_END) {
ali@447
   774
		razor_atomic_abort(installer->atomic, RAZOR_ZLIB_ERROR, err,
ali@447
   775
				   "Failed to inflate");
rhughes@241
   776
		return -1;
rhughes@241
   777
	}
rhughes@241
   778
rhughes@241
   779
	installer->rest -= length;
rhughes@241
   780
	installer->length = length;
rhughes@241
   781
rhughes@241
   782
	return 0;
rhughes@241
   783
}
rhughes@241
   784
rhughes@241
   785
static int
rhughes@241
   786
installer_align(struct installer *installer, size_t size)
rhughes@241
   787
{
rhughes@241
   788
	unsigned char buffer[4];
rhughes@241
   789
	int err;
rhughes@241
   790
rhughes@241
   791
	installer->stream.next_out = buffer;
rhughes@241
   792
	installer->stream.avail_out =
rhughes@241
   793
		(size - installer->stream.total_out) & (size - 1);
rhughes@241
   794
rhughes@241
   795
	if (installer->stream.avail_out == 0)
rhughes@241
   796
		return 0;
rhughes@241
   797
rhughes@241
   798
	err = inflate(&installer->stream, Z_SYNC_FLUSH);
rhughes@241
   799
	if (err != Z_OK && err != Z_STREAM_END) {
ali@447
   800
		razor_atomic_abort(installer->atomic, RAZOR_ZLIB_ERROR, err,
ali@447
   801
				   "Failed to inflate");
rhughes@241
   802
		return -1;
rhughes@241
   803
	}
rhughes@241
   804
rhughes@241
   805
	return 0;
rhughes@241
   806
}
rhughes@241
   807
rhughes@241
   808
static int
rhughes@241
   809
create_path(struct installer *installer, const char *path, unsigned int mode)
rhughes@241
   810
{
ali@403
   811
	char *s, *buffer;
ali@403
   812
	int h, ret;
rhughes@241
   813
ali@403
   814
	if (razor_atomic_make_dirs(installer->atomic, installer->root, path))
rhughes@241
   815
		return -1;
rhughes@241
   816
ali@403
   817
	buffer = razor_concat(installer->root, path, NULL);
rhughes@241
   818
rhughes@241
   819
	switch (mode >> 12) {
rhughes@241
   820
	case REG:
rhughes@241
   821
		/* FIXME: handle the case where a file is already there. */
ali@403
   822
		h = razor_atomic_create_file(installer->atomic, buffer, mode);
ali@403
   823
		free(buffer);
ali@403
   824
		if (h < 0)
rhughes@241
   825
			return -1;
ali@403
   826
		while (installer->rest > 0) {
ali@403
   827
			if (installer_inflate(installer))
ali@403
   828
				return -1;
ali@403
   829
			if (razor_atomic_write(installer->atomic, h,
ali@403
   830
					       installer->buffer,
ali@403
   831
					       installer->length))
ali@403
   832
				return -1;
rhughes@241
   833
		}
ali@403
   834
		return razor_atomic_close(installer->atomic, h);
rhughes@241
   835
	case XDIR:
ali@403
   836
		ret = razor_atomic_create_dir(installer->atomic, buffer, mode);
ali@403
   837
		free(buffer);
ali@403
   838
		return ret;
rhughes@241
   839
	case LINK:
ali@327
   840
#if HAVE_SYMLINK
ali@403
   841
		if (installer_inflate(installer))
rhughes@241
   842
			return -1;
rhughes@241
   843
		if (installer->length >= sizeof installer->buffer) {
ali@403
   844
			razor_atomic_abort(installer->atomic,
ali@447
   845
			  RAZOR_GENERAL_ERROR,
ali@447
   846
			  RAZOR_GENERAL_ERROR_RPM_UNSUPPORTED,
ali@403
   847
			  "Link target too long");
rhughes@241
   848
			return -1;
rhughes@241
   849
		}
rhughes@241
   850
		installer->buffer[installer->length] = '\0';
ali@403
   851
		ret = razor_atomic_create_symlink(installer->atomic,
ali@403
   852
		  (const char *)installer->buffer, buffer);
ali@403
   853
		free(buffer);
ali@403
   854
		return ret;
ali@327
   855
#else
ali@403
   856
		s = "Symbolic links";
ali@403
   857
		goto unsupported;
ali@327
   858
#endif
ali@327
   859
	case PIPE:
ali@403
   860
		s = "Named pipes";
ali@403
   861
unsupported:
ali@403
   862
		free(buffer);
ali@403
   863
		buffer = razor_concat(s, " are not supported on this platform",
ali@403
   864
		  NULL);
ali@447
   865
		razor_atomic_abort(installer->atomic, RAZOR_GENERAL_ERROR,
ali@447
   866
		  RAZOR_GENERAL_ERROR_RPM_UNSUPPORTED, buffer);
ali@403
   867
		free(buffer);
ali@403
   868
		return -1;
ali@327
   869
	case CDEV:
ali@403
   870
		s = "Character devices";
ali@403
   871
		goto unsupported;
ali@327
   872
	case BDEV:
ali@403
   873
		s = "Block devices";
ali@403
   874
		goto unsupported;
ali@327
   875
	case SOCK:
ali@403
   876
		s = "Named sockets";
ali@403
   877
		goto unsupported;
rhughes@241
   878
	default:
ali@403
   879
		free(buffer);
ali@447
   880
		razor_atomic_abort(installer->atomic, RAZOR_GENERAL_ERROR,
ali@447
   881
		  RAZOR_GENERAL_ERROR_RPM_UNSUPPORTED, "Unknown file type");
ali@403
   882
		return -1;
rhughes@241
   883
	}
rhughes@241
   884
}
rhughes@241
   885
ali@353
   886
static int chroot_push(const char *root)
ali@353
   887
{
ali@353
   888
	int fd;
ali@353
   889
#if HAVE_CHROOT
ali@353
   890
	if (geteuid() == 0) {
ali@353
   891
		fd = open("/", O_RDONLY, 0);
ali@353
   892
		if (chroot(root) < 0) {
ali@353
   893
			fprintf(stderr, "failed to chroot to %s: %s\n",
ali@353
   894
				root, strerror(errno));
ali@353
   895
			exit(-1);
ali@353
   896
		}
ali@353
   897
	} else
ali@353
   898
#endif
ali@353
   899
		fd = -1;
ali@353
   900
	return fd;
ali@353
   901
}
ali@353
   902
ali@353
   903
static void chroot_pop(int fd)
rhughes@241
   904
{
ali@328
   905
#if HAVE_CHROOT
ali@353
   906
	if (fd >= 0) {
ali@353
   907
		fchdir(fd);
ali@353
   908
		close(fd);
ali@353
   909
		chroot(".");
ali@353
   910
	}
ali@353
   911
#endif
ali@353
   912
}
ali@353
   913
ali@353
   914
static int
ali@376
   915
run_script_lua(const char *root, unsigned int script_tag, const char *script,
ali@376
   916
	       int arg1)
ali@353
   917
{
ali@353
   918
	int root_fd, retval;
ali@352
   919
#if HAVE_LUA
ali@353
   920
	const char *name;
ali@353
   921
ali@353
   922
	switch(script_tag) {
ali@353
   923
		case RPMTAG_PREIN:
ali@353
   924
			name = "%pre";
ali@353
   925
			break;
ali@353
   926
		case RPMTAG_POSTIN:
ali@353
   927
			name = "%post";
ali@353
   928
			break;
ali@353
   929
		case RPMTAG_PREUN:
ali@353
   930
			name = "%preun";
ali@353
   931
			break;
ali@353
   932
		case RPMTAG_POSTUN:
ali@353
   933
			name = "%postun";
ali@353
   934
			break;
ali@353
   935
		default:
ali@353
   936
			name = "script";
ali@353
   937
			break;
ali@353
   938
	}
ali@353
   939
	root_fd = chroot_push(root);
ali@376
   940
	retval = run_lua_script(root_fd < 0 ? root : NULL, name, script, -1,
ali@376
   941
				arg1);
ali@353
   942
	chroot_pop(root_fd);
ali@353
   943
#else	/* HAVE_LUA */
ali@353
   944
	fprintf(stderr, "lua not available to run script\n");
ali@353
   945
	retval = -1;
ali@353
   946
#endif	/* HAVE_LUA */
ali@353
   947
ali@353
   948
	return retval;
ali@353
   949
}
ali@353
   950
ali@353
   951
static int
ali@376
   952
run_script_external(const char *root, const char *program, const char *script,
ali@376
   953
		    int arg1)
ali@353
   954
{
ali@353
   955
	int root_fd, retval;
ali@328
   956
	FILE *fp;
ali@376
   957
	char buf[32], *command;
rhughes@241
   958
ali@353
   959
	if (program == NULL) {
ali@328
   960
#if MSWIN_API
ali@328
   961
		program = getenv("COMSPEC");
ali@328
   962
		if (program) {
ali@328
   963
			program = strchr(program, '=');
ali@328
   964
			if (program)
ali@328
   965
				program++;
ali@328
   966
		}
ali@328
   967
		if (!program)
ali@328
   968
			program = "c:\\windows\\system32\\cmd.exe";
ali@328
   969
#else
rhughes@241
   970
		program = "/bin/sh";
ali@328
   971
#endif
rhughes@241
   972
	}
rhughes@241
   973
ali@353
   974
	root_fd = chroot_push(root);
ali@376
   975
	if (arg1 >= 0) {
ali@376
   976
		sprintf(buf, "%d", arg1);
ali@376
   977
		command = malloc(strlen(program) + strlen(buf) + 2);
ali@376
   978
		sprintf(command, "%s %s", program, buf);
ali@376
   979
	} else
ali@376
   980
		command = strdup(program);
ali@376
   981
	fp = popen(command, "w");
ali@376
   982
	free(command);
rhughes@241
   983
ali@353
   984
	if (!fp) {
ali@353
   985
		perror(program);
ali@353
   986
		retval = -1;
ali@370
   987
	} else if (script && fwrite(script, strlen(script), 1, fp) != 1) {
ali@353
   988
		perror("failed to write script to program");
ali@353
   989
		retval = -1;
ali@353
   990
	} else
ali@353
   991
		retval = 0;
ali@353
   992
ali@353
   993
	if (fp)
ali@353
   994
		pclose(fp);
ali@353
   995
	chroot_pop(root_fd);
ali@353
   996
ali@353
   997
	return retval;
ali@353
   998
}
ali@353
   999
ali@353
  1000
static int
ali@353
  1001
run_script(struct installer *installer,
ali@376
  1002
	   unsigned int program_tag, unsigned int script_tag, int arg1)
ali@353
  1003
{
ali@362
  1004
	int i, retval;
ali@362
  1005
	struct razor_rpm *rpm = installer->rpm;
ali@362
  1006
	const char *script = NULL, *program = NULL, *prefix;
ali@376
  1007
	char buf[32];
ali@372
  1008
	struct environment env;
ali@353
  1009
ali@362
  1010
	program = razor_rpm_get_indirect(rpm, program_tag, NULL);
ali@362
  1011
	script = razor_rpm_get_indirect(rpm, script_tag, NULL);
ali@353
  1012
	if (program == NULL && script == NULL)
ali@362
  1013
		return 0;
ali@362
  1014
ali@362
  1015
	if (rpm->relocations) {
ali@372
  1016
		environment_init(&env);
ali@362
  1017
		for(i = 0; i < rpm->n_prefixes; i++) {
ali@362
  1018
			prefix = razor_relocations_apply(rpm->relocations,
ali@362
  1019
							 rpm->prefixes[i]);
ali@362
  1020
			sprintf(buf, "RPM_INSTALL_PREFIX%d", i);
ali@372
  1021
			environment_add_variable(&env, buf, prefix);
ali@362
  1022
		}
ali@372
  1023
		environment_set(&env);
ali@362
  1024
	}
ali@362
  1025
ali@369
  1026
	if (program && strcmp(program, "<lua>") == 0)
ali@376
  1027
		retval = run_script_lua(installer->root, script_tag, script,
ali@376
  1028
					arg1);
ali@353
  1029
	else
ali@376
  1030
		retval = run_script_external(installer->root, program, script,
ali@376
  1031
					     arg1);
ali@353
  1032
ali@362
  1033
	if (rpm->relocations) {
ali@372
  1034
		environment_unset(&env);
ali@372
  1035
		environment_release(&env);
ali@362
  1036
	}
ali@362
  1037
ali@353
  1038
	return retval;
rhughes@241
  1039
}
rhughes@241
  1040
ali@369
  1041
int
ali@369
  1042
razor_run_script(const char *root, enum razor_property_flags script,
ali@376
  1043
		 const char *program, const char *body, int arg1)
ali@369
  1044
{
ali@369
  1045
	int retval;
ali@369
  1046
	unsigned int script_tag;
ali@369
  1047
ali@369
  1048
	if (program && !*program)
ali@369
  1049
		program = NULL;
ali@369
  1050
	if (body && !*body)
ali@369
  1051
		body = NULL;
ali@369
  1052
	if (program == NULL && body == NULL)
ali@369
  1053
		return 0;
ali@369
  1054
ali@369
  1055
	if (program && strcmp(program, "<lua>") == 0)
ali@369
  1056
	{
ali@369
  1057
		switch(script) {
ali@369
  1058
		case RAZOR_PROPERTY_PRE:
ali@369
  1059
			script_tag = RPMTAG_PREIN;
ali@369
  1060
			break;
ali@369
  1061
		case RAZOR_PROPERTY_POST:
ali@369
  1062
			script_tag = RPMTAG_POSTIN;
ali@369
  1063
			break;
ali@369
  1064
		case RAZOR_PROPERTY_PREUN:
ali@369
  1065
			script_tag = RPMTAG_PREUN;
ali@369
  1066
			break;
ali@369
  1067
		case RAZOR_PROPERTY_POSTUN:
ali@369
  1068
			script_tag = RPMTAG_POSTUN;
ali@369
  1069
			break;
ali@369
  1070
		default:
ali@369
  1071
			script_tag = 0;
ali@369
  1072
			break;
ali@369
  1073
		}
ali@376
  1074
		retval = run_script_lua(root, script_tag, body, arg1);
ali@369
  1075
	}
ali@369
  1076
	else
ali@376
  1077
		retval = run_script_external(root, program, body, arg1);
ali@369
  1078
ali@369
  1079
	return retval;
ali@369
  1080
}
ali@369
  1081
rhughes@241
  1082
static int
rhughes@241
  1083
installer_init(struct installer *installer)
rhughes@241
  1084
{
rhughes@241
  1085
	unsigned char *gz_header;
rhughes@241
  1086
	int method, flags, err;
ali@403
  1087
	char buffer[32], *s;
rhughes@241
  1088
rhughes@241
  1089
	gz_header = installer->rpm->payload;
rhughes@241
  1090
	if (gz_header[0] != 0x1f || gz_header[1] != 0x8b) {
ali@447
  1091
		razor_atomic_abort(installer->atomic, RAZOR_GENERAL_ERROR,
ali@447
  1092
				   RAZOR_GENERAL_ERROR_RPM_UNSUPPORTED,
ali@403
  1093
				   "Payload section doesn't have gz header");
rhughes@241
  1094
		return -1;
rhughes@241
  1095
	}
rhughes@241
  1096
rhughes@241
  1097
	method = gz_header[2];
rhughes@241
  1098
	flags = gz_header[3];
rhughes@241
  1099
rhughes@241
  1100
	if (method != Z_DEFLATED || flags != 0) {
ali@447
  1101
		razor_atomic_abort(installer->atomic, RAZOR_GENERAL_ERROR,
ali@447
  1102
				   RAZOR_GENERAL_ERROR_RPM_UNSUPPORTED,
ali@403
  1103
				   "Unknown payload compression method or "
ali@403
  1104
				   "flags set");
rhughes@241
  1105
		return -1;
rhughes@241
  1106
	}
rhughes@241
  1107
rhughes@241
  1108
	installer->stream.zalloc = NULL;
rhughes@241
  1109
	installer->stream.zfree = NULL;
rhughes@241
  1110
	installer->stream.opaque = NULL;
rhughes@241
  1111
rhughes@241
  1112
	installer->stream.next_in  = gz_header + 10;
rhughes@241
  1113
	installer->stream.avail_in =
rhughes@241
  1114
		(installer->rpm->map + installer->rpm->size) -
rhughes@241
  1115
		(void *) installer->stream.next_in;
rhughes@241
  1116
	installer->stream.next_out = NULL;
rhughes@241
  1117
	installer->stream.avail_out = 0;
rhughes@241
  1118
rhughes@241
  1119
	err = inflateInit2(&installer->stream, -MAX_WBITS);
rhughes@241
  1120
	if (err != Z_OK) {
ali@403
  1121
		sprintf(buffer, "%d", err);
ali@442
  1122
		s = razor_concat("inflateEnd error: ", buffer, NULL);
ali@447
  1123
		razor_atomic_abort(installer->atomic, RAZOR_ZLIB_ERROR, err, s);
ali@403
  1124
		free(s);
rhughes@241
  1125
		return -1;
rhughes@241
  1126
	}
rhughes@241
  1127
rhughes@241
  1128
	return 0;
rhughes@241
  1129
}
rhughes@241
  1130
rhughes@241
  1131
static int
rhughes@241
  1132
installer_finish(struct installer *installer)
rhughes@241
  1133
{
rhughes@241
  1134
	int err;
ali@403
  1135
	char buffer[32], *s;
rhughes@241
  1136
rhughes@241
  1137
	err = inflateEnd(&installer->stream);
rhughes@241
  1138
rhughes@241
  1139
	if (err != Z_OK) {
ali@403
  1140
		sprintf(buffer, "%d", err);
ali@442
  1141
		s = razor_concat("inflateEnd error: ", buffer, NULL);
ali@447
  1142
		razor_atomic_abort(installer->atomic, RAZOR_ZLIB_ERROR, err, s);
ali@403
  1143
		free(s);
rhughes@241
  1144
	}
rhughes@241
  1145
ali@403
  1146
	return razor_atomic_in_error_state(installer->atomic);
rhughes@241
  1147
}
rhughes@241
  1148
rhughes@241
  1149
static unsigned long
rhughes@241
  1150
fixed_hex_to_ulong(const char *hex, int length)
rhughes@241
  1151
{
rhughes@241
  1152
	long l;
rhughes@241
  1153
	int i;
rhughes@241
  1154
rhughes@241
  1155
	for (i = 0, l = 0; i < length; i++) {
rhughes@241
  1156
		if (hex[i] < 'a')
rhughes@241
  1157
			l = l * 16 + hex[i] - '0';
rhughes@241
  1158
		else
rhughes@241
  1159
			l = l * 16 + hex[i] - 'a' + 10;
rhughes@241
  1160
	}
rhughes@241
  1161
rhughes@241
  1162
	return l;
rhughes@241
  1163
}
rhughes@241
  1164
krh@269
  1165
RAZOR_EXPORT int
ali@403
  1166
razor_rpm_install(struct razor_rpm *rpm, struct razor_atomic *atomic,
ali@403
  1167
		  const char *root, int install_count,
ali@403
  1168
		  enum razor_stage_type stage)
rhughes@241
  1169
{
rhughes@241
  1170
	struct installer installer;
rhughes@241
  1171
	struct cpio_file_header *header;
rhughes@241
  1172
	struct stat buf;
rhughes@241
  1173
	unsigned int mode;
ali@424
  1174
	const char *path;
rhughes@241
  1175
	size_t filesize;
ali@403
  1176
	char *s;
ali@447
  1177
	int retval = 0, code;
rhughes@241
  1178
richard@301
  1179
	assert (rpm != NULL);
richard@301
  1180
	assert (root != NULL);
richard@301
  1181
rhughes@241
  1182
	installer.rpm = rpm;
rhughes@241
  1183
	installer.root = root;
ali@403
  1184
	installer.atomic = atomic;
rhughes@241
  1185
rhughes@241
  1186
	/* FIXME: Only do this before a transaction, not per rpm. */
ali@447
  1187
	if (*root && ((retval = stat(root, &buf)) || !S_ISDIR(buf.st_mode))) {
ali@447
  1188
		code = retval ? errno : ENOTDIR;
ali@403
  1189
		s = razor_concat(root, ": Directory does not exist", NULL);
ali@447
  1190
		razor_atomic_abort(atomic, RAZOR_POSIX_ERROR, code, s);
ali@403
  1191
		free(s);
rhughes@241
  1192
		return -1;
rhughes@241
  1193
	}
rhughes@241
  1194
ali@351
  1195
	if (rpm->relocations)
ali@351
  1196
		razor_relocations_set_rpm(rpm->relocations, rpm);
ali@351
  1197
ali@403
  1198
	if (stage & RAZOR_STAGE_SCRIPTS_PRE)
ali@422
  1199
		retval = run_script(&installer, RPMTAG_PREINPROG, RPMTAG_PREIN,
ali@422
  1200
				    install_count);
rhughes@241
  1201
ali@422
  1202
	if (!retval && (stage & RAZOR_STAGE_FILES)) {
ali@403
  1203
		if (installer_init(&installer))
rhughes@241
  1204
			return -1;
rhughes@241
  1205
ali@403
  1206
		while (installer.stream.avail_in > 0) {
ali@403
  1207
			installer.rest = sizeof *header;
ali@403
  1208
			if (installer_inflate(&installer))
ali@403
  1209
				break;
rhughes@241
  1210
ali@403
  1211
			header = (struct cpio_file_header *) installer.buffer;
ali@403
  1212
			mode = fixed_hex_to_ulong(header->mode,
ali@403
  1213
						  sizeof header->mode);
ali@403
  1214
			filesize = fixed_hex_to_ulong(header->filesize,
ali@403
  1215
						      sizeof header->filesize);
rhughes@241
  1216
ali@403
  1217
			installer.rest =
ali@403
  1218
			  fixed_hex_to_ulong(header->namesize,
ali@403
  1219
					     sizeof header->namesize);
rhughes@241
  1220
ali@403
  1221
			if (installer_inflate(&installer) ||
ali@403
  1222
			    installer_align(&installer, 4))
ali@403
  1223
				break;
rhughes@241
  1224
ali@403
  1225
			path = (const char *) installer.buffer;
ali@403
  1226
			/* This convention is so lame... */
ali@403
  1227
			if (strcmp(path, "TRAILER!!!") == 0)
ali@403
  1228
				break;
ali@403
  1229
ali@403
  1230
			installer.rest = filesize;
ali@403
  1231
			path++;
ali@403
  1232
			if (rpm->relocations)
ali@403
  1233
				path = razor_relocations_apply(rpm->relocations,
ali@403
  1234
							       path);
ali@403
  1235
			if (create_path(&installer, path, mode))
ali@403
  1236
				break;
ali@403
  1237
			if (installer_align(&installer, 4))
ali@403
  1238
				break;
ali@403
  1239
		}
ali@403
  1240
ali@403
  1241
		if (installer_finish(&installer))
rhughes@241
  1242
			return -1;
ali@422
  1243
ali@422
  1244
		retval = razor_atomic_in_error_state(atomic);
rhughes@241
  1245
	}
rhughes@241
  1246
ali@422
  1247
	if (!retval && (stage & RAZOR_STAGE_SCRIPTS_POST))
ali@422
  1248
		retval = run_script(&installer, RPMTAG_POSTINPROG,
ali@422
  1249
				    RPMTAG_POSTIN, install_count);
rhughes@241
  1250
ali@422
  1251
	return retval;
rhughes@241
  1252
}
rhughes@241
  1253
krh@269
  1254
RAZOR_EXPORT int
rhughes@241
  1255
razor_rpm_close(struct razor_rpm *rpm)
rhughes@241
  1256
{
rhughes@241
  1257
	int err;
rhughes@241
  1258
richard@301
  1259
	assert (rpm != NULL);
richard@301
  1260
rhughes@241
  1261
	free(rpm->dirs);
ali@351
  1262
	free(rpm->prefixes);
ali@322
  1263
	err = razor_file_free_contents(rpm->map, rpm->size);
ali@369
  1264
	free(rpm->evr);
rhughes@241
  1265
	free(rpm);
rhughes@241
  1266
rhughes@241
  1267
	return err;
rhughes@241
  1268
}
rhughes@241
  1269
krh@269
  1270
RAZOR_EXPORT int
rhughes@241
  1271
razor_importer_add_rpm(struct razor_importer *importer, struct razor_rpm *rpm)
rhughes@241
  1272
{
ali@369
  1273
	const char *name, *version, *arch;
jbowes@289
  1274
	const char *summary, *description, *url, *license;
rhughes@241
  1275
richard@301
  1276
	assert (importer != NULL);
richard@301
  1277
	assert (rpm != NULL);
richard@301
  1278
ali@369
  1279
	razor_rpm_get_details(rpm,
ali@369
  1280
			      RAZOR_DETAIL_NAME, &name,
ali@369
  1281
			      RAZOR_DETAIL_VERSION, &version,
ali@369
  1282
			      RAZOR_DETAIL_ARCH, &arch,
ali@369
  1283
			      RAZOR_DETAIL_SUMMARY, &summary,
ali@369
  1284
			      RAZOR_DETAIL_DESCRIPTION, &description,
ali@369
  1285
			      RAZOR_DETAIL_URL, &url,
ali@369
  1286
			      RAZOR_DETAIL_LICENSE, &license,
ali@369
  1287
			      RAZOR_DETAIL_LAST);
jbowes@289
  1288
ali@369
  1289
	razor_importer_begin_package(importer, name, version, arch);
rhughes@241
  1290
jbowes@289
  1291
	razor_importer_add_details(importer, summary, description, url,
jbowes@289
  1292
				   license);
jbowes@289
  1293
rhughes@241
  1294
	import_properties(importer, RAZOR_PROPERTY_REQUIRES, rpm,
rhughes@241
  1295
			  RPMTAG_REQUIRENAME,
rhughes@241
  1296
			  RPMTAG_REQUIREVERSION,
rhughes@241
  1297
			  RPMTAG_REQUIREFLAGS);
rhughes@241
  1298
rhughes@241
  1299
	import_properties(importer, RAZOR_PROPERTY_PROVIDES, rpm,
rhughes@241
  1300
			  RPMTAG_PROVIDENAME,
rhughes@241
  1301
			  RPMTAG_PROVIDEVERSION,
rhughes@241
  1302
			  RPMTAG_PROVIDEFLAGS);
rhughes@241
  1303
rhughes@241
  1304
	import_properties(importer, RAZOR_PROPERTY_OBSOLETES, rpm,
rhughes@241
  1305
			  RPMTAG_OBSOLETENAME,
rhughes@241
  1306
			  RPMTAG_OBSOLETEVERSION,
rhughes@241
  1307
			  RPMTAG_OBSOLETEFLAGS);
rhughes@241
  1308
rhughes@241
  1309
	import_properties(importer, RAZOR_PROPERTY_CONFLICTS, rpm,
rhughes@241
  1310
			  RPMTAG_CONFLICTNAME,
rhughes@241
  1311
			  RPMTAG_CONFLICTVERSION,
rhughes@241
  1312
			  RPMTAG_CONFLICTFLAGS);
rhughes@241
  1313
rhughes@241
  1314
	import_files(importer, rpm);
rhughes@241
  1315
rhughes@241
  1316
	razor_importer_finish_package(importer);
rhughes@241
  1317
rhughes@241
  1318
	return 0;
rhughes@241
  1319
}