rpm2cpio.c
Go to the documentation of this file.
/* rpmarchive: spit out the main archive portion of a package */
#include "system.h"
const char *__progname;
#include <rpm/rpmlib.h> /* rpmReadPackageFile .. */
#include <rpm/rpmtag.h>
#include <rpm/rpmio.h>
#include <rpm/rpmpgp.h>
#include <rpm/rpmts.h>
#include "debug.h"
int main(int argc, char *argv[])
{
FD_t fdi, fdo;
Header h;
char * rpmio_flags = NULL;
int rc;
off_t payload_size;
FD_t gzdi;
setprogname(argv[0]); /* Retrofit glibc __progname */
rpmReadConfigFiles(NULL, NULL);
if (argc == 1)
fdi = fdDup(STDIN_FILENO);
else {
if (rstreq(argv[1], "-h") || rstreq(argv[1], "--help")) {
fprintf(stderr, "Usage: rpm2cpio file.rpm\n");
exit(EXIT_FAILURE);
}
fdi = Fopen(argv[1], "r.ufdio");
}
if (Ferror(fdi)) {
fprintf(stderr, "%s: %s: %s\n", argv[0],
(argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi));
exit(EXIT_FAILURE);
}
fdo = fdDup(STDOUT_FILENO);
{ rpmts ts = rpmtsCreate();
rpmVSFlags vsflags = 0;
/* XXX retain the ageless behavior of rpm2cpio */
vsflags |= _RPMVSF_NODIGESTS;
vsflags |= _RPMVSF_NOSIGNATURES;
vsflags |= RPMVSF_NOHDRCHK;
(void) rpmtsSetVSFlags(ts, vsflags);
rc = rpmReadPackageFile(ts, fdi, "rpm2cpio", &h);
ts = rpmtsFree(ts);
}
switch (rc) {
case RPMRC_OK:
case RPMRC_NOKEY:
case RPMRC_NOTTRUSTED:
break;
case RPMRC_NOTFOUND:
fprintf(stderr, _("argument is not an RPM package\n"));
exit(EXIT_FAILURE);
break;
case RPMRC_FAIL:
default:
fprintf(stderr, _("error reading header from package\n"));
exit(EXIT_FAILURE);
break;
}
/* Retrieve payload size and compression type. */
{ const char *compr = headerGetString(h, RPMTAG_PAYLOADCOMPRESSOR);
rpmio_flags = rstrscat(NULL, "r.", compr ? compr : "gzip", NULL);
payload_size = headerGetNumber(h, RPMTAG_LONGARCHIVESIZE);
}
gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */
free(rpmio_flags);
if (gzdi == NULL) {
fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi));
exit(EXIT_FAILURE);
}
rc = (ufdCopy(gzdi, fdo) == payload_size) ? EXIT_SUCCESS : EXIT_FAILURE;
Fclose(fdo);
Fclose(gzdi); /* XXX gzdi == fdi */
return rc;
}
setprogname
#define setprogname(pn)
Definition: system.h:99
ufdCopy
off_t ufdCopy(FD_t sfd, FD_t tfd)
FD_t
struct _FD_s * FD_t
RPM IO file descriptor type.
Definition: rpmtypes.h:98
debug.h
rstrscat
char * rstrscat(char **dest, const char *arg,...) RPM_GNUC_NULL_TERMINATED
Concatenate multiple strings with dynamically (re)allocated memory.
Fstrerror
const char * Fstrerror(FD_t fd)
strerror(3) clone.
rpmReadPackageFile
rpmRC rpmReadPackageFile(rpmts ts, FD_t fd, const char *fn, Header *hdrp)
Return package header from file handle, verifying digests/signatures.
RPMRC_NOKEY
Definition: rpmtypes.h:108
_
#define _(Text)
Definition: system.h:112
Fdopen
FD_t Fdopen(FD_t ofd, const char *fmode)
RPMRC_FAIL
Definition: rpmtypes.h:106
rpmReadConfigFiles
int rpmReadConfigFiles(const char *file, const char *target)
Read macro configuration file(s) for a target.
fdDup
FD_t fdDup(int fdno)
Ferror
int Ferror(FD_t fd)
ferror(3) clone.
main
int main(int argc, char *argv[])
Definition: rpm2cpio.c:15
rstreq
static int rstreq(const char *s1, const char *s2)
Test for string equality.
Definition: rpmstring.h:113
headerGetNumber
uint64_t headerGetNumber(Header h, rpmTagVal tag)
Fclose
int Fclose(FD_t fd)
fclose(3) clone.
rpmVSFlags
rpmFlags rpmVSFlags
Definition: rpmts.h:110
Fopen
FD_t Fopen(const char *path, const char *fmode)
fopen(3) clone.
headerGetString
const char * headerGetString(Header h, rpmTagVal tag)
Return a simple string tag from header.
RPMRC_NOTTRUSTED
Definition: rpmtypes.h:107
_RPMVSF_NOSIGNATURES
#define _RPMVSF_NOSIGNATURES
Definition: rpmts.h:118
rpmtsFree
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
rpmtsSetVSFlags
rpmVSFlags rpmtsSetVSFlags(rpmts ts, rpmVSFlags vsflags)
Set verify signatures flag(s).
rpmts
struct rpmts_s * rpmts
The main types involved in transaction manipulation.
Definition: rpmtypes.h:63
system.h
Some misc low-level API.
RPMRC_NOTFOUND
Definition: rpmtypes.h:105
RPMVSF_NOHDRCHK
Definition: rpmts.h:95
__progname
#define __progname
Definition: system.h:98
_RPMVSF_NODIGESTS
#define _RPMVSF_NODIGESTS
Definition: rpmts.h:112
RPMRC_OK
Definition: rpmtypes.h:104
rpmtsCreate
rpmts rpmtsCreate(void)
Create an empty transaction set.
RPMTAG_LONGARCHIVESIZE
Definition: rpmtag.h:65
RPMTAG_PAYLOADCOMPRESSOR
Definition: rpmtag.h:195
Header
struct headerToken_s * Header
RPM header and data retrieval types.
Definition: rpmtypes.h:24