18 #define _RPMFI_INTERNAL
19 #define _RPMEVR_INTERNAL
20 #define _RPMTAG_INTERNAL
41 const char * payload_format,
const char * fmodeMacro)
48 const char *failedFile = NULL;
53 {
const char *fmode =
rpmExpand(fmodeMacro, NULL);
54 if (!(fmode && fmode[0] ==
'w')) {
86 failedFile =
_free(failedFile);
102 while((nb =
Fread(buf,
sizeof(buf[0]),
sizeof(buf), csa->
cpioFdIn)) > 0) {
103 if (
Fwrite(buf,
sizeof(buf[0]), nb, fdo) != nb) {
126 const char * fn = buf;
130 fn =
rpmGetPath(
"%{_builddir}/%{?buildsubdir:%{buildsubdir}/}", file, NULL);
132 fd =
Fopen(fn,
"r.fdio");
133 if (fn != buf) fn =
_free(fn);
134 if (fd == NULL ||
Ferror(fd)) {
141 while (fgets(buf, (
int)
sizeof(buf), f)) {
226 _(
"Could not open PreIn file: %s\n"), pkg->
preInFile);
233 _(
"Could not open PreUn file: %s\n"), pkg->
preUnFile);
247 _(
"Could not open PostIn file: %s\n"), pkg->
postInFile);
254 _(
"Could not open PostUn file: %s\n"), pkg->
postUnFile);
269 _(
"Could not open VerifyScript file: %s\n"), pkg->
verifyFile);
301 _(
"Could not open Trigger script file: %s\n"),
307 static const char *bull =
"";
322 int readRPM(
const char *
fileName,
Spec *specp,
void * l,
325 const char * msg =
"";
330 fdi = (fileName != NULL)
331 ?
Fopen(fileName,
"r.fdio")
332 :
fdDup(STDIN_FILENO);
334 if (fdi == NULL ||
Ferror(fdi)) {
336 (fileName ? fileName :
"<stdin>"),
338 if (fdi) (void)
Fclose(fdi);
342 {
const char item[] =
"Lead";
347 msg =
xstrdup(
"item size is zero");
357 (fileName ? fileName :
"<stdin>"), msg);
367 (fileName ? fileName :
"<stdin>"),
Fstrerror(fdi));
391 if (sigs) *sigs = NULL;
401 (fileName ? fileName :
"<stdin>"));
406 (fileName ? fileName :
"<stdin>"));
426 #define RPMPKGVERSION_MIN 30004
427 #define RPMPKGVERSION_MAX 40003
429 static int rpmpkg_version = -1;
431 static int rpmLeadVersion(
void)
438 if (rpmpkg_version < 0) {
440 if (rpmpkg_version < RPMPKGVERSION_MIN)
441 rpmpkg_version = RPMPKGVERSION_MIN;
442 if (rpmpkg_version > RPMPKGVERSION_MAX)
443 rpmpkg_version = RPMPKGVERSION_MAX;
446 rpmlead_version = rpmpkg_version / 10000;
448 if (rpmlead_version < 3 || rpmlead_version > 4)
450 return rpmlead_version;
457 const char *N, *V, *R;
458 #ifdef RPM_VENDOR_MANDRIVA
467 const char ** provides = NULL;
468 const char ** providesEVR = NULL;
478 if (!(N && V && R)) {
485 nb = 21 + strlen(V) + 1 + strlen(R) + 1;
486 #ifdef RPM_VENDOR_MANDRIVA
490 nb += (gotD ? strlen(D) + 1 : 0);
499 sprintf(p,
"%d:", E);
503 #ifdef RPM_VENDOR_MANDRIVA
520 provides = he->
p.
argv;
521 providesCount = he->
c;
532 providesEVR = he->
p.
argv;
534 for (i = 0; i < providesCount; i++) {
536 static const char * vdummy =
"";
541 he->
p.
argv = &vdummy;
551 he->
p.
ui32p = (
void *) &fdummy;
566 provideFlags = he->
p.
ui32p;
569 if (provides && providesEVR && provideFlags)
570 for (i = 0; i < providesCount; i++) {
571 if (!(provides[i] && providesEVR[i]))
574 !strcmp(N, provides[i]) && !strcmp(pEVR, providesEVR[i])))
583 provides =
_free(provides);
584 providesEVR =
_free(providesEVR);
585 provideFlags =
_free(provideFlags);
631 if (c >=
'0' && c <=
'9')
632 return (
unsigned char) (c -
'0');
633 if (c >=
'A' && c <=
'F')
634 return (
unsigned char)((int)(c -
'A') + 10);
635 if (c >=
'a' && c <=
'f')
636 return (
unsigned char)((int)(c -
'a') + 10);
637 return (
unsigned char)
'\0';
641 CSA_t csa,
char * passPhrase,
const char ** cookie,
void * _dig)
649 const char * sigtarget = NULL;
650 const char * rpmio_flags = NULL;
651 const char * payload_format = NULL;
652 const char * SHA1 = NULL;
653 const char * msg = NULL;
679 payload_format =
rpmExpand(
"%{?_source_payload_format}", NULL);
680 rpmio_flags =
rpmExpand(
"%{?_source_payload}", NULL);
682 payload_format =
rpmExpand(
"%{?_binary_payload_format}", NULL);
683 rpmio_flags =
rpmExpand(
"%{?_binary_payload}", NULL);
686 if (!(payload_format && *payload_format)) {
687 payload_format =
_free(payload_format);
688 payload_format =
xstrdup(
"cpio");
690 if (!(rpmio_flags && *rpmio_flags)) {
691 rpmio_flags =
_free(rpmio_flags);
692 rpmio_flags =
xstrdup(
"w9.gzdio");
694 s = strchr(rpmio_flags,
'.');
697 if (payload_format) {
698 if (!strcmp(payload_format,
"tar")
699 || !strcmp(payload_format,
"ustar")) {
704 #if defined(SUPPORT_AR_PAYLOADS)
705 if (!strcmp(payload_format,
"ar")) {
714 he->
p.
str = payload_format;
720 if (s[1] ==
'g' && s[2] ==
'z') {
727 }
else if (s[1] ==
'b' && s[2] ==
'z') {
734 }
else if (s[1] ==
'l' && s[2] ==
'z') {
742 }
else if (s[1] ==
'x' && s[2] ==
'z') {
751 strncpy(buf, rpmio_flags,
sizeof(buf)-1);
752 buf[s - rpmio_flags] =
'\0';
774 if (!addsig && dig && dig->pub && dig->publen > 0) {
780 he->
p.
argv = (
const char **) &s;
819 {
const char item[] =
"Header";
824 (msg && *msg ? msg :
"write failed\n"));
851 rc =
cpio_doio(fd, h, csa, payload_format, rpmio_flags);
865 (void) fflush(stdout);
871 addsig = (passPhrase && passPhrase[0]);
877 else if (dig && dig->sig && dig->siglen > 0) {
878 switch (pubp->pubkey_algo) {
893 he->
p.
ptr = (
void *) dig->sig;
896 dig->sig =
_free(dig->sig);
912 he->
p.
ui32p = &payloadSize;
928 static const size_t align = 1024;
929 size_t nb = align - 96 - 16 - 16;
935 b = memset(
alloca(nb), 0, nb);
942 assert(sigh != NULL);
946 fd =
Fopen(fn,
"w.fdio");
947 if (fd == NULL ||
Ferror(fd)) {
955 {
const char item[] =
"Lead";
962 void * l = memset(
alloca(nl), 0, nl);
963 const char *N, *V, *R;
965 sprintf(buf,
"%s-%s-%s", N, V, R);
982 {
const char item[] =
"Signature";
988 (msg && *msg ? msg :
"write failed\n"));
997 ifd =
Fopen(sigtarget,
"r.fdio");
998 if (ifd == NULL ||
Ferror(ifd)) {
1006 {
const char item[] =
"Header";
1013 (msg && *msg ? msg :
"read failed\n"));
1030 (msg && *msg ? msg :
"write failed\n"));
1039 while ((nbr =
Fread(buf,
sizeof(buf[0]),
sizeof(buf), ifd)) > 0) {
1046 nbw = (int)
Fwrite(buf,
sizeof(buf[0]), nbr, fd);
1047 if (nbr != nbw ||
Ferror(fd)) {
1058 rpmio_flags =
_free(rpmio_flags);
1059 payload_format =
_free(payload_format);
1064 if (sigh != NULL && pkgidp != NULL) {
1068 *pkgidp = he->
p.
ui8p;
1082 (void)
Unlink(sigtarget);
1083 sigtarget =
_free(sigtarget);
1161 xx = system(pkgcheck);
1162 if (WEXITSTATUS(xx) == -1 || WEXITSTATUS(xx) == 127) {
1164 if (fail)
return 127;
1166 if (WEXITSTATUS(xx) != 0) {
1178 CSA_t csa = &csabuf;
1179 const char *errorString;
1185 for (pkg = spec->
packages; pkg != NULL; pkg = pkg->
next) {
1222 {
const char *binFormat =
rpmGetPath(
"%{_rpmfilename}", NULL);
1223 char *binRpm, *binDir;
1226 binFormat =
_free(binFormat);
1227 if (binRpm == NULL) {
1231 "filename for package %s: %s\n"), he->
p.
str, errorString);
1236 fn =
rpmGetPath(
"%{_rpmdir}/", binRpm, NULL);
1237 if ((binDir = strchr(binRpm,
'/')) != NULL) {
1241 dn =
rpmGetPath(
"%{_rpmdir}/", binRpm, NULL);
1242 if (
Stat(dn, &st) < 0) {
1250 dn, strerror(
errno));
1256 binRpm =
_free(binRpm);
1259 memset(csa, 0,
sizeof(*csa));
1260 csa->cpioArchiveSize = 0;
1263 csa->cpioFdIn =
fdNew(
"init (packageBinaries)");
1268 assert(csa->fi != NULL);
1274 csa->fi->te =
_free(csa->fi->te);
1278 csa->cpioFdIn =
fdFree(csa->cpioFdIn,
"init (packageBinaries)");
1283 char *pkgcheck =
rpmExpand(
"%{?_build_pkgcheck} ", fn, NULL);
1284 if (pkgcheck[0] !=
' ') {
1287 pkgcheck =
_free(pkgcheck);
1298 if (pkglist != NULL) {
1299 char *pkgcheck_set = NULL;
1303 for (i = 0; i <
argvCount(pkglist); i++)
1304 pkglen += strlen(pkglist[i]) + 1;
1306 for (i = 0; i <
argvCount(pkglist); i++) {
1309 strcat(pkgs, pkglist[i]);
1312 pkgcheck_set =
rpmExpand(
"%{?_build_pkgcheck_set} ", pkgs, NULL);
1313 if (pkgcheck_set[0] !=
' ') {
1316 pkgcheck_set =
_free(pkgcheck_set);
1330 CSA_t csa = &csabuf;
1333 #if defined(RPM_VENDOR_OPENPKG) || defined(RPM_VENDOR_FEDORA) || defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_ARK)
1340 #if defined(RPM_VENDOR_OPENPKG) || defined(RPM_VENDOR_FEDORA) || defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_ARK)
1359 if (ix < RPMSCRIPT_MAX) {
1374 {
const char ** av = NULL;
1376 if (av != NULL && av[0] != NULL) {
1391 {
const char *srcrpmdir =
rpmGetPath(
"%{_srcrpmdir}/", NULL);
1393 const char *pkgcheck =
rpmExpand(
"%{?_build_pkgcheck_srpm} ", fn, NULL);
1397 memset(csa, 0,
sizeof(*csa));
1398 csa->cpioArchiveSize = 0;
1401 csa->cpioFdIn =
fdNew(
"init (packageSources)");
1407 assert(csa->fi != NULL);
1409 if (csa->fi == NULL) {
1410 srcrpmdir =
_free(srcrpmdir);
1412 pkgcheck =
_free(pkgcheck);
1422 if (rc ==
RPMRC_OK && pkgcheck[0] !=
' ') {
1427 csa->fi->te =
_free(csa->fi->te);
1431 csa->cpioFdIn =
fdFree(csa->cpioFdIn,
"init (packageSources)");
1434 srcrpmdir =
_free(srcrpmdir);
1436 pkgcheck =
_free(pkgcheck);
pgpDigParams pgpGetPubkey(pgpDig dig)
Return OpenPGP pubkey parameters.
int rpmAddSignature(Header sigh, const char *file, rpmSigTag sigTag, const char *passPhrase)
Generate signature(s) from a header+payload file, save in signature header.
const char * buildHost(void)
Return build hostname.
static int addFileToTag(Spec spec, const char *file, Header h, rpmTag tag)
const char bson_timestamp_t * ts
const char * sourceRpmName
void headerMergeLegacySigs(Header h, const Header sigh)
Translate and merge legacy signature tags into header.
static void * fdGetFp(FD_t fd)
Package newPackage(Spec spec)
Create and initialize package control structure.
rpmRC rpmpkgWrite(const char *fn, FD_t fd, void *ptr, const char **msg)
Write item onto file descriptor.
size_t Fwrite(const void *buf, size_t size, size_t nmemb, FD_t fd)
fwrite(3) clone.
char * xstrdup(const char *str)
FD_t Fopen(const char *path, const char *_fmode)
fopen(3) clone.
struct pgpDigParams_s * pgpDigParams
char * rpmGetPath(const char *path,...)
Return (malloc'ed) expanded, canonicalized, file path.
static int addFileToArrayTag(Spec spec, const char *file, Header h, rpmTag tag)
Structure(s) used for file info tag sets.
int rpmioMkpath(const char *path, mode_t mode, uid_t uid, gid_t gid)
Insure that directories in path exist, creating as needed.
static unsigned char nibble(char c)
Convert hex to binary nibble.
int Stat(const char *path, struct stat *st)
stat(2) clone.
char * pgpArmorWrap(rpmuint8_t atype, const unsigned char *s, size_t ns)
Wrap a OpenPGP packets in ascii armor for transport.
int Fflush(FD_t fd)
fflush(3) clone.
rpmfi rpmfiFree(rpmfi fi)
Destroy a file info set.
rpmiob rpmiobFree(rpmiob iob)
Destroy a I/O buffer instance.
static void rpmlog(int code, const char *fmt,...)
rpmiob rpmiobAppend(rpmiob iob, const char *s, size_t nl)
Append string to I/O buffer.
int Fseek(FD_t fd, _libio_off_t offset, int whence)
fseek(3) clone.
static void fdInitDigest(FD_t fd, pgpHashAlgo hashalgo, int _flags)
Attach digest to fd.
FD_t fdNew(const char *msg)
static int rpmlibMarkers(Header h)
char * headerSprintf(Header h, const char *fmt, headerTagTableEntry tags, headerSprintfExtension exts, errmsg_t *errmsg)
Return formatted output string from header tags.
rpmuint32_t rpmlibVendor(void)
const char * Fstrerror(FD_t fd)
strerror(3) clone.
void * xcalloc(size_t nmemb, size_t size)
rpmRC packageSources(Spec spec)
Generate source package.
int rpmGetMacroEntries(MacroContext mc, void *_mire, int used, const char ***avp)
Return macro entries as string array.
FD_t fdFree(FD_t fd, const char *msg)
size_t rpmpkgSizeof(const char *fn, const void *ptr)
Return size of item in bytes.
unsigned char rpmuint8_t
Private int typedefs to avoid C99 portability issues.
struct rpmfi_s * rpmfi
File info tag sets from a header, so that a header can be discarded early.
int rpmTempFile(const char *prefix, const char **fnptr, void *fdptr)
Return file handle for a temporaray file.
int argvCount(const ARGV_t argv)
Return no.
enum evrFlags_e rpmsenseFlags
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
pgpDigParams pgpGetSignature(pgpDig dig)
Return OpenPGP signature parameters.
rpmuint32_t * getBuildTime(void)
Return build time stamp.
rpmuint32_t sstates[RPMSCRIPT_MAX]
static rpmiob addFileToTagAux(Spec spec, const char *file, rpmiob iob)
rpmRC rpmReadPackageFile(rpmts ts, FD_t fd, const char *fn, Header *hdrp)
Return package header from file handle, verifying digests/signatures.
struct TriggerFileEntry * triggerFiles
rpmuint32_t smetrics[RPMSCRIPT_MAX]
static rpmRC checkPackages(const char *pkgcheck)
The FD_t File Handle data structure.
static void fdFiniDigest(FD_t fd, pgpHashAlgo hashalgo, void *datap, size_t *lenp, int asAscii)
int argvAdd(ARGV_t *argvp, ARGstr_t val)
Add a string to an argv array.
Generate and verify rpm package signatures.
The structure used to store values parsed from a spec file.
Header headerFree(Header h)
Dereference a header instance.
rpmuint32_t cpioArchiveSize
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
Spec freeSpec(Spec spec)
Destroy a spec file control structure.
static rpmRC cpio_copy(FD_t fdo, CSA_t csa)
size_t Fread(void *buf, size_t size, size_t nmemb, FD_t fd)
fread(3) clone.
struct TriggerFileEntry * next
rpmuint32_t rpmlibVersion(void)
int Fclose(FD_t fd)
fclose(3) clone.
char * iosmStrerror(int rc)
Return formatted error message on payload handling failure.
rpmiob rpmiobNew(size_t len)
Create an I/O buffer.
int fsmTeardown(void *_fsm)
Clean file state machine.
Header headerLink(Header h)
Reference a header instance.
Routines to read and write packages.
Spec newSpec(void)
Create and initialize Spec structure.
rpmuint32_t rpmlibTimestamp(void)
enum rpmRC_e rpmRC
RPM return codes.
int Ferror(FD_t fd)
ferror(3) clone.
char * rpmiobStr(rpmiob iob)
Return I/O buffer (as string).
This is the only module users of librpmbuild should need to include.
rpmfi rpmfiLink(rpmfi fi, const char *msg)
Reference a file info set instance.
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
rpmRC packageBinaries(Spec spec)
Generate binary package(s).
rpmts rpmtsCreate(void)
Create an empty transaction set.
Methods to handle package elements.
char * stpcpy(char *dest, const char *src)
struct rpmts_s * rpmts
The RPM Transaction Set.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
int headerNEVRA(Header h, const char **np, const char **ep, const char **vp, const char **rp, const char **ap)
Return name, epoch, version, release, arch strings from header.
FD_t Fdopen(FD_t ofd, const char *fmode)
File state machine to handle a payload within an rpm package.
rpmRC processScriptFiles(Spec spec, Package pkg)
Append files (if any) to scriptlet tags.
int fsmSetup(void *_fsm, iosmFileStage goal, const char *afmt, const void *_ts, const void *_fi, FD_t cfd, unsigned int *archiveSize, const char **failedFile)
Load external data into file state machine.
rpmRC writeRPM(Header *hdrp, unsigned char **pkgidp, const char *fn, CSA_t csa, char *passPhrase, const char **cookie, void *_dig)
Write rpm package to file.
int expandMacros(void *spec, MacroContext mc, char *sbuf, size_t slen)
Expand macro into buffer.
int Fileno(FD_t fd)
fileno(3) clone.
The structure used to store values for a package.
rpmRC rpmpkgRead(const char *fn, FD_t fd, void *ptr, const char **msg)
Read item from file descriptor.
static rpmRC cpio_doio(FD_t fdo, Header h, CSA_t csa, const char *payload_format, const char *fmodeMacro)
void providePackageNVR(Header h)
Retrofit an explicit Provides: N = E:V-R dependency into package headers.
const char * postTransFile
int rpmExpandNumeric(const char *arg)
Return macro expansion as a numeric value.
DIGEST_CTX rpmDigestDup(DIGEST_CTX octx)
Duplicate a digest context.
const char * preTransFile
unsigned char * sourcePkgId
int pgpExportSignature(pgpDig dig, DIGEST_CTX ctx)
const char * sanityCheckFile
int rpmlibNeedsFeature(Header h, const char *feature, const char *featureEVR)
Add rpmlib feature dependency.
int Unlink(const char *path)
unlink(2) clone.