Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate rpm format detection and terminology #3461

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ static void genCpioListAndHeader(FileList fl, rpmSpec spec, Package pkg, int isS
rpmstrPoolStr(fl->pool, flp->gname));

/* Use 64bit filesizes always on v6, on older only if required. */
if (pkg->rpmver >= 6 || fl->largeFiles) {
if (pkg->rpmformat >= 6 || fl->largeFiles) {
rpm_loff_t rsize64 = (rpm_loff_t)flp->fl_size;
headerPutUint64(h, RPMTAG_LONGFILESIZES, &rsize64, 1);
(void) rpmlibNeedsFeature(pkg, "LargeFiles", "4.12.0-1");
Expand Down Expand Up @@ -1281,7 +1281,7 @@ static void genCpioListAndHeader(FileList fl, rpmSpec spec, Package pkg, int isS
pkg->dpaths[npaths] = NULL;

/* Use 64bit sizes always on v6, on older only if required. */
if (pkg->rpmver < 6 && totalFileSize < UINT32_MAX) {
if (pkg->rpmformat < 6 && totalFileSize < UINT32_MAX) {
rpm_off_t totalsize = totalFileSize;
headerPutUint32(h, RPMTAG_SIZE, &totalsize, 1);
} else {
Expand Down
16 changes: 8 additions & 8 deletions build/pack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,16 +476,16 @@ static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp,
headerPutString(pkg->header, RPMTAG_COOKIE, *cookie);
}

if (pkg->rpmver >= 6)
headerPutUint32(pkg->header, RPMTAG_RPMFORMAT, &(pkg->rpmver), 1);
if (pkg->rpmformat >= 6)
headerPutUint32(pkg->header, RPMTAG_RPMFORMAT, &(pkg->rpmformat), 1);

/* Create a dummy payload digests to get the header size right */
pld = (char *)nullDigest(pld_algo, 1);
headerPutUint32(pkg->header, RPMTAG_PAYLOADDIGESTALGO, &pld_algo, 1);
headerPutString(pkg->header, RPMTAG_PAYLOADDIGEST, pld);
headerPutString(pkg->header, RPMTAG_PAYLOADDIGESTALT, pld);
pld = _free(pld);
if (pkg->rpmver >= 6) {
if (pkg->rpmformat >= 6) {
headerPutUint64(pkg->header, RPMTAG_PAYLOADSIZE, &payloadSize, 1);
headerPutUint64(pkg->header, RPMTAG_PAYLOADSIZEALT, &archiveSize, 1);
}
Expand All @@ -512,12 +512,12 @@ static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp,
sigStart = Ftell(fd);

/* Generate and write a placeholder signature header */
if (pkg->rpmver < 6) {
if (pkg->rpmformat < 6) {
SHA1 = (char *)nullDigest(RPM_HASH_SHA1, 1);
MD5 = (uint8_t *)nullDigest(RPM_HASH_MD5, 0);
}
SHA256 = (char *)nullDigest(RPM_HASH_SHA256, 1);
if (rpmGenerateSignature(SHA256, SHA1, MD5, 0, 0, fd, pkg->rpmver))
if (rpmGenerateSignature(SHA256, SHA1, MD5, 0, 0, fd, pkg->rpmformat))
goto exit;
SHA1 = _free(SHA1);
SHA256 = _free(SHA256);
Expand Down Expand Up @@ -548,7 +548,7 @@ static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp,
headerPutString(pkg->header, RPMTAG_PAYLOADDIGESTALT, upld);
pld = _free(pld);

if (pkg->rpmver >= 6) {
if (pkg->rpmformat >= 6) {
headerDel(pkg->header, RPMTAG_PAYLOADSIZE);
headerPutUint64(pkg->header, RPMTAG_PAYLOADSIZE, &payloadSize, 1);
headerDel(pkg->header, RPMTAG_PAYLOADSIZEALT);
Expand All @@ -562,7 +562,7 @@ static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp,
goto exit;

/* Calculate the digests */
if (pkg->rpmver < 6) {
if (pkg->rpmformat < 6) {
/* SHA1 and legacy MD5 on header + payload only in v4 */
fdInitDigestID(fd, RPM_HASH_MD5, RPMTAG_SIGMD5, 0);
fdInitDigestID(fd, RPM_HASH_SHA1, RPMTAG_SHA1HEADER, 0);
Expand All @@ -582,7 +582,7 @@ static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp,

/* Generate the signature. Now with right values */
if (rpmGenerateSignature(SHA256, SHA1, MD5, payloadEnd - hdrStart,
archiveSize, fd, pkg->rpmver)) {
archiveSize, fd, pkg->rpmformat)) {
goto exit;
}

Expand Down
2 changes: 1 addition & 1 deletion build/rpmbuild_internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ struct Package_s {
rpmds dependencies[PACKAGE_NUM_DEPS];
rpmfiles cpioList;
ARGV_t dpaths;
unsigned int rpmver; /* v4, v6? */
unsigned int rpmformat; /* v4, v6? */

struct Source * icon;

Expand Down
2 changes: 1 addition & 1 deletion build/rpmfc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ rpmRC rpmfcGenerateDepends(const rpmSpec spec, Package pkg)
/* Add per-file colors(#files) */
headerPutUint32(pkg->header, RPMTAG_FILECOLORS, fc->fcolor.data(), fc->nfiles);

if (pkg->rpmver >= 6) {
if (pkg->rpmformat >= 6) {
/* Add mime types(#mime types) */
for (rpmsid id = 1; id <= rpmstrPoolNumStr(fc->mdict); id++) {
headerPutString(pkg->header, RPMTAG_MIMEDICT,
Expand Down
11 changes: 10 additions & 1 deletion build/spec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "rpmfi_internal.hh" /* rpmfiles stuff */
#include "rpmbuild_internal.hh"
#include "rpmlog_internal.hh"

#include "debug.h"

Expand Down Expand Up @@ -102,7 +103,15 @@ Package newPackage(const char *name, rpmstrPool pool, Package *pkglist)
p->policyList = NULL;
p->pool = rpmstrPoolLink(pool);
p->dpaths = NULL;
p->rpmver = rpmExpandNumeric("%_rpmfilever");
p->rpmformat = rpmExpandNumeric("%{?_rpmformat}");

if (p->rpmformat != 4 && p->rpmformat != 6) {
int default_rpmformat = 4;
rpmlogOnce(0, "rpmformat", RPMLOG_WARNING,
_("invalid rpm format %d requested, using %d\n"),
p->rpmformat, default_rpmformat);
p->rpmformat = 4;
}

if (name)
p->name = rpmstrPoolId(p->pool, name, 1);
Expand Down
2 changes: 2 additions & 0 deletions docs/manual/tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Policyflags | 5033 | int32 array
Policynames | 5030 | string array
Policytypes | 5031 | string array
Policytypesindexes | 5032 | int32 array
Rpmformat | 5114 | int32 | Rpm package format version
Rpmversion | 1064 | string | Version of rpm used to build the package.
Sourcepkgid | 1146 | bin
Sourcerpm | 1044 | string | Package source rpm file name.
Expand Down Expand Up @@ -455,6 +456,7 @@ Obsoletenevrs | 5043 | string array | Formatted `name [op version]` obso
Enhancenevrs | 5061 | string array | Formatted `name [op version]` enhance dependency strings.
Recommendnevrs | 5058 | string array | Formatted `name [op version]` recommend dependency strings.
Requirenevrs | 5041 | string array | Formatted `name [op version]` require dependency strings.
Rpmformat | 5114 | int32 | Detected rpm format version (3/4/6)
Suggestnevrs | 5059 | string array | Formatted `name [op version]` suggest dependency strings.
Supplementnevrs | 5060 | string array | Formatted `name [op version]` supplement dependency strings.
Sysusers | 5109 | string array | Formatted systemd-sysusers lines for the package. |
Expand Down
17 changes: 17 additions & 0 deletions lib/tagexts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,22 @@ static int openpgpTag(Header h, rpmtd td, headerGetFlags hgflags)
return td->count != 0;
}

static int rpmformatTag(Header h, rpmtd td, headerGetFlags hgflags)
{
if (headerGet(h, RPMTAG_RPMFORMAT, td, HEADERGET_ALLOC))
return 1;

uint32_t *nump = (uint32_t *)xcalloc(1, sizeof(*nump));
*nump = headerIsEntry(h, RPMTAG_HEADERIMMUTABLE) ? 4 : 3;

td->data = nump;
td->count = 1;
td->type = RPM_INT32_TYPE;
td->flags = RPMTD_ALLOCED;

return 1;
}

static const struct headerTagFunc_s rpmHeaderTagExtensions[] = {
{ RPMTAG_GROUP, groupTag },
{ RPMTAG_DESCRIPTION, descriptionTag },
Expand Down Expand Up @@ -1127,6 +1143,7 @@ static const struct headerTagFunc_s rpmHeaderTagExtensions[] = {
{ RPMTAG_SYSUSERS, sysusersTag },
{ RPMTAG_FILEMIMES, filemimesTag },
{ RPMTAG_OPENPGP, openpgpTag },
{ RPMTAG_RPMFORMAT, rpmformatTag },
{ 0, NULL }
};

Expand Down
2 changes: 1 addition & 1 deletion macros.in
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ Supplements: (%{name} = %{version}-%{release} and langpacks-%{1})\
# This does NOT generate actual v6 format, the exact format
# hasn't been finalized yet.
# Which rpm format go generate (4 or 6)
%_rpmfilever 4
%_rpmformat 4

# The directory where sources/patches from a source package will be
# installed. This is also where sources/patches are found when building.
Expand Down
11 changes: 7 additions & 4 deletions sign/rpmgensig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ static int rpmSign(const char *rpm, int deleting, int flags)
struct sigTarget_s sigt_v4;
unsigned int origSigSize;
int insSig = 0;
rpmTagVal reserveTag = RPMSIGTAG_RESERVEDSPACE;
int rpmformat = 0;
rpmTagVal reserveTag = 0;

if (manageFile(&fd, rpm, O_RDWR))
goto exit;
Expand Down Expand Up @@ -671,7 +672,9 @@ static int rpmSign(const char *rpm, int deleting, int flags)
goto exit;
}

if (!headerIsEntry(h, RPMTAG_HEADERIMMUTABLE)) {
rpmformat = headerGetNumber(h, RPMTAG_RPMFORMAT);

if (rpmformat < 4) {
rpmlog(RPMLOG_ERR, _("Cannot sign RPM v3 packages: %s\n"), rpm);
goto exit;
}
Expand All @@ -682,8 +685,7 @@ static int rpmSign(const char *rpm, int deleting, int flags)
flags |= RPMSIGN_FLAG_RPMV3;
}

/* Only v6 packages have this */
if (headerIsEntry(sigh, RPMSIGTAG_RESERVED)) {
if (rpmformat >= 6) {
flags |= RPMSIGN_FLAG_RPMV6;
reserveTag = RPMSIGTAG_RESERVED;
/* v3 signatures are not welcome in v6 packages */
Expand All @@ -694,6 +696,7 @@ static int rpmSign(const char *rpm, int deleting, int flags)
}
} else {
flags |= RPMSIGN_FLAG_RPMV4;
reserveTag = RPMSIGTAG_RESERVEDSPACE;
/* Ensure only one legacy signature is added if adding v6 signatures */
if ((flags & RPMSIGN_FLAG_RPMV6) && haveLegacySig(sigh))
flags &= ~(RPMSIGN_FLAG_RPMV4|RPMSIGN_FLAG_RPMV3);
Expand Down
2 changes: 1 addition & 1 deletion tests/pinned/common/buildrepr.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
runroot rpmbuild -bb --quiet \
--define "_rpmfilever ${ver}" \
--define "_rpmformat ${ver}" \
--define "_rpmdir %{_topdir}/RPMS/${ver}" \
--define "optflags -O2 -g" \
--define "_target_platform noarch-linux" \
Expand Down
45 changes: 42 additions & 3 deletions tests/rpmpkgfmt.at
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AT_SETUP([rpm v4 format])
AT_KEYWORDS([pkgformat v4])
AT_KEYWORDS([rpmformat v4])
RPMDB_INIT

RPMTEST_CHECK([
Expand All @@ -13,10 +13,18 @@ runroot_other ${RPM_CONFIGDIR_PATH}/rpmdump ${pkg}
[0],
[expout],
[])

RPMTEST_CHECK([
rpm -qp --qf "%{rpmformat}\n" ${RPMTEST}/build/RPMS/4/noarch/attrtest-1.0-1.noarch.rpm
],
[0],
[4
],
[])
RPMTEST_CLEANUP

AT_SETUP([rpm v6 format])
AT_KEYWORDS([pkgformat v6])
AT_KEYWORDS([rpmformat v6])
RPMDB_INIT

RPMTEST_CHECK([
Expand All @@ -30,10 +38,18 @@ runroot_other ${RPM_CONFIGDIR_PATH}/rpmdump ${pkg}
[0],
[expout],
[])

RPMTEST_CHECK([
rpm -qp --qf "%{rpmformat}\n" ${RPMTEST}/build/RPMS/6/noarch/attrtest-1.0-1.noarch.rpm
],
[0],
[6
],
[])
RPMTEST_CLEANUP

AT_SETUP([rpm v3 format])
AT_KEYWORDS([pkgformat install query v3])
AT_KEYWORDS([rpmformat install query v3])
RPMDB_INIT
RPMTEST_CHECK([
runroot rpm -qpl /data/RPMS/hello-1.0-1.x86_64.rpm-v3
Expand Down Expand Up @@ -74,4 +90,27 @@ runroot rpm -U --nodeps --noverify /data/RPMS/hello-1.0-1.x86_64.rpm-v3
[warning: RPM v3 packages are deprecated: hello-1.0-1.x86_64
error: package format not supported: /data/RPMS/hello-1.0-1.x86_64.rpm-v3
])

RPMTEST_CHECK([
rpm -qp --qf "%{rpmformat}\n" /data/RPMS/hello-1.0-1.x86_64.rpm-v3
],
[0],
[3
],
[ignore])
RPMTEST_CLEANUP

AT_SETUP([invalid rpmformat])
AT_KEYWORDS([rpmformat build])

RPMTEST_CHECK([
rpmspec -q --define "_rpmformat 9" /data/SPECS/test-subpackages.spec
],
[0],
[test-1.0-1.x86_64
test-test2-1.0-1.x86_64
test-test3-1.0-1.x86_64
],
[warning: invalid rpm format 9 requested, using 4
])
RPMTEST_CLEANUP
4 changes: 2 additions & 2 deletions tests/rpmquery.at
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ RPMDB_INIT
RPMTEST_CHECK([[
# v4 packages
runroot rpmbuild -bb --quiet \
--define "_rpmfilever 4" /data/SPECS/filetypes.spec
--define "_rpmformat 4" /data/SPECS/filetypes.spec
runroot rpm -qp --fileclass /build/RPMS/noarch/filetypes-1.0-1.noarch.rpm | sed -e 's/[[:space:]]*$//'
]],
[0],
Expand All @@ -1385,7 +1385,7 @@ runroot rpm -qp --filemime /build/RPMS/noarch/filetypes-1.0-1.noarch.rpm | sed -
# v6 variants of the same
RPMTEST_CHECK([[
runroot rpmbuild -bb --quiet \
--define "_rpmfilever 6" \
--define "_rpmformat 6" \
/data/SPECS/filetypes.spec
runroot rpm -qp --fileclass /build/RPMS/noarch/filetypes-1.0-1.noarch.rpm | sed -e 's/[[:space:]]*$//'
]],
Expand Down
2 changes: 1 addition & 1 deletion tests/rpmsigdig.at
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ runroot rpmkeys --import /data/keys/*.pub

RPMTEST_CHECK([
runroot rpmbuild -bb --quiet \
--define "_rpmfilever 6" \
--define "_rpmformat 6" \
/data/SPECS/attrtest.spec
runroot rpmsign --addsign /build/RPMS/noarch/attrtest-1.0-1.noarch.rpm
],
Expand Down
Loading