Data Structures | Defines | Functions | Variables

# rpmdb/pkgio.c File Reference

`#include "system.h"`
`#include <netinet/in.h>`
`#include <rpmio_internal.h>`
`#include <rpmbc.h>`
`#include <rpmcb.h>`
`#include <rpmmacro.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...
## Defines
#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.
rpmop | rpmtsOp (rpmts ts, rpmtsOpX opx)
| Retrieve operation timestamp from a transaction set.
pgpDigParams | rpmtsPubkey (const rpmts ts)
| Return OpenPGP pubkey constants.
rpmdb | rpmtsGetRdb (rpmts ts)
| Get transaction set database handle.
rpmRC | rpmtsFindPubkey (rpmts ts, void *_dig)
| Retrieve pubkey from rpm database.
pgpDig | rpmtsDig (rpmts ts)
| Get OpenPGP packet parameters, i.e.
void | rpmtsCleanDig (rpmts ts)
| Free signature verification data.
static rpmRC | wrLead (FD_t fd, const void *ptr, const char **msg)
| Write lead to file handle.
static rpmRC | rdLead (FD_t fd, void *ptr, const char **msg)
| Read lead from file handle.
static rpmRC | wrSignature (FD_t fd, void *ptr, const char **msg)
| Write signature header.
static rpmRC | printSize (FD_t fd, size_t siglen, size_t pad, size_t datalen)
| Print package size.
static rpmRC | rdSignature (FD_t fd, void *ptr, const char **msg)
| Read (and verify header+payload size) signature header.
rpmRC | headerCheck (pgpDig dig, const void *uh, size_t uc, const char **msg)
| Check header consistency, performing headerGet() the hard way.
static size_t | szHeader (const void *ptr)
| Return size of Header.
static rpmRC | ckHeader (FD_t fd, const void *ptr, const char **msg)
| Check metadata header.
static rpmRC | rpmReadHeader (FD_t fd, Header *hdrp, const char **msg)
| Return checked and loaded header.
static rpmRC | rdHeader (FD_t fd, void *ptr, const char **msg)
| Read metadata header.
static rpmRC | wrHeader (FD_t fd, void *ptr, const char **msg)
| Write metadata header.
size_t | rpmpkgSizeof (const char *fn, const void *ptr)
| Return size of item in bytes.
rpmRC | rpmpkgCheck (const char *fn, FD_t fd, const void *ptr, const char **msg)
| Verify item integrity.
rpmRC | rpmpkgRead (const char *fn, FD_t fd, void *ptr, const char **msg)
| Read item from file descriptor.
rpmRC | rpmpkgWrite (const char *fn, FD_t fd, void *ptr, const char **msg)
| Write item onto file descriptor.
## Variables
int | _pkgio_debug = 0
static int | _print_pkts = 0
static unsigned char | lead_magic []

## Detailed Description

Definition in file pkgio.c.

## Define Documentation

#define _RPMTAG_INTERNAL

Definition at line 23 of file pkgio.c.

#define _RPMTS_INTERNAL

Definition at line 29 of file pkgio.c.

#define timedRead (ufdio->read)

Definition at line 57 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 1199 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:

  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 880 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_HEADERIMMUTABLE, rpmVerifySignature(), RPMVSF_NODSAHEADER, RPMVSF_NORSAHEADER, RPMVSF_NOSHA1HEADER, snprintf(), entryInfo_s::tag, entryInfo_s::type, xmalloc(), and xstrdup().

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

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

Print package size.

Todo:
  rpmio: use fdSize rather than fstat(2) to get file 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 618 of file pkgio.c.

References D_, Fileno(), 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 1357 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 455 of file pkgio.c.

References _, _free(), _pkgio_debug, errno, fdGetOPath(), fdGetXAR(), fdSetXAR(), Ferror(), Fstrerror(), lead_magic, RPMRC_FAIL, RPMRC_NOTFOUND, RPMRC_OK, snprintf(), timedRead, 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 allocated?

< Signature header?

Definition at line 654 of file pkgio.c.

References _, _free(), _pkgio_debug, alloca(), block(), entryInfo_s::count, fdGetXAR(), headerToken_s::flags, HEADERFLAG_ALLOCATED, HEADERFLAG_SIGNATURE, headerFree(), headerGet(), headerGetMagic(), headerLink(), headerLoad(), 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, snprintf(), _HE_s::tag, entryInfo_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 1402 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 1414 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 1386 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 1432 of file pkgio.c.

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

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

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

Return checked and loaded header.

Parameters:

  dig | signature parameters container
  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 allocated?

Definition at line 1223 of file pkgio.c.

References _, _free(), _pkgio_debug, block(), fdGetDig(), fdGetOPath(), fdGetXAR(), fdSetDig(), headerToken_s::flags, hdrchkData, hdrchkTags, headerCheck(), HEADERFLAG_ALLOCATED, headerFree(), headerGetMagic(), headerLink(), headerLoad(), headerSetOrigin(), pgpDigFree(), pgpDigLink(), pgpDigNew(), RPMRC_FAIL, RPMRC_NOTFOUND, RPMRC_OK, snprintf(), timedRead, 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 1182 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 1375 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 417 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 581 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 46 of file pkgio.c.

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

int _print_pkts = 0`[static]`

Definition at line 49 of file pkgio.c.

unsigned char lead_magic[]`[static]`

Initial value:

     {
        0xed, 0xab, 0xee, 0xdb, 0x00, 0x00, 0x00, 0x00
    }

Definition at line 403 of file pkgio.c.

Referenced by rdLead(), and wrLead().