Main Page Modules Data Structures File List Data Fields Globals Related Pages

# lib/package.c File Reference

More...

`#include "system.h"`
`#include <netinet/in.h>`
`#include <rpmio_internal.h>`
`#include <rpmlib.h>`
`#include "rpmts.h"`
`#include "misc.h"`
`#include "legacy.h"`
`#include "rpmlead.h"`
`#include "header_internal.h"`
`#include "signature.h"`
`#include "debug.h"`

Go to the source code of this file.

## Defines
#define | alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
#define | hdrchkTags(_ntags) ((_ntags) & 0xffff0000)
| Sanity check on no. More...
#define | hdrchkType(_type) ((_type) < RPM_MIN_TYPE || (_type) > RPM_MAX_TYPE)
| Sanity check on type values. More...
#define | hdrchkData(_nbytes) ((_nbytes) & 0xff000000)
| Sanity check on data size and/or offset. More...
#define | hdrchkAlign(_type, _off) ((_off) & (typeAlign[_type]-1))
| Sanity check on data alignment for data type. More...
#define | hdrchkRange(_dl, _off) ((_off) < 0 || (_off) > (_dl))
| Sanity check on range of data offset. More...
#define | _chk(_mask) (sigtag == 0 && !(vsflags & (_mask)))
## Functions
void | headerMergeLegacySigs (Header h, const Header sigh)
Header | headerRegenSigHeader (const Header h, int noArchiveSize)
int | rpmtsStashKeyid (rpmts ts)
| Remember current key id. More...
int | headerVerifyInfo (int il, int dl, const void *pev, void *iv, int negate)
| Perform simple sanity and range checks on header tag(s). More...
rpmRC | headerCheck (rpmts ts, const void *uh, size_t uc, const char **msg)
| Check header consistency, performing headerGetEntry() the hard way. More...
rpmRC | rpmReadHeader (rpmts ts, FD_t fd, Header *hdrp, const char **msg)
| Return checked and loaded header. More...
int | rpmReadPackageFile (rpmts ts, FD_t fd, const char *fn, Header *hdrp)
| Return package header from file handle, verifying digests/signatures. More...
## Variables
int | _print_pkts = 0
unsigned int | nkeyids_max = 256
unsigned int | nkeyids = 0
unsigned int | nextkeyid = 0
unsigned int * | keyids
unsigned char | header_magic [8]
int | typeAlign [16]
| Alignment needs (and sizeof scalars types) for internal rpm data types. More...

## Detailed Description

Definition in file package.c.

## Define Documentation

#define _chk | ( | _mask |  | ) | (sigtag == 0 && !(vsflags & (_mask)))

#define alloca_strdup | ( | _s |  | ) | strcpy(alloca(strlen(_s)+1), (_s))

| Definition at line 22 of file package.c. Referenced by ftpNLST, and legacyRetrofit.

#define hdrchkAlign | ( | _type,
|  | _off |  | ) | ((_off) & (typeAlign[_type]-1))

| Sanity check on data alignment for data type. Definition at line 92 of file package.c. Referenced by headerVerifyInfo.

#define hdrchkData | ( | _nbytes |  | ) | ((_nbytes) & 0xff000000)

| Sanity check on data size and/or offset. This check imposes a limit of 16 MB, more than enough. Definition at line 87 of file package.c. Referenced by doHeaderUnload, headerCopyLoad, headerLoad, headerMergeLegacySigs, headerRead, headerVerifyInfo, regionSwab, and rpmReadHeader.

#define hdrchkRange | ( | _dl,
|  | _off |  | ) | ((_off) < 0 || (_off) > (_dl))

| Sanity check on range of data offset. Definition at line 97 of file package.c. Referenced by headerVerifyInfo.

#define hdrchkTags | ( | _ntags |  | ) | ((_ntags) & 0xffff0000)

| Sanity check on no. of tags. This check imposes a limit of 65K tags, more than enough. Definition at line 76 of file package.c. Referenced by doHeaderUnload, headerCopyLoad, headerLoad, headerRead, and rpmReadHeader.

#define hdrchkType | ( | _type |  | ) | ((_type) < RPM_MIN_TYPE || (_type) > RPM_MAX_TYPE)

| Sanity check on type values. Definition at line 81 of file package.c. Referenced by headerMergeLegacySigs, and headerVerifyInfo.

## Function Documentation

rpmRC headerCheck | ( | rpmts | ts,
|  | const void * | uh,
|  | size_t | uc,
|  | const char ** | msg
| ) |

  | Check header consistency, performing headerGetEntry() the hard way. Sanity checks on the header are performed while looking for a header-only digest or signature to verify the blob. If found, the digest or signature is verified. Parameters:
  ts | transaction set
  uh | unloaded header blob
  uc | no. of bytes in blob (or 0 to disable)
  Return values:
  msg | signature verification msg
Returns: RPMRC_OK/RPMRC_NOTFOUND/RPMRC_FAIL Definition at line 323 of file package.c. References _, _print_pkts, alloca, entryInfo_s::count, pgpDig_s::hdrsha1ctx, header_magic, headerVerifyInfo, indexEntry_s::info, int_32, pgpDig_s::nbytes, entryInfo_s::offset, PGPHASHALGO_MD5, PGPHASHALGO_SHA1, pgpPrtPkts, REGION_TAG_COUNT, RPM_BIN_TYPE, RPM_STRING_TYPE, RPMDIGEST_NONE, rpmDigestInit, rpmDigestUpdate, rpmRC, RPMRC_FAIL, RPMRC_NOTFOUND, RPMRC_OK, RPMTAG_DSAHEADER, RPMTAG_HEADERIMMUTABLE, RPMTAG_RSAHEADER, RPMTAG_SHA1HEADER, rpmts, rpmtsCleanDig, rpmtsDig, rpmtsSetSig, rpmtsVSFlags, rpmVerifySignature, RPMVSF_NODSAHEADER, RPMVSF_NOSHA1HEADER, rpmVSFlags, pgpDig_s::signature, entryInfo_s::tag, entryInfo_s::type, pgpDigParams_s::version, xmalloc, and xstrdup.

