rpm 5.2.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

Data Structures | Macros | Functions | Variables
pkgio.c File Reference
`#include "system.h"`
`#include <netinet/in.h>`
`#include <rpmiotypes.h>`
`#include <rpmio_internal.h>`
`#include <rpmcb.h>`
`#include <rpmbc.h>`
`#include <rpmmacro.h>`
`#include <rpmku.h>`
`#include "header_internal.h"`
`#include <rpmdb.h>`
`#include <pkgio.h>`
`#include "rpmts.h"`
`#include <rpmxar.h>`
`#include "signature.h"`
`#include "debug.h"`
Include dependency graph for pkgio.c:

Go to the source code of this file.

## Data Structures
struct | rpmlead
| The lead data structure. More...

## Macros
#define | _RPMIOB_INTERNAL
#define | _RPMTAG_INTERNAL
#define | _RPMTS_INTERNAL
#define | timedRead (ufdio->read)

## Functions
ssize_t | timedRead (FD_t fd, void *bufptr, size_t length)
static rpmRC | rpmWriteHeader (FD_t fd, Header h, const char **msg)
| Write (with unload) header to file handle. More...
rpmop | rpmtsOp (rpmts ts, rpmtsOpX opx)
| Retrieve operation timestamp from a transaction set. More...
pgpDigParams | rpmtsPubkey (const rpmts ts)
| Return OpenPGP pubkey constants. More...
rpmdb | rpmtsGetRdb (rpmts ts)
| Get transaction set database handle. More...
rpmRC | rpmtsFindPubkey (rpmts ts, void *_dig)
| Retrieve pubkey from rpm database. More...
pgpDig | rpmtsDig (rpmts ts)
| Get OpenPGP packet parameters, i.e. More...
void | rpmtsCleanDig (rpmts ts)
| Free signature verification data. More...
static rpmRC | wrLead (FD_t fd, const void *ptr, const char **msg)
| Write lead to file handle. More...
static rpmRC | rdLead (FD_t fd, void *ptr, const char **msg)
| Read lead from file handle. More...
static rpmRC | wrSignature (FD_t fd, void *ptr, const char **msg)
| Write signature header. More...
static rpmRC | printSize (FD_t fd, size_t siglen, size_t pad, size_t datalen)
| Print package size. More...
static rpmRC | rdSignature (FD_t fd, void *ptr, const char **msg)
| Read (and verify header+payload size) signature header. More...
rpmRC | headerCheck (pgpDig dig, const void *uh, size_t uc, const char **msg)
| Check header consistency, performing headerGet() the hard way. More...
static size_t | szHeader (const void *ptr)
| Return size of Header. More...
static rpmRC | ckHeader (FD_t fd, const void *ptr, const char **msg)
| Check metadata header. More...
static rpmRC | rpmReadHeader (FD_t fd, Header *hdrp, const char **msg)
| Return checked and loaded header. More...
static rpmRC | rdHeader (FD_t fd, void *ptr, const char **msg)
| Read metadata header. More...
static rpmRC | wrHeader (FD_t fd, void *ptr, const char **msg)
| Write metadata header. More...
size_t | rpmpkgSizeof (const char *fn, const void *ptr)
| Return size of item in bytes. More...
rpmRC | rpmpkgCheck (const char *fn, FD_t fd, const void *ptr, const char **msg)
| Verify item integrity. More...
rpmRC | rpmpkgRead (const char *fn, FD_t fd, void *ptr, const char **msg)
| Read item from file descriptor. More...
rpmRC | rpmpkgWrite (const char *fn, FD_t fd, void *ptr, const char **msg)
| Write item onto file descriptor. More...

## Variables
int | _pkgio_debug = 0
static int | _print_pkts = 0
static unsigned char | lead_magic []

## Macro Definition Documentation

#define _RPMIOB_INTERNAL

Definition at line 14 of file pkgio.c.

#define _RPMTAG_INTERNAL

Definition at line 22 of file pkgio.c.

#define _RPMTS_INTERNAL

