1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
1996-02-20 12:31:08 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
#include "build/rpmbuild.h"
|
|
|
|
|
1996-07-21 07:21:18 +08:00
|
|
|
#include "install.h"
|
1997-02-12 12:48:51 +08:00
|
|
|
#include "url.h"
|
1996-02-20 12:31:08 +08:00
|
|
|
#include "verify.h"
|
|
|
|
|
1998-09-25 01:47:41 +08:00
|
|
|
static int verifyHeader(char * prefix, Header h, int verifyFlags);
|
|
|
|
static int verifyMatches(char * prefix, rpmdb db, dbiIndexSet matches,
|
1996-07-21 07:21:18 +08:00
|
|
|
int verifyFlags);
|
1998-09-25 01:47:41 +08:00
|
|
|
static int verifyDependencies(rpmdb db, Header h);
|
1996-02-20 12:31:08 +08:00
|
|
|
|
1998-09-25 01:47:41 +08:00
|
|
|
static int verifyHeader(char * prefix, Header h, int verifyFlags) {
|
1996-02-20 12:31:08 +08:00
|
|
|
char ** fileList;
|
|
|
|
int count, type;
|
1996-02-21 03:42:47 +08:00
|
|
|
int verifyResult;
|
1998-09-25 01:47:41 +08:00
|
|
|
int i, ec, rc;
|
1996-03-05 06:52:34 +08:00
|
|
|
int_32 * fileFlagsList;
|
1997-01-24 04:56:45 +08:00
|
|
|
int omitMask = 0;
|
1996-03-05 06:52:34 +08:00
|
|
|
|
1998-09-25 01:47:41 +08:00
|
|
|
ec = 0;
|
1997-01-24 04:56:45 +08:00
|
|
|
if (!(verifyFlags & VERIFY_MD5)) omitMask = RPMVERIFY_MD5;
|
1996-02-20 12:31:08 +08:00
|
|
|
|
1998-11-21 04:18:22 +08:00
|
|
|
if (headerGetEntry(h, RPMTAG_FILEFLAGS, NULL, (void **) &fileFlagsList, NULL) &&
|
|
|
|
headerGetEntry(h, RPMTAG_FILENAMES, &type, (void **) &fileList, &count)) {
|
1996-02-20 12:31:08 +08:00
|
|
|
for (i = 0; i < count; i++) {
|
1998-09-25 01:47:41 +08:00
|
|
|
if ((rc = rpmVerifyFile(prefix, h, i, &verifyResult, omitMask)) != 0) {
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stdout, _("missing %s\n"), fileList[i]);
|
1998-09-25 01:47:41 +08:00
|
|
|
} else {
|
1998-12-06 03:38:29 +08:00
|
|
|
const char * size, * md5, * link, * mtime, * mode;
|
|
|
|
const char * group, * user, * rdev;
|
|
|
|
static const char * aok = ".";
|
|
|
|
static const char * unknown = "?";
|
1996-02-20 12:31:08 +08:00
|
|
|
|
1996-02-21 06:18:36 +08:00
|
|
|
if (!verifyResult) continue;
|
|
|
|
|
1998-09-25 01:47:41 +08:00
|
|
|
rc = 1;
|
1998-12-06 03:38:29 +08:00
|
|
|
|
|
|
|
#define _verify(_RPMVERIFY_F, _C) \
|
|
|
|
((verifyResult & _RPMVERIFY_F) ? _C : aok)
|
|
|
|
#define _verifylink(_RPMVERIFY_F, _C) \
|
|
|
|
((verifyResult & RPMVERIFY_READLINKFAIL) ? unknown : \
|
|
|
|
(verifyResult & _RPMVERIFY_F) ? _C : aok)
|
|
|
|
#define _verifyfile(_RPMVERIFY_F, _C) \
|
|
|
|
((verifyResult & RPMVERIFY_READFAIL) ? unknown : \
|
|
|
|
(verifyResult & _RPMVERIFY_F) ? _C : aok)
|
|
|
|
|
|
|
|
md5 = _verifyfile(RPMVERIFY_MD5, "5");
|
|
|
|
size = _verify(RPMVERIFY_FILESIZE, "S");
|
|
|
|
link = _verifylink(RPMVERIFY_LINKTO, "L");
|
|
|
|
mtime = _verify(RPMVERIFY_MTIME, "T");
|
|
|
|
rdev = _verify(RPMVERIFY_RDEV, "D");
|
|
|
|
user = _verify(RPMVERIFY_USER, "U");
|
|
|
|
group = _verify(RPMVERIFY_GROUP, "G");
|
|
|
|
mode = _verify(RPMVERIFY_MODE, "M");
|
|
|
|
|
|
|
|
#undef _verify
|
|
|
|
#undef _verifylink
|
|
|
|
#undef _verifyfile
|
1996-02-20 12:31:08 +08:00
|
|
|
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stdout, "%s%s%s%s%s%s%s%s %c %s\n",
|
1996-02-21 06:18:36 +08:00
|
|
|
size, mode, md5, rdev, link, user, group, mtime,
|
1996-03-05 06:52:34 +08:00
|
|
|
fileFlagsList[i] & RPMFILE_CONFIG ? 'c' : ' ',
|
1996-02-21 06:18:36 +08:00
|
|
|
fileList[i]);
|
|
|
|
}
|
1998-09-25 01:47:41 +08:00
|
|
|
if (rc)
|
|
|
|
ec = rc;
|
1996-02-20 12:31:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
free(fileList);
|
|
|
|
}
|
1998-09-25 01:47:41 +08:00
|
|
|
return ec;
|
1996-02-20 12:31:08 +08:00
|
|
|
}
|
|
|
|
|
1998-09-25 01:47:41 +08:00
|
|
|
static int verifyDependencies(rpmdb db, Header h) {
|
1996-07-21 07:21:18 +08:00
|
|
|
rpmDependencies rpmdep;
|
|
|
|
struct rpmDependencyConflict * conflicts;
|
|
|
|
int numConflicts;
|
|
|
|
char * name, * version, * release;
|
|
|
|
int type, count, i;
|
|
|
|
|
|
|
|
rpmdep = rpmdepDependencies(db);
|
1997-07-02 00:24:08 +08:00
|
|
|
rpmdepAddPackage(rpmdep, h, NULL);
|
1996-07-21 07:21:18 +08:00
|
|
|
|
|
|
|
rpmdepCheck(rpmdep, &conflicts, &numConflicts);
|
|
|
|
rpmdepDone(rpmdep);
|
|
|
|
|
|
|
|
if (numConflicts) {
|
1996-11-19 02:02:36 +08:00
|
|
|
headerGetEntry(h, RPMTAG_NAME, &type, (void **) &name, &count);
|
|
|
|
headerGetEntry(h, RPMTAG_VERSION, &type, (void **) &version, &count);
|
|
|
|
headerGetEntry(h, RPMTAG_RELEASE, &type, (void **) &release, &count);
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stdout, _("Unsatisfied dependencies for %s-%s-%s: "),
|
|
|
|
name, version, release);
|
1996-07-21 07:21:18 +08:00
|
|
|
for (i = 0; i < numConflicts; i++) {
|
1998-09-28 06:03:52 +08:00
|
|
|
if (i) fprintf(stdout, ", ");
|
|
|
|
fprintf(stdout, "%s", conflicts[i].needsName);
|
1996-07-21 07:21:18 +08:00
|
|
|
if (conflicts[i].needsFlags) {
|
|
|
|
printDepFlags(stdout, conflicts[i].needsVersion,
|
|
|
|
conflicts[i].needsFlags);
|
|
|
|
}
|
|
|
|
}
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stdout, "\n");
|
1996-10-21 09:21:48 +08:00
|
|
|
rpmdepFreeConflicts(conflicts, numConflicts);
|
1998-09-25 01:47:41 +08:00
|
|
|
return 1;
|
1996-07-21 07:21:18 +08:00
|
|
|
}
|
1998-09-25 01:47:41 +08:00
|
|
|
return 0;
|
1996-07-21 07:21:18 +08:00
|
|
|
}
|
|
|
|
|
1998-09-25 01:47:41 +08:00
|
|
|
static int verifyPackage(char * root, rpmdb db, Header h, int verifyFlags) {
|
|
|
|
int ec, rc;
|
1998-11-19 05:41:05 +08:00
|
|
|
FD_t fdo;
|
1998-09-25 01:47:41 +08:00
|
|
|
ec = 0;
|
|
|
|
if ((verifyFlags & VERIFY_DEPS) &&
|
|
|
|
(rc = verifyDependencies(db, h)) != 0)
|
|
|
|
ec = rc;
|
|
|
|
if ((verifyFlags & VERIFY_FILES) &&
|
|
|
|
(rc = verifyHeader(root, h, verifyFlags)) != 0)
|
|
|
|
ec = rc;;
|
1998-11-20 02:10:28 +08:00
|
|
|
fdo = fdDup(STDOUT_FILENO);
|
1998-09-25 01:47:41 +08:00
|
|
|
if ((verifyFlags & VERIFY_SCRIPT) &&
|
1998-11-19 05:41:05 +08:00
|
|
|
(rc = rpmVerifyScript(root, h, fdo)) != 0)
|
1998-09-25 01:47:41 +08:00
|
|
|
ec = rc;
|
1998-11-21 04:18:22 +08:00
|
|
|
fdClose(fdo);
|
1998-09-25 01:47:41 +08:00
|
|
|
return ec;
|
1996-11-23 01:19:14 +08:00
|
|
|
}
|
|
|
|
|
1998-09-25 01:47:41 +08:00
|
|
|
static int verifyMatches(char * prefix, rpmdb db, dbiIndexSet matches,
|
1996-07-21 07:21:18 +08:00
|
|
|
int verifyFlags) {
|
1998-09-25 01:47:41 +08:00
|
|
|
int ec, rc;
|
1996-02-20 12:31:08 +08:00
|
|
|
int i;
|
|
|
|
Header h;
|
|
|
|
|
1998-09-25 01:47:41 +08:00
|
|
|
ec = 0;
|
1998-11-20 02:10:28 +08:00
|
|
|
for (i = 0; i < dbiIndexSetCount(matches); i++) {
|
|
|
|
unsigned int recOffset = dbiIndexRecordOffset(matches, i);
|
|
|
|
if (recOffset == 0)
|
1998-09-25 01:47:41 +08:00
|
|
|
continue;
|
1998-11-20 02:10:28 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("verifying record number %u\n"),
|
|
|
|
recOffset);
|
1996-02-20 12:31:08 +08:00
|
|
|
|
1998-11-20 02:10:28 +08:00
|
|
|
h = rpmdbGetRecord(db, recOffset);
|
1998-11-17 05:40:28 +08:00
|
|
|
if (h == NULL) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("error: could not read database record\n"));
|
1998-09-25 01:47:41 +08:00
|
|
|
ec = 1;
|
|
|
|
} else {
|
|
|
|
if ((rc = verifyPackage(prefix, db, h, verifyFlags)) != 0)
|
|
|
|
ec = rc;
|
1996-11-19 02:02:36 +08:00
|
|
|
headerFree(h);
|
1996-02-20 12:31:08 +08:00
|
|
|
}
|
|
|
|
}
|
1998-09-25 01:47:41 +08:00
|
|
|
return ec;
|
1996-02-20 12:31:08 +08:00
|
|
|
}
|
|
|
|
|
1998-09-25 01:47:41 +08:00
|
|
|
int doVerify(char * prefix, enum verifysources source, char ** argv,
|
1996-07-21 07:21:18 +08:00
|
|
|
int verifyFlags) {
|
1996-02-20 12:31:08 +08:00
|
|
|
Header h;
|
|
|
|
int offset;
|
1998-09-25 01:47:41 +08:00
|
|
|
int ec, rc;
|
1996-02-20 12:31:08 +08:00
|
|
|
int isSource;
|
|
|
|
rpmdb db;
|
1996-11-19 02:02:36 +08:00
|
|
|
dbiIndexSet matches;
|
1996-02-20 12:31:08 +08:00
|
|
|
char * arg;
|
1998-12-15 05:34:11 +08:00
|
|
|
char path[PATH_MAX];
|
1996-02-20 12:31:08 +08:00
|
|
|
|
1998-09-25 01:47:41 +08:00
|
|
|
ec = 0;
|
1997-01-31 03:58:55 +08:00
|
|
|
if (source == VERIFY_RPM && !(verifyFlags & VERIFY_DEPS)) {
|
1996-10-16 03:08:14 +08:00
|
|
|
db = NULL;
|
|
|
|
} else {
|
1996-02-20 12:31:08 +08:00
|
|
|
if (rpmdbOpen(prefix, &db, O_RDONLY, 0644)) {
|
1998-11-21 04:18:22 +08:00
|
|
|
return 1; /* XXX was exit(EXIT_FAILURE) */
|
1996-02-20 12:31:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (source == VERIFY_EVERY) {
|
1998-09-25 01:47:41 +08:00
|
|
|
for (offset = rpmdbFirstRecNum(db);
|
|
|
|
offset != 0;
|
|
|
|
offset = rpmdbNextRecNum(db, offset)) {
|
|
|
|
h = rpmdbGetRecord(db, offset);
|
1998-11-17 05:40:28 +08:00
|
|
|
if (h == NULL) {
|
1998-09-25 01:47:41 +08:00
|
|
|
fprintf(stderr, _("could not read database record!\n"));
|
1998-11-21 04:18:22 +08:00
|
|
|
return 1; /* XXX was exit(EXIT_FAILURE) */
|
1998-09-25 01:47:41 +08:00
|
|
|
}
|
|
|
|
if ((rc = verifyPackage(prefix, db, h, verifyFlags)) != 0)
|
|
|
|
ec = rc;
|
|
|
|
headerFree(h);
|
1996-02-20 12:31:08 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (*argv) {
|
|
|
|
arg = *argv++;
|
|
|
|
|
1998-10-08 19:55:37 +08:00
|
|
|
rc = 0;
|
1996-02-20 12:31:08 +08:00
|
|
|
switch (source) {
|
1998-12-15 05:34:11 +08:00
|
|
|
case VERIFY_RPM:
|
1998-12-01 08:10:18 +08:00
|
|
|
{ FD_t fd;
|
|
|
|
|
|
|
|
fd = ufdOpen(arg, O_RDONLY, 0);
|
|
|
|
if (fd == NULL) {
|
|
|
|
fprintf(stderr, _("open of %s failed\n"), arg);
|
|
|
|
break;
|
1997-02-12 12:48:51 +08:00
|
|
|
}
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
if (fdFileno(fd) >= 0) {
|
1996-11-19 02:02:36 +08:00
|
|
|
rc = rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL);
|
1996-02-20 12:31:08 +08:00
|
|
|
}
|
1998-12-01 08:10:18 +08:00
|
|
|
|
|
|
|
ufdClose(fd);
|
|
|
|
|
|
|
|
switch (rc) {
|
|
|
|
case 0:
|
|
|
|
rc = verifyPackage(prefix, db, h, verifyFlags);
|
|
|
|
headerFree(h);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
fprintf(stderr, _("%s is not an RPM\n"), arg);
|
|
|
|
break;
|
|
|
|
}
|
1998-11-19 05:41:05 +08:00
|
|
|
} break;
|
1996-02-20 12:31:08 +08:00
|
|
|
|
1998-12-15 05:34:11 +08:00
|
|
|
case VERIFY_GRP:
|
1996-02-20 12:31:08 +08:00
|
|
|
if (rpmdbFindByGroup(db, arg, &matches)) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr,
|
1997-05-01 22:53:48 +08:00
|
|
|
_("group %s does not contain any packages\n"),
|
1997-04-29 10:45:19 +08:00
|
|
|
arg);
|
1996-02-20 12:31:08 +08:00
|
|
|
} else {
|
1998-09-25 01:47:41 +08:00
|
|
|
rc = verifyMatches(prefix, db, matches, verifyFlags);
|
1996-11-19 02:02:36 +08:00
|
|
|
dbiFreeIndexRecord(matches);
|
1996-02-20 12:31:08 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-12-15 05:34:11 +08:00
|
|
|
case VERIFY_PATH:
|
1996-02-20 12:31:08 +08:00
|
|
|
if (rpmdbFindByFile(db, arg, &matches)) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("file %s is not owned by any package\n"),
|
1996-02-20 12:31:08 +08:00
|
|
|
arg);
|
|
|
|
} else {
|
1998-09-25 01:47:41 +08:00
|
|
|
rc = verifyMatches(prefix, db, matches, verifyFlags);
|
1996-11-19 02:02:36 +08:00
|
|
|
dbiFreeIndexRecord(matches);
|
1996-02-20 12:31:08 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-12-15 05:34:11 +08:00
|
|
|
case VERIFY_PACKAGE:
|
1997-05-31 05:14:34 +08:00
|
|
|
rc = rpmdbFindByLabel(db, arg, &matches);
|
1996-02-20 12:31:08 +08:00
|
|
|
if (rc == 1)
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("package %s is not installed\n"), arg);
|
1996-02-20 12:31:08 +08:00
|
|
|
else if (rc == 2) {
|
1997-04-29 10:45:19 +08:00
|
|
|
fprintf(stderr, _("error looking for package %s\n"), arg);
|
1996-02-20 12:31:08 +08:00
|
|
|
} else {
|
1998-09-25 01:47:41 +08:00
|
|
|
rc = verifyMatches(prefix, db, matches, verifyFlags);
|
1996-11-19 02:02:36 +08:00
|
|
|
dbiFreeIndexRecord(matches);
|
1996-02-20 12:31:08 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-12-15 05:34:11 +08:00
|
|
|
case VERIFY_EVERY:
|
|
|
|
break;
|
1996-02-20 12:31:08 +08:00
|
|
|
}
|
1998-09-25 01:47:41 +08:00
|
|
|
if (rc)
|
|
|
|
ec = rc;
|
1996-02-20 12:31:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-01-31 03:58:55 +08:00
|
|
|
if (source != VERIFY_RPM) {
|
1996-02-20 12:31:08 +08:00
|
|
|
rpmdbClose(db);
|
|
|
|
}
|
1998-09-25 01:47:41 +08:00
|
|
|
return ec;
|
1996-02-20 12:31:08 +08:00
|
|
|
}
|