lib/package.c File Reference

#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.
#define hdrchkType(_type)   ((_type) < RPM_MIN_TYPE || (_type) > RPM_MAX_TYPE)
 Sanity check on type values.
#define hdrchkData(_nbytes)   ((_nbytes) & 0xff000000)
 Sanity check on data size and/or offset and/or count.
#define hdrchkAlign(_type, _off)   ((_off) & (typeAlign[_type]-1))
 Sanity check on data alignment for data type.
#define hdrchkRange(_dl, _off)   ((_off) < 0 || (_off) > (_dl))
 Sanity check on range of data offset.
#define _chk(_mask)   (sigtag == 0 && !(vsflags & (_mask)))

Functions

void headerMergeLegacySigs (Header h, const Header sigh)
 Translate and merge legacy signature tags into header.
Header headerRegenSigHeader (const Header h, int noArchiveSize)
 Regenerate signature header.
static int rpmtsStashKeyid (rpmts ts)
 Remember current key id.
int headerVerifyInfo (int il, int dl, const void *pev, void *iv, int negate)
 Perform simple sanity and range checks on header tag(s).
rpmRC headerCheck (rpmts ts, const void *uh, size_t uc, const char **msg)
 Check header consistency, performing headerGetEntry() the hard way.
rpmRC rpmReadHeader (rpmts ts, FD_t fd, Header *hdrp, const char **msg)
 Return checked and loaded header.
rpmRC rpmReadPackageFile (rpmts ts, FD_t fd, const char *fn, Header *hdrp)
 Return package header from file handle, verifying digests/signatures.
rpmRC headerCheckPayloadFormat (Header h)
 Check for supported payload format in header.

Variables

static int _print_pkts = 0
static unsigned int nkeyids_max = 256
static unsigned int nkeyids = 0
static unsigned int nextkeyid = 0
static unsigned int * keyids
static unsigned char header_magic [8]
static int typeAlign [16]
 Alignment needs (and sizeof scalars types) for internal rpm data types.


Detailed Description

Definition in file package.c.


Define Documentation

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

Referenced by rpmReadPackageFile().

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

Definition at line 22 of file package.c.

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

Sanity check on data alignment for data type.

Definition at line 91 of file package.c.

Referenced by headerVerifyInfo(), and regionSwab().

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

Sanity check on data size and/or offset and/or count.

This check imposes a limit of 16 MB, more than enough.

Definition at line 86 of file package.c.

Referenced by doHeaderUnload(), headerMergeLegacySigs(), headerVerifyInfo(), regionSwab(), and rpmReadHeader().

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

Sanity check on range of data offset.

Definition at line 96 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 75 of file package.c.

Referenced by doHeaderUnload(), and rpmReadHeader().

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

Sanity check on type values.

Definition at line 80 of file package.c.

Referenced by headerMergeLegacySigs(), headerVerifyInfo(), and regionSwab().


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 325 of file package.c.

References _, alloca(), headerVerifyInfo(), REGION_TAG_COUNT, RPM_BIN_TYPE, RPM_STRING_TYPE, RPMRC_FAIL, RPMRC_NOTFOUND, RPMTAG_HEADERIMMUTABLE, RPMTAG_SHA1HEADER, rpmtsVSFlags(), RPMVSF_NOSHA1HEADER, snprintf(), and vsflags.

Referenced by rpmpsmStage(), rpmReadHeader(), rpmts_HdrCheck(), rpmtsInitIterator(), and rpmtsRebuildDB().

rpmRC headerCheckPayloadFormat ( Header  h  ) 

Check for supported payload format in header.

Parameters:
h header to check
Returns:
RPMRC_OK if supported, RPMRC_FAIL otherwise

Definition at line 1075 of file package.c.

References _, _free(), headerGetEntry(), hGetNEVRA(), RPMMESS_ERROR, rpmMessage, RPMRC_FAIL, RPMRC_OK, and RPMTAG_PAYLOADFORMAT.

Referenced by rpmtsAddInstallElement().

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.

Referenced by headerCheck(), and rpmReadSignature().

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 (or NULL)
Returns:
RPMRC_OK on success

Definition at line 650 of file package.c.

References _, _free(), block(), headerToken_s::flags, hdrchkData, hdrchkTags, header_magic, headerCheck(), HEADERFLAG_ALLOCATED, headerFree(), headerLink(), headerLoad(), RPMRC_FAIL, RPMRC_OK, snprintf(), timedRead, xmalloc(), and xstrdup().

