summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorjbj <devnull@localhost>1999-07-13 23:33:02 +0000
committerjbj <devnull@localhost>1999-07-13 23:33:02 +0000
commit4bd2f3531a51fd99adb4e3e7007a3ffee1b178ef (patch)
treeee451ca89af0649686aca0d9bd5e30028c9682e6 /lib
parentfca8845a9a45f9d2d8940f145b311ef79d51c1ee (diff)
downloadlibrpm-tizen-4bd2f3531a51fd99adb4e3e7007a3ffee1b178ef.tar.gz
librpm-tizen-4bd2f3531a51fd99adb4e3e7007a3ffee1b178ef.tar.bz2
librpm-tizen-4bd2f3531a51fd99adb4e3e7007a3ffee1b178ef.zip
File internals rearranged to taste.
CVS patchset: 3152 CVS date: 1999/07/13 23:33:02
Diffstat (limited to 'lib')
-rw-r--r--lib/lookup.c100
-rw-r--r--lib/package.c12
-rw-r--r--lib/problems.c10
-rw-r--r--lib/signature.c266
4 files changed, 192 insertions, 196 deletions
diff --git a/lib/lookup.c b/lib/lookup.c
index cab17bb13..d9db80ad7 100644
--- a/lib/lookup.c
+++ b/lib/lookup.c
@@ -3,55 +3,7 @@
#include <rpmlib.h>
#include "lookup.h"
-/* 0 found matches */
-/* 1 no matches */
-/* 2 error */
-int rpmdbFindByHeader(rpmdb db, Header h, dbiIndexSet * matches) {
- char * name, * version, * release;
-
- headerGetEntry(h, RPMTAG_NAME, NULL, (void **) &name, NULL);
- headerGetEntry(h, RPMTAG_VERSION, NULL, (void **) &version, NULL);
- headerGetEntry(h, RPMTAG_RELEASE, NULL, (void **) &release, NULL);
-
- return findMatches(db, name, version, release, matches);
-}
-
-/* 0 found matches */
-/* 1 no matches */
-/* 2 error */
-int rpmdbFindByLabel(rpmdb db, const char * arg, dbiIndexSet * matches) {
- char * localarg, * chptr;
- char * release;
- int rc;
-
- if (!strlen(arg)) return 1;
-
- /* did they give us just a name? */
- rc = findMatches(db, arg, NULL, NULL, matches);
- if (rc != 1) return rc;
-
- /* maybe a name and a release */
- localarg = alloca(strlen(arg) + 1);
- strcpy(localarg, arg);
-
- chptr = (localarg + strlen(localarg)) - 1;
- while (chptr > localarg && *chptr != '-') chptr--;
- if (chptr == localarg) return 1;
-
- *chptr = '\0';
- rc = findMatches(db, localarg, chptr + 1, NULL, matches);
- if (rc != 1) return rc;
-
- /* how about name-version-release? */
-
- release = chptr + 1;
- while (chptr > localarg && *chptr != '-') chptr--;
- if (chptr == localarg) return 1;
-
- *chptr = '\0';
- return findMatches(db, localarg, chptr + 1, release, matches);
-}
-
+/* XXX used in transaction.c */
/* 0 found matches */
/* 1 no matches */
/* 2 error */
@@ -113,3 +65,53 @@ int findMatches(rpmdb db, const char * name, const char * version,
return 0;
}
+/* 0 found matches */
+/* 1 no matches */
+/* 2 error */
+int rpmdbFindByHeader(rpmdb db, Header h, dbiIndexSet * matches)
+{
+ char * name, * version, * release;
+
+ headerGetEntry(h, RPMTAG_NAME, NULL, (void **) &name, NULL);
+ headerGetEntry(h, RPMTAG_VERSION, NULL, (void **) &version, NULL);
+ headerGetEntry(h, RPMTAG_RELEASE, NULL, (void **) &release, NULL);
+
+ return findMatches(db, name, version, release, matches);
+}
+
+/* 0 found matches */
+/* 1 no matches */
+/* 2 error */
+int rpmdbFindByLabel(rpmdb db, const char * arg, dbiIndexSet * matches)
+{
+ char * localarg, * chptr;
+ char * release;
+ int rc;
+
+ if (!strlen(arg)) return 1;
+
+ /* did they give us just a name? */
+ rc = findMatches(db, arg, NULL, NULL, matches);
+ if (rc != 1) return rc;
+
+ /* maybe a name and a release */
+ localarg = alloca(strlen(arg) + 1);
+ strcpy(localarg, arg);
+
+ chptr = (localarg + strlen(localarg)) - 1;
+ while (chptr > localarg && *chptr != '-') chptr--;
+ if (chptr == localarg) return 1;
+
+ *chptr = '\0';
+ rc = findMatches(db, localarg, chptr + 1, NULL, matches);
+ if (rc != 1) return rc;
+
+ /* how about name-version-release? */
+
+ release = chptr + 1;
+ while (chptr > localarg && *chptr != '-') chptr--;
+ if (chptr == localarg) return 1;
+
+ *chptr = '\0';
+ return findMatches(db, localarg, chptr + 1, release, matches);
+}
diff --git a/lib/package.c b/lib/package.c
index 3c94289ec..b89f58ccc 100644
--- a/lib/package.c
+++ b/lib/package.c
@@ -12,7 +12,8 @@
#if defined(ENABLE_V1_PACKAGES)
/* 0 = success */
/* !0 = error */
-static int readOldHeader(FD_t fd, Header * hdr, int * isSource) {
+static int readOldHeader(FD_t fd, Header * hdr, int * isSource)
+{
struct oldrpmHeader oldheader;
struct oldrpmHeaderSpec spec;
Header dbentry;
@@ -193,7 +194,8 @@ static int readOldHeader(FD_t fd, Header * hdr, int * isSource) {
/* 1 = bad magic */
/* 2 = error */
static int readPackageHeaders(FD_t fd, struct rpmlead * leadPtr,
- Header * sigs, Header * hdrPtr) {
+ Header * sigs, Header * hdrPtr)
+{
Header hdrBlock;
struct rpmlead leadBlock;
Header * hdr;
@@ -299,7 +301,8 @@ static int readPackageHeaders(FD_t fd, struct rpmlead * leadPtr,
/* 0 = success */
/* 1 = bad magic */
/* 2 = error */
-int rpmReadPackageInfo(FD_t fd, Header * signatures, Header * hdr) {
+int rpmReadPackageInfo(FD_t fd, Header * signatures, Header * hdr)
+{
return readPackageHeaders(fd, NULL, signatures, hdr);
}
@@ -307,7 +310,8 @@ int rpmReadPackageInfo(FD_t fd, Header * signatures, Header * hdr) {
/* 1 = bad magic */
/* 2 = error */
int rpmReadPackageHeader(FD_t fd, Header * hdr, int * isSource, int * major,
- int * minor) {
+ int * minor)
+{
int rc;
struct rpmlead lead;
diff --git a/lib/problems.c b/lib/problems.c
index 38559a3e2..4216045d1 100644
--- a/lib/problems.c
+++ b/lib/problems.c
@@ -6,7 +6,9 @@
#include "misc.h"
/* XXX FIXME: merge into problems */
-void printDepFlags(FILE * fp, const char * version, int flags) {
+/* XXX used in verify.c */
+void printDepFlags(FILE * fp, const char * version, int flags)
+{
if (flags)
fprintf(fp, " ");
@@ -27,7 +29,8 @@ void printDepFlags(FILE * fp, const char * version, int flags) {
/* XXX FIXME: merge into problems */
void printDepProblems(FILE * fp, struct rpmDependencyConflict * conflicts,
- int numConflicts) {
+ int numConflicts)
+{
int i;
for (i = 0; i < numConflicts; i++) {
@@ -46,7 +49,8 @@ void printDepProblems(FILE * fp, struct rpmDependencyConflict * conflicts,
}
}
-char * rpmProblemString(rpmProblem prob) {
+char * rpmProblemString(rpmProblem prob)
+{
char * name, * version, * release;
char * buf;
char * altName, * altVersion, * altRelease;
diff --git a/lib/signature.c b/lib/signature.c
index eb2748ad9..ccf1972fe 100644
--- a/lib/signature.c
+++ b/lib/signature.c
@@ -23,20 +23,6 @@
typedef int (*md5func)(const char * fn, unsigned char * digest);
-static int makePGPSignature(const char *file, void **sig, int_32 *size,
- const char *passPhrase, int sigTag);
-static int makeGPGSignature(const char *file, void **sig, int_32 *size,
- const char *passPhrase);
-static int checkSize(FD_t fd, int size, int sigsize);
-static int verifySizeSignature(const char *datafile, int_32 size, char *result);
-static int verifyMD5Signature(const char *datafile, unsigned char *sig,
- char *result, md5func fn);
-static int verifyPGPSignature(const char *datafile, void *sig,
- int count, char *result, int sigTag);
-static int verifyGPGSignature(const char *datafile, void *sig,
- int count, char *result);
-static int checkPassPhrase(const char *passPhrase, const int sigTag);
-
int rpmLookupSignatureType(int action)
{
static int rc = 0;
@@ -126,6 +112,27 @@ const char * rpmDetectPGPVersion(int sigTag)
return NULL;
}
+static int checkSize(FD_t fd, int size, int sigsize)
+{
+ int headerArchiveSize;
+ struct stat statbuf;
+
+ fstat(fdFileno(fd), &statbuf);
+
+ if (S_ISREG(statbuf.st_mode)) {
+ headerArchiveSize = statbuf.st_size - sizeof(struct rpmlead) - sigsize;
+
+ rpmMessage(RPMMESS_DEBUG, _("sigsize : %d\n"), sigsize);
+ rpmMessage(RPMMESS_DEBUG, _("Header + Archive: %d\n"), headerArchiveSize);
+ rpmMessage(RPMMESS_DEBUG, _("expected size : %d\n"), size);
+
+ return size - headerArchiveSize;
+ } else {
+ rpmMessage(RPMMESS_DEBUG, _("file is not regular -- skipping size check\n"));
+ return 0;
+ }
+}
+
/* rpmReadSignature() emulates the new style signatures if it finds an */
/* old-style one. It also immediately verifies the header+archive */
/* size and returns an error if it doesn't match. */
@@ -228,42 +235,6 @@ void rpmFreeSignature(Header h)
headerFree(h);
}
-int rpmAddSignature(Header header, const char *file, int_32 sigTag, const char *passPhrase)
-{
- struct stat statbuf;
- int_32 size;
- unsigned char buf[16];
- void *sig;
- int ret = -1;
-
- switch (sigTag) {
- case RPMSIGTAG_SIZE:
- stat(file, &statbuf);
- size = statbuf.st_size;
- ret = 0;
- headerAddEntry(header, RPMSIGTAG_SIZE, RPM_INT32_TYPE, &size, 1);
- break;
- case RPMSIGTAG_MD5:
- ret = mdbinfile(file, buf);
- if (ret == 0)
- headerAddEntry(header, sigTag, RPM_BIN_TYPE, buf, 16);
- break;
- case RPMSIGTAG_PGP:
- case RPMSIGTAG_PGP5:
- ret = makePGPSignature(file, &sig, &size, passPhrase, sigTag);
- if (ret == 0)
- headerAddEntry(header, sigTag, RPM_BIN_TYPE, sig, size);
- break;
- case RPMSIGTAG_GPG:
- ret = makeGPGSignature(file, &sig, &size, passPhrase);
- if (ret == 0)
- headerAddEntry(header, sigTag, RPM_BIN_TYPE, sig, size);
- break;
- }
-
- return ret;
-}
-
static int makePGPSignature(const char *file, void **sig, int_32 *size,
const char *passPhrase, int sigTag)
{
@@ -423,60 +394,40 @@ static int makeGPGSignature(const char *file, void **sig, int_32 *size,
return 0;
}
-static int checkSize(FD_t fd, int size, int sigsize)
+int rpmAddSignature(Header header, const char *file, int_32 sigTag, const char *passPhrase)
{
- int headerArchiveSize;
struct stat statbuf;
-
- fstat(fdFileno(fd), &statbuf);
-
- if (S_ISREG(statbuf.st_mode)) {
- headerArchiveSize = statbuf.st_size - sizeof(struct rpmlead) - sigsize;
-
- rpmMessage(RPMMESS_DEBUG, _("sigsize : %d\n"), sigsize);
- rpmMessage(RPMMESS_DEBUG, _("Header + Archive: %d\n"), headerArchiveSize);
- rpmMessage(RPMMESS_DEBUG, _("expected size : %d\n"), size);
-
- return size - headerArchiveSize;
- } else {
- rpmMessage(RPMMESS_DEBUG, _("file is not regular -- skipping size check\n"));
- return 0;
- }
-}
-
-int rpmVerifySignature(const char *file, int_32 sigTag, void *sig, int count,
- char *result)
-{
+ int_32 size;
+ unsigned char buf[16];
+ void *sig;
+ int ret = -1;
+
switch (sigTag) {
case RPMSIGTAG_SIZE:
- if (verifySizeSignature(file, *(int_32 *)sig, result)) {
- return RPMSIG_BAD;
- }
+ stat(file, &statbuf);
+ size = statbuf.st_size;
+ ret = 0;
+ headerAddEntry(header, RPMSIGTAG_SIZE, RPM_INT32_TYPE, &size, 1);
break;
case RPMSIGTAG_MD5:
- if (verifyMD5Signature(file, sig, result, mdbinfile)) {
- return 1;
- }
- break;
- case RPMSIGTAG_LEMD5_1:
- case RPMSIGTAG_LEMD5_2:
- if (verifyMD5Signature(file, sig, result, mdbinfileBroken)) {
- return 1;
- }
+ ret = mdbinfile(file, buf);
+ if (ret == 0)
+ headerAddEntry(header, sigTag, RPM_BIN_TYPE, buf, 16);
break;
case RPMSIGTAG_PGP:
case RPMSIGTAG_PGP5:
- return verifyPGPSignature(file, sig, count, result, sigTag);
+ ret = makePGPSignature(file, &sig, &size, passPhrase, sigTag);
+ if (ret == 0)
+ headerAddEntry(header, sigTag, RPM_BIN_TYPE, sig, size);
break;
case RPMSIGTAG_GPG:
- return verifyGPGSignature(file, sig, count, result);
+ ret = makeGPGSignature(file, &sig, &size, passPhrase);
+ if (ret == 0)
+ headerAddEntry(header, sigTag, RPM_BIN_TYPE, sig, size);
break;
- default:
- sprintf(result, "Do not know how to verify sig type %d\n", sigTag);
- return RPMSIG_UNKNOWN;
}
- return RPMSIG_OK;
+ return ret;
}
static int verifySizeSignature(const char *datafile, int_32 size, char *result)
@@ -700,56 +651,6 @@ static int verifyGPGSignature(const char *datafile, void *sig,
return res;
}
-char *rpmGetPassPhrase(const char *prompt, const int sigTag)
-{
- char *pass;
- int aok;
-
- switch (sigTag) {
- case RPMSIGTAG_GPG:
- { const char *name = rpmExpand("%{_gpg_name}", NULL);
- aok = (name && *name != '%');
- xfree(name);
- }
- if (!aok) {
- rpmError(RPMERR_SIGGEN,
- _("You must set \"%%_gpg_name\" in your macro file"));
- return NULL;
- }
- break;
- case RPMSIGTAG_PGP:
- case RPMSIGTAG_PGP5:
- { const char *name = rpmExpand("%{_pgp_name}", NULL);
- aok = (name && *name != '%');
- xfree(name);
- }
- if (!aok) {
- rpmError(RPMERR_SIGGEN,
- _("You must set \"%%_pgp_name\" in your macro file"));
- return NULL;
- }
- break;
- default:
- /* Currently the calling function (rpm.c:main) is checking this and
- * doing a better job. This section should never be accessed.
- */
- rpmError(RPMERR_SIGGEN, _("Invalid %%_signature spec in macro file"));
- return NULL;
- }
-
- if (prompt) {
- pass = getpass(prompt);
- } else {
- pass = getpass("");
- }
-
- if (checkPassPhrase(pass, sigTag)) {
- return NULL;
- }
-
- return pass;
-}
-
static int checkPassPhrase(const char *passPhrase, const int sigTag)
{
int passPhrasePipe[2];
@@ -832,3 +733,88 @@ static int checkPassPhrase(const char *passPhrase, const int sigTag)
/* passPhrase is good */
return 0;
}
+
+char *rpmGetPassPhrase(const char *prompt, const int sigTag)
+{
+ char *pass;
+ int aok;
+
+ switch (sigTag) {
+ case RPMSIGTAG_GPG:
+ { const char *name = rpmExpand("%{_gpg_name}", NULL);
+ aok = (name && *name != '%');
+ xfree(name);
+ }
+ if (!aok) {
+ rpmError(RPMERR_SIGGEN,
+ _("You must set \"%%_gpg_name\" in your macro file"));
+ return NULL;
+ }
+ break;
+ case RPMSIGTAG_PGP:
+ case RPMSIGTAG_PGP5:
+ { const char *name = rpmExpand("%{_pgp_name}", NULL);
+ aok = (name && *name != '%');
+ xfree(name);
+ }
+ if (!aok) {
+ rpmError(RPMERR_SIGGEN,
+ _("You must set \"%%_pgp_name\" in your macro file"));
+ return NULL;
+ }
+ break;
+ default:
+ /* Currently the calling function (rpm.c:main) is checking this and
+ * doing a better job. This section should never be accessed.
+ */
+ rpmError(RPMERR_SIGGEN, _("Invalid %%_signature spec in macro file"));
+ return NULL;
+ }
+
+ if (prompt) {
+ pass = getpass(prompt);
+ } else {
+ pass = getpass("");
+ }
+
+ if (checkPassPhrase(pass, sigTag)) {
+ return NULL;
+ }
+
+ return pass;
+}
+
+int rpmVerifySignature(const char *file, int_32 sigTag, void *sig, int count,
+ char *result)
+{
+ switch (sigTag) {
+ case RPMSIGTAG_SIZE:
+ if (verifySizeSignature(file, *(int_32 *)sig, result)) {
+ return RPMSIG_BAD;
+ }
+ break;
+ case RPMSIGTAG_MD5:
+ if (verifyMD5Signature(file, sig, result, mdbinfile)) {
+ return 1;
+ }
+ break;
+ case RPMSIGTAG_LEMD5_1:
+ case RPMSIGTAG_LEMD5_2:
+ if (verifyMD5Signature(file, sig, result, mdbinfileBroken)) {
+ return 1;
+ }
+ break;
+ case RPMSIGTAG_PGP:
+ case RPMSIGTAG_PGP5:
+ return verifyPGPSignature(file, sig, count, result, sigTag);
+ break;
+ case RPMSIGTAG_GPG:
+ return verifyGPGSignature(file, sig, count, result);
+ break;
+ default:
+ sprintf(result, "Do not know how to verify sig type %d\n", sigTag);
+ return RPMSIG_UNKNOWN;
+ }
+
+ return RPMSIG_OK;
+}