int headerVerifyInfo | ( | int | il,
|  | int | dl,
|  | const void * | pev,
|  | void * | iv,
|  | int | negate
| ) |

  | Perform simple sanity and range checks on header tag(s). Parameters:
  il | no. of tags in header
  dl | no. of bytes in header data.
  pev | 1st element in tag array, big-endian
  iv | failing (or last) tag element, host-endian
  negate | negative offset expected?
Returns: -1 on success, otherwise failing tag element index Definition at line 281 of file package.c. References entryInfo_s::count, hdrchkAlign, hdrchkData, hdrchkRange, hdrchkType, entryInfo_s::offset, entryInfo_s::tag, and entryInfo_s::type.

rpmRC rpmReadHeader | ( | rpmts | ts,
|  | FD_t | fd,
|  | Header * | hdrp,
|  | const char ** | msg
| ) |

  | Return checked and loaded header. Parameters:
  ts | transaction set
  fd | file handle
  Return values:
  hdrp | address of header (or NULL)
  msg | verification error message
Returns: RPMRC_OK on success Definition at line 600 of file package.c. References _free, headerToken::flags, hdrchkData, hdrchkTags, header_magic, headerCheck, HEADERFLAG_ALLOCATED, headerFree, headerLink, headerLoad, int_32, rpmRC, RPMRC_FAIL, RPMRC_OK, rpmts, timedRead, and xmalloc.

int rpmReadPackageFile | ( | rpmts | ts,
|  | FD_t | fd,
|  | const char * | fn,
|  | Header * | hdrp
| ) |

  | Return package header from file handle, verifying digests/signatures. Parameters:
  ts | transaction set
  fd | file handle
  fn | file name
  Return values:
  hdrp | address of header (or NULL)
Returns: 0 on success Definition at line 653 of file package.c. References _, _free, _print_pkts, alloca, _FD_s::digests, fdInitDigest, Fileno, Fread, Fstrerror, _FDDIGEST_s::hashalgo, _FDDIGEST_s::hashctx, pgpDig_s::hdrsha1ctx, header_magic, HEADER_MAGIC_NO, HEADER_MAGIC_YES, headerFree, headerFreeData, headerGetEntry, headerIsEntry, headerLink, headerMergeLegacySigs, headerSizeof, int_32, legacyRetrofit, pgpDig_s::md5ctx, pgpDig_s::nbytes, _FD_s::ndigests, PGPHASHALGO_MD5, PGPHASHALGO_SHA1, pgpPrtPkts, readLead, RPMDIGEST_NONE, rpmDigestInit, rpmDigestUpdate, rpmFreeSignature, rpmRC, RPMRC_FAIL, RPMRC_NOKEY, RPMRC_NOTFOUND, RPMRC_NOTTRUSTED, RPMRC_OK, rpmReadHeader, rpmReadSignature, RPMTAG_HEADERIMMUTABLE, rpmts, rpmtsCleanDig, rpmtsDig, rpmtsSetSig, rpmtsStashKeyid, rpmtsVSFlags, rpmVerifySignature, RPMVSF_NEEDPAYLOAD, RPMVSF_NODSA, RPMVSF_NODSAHEADER, RPMVSF_NOMD5, RPMVSF_NORSA, RPMVSF_NORSAHEADER, RPMVSF_NOSHA1HEADER, rpmVSFlags, pgpDig_s::sha1ctx, pgpDig_s::signature, and pgpDigParams_s::version.

int rpmtsStashKeyid | ( | rpmts | ts | ) | `[static]`

  | Remember current key id. Parameters:
  ts | transaction set
Returns: 0 if new keyid, otherwise 1 Definition at line 243 of file package.c. References keyids, nextkeyid, nkeyids, nkeyids_max, pgpGrab, rpmts, rpmtsDig, rpmtsSig, rpmtsSignature, pgpDigParams_s::signid, and xrealloc. Referenced by rpmReadPackageFile.

## Variable Documentation

int _print_pkts = 0`[static]`

| Definition at line 33 of file package.c. Referenced by headerCheck, and rpmReadPackageFile.

unsigned char header_magic[8]`[static]`

| Initial value:
     {
            0x8e, 0xad, 0xe8, 0x01, 0x00, 0x00, 0x00, 0x00
    }
Definition at line 45 of file package.c. Referenced by headerCheck, rpmReadHeader, and rpmReadPackageFile.

unsigned int* keyids`[static]`

| Definition at line 42 of file package.c. Referenced by rpmtsStashKeyid.

unsigned int nextkeyid = 0`[static]`

| Definition at line 40 of file package.c. Referenced by rpmtsStashKeyid.

unsigned int nkeyids = 0`[static]`

| Definition at line 38 of file package.c. Referenced by rpmtsStashKeyid.

unsigned int nkeyids_max = 256`[static]`

| Definition at line 36 of file package.c. Referenced by rpmtsStashKeyid.

int typeAlign[16]`[static]`

| Initial value:
      {
        1,
        1,
        1,
        2,
        4,
        8,
        1,
        1,
        1,
        1,
        0,
        0,
        0,
        0,
        0,
        0
    }
Alignment needs (and sizeof scalars types) for internal rpm data types. Definition at line 53 of file package.c.