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'))
84 failedFile =
_free(failedFile);
100 while((nb =
Fread(buf,
sizeof(buf[0]),
sizeof(buf), csa->
cpioFdIn)) > 0) {
101 if (
Fwrite(buf,
sizeof(buf[0]), nb, fdo) != nb) {
124 const char * fn = buf;
128 fn =
rpmGetPath(
"%{_builddir}/%{?buildsubdir:%{buildsubdir}/}", file, NULL);
130 fd =
Fopen(fn,
"r.fdio");
131 if (fn != buf) fn =
_free(fn);
132 if (fd == NULL ||
Ferror(fd)) {
139 while (fgets(buf, (
int)
sizeof(buf), f)) {
224 _(
"Could not open PreIn file: %s\n"), pkg->
preInFile);
231 _(
"Could not open PreUn file: %s\n"), pkg->
preUnFile);
245 _(
"Could not open PostIn file: %s\n"), pkg->
postInFile);
252 _(
"Could not open PostUn file: %s\n"), pkg->
postUnFile);
267 _(
"Could not open VerifyScript file: %s\n"), pkg->
verifyFile);
299 _(
"Could not open Trigger script file: %s\n"),
305 static const char *bull =
"";
320 int readRPM(
const char *
fileName,
Spec *specp,
void * l,
323 const char * msg =
"";
330 :
fdDup(STDIN_FILENO);
332 if (fdi == NULL ||
Ferror(fdi)) {
336 if (fdi) (void)
Fclose(fdi);
340 {
const char item[] =
"Lead";
345 msg =
xstrdup(
"item size is zero");
389 if (sigs) *sigs = NULL;
404 (fileName ? fileName :
"<stdin>"));
424 #define RPMPKGVERSION_MIN 30004 425 #define RPMPKGVERSION_MAX 40003 427 static int rpmpkg_version = -1;
429 static int rpmLeadVersion(
void)
436 if (rpmpkg_version < 0) {
438 if (rpmpkg_version < RPMPKGVERSION_MIN)
439 rpmpkg_version = RPMPKGVERSION_MIN;
440 if (rpmpkg_version > RPMPKGVERSION_MAX)
441 rpmpkg_version = RPMPKGVERSION_MAX;
444 rpmlead_version = rpmpkg_version / 10000;
446 if (rpmlead_version < 3 || rpmlead_version > 4)
448 return rpmlead_version;
455 const char *N, *V, *R;
456 #ifdef RPM_VENDOR_MANDRIVA 465 const char ** provides = NULL;
466 const char ** providesEVR = NULL;
479 nb = 21 + strlen(V) + 1 + strlen(R) + 1;
480 #ifdef RPM_VENDOR_MANDRIVA 484 nb += (gotD ? strlen(D) + 1 : 0);
493 sprintf(p,
"%d:", E);
497 #ifdef RPM_VENDOR_MANDRIVA 514 provides = he->
p.
argv;
515 providesCount = he->
c;
526 providesEVR = he->
p.
argv;
528 for (i = 0; i < providesCount; i++) {
530 static const char * vdummy =
"";
535 he->
p.
argv = &vdummy;
545 he->
p.
ui32p = (
void *) &fdummy;
560 provideFlags = he->
p.
ui32p;
563 if (provides && providesEVR && provideFlags)
564 for (i = 0; i < providesCount; i++) {
565 if (!(provides[i] && providesEVR[i]))
568 !strcmp(N, provides[i]) && !strcmp(pEVR, providesEVR[i])))
577 provides =
_free(provides);
578 providesEVR =
_free(providesEVR);
579 provideFlags =
_free(provideFlags);
625 if (c >=
'0' && c <=
'9')
626 return (
unsigned char) (c -
'0');
627 if (c >=
'A' && c <=
'F')
628 return (
unsigned char)((int)(c -
'A') + 10);
629 if (c >=
'a' && c <=
'f')
630 return (
unsigned char)((int)(c -
'a') + 10);
631 return (
unsigned char)
'\0';
635 CSA_t csa,
char * passPhrase,
const char ** cookie,
void * _dig)
643 const char * sigtarget;
644 const char * rpmio_flags = NULL;
645 const char * payload_format = NULL;
646 const char * SHA1 = NULL;
647 const char * msg = NULL;
652 int addsig = (passPhrase && passPhrase[0]);
673 payload_format =
rpmExpand(
"%{?_source_payload_format}", NULL);
674 rpmio_flags =
rpmExpand(
"%{?_source_payload}", NULL);
676 payload_format =
rpmExpand(
"%{?_binary_payload_format}", NULL);
677 rpmio_flags =
rpmExpand(
"%{?_binary_payload}", NULL);
680 if (!(payload_format && *payload_format)) {
681 payload_format =
_free(payload_format);
682 payload_format =
xstrdup(
"cpio");
684 if (!(rpmio_flags && *rpmio_flags)) {
685 rpmio_flags =
_free(rpmio_flags);
686 rpmio_flags =
xstrdup(
"w9.gzdio");
688 s = strchr(rpmio_flags,
'.');
691 if (payload_format) {
692 if (!strcmp(payload_format,
"tar")
693 || !strcmp(payload_format,
"ustar")) {
698 #if defined(SUPPORT_AR_PAYLOADS) 699 if (!strcmp(payload_format,
"ar")) {
708 he->
p.
str = payload_format;
714 if (s[1] ==
'g' && s[2] ==
'z') {
721 }
else if (s[1] ==
'b' && s[2] ==
'z') {
728 }
else if (s[1] ==
'l' && s[2] ==
'z') {
736 }
else if (s[1] ==
'x' && s[2] ==
'z') {
745 strcpy(buf, rpmio_flags);
746 buf[s - rpmio_flags] =
'\0';
768 if (!addsig && dig && dig->pub && dig->publen > 0) {
774 he->
p.
argv = (
const char **) &s;
806 {
const char item[] =
"Header";
811 (msg && *msg ? msg :
"write failed\n"));
840 rc =
cpio_doio(fd, h, csa, payload_format, rpmio_flags);
846 rpmio_flags =
_free(rpmio_flags);
847 payload_format =
_free(payload_format);
856 (void) fflush(stdout);
867 else if (dig && dig->sig && dig->siglen > 0) {
870 he->
p.
ptr = (
void *) dig->sig;
873 dig->sig =
_free(dig->sig);
889 he->
p.
ui32p = &payloadSize;
905 static const size_t align = 1024;
906 size_t nb = align - 96 - 16 - 16;
912 b = memset(
alloca(nb), 0, nb);
919 assert(sigh != NULL);
923 fd =
Fopen(fn,
"w.fdio");
924 if (fd == NULL ||
Ferror(fd)) {
932 {
const char item[] =
"Lead";
939 void * l = memset(
alloca(nl), 0, nl);
940 const char *N, *V, *R;
942 sprintf(buf,
"%s-%s-%s", N, V, R);
959 {
const char item[] =
"Signature";
965 (msg && *msg ? msg :
"write failed\n"));
974 ifd =
Fopen(sigtarget,
"r.fdio");
975 if (ifd == NULL ||
Ferror(ifd)) {
983 {
const char item[] =
"Header";
990 (msg && *msg ? msg :
"read failed\n"));
1007 (msg && *msg ? msg :
"write failed\n"));
1016 while ((nbr =
Fread(buf,
sizeof(buf[0]),
sizeof(buf), ifd)) > 0) {
1023 nbw = (int)
Fwrite(buf,
sizeof(buf[0]), nbr, fd);
1024 if (nbr != nbw ||
Ferror(fd)) {
1039 if (sigh != NULL && pkgidp != NULL) {
1043 *pkgidp = he->
p.
ui8p;
1057 (void)
Unlink(sigtarget);
1058 sigtarget =
_free(sigtarget);
1136 xx = system(pkgcheck);
1137 if (WEXITSTATUS(xx) == -1 || WEXITSTATUS(xx) == 127) {
1139 if (fail)
return 127;
1141 if (WEXITSTATUS(xx) != 0) {
1153 CSA_t csa = &csabuf;
1154 const char *errorString;
1160 for (pkg = spec->
packages; pkg != NULL; pkg = pkg->
next) {
1197 {
const char *binFormat =
rpmGetPath(
"%{_rpmfilename}", NULL);
1198 char *binRpm, *binDir;
1201 binFormat =
_free(binFormat);
1202 if (binRpm == NULL) {
1206 "filename for package %s: %s\n"), he->
p.
str, errorString);
1211 fn =
rpmGetPath(
"%{_rpmdir}/", binRpm, NULL);
1212 if ((binDir = strchr(binRpm,
'/')) != NULL) {
1216 dn =
rpmGetPath(
"%{_rpmdir}/", binRpm, NULL);
1217 if (
Stat(dn, &st) < 0) {
1225 dn, strerror(
errno));
1231 binRpm =
_free(binRpm);
1234 memset(csa, 0,
sizeof(*csa));
1235 csa->cpioArchiveSize = 0;
1238 csa->cpioFdIn =
fdNew(
"init (packageBinaries)");
1243 assert(csa->fi != NULL);
1249 csa->fi->te =
_free(csa->fi->te);
1253 csa->cpioFdIn =
fdFree(csa->cpioFdIn,
"init (packageBinaries)");
1258 char *pkgcheck =
rpmExpand(
"%{?_build_pkgcheck} ", fn, NULL);
1259 if (pkgcheck[0] !=
' ') {
1262 pkgcheck =
_free(pkgcheck);
1273 if (pkglist != NULL) {
1274 char *pkgcheck_set = NULL;
1278 for (i = 0; i <
argvCount(pkglist); i++)
1279 pkglen += strlen(pkglist[i]) + 1;
1281 for (i = 0; i <
argvCount(pkglist); i++) {
1284 strcat(pkgs, pkglist[i]);
1287 pkgcheck_set =
rpmExpand(
"%{?_build_pkgcheck_set} ", pkgs, NULL);
1288 if (pkgcheck_set[0] !=
' ') {
1291 pkgcheck_set =
_free(pkgcheck_set);
1305 CSA_t csa = &csabuf;
1308 #if defined(RPM_VENDOR_OPENPKG) || defined(RPM_VENDOR_FEDORA) || defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_ARK) 1315 #if defined(RPM_VENDOR_OPENPKG) || defined(RPM_VENDOR_FEDORA) || defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_ARK) 1334 if (ix >= 0 && ix < RPMSCRIPT_MAX) {
1349 {
const char ** av = NULL;
1351 if (av != NULL && av[0] != NULL) {
1366 {
const char *srcrpmdir =
rpmGetPath(
"%{_srcrpmdir}/", NULL);
1368 const char *pkgcheck =
rpmExpand(
"%{?_build_pkgcheck_srpm} ", fn, NULL);
1372 memset(csa, 0,
sizeof(*csa));
1373 csa->cpioArchiveSize = 0;
1376 csa->cpioFdIn =
fdNew(
"init (packageSources)");
1382 assert(csa->fi != NULL);
1384 if (csa->fi == NULL)
1393 if (rc ==
RPMRC_OK && pkgcheck[0] !=
' ') {
1398 csa->fi->te =
_free(csa->fi->te);
1402 csa->cpioFdIn =
fdFree(csa->cpioFdIn,
"init (packageSources)");
1405 srcrpmdir =
_free(srcrpmdir);
1407 pkgcheck =
_free(pkgcheck);
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 * 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.
int rpmbcExportSignature(pgpDig dig, DIGEST_CTX ctx)
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
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.