Product SiteDocumentation Site

Reading the RPM lead and signature

Once you have opened an RPM file, you can start to read header information, which is the most interesting information to most RPM programs. (You may also want to read the files in the RPM payload, for example.) Before you can start reading the header, though, you must read forward in the RPM file past the lead and signature.
Cross Reference
Chapter 2, RPM Overview introduces the lead and signature.
Even if your programs don’t want to examine the lead or signature, you must read past to position the file offset properly for reading the header information. To read past the lead, call readLead:
int readLead(FD_t fd, struct rpmlead *lead);
The readLead function returns 0 on success or 1 on an error. It fills in an rpmlead struct:
struct rpmlead {
unsigned char magic[4];
unsigned char major;
unsigned char minor;
short type;
short archnum;
char name[66];
short osnum;
short signature_type;
char reserved[16];
};
To read past the signature, call rpmReadSignature:
rpmRC rpmReadSignature(FD_t fd,
Header * header,
sigType sig_type);
The return code is one of the values listed in Table 16-8.
Table 16-8 Return codes from rpmReadSignature
Code
RPMRC_OK
RPMRC_BADMAGIC
RPMRC_FAIL
RPMRC_BADSIZE
RPMRC_SHORTREAD
You can do more with the signature than merely reading past it, of course. Look in the online RPM documentation for more on verifying signatures.
After reading the signature, you can start to read the general header entries.