Referenced by rpmReadPackageFile().

rpmRC 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:
RPMRC_OK on success

Todo:
Implement disable/enable/warn/error/anal policy.

Definition at line 748 of file package.c.

References _, _chk, _free(), _print_pkts, alloca(), entryInfo_s::count, rpmop_s::count, _FD_s::digests, fdInitDigest(), FDSTAT_READ, Fileno(), Fread(), Fstrerror(), pgpDigParams_s::hash_algo, _FDDIGEST_s::hashalgo, _FDDIGEST_s::hashctx, pgpDig_s::hdrmd5ctx, pgpDig_s::hdrsha1ctx, header_magic, headerFree(), headerFreeData(), headerGetEntry(), headerIsEntry(), headerLink(), headerMergeLegacySigs(), legacyRetrofit(), pgpDig_s::md5ctx, pgpDig_s::nbytes, _FD_s::ndigests, PGPHASHALGO_MD5, PGPHASHALGO_SHA1, PGPHASHALGO_SHA256, PGPHASHALGO_SHA384, PGPHASHALGO_SHA512, pgpPrtPkts(), readLead(), RPMDIGEST_NONE, rpmDigestInit(), rpmDigestUpdate(), RPMERR_FREAD, RPMERR_NEWPACKAGE, RPMERR_SIGGEN, rpmError, rpmFreeSignature(), rpmIsDebug, RPMMESS_DEBUG, RPMMESS_ERROR, RPMMESS_WARNING, rpmMessage, RPMRC_FAIL, RPMRC_NOKEY, RPMRC_NOTFOUND, RPMRC_NOTTRUSTED, RPMRC_OK, rpmReadHeader(), rpmReadSignature(), RPMSIGTAG_DSA, RPMSIGTAG_GPG, RPMSIGTAG_MD5, RPMSIGTAG_PGP, RPMSIGTAG_PGP5, RPMSIGTAG_RSA, RPMSIGTAG_SHA1, rpmswEnter(), rpmswExit(), RPMTAG_HEADERIMMUTABLE, RPMTS_OP_DIGEST, RPMTS_OP_SIGNATURE, rpmtsCleanDig(), rpmtsDig(), rpmtsOp(), rpmtsSetSig(), rpmtsStashKeyid(), rpmtsVSFlags(), rpmVerifySignature(), RPMVSF_NEEDPAYLOAD, RPMVSF_NODSA, RPMVSF_NOMD5, RPMVSF_NORSA, RPMVSF_NOSHA1HEADER, pgpDig_s::sha1ctx, pgpDig_s::signature, _FD_s::stats, pgpDigParams_s::version, and vsflags.

Referenced by ftsStashLatest(), IDTXglob(), main(), readRPM(), rpmgiReadHeader(), rpmGraph(), rpmInstall(), rpmInstallSourcePackage(), rpmts_HdrFromFdno(), rpmtsRun(), and rpmtsSolve().

static int rpmtsStashKeyid ( rpmts  ts  )  [static]

Remember current key id.

Parameters:
ts transaction set
Returns:
0 if new keyid, otherwise 1

Definition at line 242 of file package.c.

References keyids, nextkeyid, nkeyids, nkeyids_max, pgpGrab(), rpmtsDig(), rpmtsSig(), rpmtsSignature(), pgpDigParams_s::signid, and xrealloc().

Referenced by rpmReadPackageFile().


Variable Documentation

int _print_pkts = 0 [static]

Definition at line 32 of file package.c.

Referenced by rpmReadPackageFile(), and rpmVerifySignatures().

unsigned char header_magic[8] [static]

Initial value:

 {
        0x8e, 0xad, 0xe8, 0x01, 0x00, 0x00, 0x00, 0x00
}

Definition at line 44 of file package.c.

Referenced by makeHDRSignature(), rpmReadHeader(), rpmReadPackageFile(), and rpmReadSignature().

unsigned int* keyids [static]

Definition at line 41 of file package.c.

Referenced by rpmtsStashKeyid().

unsigned int nextkeyid = 0 [static]

Definition at line 39 of file package.c.

Referenced by rpmtsStashKeyid().

unsigned int nkeyids = 0 [static]

Definition at line 37 of file package.c.

Referenced by rpmtsStashKeyid().

unsigned int nkeyids_max = 256 [static]

Definition at line 35 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 52 of file package.c.


Generated on Fri Oct 12 08:44:55 2007 for rpm by  doxygen 1.5.2