Definition at line 28 of file pkgio.c.

#define timedRead (ufdio->read)

Definition at line 58 of file pkgio.c.

Referenced by rdLead(), rdSignature(), and rpmReadHeader().

## Function Documentation

static rpmRC ckHeader | ( | FD_t | fd,
|  | const void * | ptr,
|  | const char ** | msg
| ) |  |
| static

Check metadata header.

Parameters

  fd | file handle
  ptr | metadata header

Return values

  *msg | failure msg

Returns
  rpmRC return code

Definition at line 1250 of file pkgio.c.

References headerFree(), headerLoad(), RPMRC_FAIL, and RPMRC_OK.

Referenced by rpmpkgCheck().

rpmRC headerCheck | ( | pgpDig | dig,
|  | const void * | uh,
|  | size_t | uc,
|  | const char ** | msg
| ) |  |

Check header consistency, performing headerGet() the hard way.

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

  dig | signature parameters container
  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 921 of file pkgio.c.

References _, _free(), _pkgio_debug, _print_pkts, alloca(), entryInfo_s::count, headerGetMagic(), headerVerifyInfo(), indexEntry_s::info, entryInfo_s::offset, pgpDigVSFlags, pgpGetSig(), PGPHASHALGO_SHA1, pgpPrtPkts(), pgpSetSig(), pgpStatsAccumulator(), REGION_TAG_COUNT, RPM_BIN_TYPE, RPM_STRING_TYPE, RPMDIGEST_NONE, rpmDigestInit(), rpmDigestUpdate(), rpmIsDebug, rpmlog(), RPMLOG_ERR, RPMRC_FAIL, RPMRC_NOTFOUND, RPMRC_OK, rpmswEnter(), rpmswExit(), RPMTAG_DSAHEADER, RPMTAG_HEADERIMMUTABLE, RPMTAG_RSAHEADER, RPMTAG_SHA1HEADER, rpmVerifySignature(), RPMVSF_NODSAHEADER, RPMVSF_NORSAHEADER, RPMVSF_NOSHA1HEADER, snprintf(), entryInfo_s::tag, entryInfo_s::type, vsflags, xmalloc(), and xstrdup().

Referenced by miFreeHeader(), rpmdbAdd(), rpmmiNext(), rpmReadHeader(), and rpmts_HdrCheck().

static rpmRC printSize | ( | FD_t | fd,
|  | size_t | siglen,
|  | size_t | pad,
|  | size_t | datalen
| ) |  |
| inline static

Print package size.

Parameters

  fd | package file handle
  siglen | signature header size
  pad | signature padding
  datalen | length of header+payload

Returns
  rpmRC return code

Definition at line 615 of file pkgio.c.

References D_, Fileno(), Fstat(), rpmlog(), RPMLOG_DEBUG, rpmpkgSizeof(), RPMRC_FAIL, and RPMRC_OK.

Referenced by rdSignature().

static rpmRC rdHeader | ( | FD_t | fd,
|  | void * | ptr,
|  | const char ** | msg
| ) |  |
| static

Read metadata header.

Parameters

  fd | file handle

Return values

  *ptr | metadata header (or NULL)
  *msg | failure msg

Returns
  rpmRC return code

Definition at line 1467 of file pkgio.c.

References rpmReadHeader().

Referenced by rpmpkgRead().

static rpmRC rdLead | ( | FD_t | fd,
|  | void * | ptr,
|  | const char ** | msg
| ) |  |
| static

Read lead from file handle.

Parameters

  fd | file handle

Return values

  *ptr | package lead
  *msg | failure msg

Returns
  rpmRC return code

Definition at line 451 of file pkgio.c.

References _, _free(), _pkgio_debug, rpmlead::archnum, errno, fdGetOPath(), fdGetXAR(), fdSetXAR(), Ferror(), Fstrerror(), lead_magic, rpmlead::magic, rpmlead::major, rpmlead::osnum, RPMRC_FAIL, RPMRC_NOTFOUND, RPMRC_OK, rpmxarFree(), rpmxarNew(), rpmxarNext(), rpmxarPull(), rpmxarSwapBuf(), rpmlead::signature_type, snprintf(), timedRead, rpmlead::type, xcalloc(), and xstrdup().

