From: marc Date: Tue, 20 Feb 1996 04:40:53 +0000 (+0000) Subject: Initial revision X-Git-Tag: tznext/4.11.0.1.tizen20130304~11612 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09ba912bd2fe1428fa8c96e5ce13487fc3f44bd5;p=tools%2Flibrpm-tizen.git Initial revision CVS patchset: 348 CVS date: 1996/02/20 04:40:53 --- diff --git a/lib/verify.c b/lib/verify.c new file mode 100644 index 0000000..f02858d --- /dev/null +++ b/lib/verify.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include + +#include "md5.h" +#include "rpmlib.h" + +int rpmVerifyFile(char * prefix, Header h, int filenum, int * result) { + char ** fileList, ** md5List, ** linktoList; + int_32 * verifyFlags, flags; + int_32 * sizeList, * mtimeList; + int_16 * modeList, * rdevList; + char * filespec; + int type, count; + struct stat sb; + unsigned char md5sum[40]; + + getEntry(h, RPMTAG_FILENAMES, &type, (void **) &fileList, &count); + getEntry(h, RPMTAG_FILEMODES, &type, (void **) &modeList, &count); + + if (getEntry(h, RPMTAG_FILEVERIFYFLAGS, &type, (void **) &verifyFlags, + &count)) { + flags = verifyFlags[filenum]; + } else { + flags = VERIFY_ALL; + } + + filespec = alloca(strlen(fileList[filenum]) + strlen(prefix) + 5); + strcpy(filespec, prefix); + strcat(filespec, "/"); + strcat(filespec, fileList[filenum]); + + free(fileList); + + if (lstat(filespec, &sb)) + return 1; + + *result = 0; + + if (!S_ISDIR(modeList[filenum]) && (flags & VERIFY_MD5)) { + getEntry(h, RPMTAG_FILEMD5S, &type, (void **) &md5List, &count); + if (mdfile(filespec, md5sum)) + *result |= VERIFY_MD5; + else if (strcmp(md5sum, md5List[filenum])) + *result |= VERIFY_MD5; + free(md5List); + } + if (flags & VERIFY_LINKTO) { + getEntry(h, RPMTAG_FILELINKTOS, &type, (void **) &linktoList, &count); + free(linktoList); + } + if (!S_ISDIR(modeList[filenum]) && (flags & VERIFY_FILESIZE)) { + getEntry(h, RPMTAG_FILESIZES, &type, (void **) &sizeList, &count); + if (sizeList[filenum] != sb.st_size) + *result |= VERIFY_FILESIZE; + } + if (flags & VERIFY_MODE) { + if (sizeList[filenum] != sb.st_size) + *result |= VERIFY_MODE; + } + if (flags & VERIFY_RDEV) { + getEntry(h, RPMTAG_FILERDEVS, &type, (void **) &rdevList, &count); + if (rdevList[filenum] != sb.st_rdev) + *result |= VERIFY_RDEV; + } + if (!S_ISDIR(modeList[filenum]) && (flags & VERIFY_MTIME)) { + getEntry(h, RPMTAG_FILEMTIMES, &type, (void **) &mtimeList, &count); + if (mtimeList[filenum] != sb.st_mtime) + *result |= VERIFY_MTIME; + } + + return 0; +}