summaryrefslogtreecommitdiff
path: root/checksig.c
diff options
context:
space:
mode:
authorroot <devnull@localhost>1996-03-28 23:56:49 +0000
committerroot <devnull@localhost>1996-03-28 23:56:49 +0000
commite587de6e8690a3036c34dcb92e606e81af3ddeee (patch)
tree0a3bc4d2d052831564e0469c51442f3a69889449 /checksig.c
parent5e3b53f7afb02c5aac2373bb48287e4a37bd6b93 (diff)
downloadlibrpm-tizen-e587de6e8690a3036c34dcb92e606e81af3ddeee.tar.gz
librpm-tizen-e587de6e8690a3036c34dcb92e606e81af3ddeee.tar.bz2
librpm-tizen-e587de6e8690a3036c34dcb92e606e81af3ddeee.zip
added doReSign()
CVS patchset: 485 CVS date: 1996/03/28 23:56:49
Diffstat (limited to 'checksig.c')
-rw-r--r--checksig.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/checksig.c b/checksig.c
index ac803526b..188f256b0 100644
--- a/checksig.c
+++ b/checksig.c
@@ -1,6 +1,7 @@
/* checksig.c: verify the signature of an RPM */
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
@@ -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;