From e587de6e8690a3036c34dcb92e606e81af3ddeee Mon Sep 17 00:00:00 2001 From: root Date: Thu, 28 Mar 1996 23:56:49 +0000 Subject: [PATCH] added doReSign() CVS patchset: 485 CVS date: 1996/03/28 23:56:49 --- checksig.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ checksig.h | 2 ++ 2 files changed, 113 insertions(+) diff --git a/checksig.c b/checksig.c index ac80352..188f256 100644 --- a/checksig.c +++ b/checksig.c @@ -1,6 +1,7 @@ /* checksig.c: verify the signature of an RPM */ #include +#include #include #include @@ -9,6 +10,116 @@ #include "rpmlead.h" #include "signature.h" +int doReSign(char *passPhrase, char **argv) +{ + int fd, ofd, count; + struct rpmlead lead; + unsigned short sigtype; + char *sig, *rpm, *sigtarget; + char tmprpm[1024]; + unsigned char buffer[8192]; + + /* Figure out the signature type */ + if ((sigtype = sigLookupType()) == RPMSIG_BAD) { + fprintf(stderr, "Bad signature type in rpmrc\n"); + exit(1); + } + + while (*argv) { + rpm = *argv++; + if ((fd = open(rpm, O_RDONLY, 0644)) < 0) { + fprintf(stderr, "%s: Open failed\n", rpm); + exit(1); + } + if (readLead(fd, &lead)) { + fprintf(stderr, "%s: readLead failed\n", rpm); + exit(1); + } + if (lead.major == 1) { + fprintf(stderr, "%s: Can't sign v1.0 RPM\n", rpm); + exit(1); + } + if (!readSignature(fd, lead.signature_type, (void **) &sig)) { + fprintf(stderr, "%s: readSignature failed\n", rpm); + exit(1); + } + if (sig) { + free(sig); + } + + /* Write the rest to a temp file */ + sigtarget = tempnam("/usr/tmp", "rpmbuild"); + ofd = open(sigtarget, O_WRONLY|O_CREAT|O_TRUNC, 0644); + while ((count = read(fd, buffer, sizeof(buffer))) > 0) { + if (count == -1) { + perror("Couldn't read the header/archvie"); + close(ofd); + unlink(sigtarget); + exit(1); + } + if (write(ofd, buffer, count) < 0) { + perror("Couldn't write header/archive to temp file"); + close(ofd); + unlink(sigtarget); + exit(1); + } + } + close(fd); + close(ofd); + + /* Start writing the new RPM */ + sprintf(tmprpm, "%s.tmp", rpm); + ofd = open(tmprpm, O_WRONLY|O_CREAT|O_TRUNC, 0644); + lead.signature_type = sigtype; + if (writeLead(ofd, &lead)) { + perror("writeLead()"); + close(ofd); + unlink(sigtarget); + unlink(tmprpm); + exit(1); + } + + /* Generate the signature */ + if (makeSignature(sigtarget, sigtype, ofd, passPhrase)) { + fprintf(stderr, "makeSignature() failed\n"); + close(ofd); + unlink(sigtarget); + unlink(tmprpm); + exit(1); + } + + /* Append the header and archive */ + fd = open(sigtarget, O_RDONLY); + while ((count = read(fd, buffer, sizeof(buffer))) > 0) { + if (count == -1) { + perror("Couldn't read sigtarget"); + close(ofd); + close(fd); + unlink(sigtarget); + unlink(tmprpm); + exit(1); + } + if (write(ofd, buffer, count) < 0) { + perror("Couldn't write package"); + close(ofd); + close(fd); + unlink(sigtarget); + unlink(tmprpm); + exit(1); + } + } + close(fd); + close(ofd); + unlink(sigtarget); + + /* Move it in to place */ + unlink(rpm); + rename(tmprpm, rpm); + } + + return 0; +} + int doCheckSig(char **argv) { int fd; diff --git a/checksig.h b/checksig.h index 6868286..a6884e4 100644 --- a/checksig.h +++ b/checksig.h @@ -3,4 +3,6 @@ int doCheckSig(char **argv); +int doReSign(char *passPhrase, char **argv); + #endif -- 2.7.4