Referenced by rpmpkgRead().

static rpmRC rdSignature | ( | FD_t | fd,
|  | void * | ptr,
|  | const char ** | msg
| ) |  |
| static

Read (and verify header+payload size) signature header.

Parameters

  fd | file handle

Return values

  *ptr | signature header (or NULL)
  *msg | failure msg

Returns
  rpmRC return code

< Is 1st header region mmap'd?

< Is 1st header region rdonly?

< Is 1st header region allocated?

< Signature header?

Definition at line 655 of file pkgio.c.

References _, _free(), _pkgio_debug, alloca(), entryInfo_s::count, errno, fdGetXAR(), FDSTAT_READ, headerToken_s::flags, HEADERFLAG_ALLOCATED, HEADERFLAG_MAPPED, HEADERFLAG_RDONLY, HEADERFLAG_SIGNATURE, headerFree(), headerGet(), headerGetMagic(), headerLink(), headerLoad(), headerSetEndOff(), headerSetStartOff(), headerSizeof(), headerVerifyInfo(), indexEntry_s::info, entryInfo_s::offset, _HE_s::p, printSize(), rpmDataType_u::ptr, REGION_TAG_COUNT, RPM_BIN_TYPE, RPMRC_FAIL, RPMRC_NOTFOUND, RPMRC_OK, RPMSIGTAG_SIZE, RPMTAG_HEADERIMAGE, RPMTAG_HEADERSIGNATURES, rpmxarNext(), rpmxarPull(), snprintf(), _FD_s::stats, entryInfo_s::tag, _HE_s::tag, timedRead, entryInfo_s::type, rpmDataType_u::ui32p, xmalloc(), and xstrdup().

Referenced by rpmpkgRead().

rpmRC rpmpkgCheck | ( | const char * | fn,
|  | FD_t | fd,
|  | const void * | ptr,
|  | const char ** | msg
| ) |  |

Verify item integrity.

Parameters

  fn | item name
  fd | file handle
  ptr | item buffer

Return values

  *msg | item check failure message

Returns
  RPMRC_OK on success

Definition at line 1513 of file pkgio.c.

References ckHeader(), and RPMRC_FAIL.

rpmRC rpmpkgRead | ( | const char * | fn,
|  | FD_t | fd,
|  | void * | ptr,
|  | const char ** | msg
| ) |  |

Read item from file descriptor.

Parameters

  fn | item name
  fd | file handle

Return values

  *ptr | item buffer
  *msg | item check failure message

Returns
  RPMRC_OK on success

Definition at line 1525 of file pkgio.c.

References rdHeader(), rdLead(), rdSignature(), and RPMRC_FAIL.

Referenced by makeHDRSignature(), readFile(), rpmgiNext(), rpmReadHeaders(), rpmReadPackageFile(), rpmReSign(), rpmSingleHeaderFromFD(), rpmVerifySignatures(), and writeRPM().

size_t rpmpkgSizeof | ( | const char * | fn,
|  | const void * | ptr
| ) |  |

Return size of item in bytes.

Parameters

  fn | item name
  ptr | item buffer

Returns
  size of item in bytes.

Definition at line 1497 of file pkgio.c.

References szHeader().

Referenced by printSize(), rpmpsmStage(), and writeRPM().

rpmRC rpmpkgWrite | ( | const char * | fn,
|  | FD_t | fd,
|  | void * | ptr,
|  | const char ** | msg
| ) |  |

Write item onto file descriptor.

Parameters

  fn | item name
  fd | file handle
  ptr | item buffer

Return values

  *msg | item check failure message

Returns
  RPMRC_OK on success

Definition at line 1543 of file pkgio.c.

References RPMRC_FAIL, wrHeader(), wrLead(), and wrSignature().

