archive: update for new place of checksum in tar header

and take checksums for symlinks too.
cute-signatures
Timo Teras 2009-08-11 19:57:30 +03:00
parent addae04c26
commit bd9835a20e
2 changed files with 26 additions and 19 deletions

View File

@ -50,7 +50,7 @@ struct apk_tar_digest_info {
char id[4]; char id[4];
uint16_t nid; uint16_t nid;
uint16_t size; uint16_t size;
char digest[]; unsigned char digest[];
}; };
#define GET_OCTAL(s) get_octal(s, sizeof(s)) #define GET_OCTAL(s) get_octal(s, sizeof(s))
@ -124,12 +124,13 @@ int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser,
.tar_is = is, .tar_is = is,
}; };
struct tar_header buf; struct tar_header buf;
struct apk_tar_digest_info *di; struct apk_tar_digest_info *odi, *di;
unsigned long offset = 0; unsigned long offset = 0;
int end = 0, r; int end = 0, r;
size_t toskip; size_t toskip;
di = (struct apk_tar_digest_info *) &buf.linkname[3]; odi = (struct apk_tar_digest_info *) &buf.linkname[3];
di = (struct apk_tar_digest_info *) &buf.devmajor[0];
EVP_MD_CTX_init(&teis.mdctx); EVP_MD_CTX_init(&teis.mdctx);
memset(&entry, 0, sizeof(entry)); memset(&entry, 0, sizeof(entry));
while ((r = is->read(is, &buf, 512)) == 512) { while ((r = is->read(is, &buf, 512)) == 512) {
@ -155,6 +156,13 @@ int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser,
}; };
teis.csum = NULL; teis.csum = NULL;
if (memcmp(di->id, "APK2", 4) == 0 &&
di->size <= sizeof(entry.csum.data)) {
entry.csum.type = di->size;
memcpy(&entry.csum.data[0], buf.devminor, sizeof(buf.devminor));
memcpy(&entry.csum.data[sizeof(buf.devminor)], buf.padding, sizeof(buf.padding));
}
switch (buf.typeflag) { switch (buf.typeflag) {
case 'L': case 'L':
if (entry.name != NULL) if (entry.name != NULL)
@ -168,12 +176,14 @@ int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser,
case '0': case '0':
case '7': /* regular file */ case '7': /* regular file */
entry.mode |= S_IFREG; entry.mode |= S_IFREG;
if (memcmp(di->id, "APK2", 4) == 0 && if (entry.csum.type == APK_CHECKSUM_NONE) {
di->size <= sizeof(entry.csum.data)) { if (memcmp(odi->id, "APK2", 4) == 0 &&
entry.csum.type = di->size; odi->size <= sizeof(entry.csum.data)) {
memcpy(entry.csum.data, di->digest, di->size); entry.csum.type = odi->size;
} else if (soft_checksums) { memcpy(entry.csum.data, odi->digest,
teis.csum = &entry.csum; odi->size);
} else if (soft_checksums)
teis.csum = &entry.csum;
} }
break; break;
case '1': /* hard link */ case '1': /* hard link */
@ -183,6 +193,13 @@ int apk_tar_parse(struct apk_istream *is, apk_archive_entry_parser parser,
case '2': /* symbolic link */ case '2': /* symbolic link */
entry.mode |= S_IFLNK; entry.mode |= S_IFLNK;
entry.link_target = buf.linkname; entry.link_target = buf.linkname;
if (entry.csum.type == APK_CHECKSUM_NONE &&
soft_checksums) {
EVP_Digest(buf.linkname, strlen(buf.linkname),
entry.csum.data, NULL,
apk_checksum_default(), NULL);
entry.csum.type = APK_CHECKSUM_DEFAULT;
}
break; break;
case '3': /* char device */ case '3': /* char device */
entry.mode |= S_IFCHR; entry.mode |= S_IFCHR;

View File

@ -1567,16 +1567,6 @@ static int apk_db_install_archive_entry(void *_ctx,
struct apk_db_dir_instance *ldiri; struct apk_db_dir_instance *ldiri;
struct hlist_node *n; struct hlist_node *n;
if (S_ISLNK(ae->mode)) {
EVP_Digest(ae->link_target,
strlen(ae->link_target),
file->csum.data, NULL,
apk_checksum_default(),
NULL);
file->csum.type = APK_CHECKSUM_DEFAULT;
break;
}
if (!apk_blob_rsplit(APK_BLOB_STR(ae->link_target), if (!apk_blob_rsplit(APK_BLOB_STR(ae->link_target),
'/', &bdir, &bfile)) '/', &bdir, &bfile))
break; break;