7 #include <netinet/in.h>
12 #if defined(RPM_VENDOR_MANDRIVA)
13 #define _RPMEVR_INTERNAL
27 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
50 0x8e, 0xad, 0xe8, 0x01, 0x00, 0x00, 0x00, 0x00
80 #define hdrchkTags(_ntags) ((_ntags) & 0xffff0000)
85 #define hdrchkType(_type) ((_type) < RPM_MIN_TYPE || (_type) > RPM_MAX_TYPE)
91 #define hdrchkData(_nbytes) ((_nbytes) & 0xff000000)
96 #define hdrchkAlign(_type, _off) ((_off) & (typeAlign[_type]-1))
101 #define hdrchkRange(_dl, _off) ((_off) < 0 || (_off) > (_dl))
103 #if defined(RPM_VENDOR_MANDRIVA)
105 static int dncmp(
const void * a,
const void * b)
108 const char *
const * first = a;
109 const char *
const * second = b;
110 return strcmp(*first, *second);
127 const char ** dirNames;
128 const char ** baseNames;
148 if (fileNames == NULL || count <= 0)
151 dirNames =
alloca(
sizeof(*dirNames) * count);
152 baseNames =
alloca(
sizeof(*dirNames) * count);
153 dirIndexes =
alloca(
sizeof(*dirIndexes) * count);
155 if (fileNames[0][0] !=
'/') {
158 dirNames[dirIndex] =
"";
159 for (i = 0; i < count; i++) {
160 dirIndexes[i] = dirIndex;
161 baseNames[i] = fileNames[i];
167 for (i = 0; i < count; i++) {
168 const char ** needle;
173 if (fileNames[i] == NULL)
175 baseName = strrchr(fileNames[i],
'/') + 1;
176 len = baseName - fileNames[i];
178 savechar = *baseName;
182 (needle = bsearch(&fileNames[i], dirNames, dirIndex + 1,
sizeof(dirNames[0]),
dncmp)) == NULL) {
183 char *s =
alloca(len + 1);
184 memcpy(s, fileNames[i], len + 1);
186 dirIndexes[i] = ++dirIndex;
187 dirNames[dirIndex] = s;
189 dirIndexes[i] = needle - dirNames;
192 *baseName = savechar;
193 baseNames[i] = baseName;
203 dirNames, dirIndex + 1);
206 fileNames = hfd(fileNames, fnt);
219 const char *
name, *version, *release;
224 const char ** provides = NULL;
225 const char ** providesEVR = NULL;
227 int_32 * provideFlags = NULL;
233 xx =
headerNVR(h, &name, &version, &release);
234 if (!(name && version && release))
236 pEVR = p =
alloca(21 + strlen(version) + 1 + strlen(release) + 1);
238 if (hge(h,
RPMTAG_EPOCH, NULL, (
void **) &epoch, NULL)) {
239 sprintf(p,
"%d:", *epoch);
256 for (i = 0; i < providesCount; i++) {
270 if (provides && providesEVR && provideFlags)
271 for (i = 0; i < providesCount; i++) {
272 if (!(provides[i] && providesEVR[i]))
275 !strcmp(name, provides[i]) && !strcmp(pEVR, providesEVR[i])))
283 provides = hfd(provides, pnt);
284 providesEVR = hfd(providesEVR, pvt);
296 static void add_RPMTAG_SOURCERPM(
Header h)
312 if ((!rpmversion) || rpmversion[0] <
'4') {
313 add_RPMTAG_SOURCERPM(h);
323 static int dncmp(
const void * a,
const void * b)
326 const char *
const * first = a;
327 const char *
const * second = b;
328 return strcmp(*first, *second);
345 const char ** dirNames;
346 const char ** baseNames;
366 if (fileNames == NULL || count <= 0)
369 dirNames =
alloca(
sizeof(*dirNames) * count);
370 baseNames =
alloca(
sizeof(*dirNames) * count);
371 dirIndexes =
alloca(
sizeof(*dirIndexes) * count);
373 if (fileNames[0][0] !=
'/') {
376 dirNames[dirIndex] =
"";
377 for (i = 0; i < count; i++) {
378 dirIndexes[i] = dirIndex;
379 baseNames[i] = fileNames[i];
385 for (i = 0; i < count; i++) {
386 const char ** needle;
391 if (fileNames[i] == NULL)
393 baseName = strrchr(fileNames[i],
'/') + 1;
394 len = baseName - fileNames[i];
396 savechar = *baseName;
400 (needle = bsearch(&fileNames[i], dirNames, dirIndex + 1,
sizeof(dirNames[0]),
dncmp)) == NULL) {
401 char *s =
alloca(len + 1);
402 memcpy(s, fileNames[i], len + 1);
404 dirIndexes[i] = ++dirIndex;
405 dirNames[dirIndex] = s;
407 dirIndexes[i] = needle - dirNames;
410 *baseName = savechar;
411 baseNames[i] = baseName;
421 dirNames, dirIndex + 1);
424 fileNames = hfd(fileNames, fnt);
437 if ((!rpmversion) || rpmversion[0] <
'4') {
439 const char *
name, *version, *release;
444 if (
headerNVR(h, &name, &version, &release) == 0) {
445 pEVR = p =
alloca(21 + strlen(version) + 1 + strlen(release) + 1);
448 sprintf(p,
"%d:", *epoch);
475 ptr = hfd(ptr, type))
511 if (ptr == NULL)
continue;
530 if (count >= 16*1024)
538 xx = hae(h, tag, type, ptr, count);
549 int_32 tag, stag, type, count;
555 ptr = hfd(ptr, type))
595 if (ptr == NULL)
continue;
618 if (sig == NULL || dig == NULL || sigp == NULL)
626 for (i = 0; i <
nkeyids; i++) {
656 for (i = 0; i < il; i++) {
657 info->
tag = ntohl(pe[i].tag);
658 info->
type = ntohl(pe[i].type);
659 info->
offset = ntohl(pe[i].offset);
662 info->
count = ntohl(pe[i].count);
694 unsigned char buf[8*BUFSIZ];
704 int_32 pvlen =
sizeof(ildl) + (il *
sizeof(*pe)) + dl;
705 unsigned char * dataStart = (
unsigned char *) (pe + il);
708 const void * sig = NULL;
715 unsigned char * regionEnd = NULL;
727 if (uc > 0 && pvlen != uc) {
729 _(
"blob size(%d): BAD, 8 + 16 * il(%d) + dl(%d)\n"),
730 (int)uc, (
int)il, (int)dl);
738 _(
"tag[%d]: BAD, tag %d type %d offset %d count %d\n"),
758 _(
"region offset: BAD, tag %d type %d offset %d count %d\n"),
779 _(
"region trailer: BAD, tag %d type %d offset %d count %d\n"),
786 memset(info, 0,
sizeof(*info));
791 if ((entry->
info.
offset %
sizeof(*pe)) || ril > il) {
793 _(
"region size: BAD, ril(%d) > il(%d)\n"), ril, il);
798 for (i = ril; i < il; i++) {
802 _(
"tag[%d]: BAD, tag %d type %d offset %d count %d\n"),
814 for (b = dataStart + entry->
info.
offset; *b !=
'\0'; b++) {
815 if (strchr(
"0123456789abcdefABCDEF", *b) == NULL)
821 (void)
snprintf(buf,
sizeof(buf),
_(
"hdr SHA1: BAD, not hex\n"));
825 if (info->
tag == 0) {
836 (void)
snprintf(buf,
sizeof(buf),
_(
"hdr RSA: BAD, not binary\n"));
842 siglen = info->
count;
848 (void)
snprintf(buf,
sizeof(buf),
_(
"hdr DSA: BAD, not binary\n"));
854 siglen = info->
count;
866 buf[
sizeof(buf)-1] =
'\0';
874 if (info->
tag == 0) {
879 _(
"tag[%d]: BAD, tag %d type %d offset %d count %d\n"),
884 (void)
snprintf(buf,
sizeof(buf),
"Header sanity check: OK\n");
888 buf[
sizeof(buf)-1] =
'\0';
898 goto verifyinfo_exit;
902 sig = memcpy(
xmalloc(siglen), dataStart + info->
offset, siglen);
912 _(
"skipping header with unverifiable V%u signature\n"),
919 ildl[0] = htonl(ril);
920 ildl[1] = (regionEnd - dataStart);
921 ildl[1] = htonl(ildl[1]);
931 b = (
unsigned char *) ildl;
936 b = (
unsigned char *) pe;
937 nb = (htonl(ildl[0]) *
sizeof(*pe));
941 b = (
unsigned char *) dataStart;
953 _(
"skipping header with unverifiable V%u signature\n"),
962 ildl[0] = htonl(ril);
963 ildl[1] = (regionEnd - dataStart);
964 ildl[1] = htonl(ildl[1]);
975 b = (
unsigned char *) ildl;
980 b = (
unsigned char *) pe;
981 nb = (htonl(ildl[0]) *
sizeof(*pe));
985 b = (
unsigned char *) dataStart;
1003 buf[
sizeof(buf)-1] =
'\0';
1027 const char * origin = NULL;
1041 memset(block, 0,
sizeof(block));
1042 if ((xx =
timedRead(fd, (
char *)block,
sizeof(block))) !=
sizeof(block)) {
1044 _(
"hdr size(%d): BAD, read returned %d\n"), (int)
sizeof(block), xx);
1048 (void)
snprintf(buf,
sizeof(buf),
_(
"hdr magic: BAD\n"));
1052 il = ntohl(block[2]);
1056 _(
"hdr tags: BAD, no. of tags(%d) out of range\n"), il);
1061 dl = ntohl(block[3]);
1065 _(
"hdr data: BAD, no. of bytes(%d) out of range\n"), dl);
1072 uc =
sizeof(il) +
sizeof(dl) + nb;
1077 if ((xx =
timedRead(fd, (
char *)&ei[2], nb)) != nb) {
1079 _(
"hdr blob(%d): BAD, read returned %d\n"), nb, xx);
1092 (void)
snprintf(buf,
sizeof(buf),
_(
"hdr load: BAD\n"));
1100 if (origin != NULL) {
1101 const char * lpath = NULL;
1102 int ut =
urlPath(origin, &lpath);
1104 if (lpath && *lpath !=
'/') {
1105 char * rpath =
Realpath(origin, NULL);
1107 rpath =
_free(rpath);
1113 (void) fstat(
Fileno(fd), st);
1128 if (msg != NULL && *msg == NULL && buf[0] !=
'\0') {
1129 buf[
sizeof(buf)-1] =
'\0';
1155 rpmop opsave = memset(
alloca(
sizeof(*opsave)), 0,
sizeof(*opsave));
1159 if (hdrp) *hdrp = NULL;
1164 memset(&st, 0,
sizeof(st));
1166 (void) fstat(
Fileno(fd), &st);
1168 if (S_ISREG(st.st_mode) && st.st_size <
sizeof(*l)) {
1178 memset(l, 0,
sizeof(*l));
1186 _(
"packaging version 1 is not supported by this version of RPM\n"));
1196 "is supported by this version of RPM\n"));
1208 (msg && *msg ? msg :
"\n"));
1222 #define _chk(_mask) (sigtag == 0 && !(vsflags & (_mask)))
1282 (msg && *msg ? msg :
"\n"));
1303 xx =
headerGetEntry(sigh, sigtag, &sigtype, (
void **) &sig, &siglen);
1308 (void)
rpmtsSetSig(ts, sigtag, sigtype, sig, siglen);
1316 _(
"skipping package %s with unverifiable V%u signature\n"),
1342 _(
"skipping package %s with unverifiable V%u signature\n"),
1374 _(
"skipping package %s with unverifiable V%u signature\n"),
1383 while ((count =
Fread(buf,
sizeof(buf[0]),
sizeof(buf), fd)) > 0)
1396 for (i = fd->
ndigests - 1; i >= 0; i--) {
1406 #if HAVE_BEECRYPT_API_H
1447 if (rc !=
RPMRC_FAIL && h != NULL && hdrp != NULL) {
1452 #if defined(RPM_VENDOR_MANDRIVA)