home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / misc / src / rpm / tools / rpmchecksig.c < prev    next >
C/C++ Source or Header  |  1997-09-17  |  791b  |  41 lines

  1. /* rpmchecksig: verify the signature of an RPM */
  2.  
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <fcntl.h>
  6.  
  7. #include "rpmlib.h"
  8. #include "rpmlead.h"
  9. #include "signature.h"
  10.  
  11. int main(int argc, char **argv)
  12. {
  13.     int fd;
  14.     struct rpmlead lead;
  15.     char *sig;
  16.     char result[1024];
  17.     int res;
  18.     
  19.     if (argc == 1) {
  20.     fd = 0;
  21.     } else {
  22.     fd = open(argv[1], O_RDONLY, 0644);
  23.     }
  24.  
  25.     /* Need this for any PGP settings */
  26.     if (rpmReadConfigFiles(NULL, NULL, NULL, 0))
  27.     exit(-1);
  28.  
  29.     readLead(fd, &lead);
  30.     rpmReadSignature(fd, lead.signature_type, (void **) &sig);
  31.     res = verifySignature(fd, lead.signature_type, sig, result, 1);
  32.     printf("%s", result);
  33.     if (res) {
  34.     printf("Signature OK.\n");
  35.     return 0;
  36.     } else {
  37.     printf("Signature NOT OK!\n");
  38.     return 1;
  39.     }
  40. }
  41.