Referenced by makeHDRSignature(), rpmpsmStage(), rpmReSign(), rpmWriteHeaders(), and writeRPM().

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

Return checked and loaded header.

Parameters

  fd | file handle

Return values

  hdrp | address of header (or NULL)
  *msg | verification error message (or NULL)

Returns
  RPMRC_OK on success

< Is 1st header region mmap'd?

< Is 1st header region rdonly?

< Is 1st header region allocated?

Definition at line 1274 of file pkgio.c.

References _, _free(), _pkgio_debug, errno, fdGetDig(), fdGetOPath(), fdGetXAR(), fdSetDig(), FDSTAT_READ, headerToken_s::flags, Fstat(), hdrchkData, hdrchkTags, headerCheck(), HEADERFLAG_ALLOCATED, HEADERFLAG_MAPPED, HEADERFLAG_RDONLY, headerFree(), headerGetMagic(), headerGetStatbuf(), headerLink(), headerLoad(), headerSetEndOff(), headerSetOrigin(), headerSetStartOff(), pgpDigFree(), pgpDigLink(), pgpDigNew(), Realpath(), RPMRC_FAIL, RPMRC_NOTFOUND, RPMRC_OK, rpmxarNext(), rpmxarPull(), snprintf(), _FD_s::stats, timedRead, urlPath(), xmalloc(), and xstrdup().

Referenced by rdHeader().

static size_t szHeader | ( | const void * | ptr | ) |
| static

Return size of Header.

Parameters

  ptr | metadata header (at least 32 bytes)

Returns
  size of header

Definition at line 1233 of file pkgio.c.

Referenced by rpmpkgSizeof().

ssize_t timedRead | ( | FD_t | fd,
|  | void * | bufptr,
|  | size_t | length
| ) |  |

static rpmRC wrHeader | ( | FD_t | fd,
|  | void * | ptr,
|  | const char ** | msg
| ) |  |
| static

Write metadata header.

Parameters

  fd | file handle
  ptr | metadata header

Return values

  *msg | failure msg

Returns
  rpmRC return code

Definition at line 1485 of file pkgio.c.

References rpmWriteHeader().

Referenced by rpmpkgWrite().

static rpmRC wrLead | ( | FD_t | fd,
|  | const void * | ptr,
|  | const char ** | msg
| ) |  |
| static

Write lead to file handle.

Parameters

  fd | file handle
  ptr | package lead
  *msg | name to include in lead (or NULL)

Returns
  RPMRC_OK on success, RPMRC_FAIL on error

Definition at line 413 of file pkgio.c.

References _pkgio_debug, rpmlead::archnum, Fwrite(), lead_magic, rpmlead::magic, rpmlead::major, rpmlead::name, rpmlead::osnum, RPMRC_FAIL, RPMRC_OK, rpmlead::signature_type, and rpmlead::type.

Referenced by rpmpkgWrite().

static rpmRC wrSignature | ( | FD_t | fd,
|  | void * | ptr,
|  | const char ** | msg
| ) |  |
| static

Write signature header.

Parameters

  fd | file handle
  ptr | signature header

Return values

  *msg | failure msg

Returns
  rpmRC return code

Definition at line 578 of file pkgio.c.

References _pkgio_debug, D_, Fwrite(), headerSizeof(), rpmlog(), RPMLOG_DEBUG, RPMRC_FAIL, RPMRC_OK, and rpmWriteHeader().

Referenced by rpmpkgWrite().

## Variable Documentation

int _pkgio_debug = 0

Definition at line 47 of file pkgio.c.

Referenced by headerCheck(), rdLead(), rdSignature(), rpmReadHeader(), rpmWriteHeader(), wrLead(), and wrSignature().

int _print_pkts = 0
| static

Definition at line 50 of file pkgio.c.

unsigned char lead_magic[]
| static

Initial value:
= {
0xed, 0xab, 0xee, 0xdb, 0x00, 0x00, 0x00, 0x00
}

Definition at line 399 of file pkgio.c.

Referenced by rdLead(), and wrLead().