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;
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);
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);
336 (fileName ? fileName :
"<stdin>"),
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);
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';
649 const char * sigtarget =
NULL;
650 const char * rpmio_flags =
NULL;
651 const char * payload_format =
NULL;
653 const char * msg =
NULL;
679 payload_format =
rpmExpand(
"%{?_source_payload_format}",
NULL);
682 payload_format =
rpmExpand(
"%{?_binary_payload_format}",
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;
812 {
const char item[] =
"Header";
817 (msg && *msg ? msg :
"write failed\n"));
846 rc =
cpio_doio(fd, h, csa, payload_format, rpmio_flags);
860 (
void) fflush(stdout);
866 addsig = (passPhrase && passPhrase[0]);
872 else if (dig && dig->sig && dig->siglen > 0) {
875 he->
p.
ptr = (
void *) dig->sig;
878 dig->sig =
_free(dig->sig);
894 he->
p.
ui32p = &payloadSize;
910 static const size_t align = 1024;
911 size_t nb = align - 96 - 16 - 16;
928 fd =
Fopen(fn,
"w.fdio");
937 {
const char item[] =
"Lead";
945 const char *
N, *V, *R;
947 sprintf(buf,
"%s-%s-%s", N, V, R);
964 {
const char item[] =
"Signature";
970 (msg && *msg ? msg :
"write failed\n"));
979 ifd =
Fopen(sigtarget,
"r.fdio");
988 {
const char item[] =
"Header";
995 (msg && *msg ? msg :
"read failed\n"));
1012 (msg && *msg ? msg :
"write failed\n"));
1021 while ((nbr =
Fread(buf,
sizeof(buf[0]),
sizeof(buf), ifd)) > 0) {
1029 if (nbr != nbw ||
Ferror(fd)) {
1040 rpmio_flags =
_free(rpmio_flags);
1041 payload_format =
_free(payload_format);
1046 if (sigh !=
NULL && pkgidp !=
NULL) {
1050 *pkgidp = he->
p.
ui8p;
1065 sigtarget =
_free(sigtarget);
1143 xx = system(pkgcheck);
1144 if (WEXITSTATUS(xx) == -1 || WEXITSTATUS(xx) == 127) {
1146 if (fail)
return 127;
1148 if (WEXITSTATUS(xx) != 0) {
1160 CSA_t csa = &csabuf;
1161 const char *errorString;
1205 char *binRpm, *binDir;
1208 binFormat =
_free(binFormat);
1209 if (binRpm ==
NULL) {
1213 "filename for package %s: %s\n"), he->
p.
str, errorString);
1219 if ((binDir = strchr(binRpm,
'/')) !=
NULL) {
1224 if (
Stat(dn, &st) < 0) {
1232 dn, strerror(
errno));
1238 binRpm =
_free(binRpm);
1241 memset(csa, 0,
sizeof(*csa));
1242 csa->cpioArchiveSize = 0;
1245 csa->cpioFdIn =
fdNew(
"init (packageBinaries)");
1256 csa->fi->te =
_free(csa->fi->te);
1260 csa->cpioFdIn =
fdFree(csa->cpioFdIn,
"init (packageBinaries)");
1265 char *pkgcheck =
rpmExpand(
"%{?_build_pkgcheck} ", fn,
NULL);
1266 if (pkgcheck[0] !=
' ') {
1269 pkgcheck =
_free(pkgcheck);
1280 if (pkglist !=
NULL) {
1281 char *pkgcheck_set =
NULL;
1285 for (i = 0; i <
argvCount(pkglist); i++)
1286 pkglen += strlen(pkglist[i]) + 1;
1288 for (i = 0; i <
argvCount(pkglist); i++) {
1291 strcat(pkgs, pkglist[i]);
1294 pkgcheck_set =
rpmExpand(
"%{?_build_pkgcheck_set} ", pkgs,
NULL);
1295 if (pkgcheck_set[0] !=
' ') {
1298 pkgcheck_set =
_free(pkgcheck_set);
1312 CSA_t csa = &csabuf;
1315 #if defined(RPM_VENDOR_OPENPKG) || defined(RPM_VENDOR_FEDORA) || defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_ARK)
1322 #if defined(RPM_VENDOR_OPENPKG) || defined(RPM_VENDOR_FEDORA) || defined(RPM_VENDOR_MANDRIVA) || defined(RPM_VENDOR_ARK)
1341 if (ix < RPMSCRIPT_MAX) {
1356 {
const char **
av =
NULL;
1375 const char *pkgcheck =
rpmExpand(
"%{?_build_pkgcheck_srpm} ", fn,
NULL);
1379 memset(csa, 0,
sizeof(*csa));
1380 csa->cpioArchiveSize = 0;
1383 csa->cpioFdIn =
fdNew(
"init (packageSources)");
1391 if (csa->fi ==
NULL) {
1392 srcrpmdir =
_free(srcrpmdir);
1394 pkgcheck =
_free(pkgcheck);
1404 if (rc ==
RPMRC_OK && pkgcheck[0] !=
' ') {
1409 csa->fi->te =
_free(csa->fi->te);
1413 csa->cpioFdIn =
fdFree(csa->cpioFdIn,
"init (packageSources)");
1416 srcrpmdir =
_free(srcrpmdir);
1418 pkgcheck =
_free(pkgcheck);
static void fdInitDigest(FD_t fd, pgpHashAlgo hashalgo, int _flags)
Attach digest to fd.
char * iosmStrerror(int rc)
Return formatted error message on payload handling failure.
rpmlog(RPMLOG_ERR,"%s\n", buf)
static int addFileToTag(Spec spec, const char *file, Header h, rpmTag tag)
const char * sourceRpmName
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.
char * rpmGetPath(const char *path,...)
Return (malloc'ed) expanded, canonicalized, file path.
Spec freeSpec(Spec spec)
Destroy a spec file control structure.
static int addFileToArrayTag(Spec spec, const char *file, Header h, rpmTag tag)
Structure(s) used for file info tag sets.
static char *size_t nb
fgets(3) analogue that reads \ continuations.
struct rpmts_s * rpmts
The RPM Transaction Set.
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
const char * buildHost(void)
Return build hostname.
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.
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.
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.
FD_t fdNew(const char *msg)
static int rpmlibMarkers(Header h)
rpmRC writeRPM(Header *hdrp, unsigned char **pkgidp, const char *fileName, CSA_t csa, char *passPhrase, const char **cookie, void *_dig)
Write rpm package to file.
unsigned char rpmuint8_t
Private int typedefs to avoid C99 portability issues.
sprintf(t," (%u)",(unsigned) dig->nbytes)
rpmRC packageBinaries(Spec spec)
Generate binary package(s).
enum rpmRC_e rpmRC
RPM return codes.
memset(_r, 0, sizeof(*_r))
rpmuint32_t rpmlibVendor(void)
rpmts rpmtsCreate(void)
Create an empty transaction set.
const char * Fstrerror(FD_t fd)
strerror(3) clone.
void * xcalloc(size_t nmemb, size_t size)
assert(key->size==sizeof(hdrNum))
Package newPackage(Spec spec)
Create and initialize package control structure.
int rpmAddSignature(Header sigh, const char *file, rpmSigTag sigTag, const char *passPhrase)
Generate signature(s) from a header+payload file, save in signature header.
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.
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
DIGEST_CTX rpmDigestDup(DIGEST_CTX octx)
Duplicate a digest context.
ARGV_t argvFree(ARGV_t argv)
Destroy an argv array.
rpmuint32_t sstates[RPMSCRIPT_MAX]
static rpmiob addFileToTagAux(Spec spec, const char *file, rpmiob iob)
rpmuint32_t * getBuildTime(void)
Return build time stamp.
pgpDigParams pgpGetSignature(pgpDig dig)
Return OpenPGP signature parameters.
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.
Spec newSpec(void)
Create and initialize Spec structure.
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.
rpmuint32_t cpioArchiveSize
char * rpmExpand(const char *arg,...)
Return (malloc'ed) concatenated macro expansion(s).
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
char * pgpArmorWrap(rpmuint8_t atype, const unsigned char *s, size_t ns)
Wrap a OpenPGP packets in ascii armor for transport.
rpmuint32_t rpmlibVersion(void)
int Fclose(FD_t fd)
fclose(3) clone.
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)
Routines to read and write packages.
static const char *char c
Return text between pl and matching pr characters.
rpmuint32_t rpmlibTimestamp(void)
int Ferror(FD_t fd)
ferror(3) clone.
char * rpmiobStr(rpmiob iob)
Return I/O buffer (as string).
return strcmp(ame->name, bme->name)
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.
Methods to handle package elements.
char * stpcpy(char *dest, const char *src)
rpmRC packageSources(Spec spec)
Generate source package.
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.
struct pgpDigParams_s * pgpDigParams
static void * fdGetFp(FD_t fd)
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.
int expandMacros(void *spec, MacroContext mc, char *sbuf, size_t slen)
Expand macro into buffer.
int Fileno(FD_t fd)
fileno(3) clone.
static void
Print copy of spec file, filling in Group/Description/Summary from specspo.
static void fdFiniDigest(FD_t fd, pgpHashAlgo hashalgo, void *datap, size_t *lenp, int asAscii)
char * buf
Parse (and execute) macro undefinition.
The structure used to store values for a package.
int
Save source and expand field into target.
struct rpmfi_s * rpmfi
File info tag sets from a header, so that a header can be discarded early.
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)
int rpmlibNeedsFeature(Header h, const char *feature, const char *featureEVR)
Add rpmlib feature dependency.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
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.
const char * preTransFile
unsigned char * sourcePkgId
const char * sanityCheckFile
int Unlink(const char *path)
unlink(2) clone.