|
|
621668 |
diff --git a/Makefile.am b/Makefile.am
|
|
|
621668 |
index 288668819..96542c8c8 100644
|
|
|
621668 |
--- a/Makefile.am
|
|
|
621668 |
+++ b/Makefile.am
|
|
|
621668 |
@@ -185,7 +185,7 @@ bin_PROGRAMS += rpmgraph
|
|
|
621668 |
rpmgraph_SOURCES = tools/rpmgraph.c
|
|
|
621668 |
rpmgraph_LDADD = lib/librpm.la rpmio/librpmio.la @WITH_POPT_LIB@
|
|
|
621668 |
|
|
|
621668 |
-dist_bin_SCRIPTS = scripts/gendiff
|
|
|
621668 |
+dist_bin_SCRIPTS = scripts/gendiff scripts/rpm2extents_dump
|
|
|
621668 |
|
|
|
621668 |
rpmconfig_DATA = rpmrc
|
|
|
621668 |
rpmrc: $(top_srcdir)/rpmrc.in
|
|
|
732e02 |
diff --git a/lib/Makefile.am b/lib/Makefile.am
|
|
|
732e02 |
index 5a1b6ca9b..2f1b3597f 100644
|
|
|
732e02 |
--- a/lib/Makefile.am
|
|
|
732e02 |
+++ b/lib/Makefile.am
|
|
|
732e02 |
@@ -40,7 +40,8 @@ librpm_la_SOURCES = \
|
|
|
732e02 |
rpmscript.h rpmscript.c \
|
|
|
732e02 |
rpmchroot.c rpmchroot.h \
|
|
|
732e02 |
rpmplugins.c rpmplugins.h rpmplugin.h rpmug.c rpmug.h \
|
|
|
732e02 |
- rpmtriggers.h rpmtriggers.c rpmvs.c rpmvs.h
|
|
|
732e02 |
+ rpmtriggers.h rpmtriggers.c rpmvs.c rpmvs.h \
|
|
|
732e02 |
+ rpmextents.c rpmextents_internal.h
|
|
|
732e02 |
|
|
|
732e02 |
librpm_la_LDFLAGS = -version-info $(rpm_version_info)
|
|
|
732e02 |
|
|
|
732e02 |
diff --git a/lib/depends.c b/lib/depends.c
|
|
|
732e02 |
index 8998afcd3..30234df3d 100644
|
|
|
732e02 |
--- a/lib/depends.c
|
|
|
732e02 |
+++ b/lib/depends.c
|
|
|
732e02 |
@@ -81,8 +81,6 @@ static rpmRC headerCheckPayloadFormat(Header h) {
|
|
|
732e02 |
*/
|
|
|
732e02 |
if (!payloadfmt) return rc;
|
|
|
732e02 |
|
|
|
732e02 |
- if (rstreq(payloadfmt, "clon")) return rc;
|
|
|
732e02 |
-
|
|
|
732e02 |
if (!rstreq(payloadfmt, "cpio")) {
|
|
|
732e02 |
char *nevra = headerGetAsString(h, RPMTAG_NEVRA);
|
|
|
732e02 |
if (payloadfmt && rstreq(payloadfmt, "drpm")) {
|
|
|
732e02 |
diff --git a/lib/fsm.c b/lib/fsm.c
|
|
|
732e02 |
index feda3750c..6972602e0 100644
|
|
|
732e02 |
--- a/lib/fsm.c
|
|
|
732e02 |
+++ b/lib/fsm.c
|
|
|
732e02 |
@@ -19,7 +19,6 @@
|
|
|
732e02 |
|
|
|
732e02 |
#include "rpmio/rpmio_internal.h" /* fdInit/FiniDigest */
|
|
|
732e02 |
#include "lib/fsm.h"
|
|
|
732e02 |
-#include "lib/rpmlib.h"
|
|
|
732e02 |
#include "lib/rpmte_internal.h" /* XXX rpmfs */
|
|
|
732e02 |
#include "lib/rpmplugins.h" /* rpm plugins hooks */
|
|
|
732e02 |
#include "lib/rpmug.h"
|
|
|
732e02 |
@@ -53,7 +52,6 @@ struct filedata_s {
|
|
|
732e02 |
int stage;
|
|
|
732e02 |
int setmeta;
|
|
|
732e02 |
int skip;
|
|
|
732e02 |
- int plugin_contents;
|
|
|
732e02 |
rpmFileAction action;
|
|
|
732e02 |
const char *suffix;
|
|
|
732e02 |
char *fpath;
|
|
|
732e02 |
@@ -893,14 +891,6 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
|
|
|
732e02 |
struct filedata_s *fdata = xcalloc(fc, sizeof(*fdata));
|
|
|
732e02 |
struct filedata_s *firstlink = NULL;
|
|
|
732e02 |
|
|
|
732e02 |
- Header h = rpmteHeader(te);
|
|
|
732e02 |
- const char *payloadfmt = headerGetString(h, RPMTAG_PAYLOADFORMAT);
|
|
|
732e02 |
- int cpio = 1;
|
|
|
732e02 |
-
|
|
|
732e02 |
- if (payloadfmt && rstreq(payloadfmt, "clon")) {
|
|
|
732e02 |
- cpio = 0;
|
|
|
732e02 |
- }
|
|
|
732e02 |
-
|
|
|
732e02 |
/* transaction id used for temporary path suffix while installing */
|
|
|
732e02 |
rasprintf(&tid, ";%08x", (unsigned)rpmtsGetTid(ts));
|
|
|
732e02 |
|
|
|
732e02 |
@@ -921,23 +911,12 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
|
|
|
732e02 |
/* Remap file perms, owner, and group. */
|
|
|
732e02 |
rc = rpmfiStat(fi, 1, &fp->sb);
|
|
|
732e02 |
|
|
|
732e02 |
+ setFileState(fs, fx);
|
|
|
732e02 |
fsmDebug(fp->fpath, fp->action, &fp->sb);
|
|
|
732e02 |
|
|
|
732e02 |
/* Run fsm file pre hook for all plugins */
|
|
|
732e02 |
rc = rpmpluginsCallFsmFilePre(plugins, fi, fp->fpath,
|
|
|
732e02 |
fp->sb.st_mode, fp->action);
|
|
|
732e02 |
- fp->plugin_contents = 0;
|
|
|
732e02 |
- switch (rc) {
|
|
|
732e02 |
- case RPMRC_OK:
|
|
|
732e02 |
- setFileState(fs, fx);
|
|
|
732e02 |
- break;
|
|
|
732e02 |
- case RPMRC_PLUGIN_CONTENTS:
|
|
|
732e02 |
- fp->plugin_contents = 1;
|
|
|
732e02 |
- // reduce reads on cpio to this value. Could be zero if
|
|
|
732e02 |
- // this is from a hard link.
|
|
|
732e02 |
- rc = RPMRC_OK;
|
|
|
732e02 |
- break;
|
|
|
732e02 |
- }
|
|
|
732e02 |
fp->stage = FILE_PRE;
|
|
|
732e02 |
}
|
|
|
732e02 |
fi = rpmfiFree(fi);
|
|
|
732e02 |
@@ -945,14 +924,24 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
|
|
|
732e02 |
if (rc)
|
|
|
732e02 |
goto exit;
|
|
|
732e02 |
|
|
|
732e02 |
- if (cpio) {
|
|
|
732e02 |
- fi = rpmfiNewArchiveReader(payload, files, RPMFI_ITER_READ_ARCHIVE);
|
|
|
732e02 |
- if (fi == NULL) {
|
|
|
732e02 |
- rc = RPMERR_BAD_MAGIC;
|
|
|
732e02 |
- goto exit;
|
|
|
732e02 |
- }
|
|
|
732e02 |
- } else {
|
|
|
732e02 |
- fi = rpmfilesIter(files, RPMFI_ITER_FWD);
|
|
|
732e02 |
+ rpmRC plugin_rc = rpmpluginsCallFsmFileArchiveReader(plugins, payload, files, &fi);
|
|
|
732e02 |
+ switch(plugin_rc) {
|
|
|
732e02 |
+ case RPMRC_PLUGIN_CONTENTS:
|
|
|
732e02 |
+ if(fi == NULL) {
|
|
|
732e02 |
+ rc = RPMERR_BAD_MAGIC;
|
|
|
732e02 |
+ goto exit;
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+ rc = RPMRC_OK;
|
|
|
732e02 |
+ break;
|
|
|
732e02 |
+ case RPMRC_OK:
|
|
|
732e02 |
+ fi = rpmfiNewArchiveReader(payload, files, RPMFI_ITER_READ_ARCHIVE);
|
|
|
732e02 |
+ if (fi == NULL) {
|
|
|
732e02 |
+ rc = RPMERR_BAD_MAGIC;
|
|
|
732e02 |
+ goto exit;
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+ break;
|
|
|
732e02 |
+ default:
|
|
|
732e02 |
+ rc = RPMRC_FAIL;
|
|
|
732e02 |
}
|
|
|
732e02 |
|
|
|
732e02 |
/* Detect and create directories not explicitly in package. */
|
|
|
732e02 |
@@ -992,14 +981,15 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
|
|
|
732e02 |
if (fp->action == FA_TOUCH)
|
|
|
732e02 |
continue;
|
|
|
732e02 |
|
|
|
732e02 |
- if (S_ISREG(fp->sb.st_mode)) {
|
|
|
732e02 |
+ rpmRC plugin_rc = rpmpluginsCallFsmFileInstall(plugins, fi, fp->fpath, fp->sb.st_mode, fp->action);
|
|
|
732e02 |
+ if(!(plugin_rc == RPMRC_PLUGIN_CONTENTS || plugin_rc == RPMRC_OK)){
|
|
|
732e02 |
+ rc = plugin_rc;
|
|
|
732e02 |
+ } else if(plugin_rc == RPMRC_PLUGIN_CONTENTS){
|
|
|
732e02 |
+ rc = RPMRC_OK;
|
|
|
732e02 |
+ } else if (S_ISREG(fp->sb.st_mode)) {
|
|
|
732e02 |
if (rc == RPMERR_ENOENT) {
|
|
|
732e02 |
- if(fp->plugin_contents) {
|
|
|
732e02 |
- rc = RPMRC_OK;
|
|
|
732e02 |
- }else {
|
|
|
732e02 |
- rc = fsmMkfile(fi, fp, files, psm, nodigest,
|
|
|
732e02 |
- &firstlink, &firstlinkfile);
|
|
|
732e02 |
- }
|
|
|
732e02 |
+ rc = fsmMkfile(fi, fp, files, psm, nodigest,
|
|
|
732e02 |
+ &firstlink, &firstlinkfile);
|
|
|
732e02 |
}
|
|
|
732e02 |
} else if (S_ISDIR(fp->sb.st_mode)) {
|
|
|
732e02 |
if (rc == RPMERR_ENOENT) {
|
|
|
732e02 |
@@ -1107,7 +1097,6 @@ int rpmPackageFilesInstall(rpmts ts, rpmte te, rpmfiles files,
|
|
|
732e02 |
rpmswAdd(rpmtsOp(ts, RPMTS_OP_DIGEST), fdOp(payload, FDSTAT_DIGEST));
|
|
|
732e02 |
|
|
|
732e02 |
exit:
|
|
|
732e02 |
- h = headerFree(h);
|
|
|
732e02 |
fi = rpmfiFree(fi);
|
|
|
732e02 |
Fclose(payload);
|
|
|
732e02 |
free(tid);
|
|
|
621668 |
diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c
|
|
|
7b1d93 |
index 40a3ab83f..7f856154e 100644
|
|
|
621668 |
--- a/lib/rpmchecksig.c
|
|
|
621668 |
+++ b/lib/rpmchecksig.c
|
|
|
732e02 |
@@ -20,6 +20,7 @@
|
|
|
732e02 |
#include "rpmio/rpmio_internal.h" /* fdSetBundle() */
|
|
|
732e02 |
#include "lib/rpmlead.h"
|
|
|
732e02 |
#include "lib/header_internal.h"
|
|
|
732e02 |
+#include "lib/rpmextents_internal.h"
|
|
|
732e02 |
#include "lib/rpmvs.h"
|
|
|
621668 |
|
|
|
732e02 |
#include "debug.h"
|
|
|
7b1d93 |
@@ -221,36 +222,24 @@ rpmRC rpmpkgRead(struct rpmvs_s *vs, FD_t fd,
|
|
|
621668 |
}
|
|
|
621668 |
|
|
|
621668 |
static int rpmpkgVerifySigs(rpmKeyring keyring, int vfylevel, rpmVSFlags flags,
|
|
|
7b1d93 |
- FD_t fd, const char *fn)
|
|
|
7b1d93 |
+ FD_t fd, rpmsinfoCb cb, void *cbdata)
|
|
|
621668 |
{
|
|
|
7b1d93 |
char *msg = NULL;
|
|
|
7b1d93 |
- struct vfydata_s vd = { .seen = 0,
|
|
|
7b1d93 |
- .bad = 0,
|
|
|
7b1d93 |
- .verbose = rpmIsVerbose(),
|
|
|
7b1d93 |
- };
|
|
|
621668 |
int rc;
|
|
|
621668 |
- struct rpmvs_s *vs = rpmvsCreate(vfylevel, flags, keyring);
|
|
|
621668 |
|
|
|
7b1d93 |
- rpmlog(RPMLOG_NOTICE, "%s:%s", fn, vd.verbose ? "\n" : "");
|
|
|
7b1d93 |
+
|
|
|
621668 |
+ if(isTranscodedRpm(fd) == RPMRC_OK){
|
|
|
7b1d93 |
+ return extentsVerifySigs(fd, 1);
|
|
|
621668 |
+ }
|
|
|
621668 |
+
|
|
|
7b1d93 |
+ struct rpmvs_s *vs = rpmvsCreate(vfylevel, flags, keyring);
|
|
|
7b1d93 |
|
|
|
621668 |
rc = rpmpkgRead(vs, fd, NULL, NULL, &msg;;
|
|
|
621668 |
|
|
|
621668 |
if (rc)
|
|
|
7b1d93 |
goto exit;
|
|
|
7b1d93 |
|
|
|
7b1d93 |
- rc = rpmvsVerify(vs, RPMSIG_VERIFIABLE_TYPE, vfyCb, &vd);
|
|
|
7b1d93 |
-
|
|
|
7b1d93 |
- if (!vd.verbose) {
|
|
|
7b1d93 |
- if (vd.seen & RPMSIG_DIGEST_TYPE) {
|
|
|
7b1d93 |
- rpmlog(RPMLOG_NOTICE, " %s", (vd.bad & RPMSIG_DIGEST_TYPE) ?
|
|
|
7b1d93 |
- _("DIGESTS") : _("digests"));
|
|
|
7b1d93 |
- }
|
|
|
7b1d93 |
- if (vd.seen & RPMSIG_SIGNATURE_TYPE) {
|
|
|
7b1d93 |
- rpmlog(RPMLOG_NOTICE, " %s", (vd.bad & RPMSIG_SIGNATURE_TYPE) ?
|
|
|
7b1d93 |
- _("SIGNATURES") : _("signatures"));
|
|
|
7b1d93 |
- }
|
|
|
7b1d93 |
- rpmlog(RPMLOG_NOTICE, " %s\n", rc ? _("NOT OK") : _("OK"));
|
|
|
7b1d93 |
- }
|
|
|
7b1d93 |
+ rc = rpmvsVerify(vs, RPMSIG_VERIFIABLE_TYPE, cb, cbdata);
|
|
|
7b1d93 |
|
|
|
7b1d93 |
exit:
|
|
|
7b1d93 |
if (rc && msg)
|
|
|
7b1d93 |
@@ -260,15 +249,39 @@ static int rpmpkgVerifySigs(rpmKeyring keyring, int vfylevel, rpmVSFlags flags,
|
|
|
621668 |
return rc;
|
|
|
621668 |
}
|
|
|
621668 |
|
|
|
7b1d93 |
+static void rpmkgVerifySigsPreLogging(struct vfydata_s *vd, const char *fn){
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_NOTICE, "%s:%s", fn, vd->verbose ? "\n" : "");
|
|
|
621668 |
+}
|
|
|
621668 |
+
|
|
|
7b1d93 |
+static void rpmkgVerifySigsPostLogging(struct vfydata_s *vd, int rc){
|
|
|
7b1d93 |
+ if (!vd->verbose) {
|
|
|
7b1d93 |
+ if (vd->seen & RPMSIG_DIGEST_TYPE) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_NOTICE, " %s", (vd->bad & RPMSIG_DIGEST_TYPE) ?
|
|
|
7b1d93 |
+ _("DIGESTS") : _("digests"));
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+ if (vd->seen & RPMSIG_SIGNATURE_TYPE) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_NOTICE, " %s", (vd->bad & RPMSIG_SIGNATURE_TYPE) ?
|
|
|
7b1d93 |
+ _("SIGNATURES") : _("signatures"));
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_NOTICE, " %s\n", rc ? _("NOT OK") : _("OK"));
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+}
|
|
|
621668 |
+
|
|
|
621668 |
/* Wrapper around rpmkVerifySigs to preserve API */
|
|
|
621668 |
int rpmVerifySignatures(QVA_t qva, rpmts ts, FD_t fd, const char * fn)
|
|
|
621668 |
{
|
|
|
7b1d93 |
int rc = 1; /* assume failure */
|
|
|
7b1d93 |
+ struct vfydata_s vd = { .seen = 0,
|
|
|
7b1d93 |
+ .bad = 0,
|
|
|
7b1d93 |
+ .verbose = rpmIsVerbose(),
|
|
|
7b1d93 |
+ };
|
|
|
7b1d93 |
if (ts && qva && fd && fn) {
|
|
|
7b1d93 |
rpmKeyring keyring = rpmtsGetKeyring(ts, 1);
|
|
|
7b1d93 |
rpmVSFlags vsflags = rpmtsVfyFlags(ts);
|
|
|
7b1d93 |
int vfylevel = rpmtsVfyLevel(ts);
|
|
|
7b1d93 |
- rc = rpmpkgVerifySigs(keyring, vfylevel, vsflags, fd, fn);
|
|
|
7b1d93 |
+ rpmkgVerifySigsPreLogging(&vd, fn);
|
|
|
7b1d93 |
+ rc = rpmpkgVerifySigs(keyring, vfylevel, vsflags, fd, vfyCb, &vd);
|
|
|
7b1d93 |
+ rpmkgVerifySigsPostLogging(&vd, rc);
|
|
|
7b1d93 |
rpmKeyringFree(keyring);
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
return rc;
|
|
|
7b1d93 |
@@ -290,12 +303,22 @@ int rpmcliVerifySignatures(rpmts ts, ARGV_const_t argv)
|
|
|
7b1d93 |
|
|
|
7b1d93 |
while ((arg = *argv++) != NULL) {
|
|
|
7b1d93 |
FD_t fd = Fopen(arg, "r.ufdio");
|
|
|
7b1d93 |
+ struct vfydata_s vd = { .seen = 0,
|
|
|
7b1d93 |
+ .bad = 0,
|
|
|
7b1d93 |
+ .verbose = rpmIsVerbose(),
|
|
|
7b1d93 |
+ };
|
|
|
7b1d93 |
if (fd == NULL || Ferror(fd)) {
|
|
|
7b1d93 |
rpmlog(RPMLOG_ERR, _("%s: open failed: %s\n"),
|
|
|
7b1d93 |
arg, Fstrerror(fd));
|
|
|
7b1d93 |
res++;
|
|
|
7b1d93 |
- } else if (rpmpkgVerifySigs(keyring, vfylevel, vsflags, fd, arg)) {
|
|
|
7b1d93 |
+ } else {
|
|
|
7b1d93 |
+ rpmkgVerifySigsPreLogging(&vd, arg);
|
|
|
7b1d93 |
+ int rc = rpmpkgVerifySigs(keyring, vfylevel, vsflags, fd,
|
|
|
7b1d93 |
+ vfyCb, &vd);
|
|
|
7b1d93 |
+ rpmkgVerifySigsPostLogging(&vd, rc);
|
|
|
7b1d93 |
+ if (rc) {
|
|
|
7b1d93 |
res++;
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
|
|
|
7b1d93 |
Fclose(fd);
|
|
|
7b1d93 |
@@ -304,3 +327,53 @@ int rpmcliVerifySignatures(rpmts ts, ARGV_const_t argv)
|
|
|
621668 |
rpmKeyringFree(keyring);
|
|
|
621668 |
return res;
|
|
|
621668 |
}
|
|
|
621668 |
+
|
|
|
621668 |
+struct vfydatafd_s {
|
|
|
621668 |
+ size_t len;
|
|
|
621668 |
+ char msg[BUFSIZ];
|
|
|
621668 |
+};
|
|
|
621668 |
+
|
|
|
621668 |
+
|
|
|
621668 |
+static int vfyFDCb(struct rpmsinfo_s *sinfo, void *cbdata)
|
|
|
621668 |
+{
|
|
|
621668 |
+ struct vfydatafd_s *vd = cbdata;
|
|
|
621668 |
+ char *vmsg, *msg;
|
|
|
621668 |
+ size_t n;
|
|
|
7b1d93 |
+ size_t remainder = BUFSIZ - vd->len >= 0 ? BUFSIZ - vd->len : 0;
|
|
|
621668 |
+
|
|
|
621668 |
+ vmsg = rpmsinfoMsg(sinfo);
|
|
|
621668 |
+ rasprintf(&msg, " %s\n", vmsg);
|
|
|
621668 |
+ n = rstrlcpy(vd->msg + vd->len, msg, remainder);
|
|
|
621668 |
+ free(vmsg);
|
|
|
621668 |
+ free(msg);
|
|
|
621668 |
+ if(n <= remainder){
|
|
|
621668 |
+ vd->len += n;
|
|
|
621668 |
+ }
|
|
|
621668 |
+ return 1;
|
|
|
621668 |
+}
|
|
|
621668 |
+
|
|
|
621668 |
+
|
|
|
621668 |
+int rpmcliVerifySignaturesFD(rpmts ts, FD_t fdi, char **msg)
|
|
|
621668 |
+{
|
|
|
621668 |
+ rpmRC rc = RPMRC_FAIL;
|
|
|
621668 |
+ rpmKeyring keyring = rpmtsGetKeyring(ts, 1);
|
|
|
621668 |
+ rpmVSFlags vsflags = rpmtsVfyFlags(ts);
|
|
|
621668 |
+ int vfylevel = rpmtsVfyLevel(ts);
|
|
|
621668 |
+ struct vfydatafd_s vd = {.len = 0};
|
|
|
621668 |
+
|
|
|
621668 |
+ vsflags |= rpmcliVSFlags;
|
|
|
621668 |
+ if (rpmcliVfyLevelMask) {
|
|
|
621668 |
+ vfylevel &= ~rpmcliVfyLevelMask;
|
|
|
621668 |
+ rpmtsSetVfyLevel(ts, vfylevel);
|
|
|
621668 |
+ }
|
|
|
621668 |
+
|
|
|
7b1d93 |
+ if (!rpmpkgVerifySigs(keyring, vfylevel, vsflags, fdi, vfyFDCb, &vd)) {
|
|
|
621668 |
+ rc = RPMRC_OK;
|
|
|
621668 |
+ }
|
|
|
621668 |
+ *msg = strdup(vd.msg);
|
|
|
621668 |
+ rpmsqPoll();
|
|
|
621668 |
+
|
|
|
621668 |
+ rpmKeyringFree(keyring);
|
|
|
621668 |
+ return rc;
|
|
|
621668 |
+}
|
|
|
621668 |
+
|
|
|
621668 |
diff --git a/lib/rpmcli.h b/lib/rpmcli.h
|
|
|
621668 |
index 906fe9951..7ff48b37a 100644
|
|
|
621668 |
--- a/lib/rpmcli.h
|
|
|
621668 |
+++ b/lib/rpmcli.h
|
|
|
621668 |
@@ -411,6 +411,16 @@ int rpmcliImportPubkeys(rpmts ts, ARGV_const_t argv);
|
|
|
621668 |
*/
|
|
|
621668 |
int rpmcliVerifySignatures(rpmts ts, ARGV_const_t argv);
|
|
|
621668 |
|
|
|
621668 |
+
|
|
|
621668 |
+/** \ingroup rpmcli
|
|
|
621668 |
+ * Verify package signatures.
|
|
|
621668 |
+ * @param ts transaction set
|
|
|
621668 |
+ * @param fd a file descriptor to verify
|
|
|
621668 |
+ * @param msg a string containing textual information about the verification, similar to rpmcliVerifySignatures output.
|
|
|
621668 |
+ * @return 0 on success
|
|
|
621668 |
+ */
|
|
|
621668 |
+int rpmcliVerifySignaturesFD(rpmts ts, FD_t fd, char **msg);
|
|
|
621668 |
+
|
|
|
621668 |
#ifdef __cplusplus
|
|
|
621668 |
}
|
|
|
621668 |
#endif
|
|
|
732e02 |
diff --git a/lib/rpmextents.c b/lib/rpmextents.c
|
|
|
732e02 |
new file mode 100644
|
|
|
7b1d93 |
index 000000000..ac43264af
|
|
|
732e02 |
--- /dev/null
|
|
|
732e02 |
+++ b/lib/rpmextents.c
|
|
|
7b1d93 |
@@ -0,0 +1,110 @@
|
|
|
732e02 |
+
|
|
|
732e02 |
+#include "system.h"
|
|
|
732e02 |
+
|
|
|
732e02 |
+#include <rpm/rpmlog.h>
|
|
|
732e02 |
+#include <rpm/rpmio.h>
|
|
|
7b1d93 |
+#include <string.h>
|
|
|
7b1d93 |
+#include <errno.h>
|
|
|
7b1d93 |
+
|
|
|
732e02 |
+
|
|
|
732e02 |
+#include "lib/rpmextents_internal.h"
|
|
|
732e02 |
+
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+int extentsVerifySigs(FD_t fd, int print_content){
|
|
|
7b1d93 |
+ rpm_loff_t current;
|
|
|
7b1d93 |
+ int32_t rc;
|
|
|
7b1d93 |
+ size_t len;
|
|
|
7b1d93 |
+ uint64_t content_len;
|
|
|
7b1d93 |
+ char *content = NULL;
|
|
|
7b1d93 |
+ struct extents_footer_t footer;
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+ current = Ftell(fd);
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+ if(extentsFooterFromFD(fd, &footer) != RPMRC_OK) {
|
|
|
7b1d93 |
+ rc = -1;
|
|
|
7b1d93 |
+ goto exit;
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+ if(Fseek(fd, footer.offsets.checksig_offset, SEEK_SET) < 0) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to seek signature verification offset\n"));
|
|
|
7b1d93 |
+ rc = -1;
|
|
|
7b1d93 |
+ goto exit;
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+ len = sizeof(rc);
|
|
|
7b1d93 |
+ if (Fread(&rc, len, 1, fd) != len) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to read Signature Verification RC\n"));
|
|
|
7b1d93 |
+ rc = -1;
|
|
|
7b1d93 |
+ goto exit;
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+ if(print_content) {
|
|
|
7b1d93 |
+ len = sizeof(content_len);
|
|
|
7b1d93 |
+ if (Fread(&content_len, len, 1, fd) != len) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to read signature content length\n"));
|
|
|
7b1d93 |
+ goto exit;
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+ content = rmalloc(content_len + 1);
|
|
|
7b1d93 |
+ if(content == NULL) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to allocate memory to read signature content\n"));
|
|
|
7b1d93 |
+ goto exit;
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+ content[content_len] = 0;
|
|
|
7b1d93 |
+ if (Fread(content, content_len, 1, fd) != content_len) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("extentsVerifySigs: Failed to read signature content\n"));
|
|
|
7b1d93 |
+ goto exit;
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_NOTICE, "%s", content);
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+exit:
|
|
|
7b1d93 |
+ if(content){
|
|
|
7b1d93 |
+ rfree(content);
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+ if (Fseek(fd, current, SEEK_SET) < 0) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("extentsVerifySigs: unable to seek back to original location\n"));
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+ return rc;
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+}
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+rpmRC extentsFooterFromFD(FD_t fd, struct extents_footer_t *footer) {
|
|
|
7b1d93 |
+
|
|
|
732e02 |
+ rpmRC rc = RPMRC_NOTFOUND;
|
|
|
732e02 |
+ rpm_loff_t current;
|
|
|
732e02 |
+ size_t len;
|
|
|
732e02 |
+
|
|
|
732e02 |
+ // If the file is not seekable, we cannot detect whether or not it is transcoded.
|
|
|
732e02 |
+ if(Fseek(fd, 0, SEEK_CUR) < 0) {
|
|
|
732e02 |
+ return RPMRC_FAIL;
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+ current = Ftell(fd);
|
|
|
732e02 |
+
|
|
|
7b1d93 |
+ len = sizeof(struct extents_footer_t);
|
|
|
7b1d93 |
+ if(Fseek(fd, -len, SEEK_END) < 0) {
|
|
|
732e02 |
+ rc = RPMRC_FAIL;
|
|
|
732e02 |
+ goto exit;
|
|
|
732e02 |
+ }
|
|
|
7b1d93 |
+ if (Fread(footer, len, 1, fd) != len) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("isTranscodedRpm: unable to read footer\n"));
|
|
|
732e02 |
+ rc = RPMRC_FAIL;
|
|
|
732e02 |
+ goto exit;
|
|
|
732e02 |
+ }
|
|
|
7b1d93 |
+ if (footer->magic != EXTENTS_MAGIC) {
|
|
|
732e02 |
+ rc = RPMRC_NOTFOUND;
|
|
|
732e02 |
+ goto exit;
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+ rc = RPMRC_OK;
|
|
|
732e02 |
+exit:
|
|
|
732e02 |
+ if (Fseek(fd, current, SEEK_SET) < 0) {
|
|
|
732e02 |
+ rpmlog(RPMLOG_ERR, _("isTranscodedRpm: unable to seek back to original location\n"));
|
|
|
732e02 |
+ rc = RPMRC_FAIL;
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+ return rc;
|
|
|
732e02 |
+}
|
|
|
732e02 |
+
|
|
|
7b1d93 |
+rpmRC isTranscodedRpm(FD_t fd) {
|
|
|
7b1d93 |
+ struct extents_footer_t footer;
|
|
|
7b1d93 |
+ return extentsFooterFromFD(fd, &footer);
|
|
|
7b1d93 |
+}
|
|
|
7b1d93 |
+
|
|
|
732e02 |
+
|
|
|
732e02 |
diff --git a/lib/rpmextents_internal.h b/lib/rpmextents_internal.h
|
|
|
732e02 |
new file mode 100644
|
|
|
7b1d93 |
index 000000000..0a3318c8e
|
|
|
732e02 |
--- /dev/null
|
|
|
732e02 |
+++ b/lib/rpmextents_internal.h
|
|
|
7b1d93 |
@@ -0,0 +1,58 @@
|
|
|
732e02 |
+#ifndef _RPMEXTENTS_INTERNAL_H
|
|
|
732e02 |
+#define _RPMEXTENTS_INTERNAL_H
|
|
|
732e02 |
+
|
|
|
732e02 |
+#ifdef __cplusplus
|
|
|
732e02 |
+extern "C" {
|
|
|
732e02 |
+#endif
|
|
|
732e02 |
+
|
|
|
732e02 |
+#include <stdint.h>
|
|
|
732e02 |
+
|
|
|
7b1d93 |
+/** \ingroup rpmextents
|
|
|
7b1d93 |
+ * RPM extents library
|
|
|
7b1d93 |
+ */
|
|
|
7b1d93 |
+
|
|
|
732e02 |
+/* magic value at end of file (64 bits) that indicates this is a transcoded
|
|
|
732e02 |
+ * rpm.
|
|
|
732e02 |
+ */
|
|
|
732e02 |
+#define EXTENTS_MAGIC 3472329499408095051
|
|
|
732e02 |
+
|
|
|
732e02 |
+typedef uint64_t extents_magic_t;
|
|
|
732e02 |
+
|
|
|
7b1d93 |
+struct __attribute__ ((__packed__)) extents_footer_offsets_t {
|
|
|
7b1d93 |
+ off64_t checksig_offset;
|
|
|
7b1d93 |
+ off64_t table_offset;
|
|
|
7b1d93 |
+ off64_t csum_offset;
|
|
|
7b1d93 |
+};
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+struct __attribute__ ((__packed__)) extents_footer_t {
|
|
|
7b1d93 |
+ struct extents_footer_offsets_t offsets;
|
|
|
7b1d93 |
+ extents_magic_t magic;
|
|
|
7b1d93 |
+};
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+/** \ingroup rpmextents
|
|
|
7b1d93 |
+ * Checks the results of the signature verification ran during transcoding.
|
|
|
7b1d93 |
+ * @param fd The FD_t of the transcoded RPM
|
|
|
7b1d93 |
+ * @param print_content Whether or not to print the result from rpmsig
|
|
|
7b1d93 |
+ * @return The number of checks that `rpmvsVerify` failed during transcoding.
|
|
|
7b1d93 |
+ */
|
|
|
7b1d93 |
+int extentsVerifySigs(FD_t fd, int print_content);
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+/** \ingroup rpmextents
|
|
|
7b1d93 |
+ * Read the RPM Extents footer from a file descriptor.
|
|
|
7b1d93 |
+ * @param fd The FD_t of the transcoded RPM
|
|
|
7b1d93 |
+ * @param[out] footer A pointer to an allocated extents_footer_t with a copy of the footer.
|
|
|
7b1d93 |
+ * @return RPMRC_OK on success, RPMRC_NOTFOUND if not a transcoded file, RPMRC_FAIL on any failure.
|
|
|
7b1d93 |
+ */
|
|
|
7b1d93 |
+rpmRC extentsFooterFromFD(FD_t fd, struct extents_footer_t *footer);
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+/** \ingroup rpmextents
|
|
|
7b1d93 |
+ * Check if a RPM is a transcoded RPM
|
|
|
7b1d93 |
+ * @param fd The FD_t of the transcoded RPM
|
|
|
7b1d93 |
+ * return RPMRC_OK on success, RPMRC_NOTFOUND if not a transcoded file, RPMRC_FAIL on any failure.
|
|
|
7b1d93 |
+ */
|
|
|
732e02 |
+rpmRC isTranscodedRpm(FD_t fd);
|
|
|
732e02 |
+
|
|
|
732e02 |
+#ifdef __cplusplus
|
|
|
732e02 |
+}
|
|
|
732e02 |
+#endif
|
|
|
7b1d93 |
+#endif /* _RPMEXTENTS_INTERNAL_H */
|
|
|
732e02 |
diff --git a/lib/rpmplugin.h b/lib/rpmplugin.h
|
|
|
732e02 |
index fd81aec8d..6dbbcff35 100644
|
|
|
732e02 |
--- a/lib/rpmplugin.h
|
|
|
732e02 |
+++ b/lib/rpmplugin.h
|
|
|
732e02 |
@@ -60,6 +60,13 @@ typedef rpmRC (*plugin_fsm_file_prepare_func)(rpmPlugin plugin, rpmfi fi,
|
|
|
732e02 |
const char* path,
|
|
|
732e02 |
const char *dest,
|
|
|
732e02 |
mode_t file_mode, rpmFsmOp op);
|
|
|
732e02 |
+typedef rpmRC (*plugin_fsm_file_install_func)(rpmPlugin plugin, rpmfi fi,
|
|
|
732e02 |
+ const char* path,
|
|
|
732e02 |
+ mode_t file_mode, rpmFsmOp op);
|
|
|
732e02 |
+typedef rpmRC (*plugin_fsm_file_archive_reader_func)(rpmPlugin plugin,
|
|
|
732e02 |
+ FD_t payload,
|
|
|
732e02 |
+ rpmfiles files, rpmfi *fi);
|
|
|
732e02 |
+
|
|
|
732e02 |
|
|
|
732e02 |
typedef struct rpmPluginHooks_s * rpmPluginHooks;
|
|
|
732e02 |
struct rpmPluginHooks_s {
|
|
|
732e02 |
@@ -80,6 +87,8 @@ struct rpmPluginHooks_s {
|
|
|
732e02 |
plugin_fsm_file_pre_func fsm_file_pre;
|
|
|
732e02 |
plugin_fsm_file_post_func fsm_file_post;
|
|
|
732e02 |
plugin_fsm_file_prepare_func fsm_file_prepare;
|
|
|
732e02 |
+ plugin_fsm_file_install_func fsm_file_install;
|
|
|
732e02 |
+ plugin_fsm_file_archive_reader_func fsm_file_archive_reader;
|
|
|
732e02 |
};
|
|
|
732e02 |
|
|
|
732e02 |
#ifdef __cplusplus
|
|
|
732e02 |
diff --git a/lib/rpmplugins.c b/lib/rpmplugins.c
|
|
|
732e02 |
index 3da3097af..901af1ac5 100644
|
|
|
732e02 |
--- a/lib/rpmplugins.c
|
|
|
732e02 |
+++ b/lib/rpmplugins.c
|
|
|
732e02 |
@@ -421,3 +421,74 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins plugins, rpmfi fi,
|
|
|
732e02 |
|
|
|
732e02 |
return rc;
|
|
|
732e02 |
}
|
|
|
732e02 |
+
|
|
|
732e02 |
+rpmRC rpmpluginsCallFsmFileInstall(rpmPlugins plugins, rpmfi fi,
|
|
|
732e02 |
+ const char *path, mode_t file_mode,
|
|
|
732e02 |
+ rpmFsmOp op)
|
|
|
732e02 |
+{
|
|
|
732e02 |
+ plugin_fsm_file_install_func hookFunc;
|
|
|
732e02 |
+ int i;
|
|
|
732e02 |
+ rpmRC rc = RPMRC_OK;
|
|
|
732e02 |
+ rpmRC hook_rc;
|
|
|
732e02 |
+
|
|
|
732e02 |
+ for (i = 0; i < plugins->count; i++) {
|
|
|
732e02 |
+ rpmPlugin plugin = plugins->plugins[i];
|
|
|
732e02 |
+ RPMPLUGINS_SET_HOOK_FUNC(fsm_file_install);
|
|
|
732e02 |
+ if (hookFunc) {
|
|
|
732e02 |
+ hook_rc = hookFunc(plugin, fi, path, file_mode, op);
|
|
|
732e02 |
+ if (hook_rc == RPMRC_FAIL) {
|
|
|
732e02 |
+ rpmlog(RPMLOG_ERR, "Plugin %s: hook fsm_file_install failed\n", plugin->name);
|
|
|
732e02 |
+ rc = RPMRC_FAIL;
|
|
|
732e02 |
+ } else if (hook_rc == RPMRC_PLUGIN_CONTENTS && rc != RPMRC_FAIL) {
|
|
|
732e02 |
+ if (rc == RPMRC_PLUGIN_CONTENTS) {
|
|
|
732e02 |
+ /* Another plugin already said it'd handle contents. It's
|
|
|
732e02 |
+ * undefined how these would combine, so treat this as a
|
|
|
732e02 |
+ * failure condition.
|
|
|
732e02 |
+ */
|
|
|
732e02 |
+ rc = RPMRC_FAIL;
|
|
|
732e02 |
+ } else {
|
|
|
732e02 |
+ /* Plugin will handle content */
|
|
|
732e02 |
+ rc = RPMRC_PLUGIN_CONTENTS;
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+
|
|
|
732e02 |
+ return rc;
|
|
|
732e02 |
+}
|
|
|
732e02 |
+
|
|
|
732e02 |
+rpmRC rpmpluginsCallFsmFileArchiveReader(rpmPlugins plugins, FD_t payload,
|
|
|
732e02 |
+ rpmfiles files, rpmfi *fi)
|
|
|
732e02 |
+{
|
|
|
732e02 |
+ plugin_fsm_file_archive_reader_func hookFunc;
|
|
|
732e02 |
+ int i;
|
|
|
732e02 |
+ rpmRC rc = RPMRC_OK;
|
|
|
732e02 |
+ rpmRC hook_rc;
|
|
|
732e02 |
+
|
|
|
732e02 |
+ for (i = 0; i < plugins->count; i++) {
|
|
|
732e02 |
+ rpmPlugin plugin = plugins->plugins[i];
|
|
|
732e02 |
+ RPMPLUGINS_SET_HOOK_FUNC(fsm_file_archive_reader);
|
|
|
732e02 |
+ if (hookFunc) {
|
|
|
732e02 |
+ hook_rc = hookFunc(plugin, payload, files, fi);
|
|
|
732e02 |
+ if (hook_rc == RPMRC_FAIL) {
|
|
|
732e02 |
+ rpmlog(RPMLOG_ERR, "Plugin %s: hook fsm_file_archive_reader failed\n", plugin->name);
|
|
|
732e02 |
+ rc = RPMRC_FAIL;
|
|
|
732e02 |
+ } else if (hook_rc == RPMRC_PLUGIN_CONTENTS && rc != RPMRC_FAIL) {
|
|
|
732e02 |
+ if (rc == RPMRC_PLUGIN_CONTENTS) {
|
|
|
732e02 |
+ /* Another plugin already said it'd handle contents. It's
|
|
|
732e02 |
+ * undefined how these would combine, so treat this as a
|
|
|
732e02 |
+ * failure condition.
|
|
|
732e02 |
+ */
|
|
|
732e02 |
+ rc = RPMRC_FAIL;
|
|
|
732e02 |
+ } else {
|
|
|
732e02 |
+ /* Plugin will handle content */
|
|
|
732e02 |
+ rc = RPMRC_PLUGIN_CONTENTS;
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+
|
|
|
732e02 |
+ return rc;
|
|
|
732e02 |
+}
|
|
|
732e02 |
+
|
|
|
732e02 |
+
|
|
|
732e02 |
diff --git a/lib/rpmplugins.h b/lib/rpmplugins.h
|
|
|
732e02 |
index 39762c376..88807c53c 100644
|
|
|
732e02 |
--- a/lib/rpmplugins.h
|
|
|
732e02 |
+++ b/lib/rpmplugins.h
|
|
|
732e02 |
@@ -167,6 +167,23 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins plugins, rpmfi fi,
|
|
|
732e02 |
const char *path, const char *dest,
|
|
|
732e02 |
mode_t mode, rpmFsmOp op);
|
|
|
732e02 |
|
|
|
732e02 |
+/** \ingroup rpmplugins
|
|
|
732e02 |
+ * Call the fsm file install plugin hook
|
|
|
732e02 |
+ * @param plugins plugins structure
|
|
|
732e02 |
+ * @param fi file info iterator (or NULL)
|
|
|
732e02 |
+ * @param path file object path
|
|
|
732e02 |
+ * @param file_mode file object mode
|
|
|
732e02 |
+ * @param op file operation + associated flags
|
|
|
732e02 |
+ * @return RPMRC_OK on success, RPMRC_FAIL otherwise
|
|
|
732e02 |
+ */
|
|
|
732e02 |
+RPM_GNUC_INTERNAL
|
|
|
732e02 |
+rpmRC rpmpluginsCallFsmFileInstall(rpmPlugins plugins, rpmfi fi,
|
|
|
732e02 |
+ const char* path, mode_t file_mode,
|
|
|
732e02 |
+ rpmFsmOp op);
|
|
|
732e02 |
+
|
|
|
732e02 |
+RPM_GNUC_INTERNAL
|
|
|
732e02 |
+rpmRC rpmpluginsCallFsmFileArchiveReader(rpmPlugins plugins, FD_t payload,
|
|
|
732e02 |
+ rpmfiles files, rpmfi *fi);
|
|
|
732e02 |
#ifdef __cplusplus
|
|
|
732e02 |
}
|
|
|
732e02 |
#endif
|
|
|
7b1d93 |
diff --git a/lib/transaction.c b/lib/transaction.c
|
|
|
7b1d93 |
index 36c2a7a64..a476a5365 100644
|
|
|
7b1d93 |
--- a/lib/transaction.c
|
|
|
7b1d93 |
+++ b/lib/transaction.c
|
|
|
7b1d93 |
@@ -37,6 +37,7 @@
|
|
|
7b1d93 |
#include "lib/rpmfi_internal.h" /* only internal apis */
|
|
|
7b1d93 |
#include "lib/rpmte_internal.h" /* only internal apis */
|
|
|
7b1d93 |
#include "lib/rpmts_internal.h"
|
|
|
7b1d93 |
+#include "lib/rpmextents_internal.h"
|
|
|
7b1d93 |
#include "lib/rpmvs.h"
|
|
|
7b1d93 |
#include "rpmio/rpmhook.h"
|
|
|
7b1d93 |
#include "lib/rpmtriggers.h"
|
|
|
7b1d93 |
@@ -1255,10 +1256,16 @@
|
|
|
7b1d93 |
.signature = RPMRC_NOTFOUND,
|
|
|
7b1d93 |
.vfylevel = vfylevel,
|
|
|
7b1d93 |
};
|
|
|
7b1d93 |
+ int verified = 0;
|
|
|
7b1d93 |
rpmRC prc = RPMRC_FAIL;
|
|
|
7b1d93 |
|
|
|
7b1d93 |
rpmtsNotify(ts, p, RPMCALLBACK_VERIFY_PROGRESS, oc++, total);
|
|
|
7b1d93 |
FD_t fd = rpmtsNotify(ts, p, RPMCALLBACK_INST_OPEN_FILE, 0, 0);
|
|
|
7b1d93 |
+ if(fd != NULL && isTranscodedRpm(fd) == RPMRC_OK) {
|
|
|
7b1d93 |
+ /* Transcoded RPMs are validated at transcoding time */
|
|
|
7b1d93 |
+ prc = RPMRC_OK;
|
|
|
7b1d93 |
+ verified = 1;
|
|
|
7b1d93 |
+ } else {
|
|
|
7b1d93 |
if (fd != NULL) {
|
|
|
7b1d93 |
prc = rpmpkgRead(vs, fd, NULL, NULL, &vd.msg);
|
|
|
7b1d93 |
rpmtsNotify(ts, p, RPMCALLBACK_INST_CLOSE_FILE, 0, 0);
|
|
|
7b1d93 |
@@ -1267,8 +1274,11 @@
|
|
|
7b1d93 |
if (prc == RPMRC_OK)
|
|
|
7b1d93 |
prc = rpmvsVerify(vs, RPMSIG_VERIFIABLE_TYPE, vfyCb, &vd);
|
|
|
7b1d93 |
|
|
|
7b1d93 |
+ verified = vd.signature == RPMRC_OK;
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
/* Record verify result, signatures only for now */
|
|
|
7b1d93 |
- rpmteSetVerified(p, vd.signature == RPMRC_OK);
|
|
|
7b1d93 |
+ rpmteSetVerified(p, verified);
|
|
|
7b1d93 |
|
|
|
7b1d93 |
if (prc)
|
|
|
7b1d93 |
rpmteAddProblem(p, RPMPROB_VERIFY, NULL, vd.msg, 0);
|
|
|
732e02 |
diff --git a/plugins/reflink.c b/plugins/reflink.c
|
|
|
7b1d93 |
index 513887604..69e6b51e6 100644
|
|
|
732e02 |
--- a/plugins/reflink.c
|
|
|
732e02 |
+++ b/plugins/reflink.c
|
|
|
732e02 |
@@ -13,6 +13,7 @@
|
|
|
732e02 |
#include <rpm/rpmlog.h>
|
|
|
732e02 |
#include "lib/rpmlib.h"
|
|
|
732e02 |
#include "lib/rpmplugin.h"
|
|
|
732e02 |
+#include "lib/rpmextents_internal.h"
|
|
|
732e02 |
#include "lib/rpmte_internal.h"
|
|
|
732e02 |
#include <rpm/rpmfileutil.h>
|
|
|
732e02 |
#include "rpmio/rpmio_internal.h"
|
|
|
592a09 |
@@ -28,7 +29,7 @@
|
|
|
592a09 |
#undef HTDATATYPE
|
|
|
592a09 |
#define HASHTYPE inodeIndexHash
|
|
|
592a09 |
#define HTKEYTYPE rpm_ino_t
|
|
|
592a09 |
-#define HTDATATYPE int
|
|
|
592a09 |
+#define HTDATATYPE const char *
|
|
|
592a09 |
#include "lib/rpmhash.H"
|
|
|
592a09 |
#include "lib/rpmhash.C"
|
|
|
592a09 |
|
|
|
732e02 |
@@ -40,11 +41,6 @@
|
|
|
732e02 |
|
|
|
732e02 |
#define BUFFER_SIZE (1024 * 128)
|
|
|
732e02 |
|
|
|
732e02 |
-/* magic value at end of file (64 bits) that indicates this is a transcoded
|
|
|
732e02 |
- * rpm.
|
|
|
732e02 |
- */
|
|
|
732e02 |
-#define MAGIC 3472329499408095051
|
|
|
732e02 |
-
|
|
|
732e02 |
struct reflink_state_s {
|
|
|
732e02 |
/* Stuff that's used across rpms */
|
|
|
732e02 |
long fundamental_block_size;
|
|
|
7b1d93 |
@@ -58,10 +54,55 @@ struct reflink_state_s {
|
|
|
732e02 |
FD_t fd;
|
|
|
732e02 |
rpmfiles files;
|
|
|
732e02 |
inodeIndexHash inodeIndexes;
|
|
|
732e02 |
+ int transcoded;
|
|
|
732e02 |
};
|
|
|
732e02 |
|
|
|
732e02 |
typedef struct reflink_state_s * reflink_state;
|
|
|
7b1d93 |
|
|
|
7b1d93 |
+/*
|
|
|
7b1d93 |
+ * bsearch_r: implements a re-entrant version of stdlib's bsearch.
|
|
|
7b1d93 |
+ * code taken and adapted from /usr/include/bits/stdlib-bsearch.h
|
|
|
7b1d93 |
+ */
|
|
|
7b1d93 |
+inline void *
|
|
|
7b1d93 |
+bsearch_r (const void *__key, const void *__base, size_t __nmemb, size_t __size,
|
|
|
7b1d93 |
+ __compar_d_fn_t __compar, void *__arg)
|
|
|
7b1d93 |
+{
|
|
|
7b1d93 |
+ size_t __l, __u, __idx;
|
|
|
7b1d93 |
+ const void *__p;
|
|
|
7b1d93 |
+ int __comparison;
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+ __l = 0;
|
|
|
7b1d93 |
+ __u = __nmemb;
|
|
|
7b1d93 |
+ while (__l < __u)
|
|
|
7b1d93 |
+ {
|
|
|
7b1d93 |
+ __idx = (__l + __u) / 2;
|
|
|
7b1d93 |
+ __p = (const void *) (((const char *) __base) + (__idx * __size));
|
|
|
7b1d93 |
+ __comparison = (*__compar) (__key, __p, __arg);
|
|
|
7b1d93 |
+ if (__comparison < 0)
|
|
|
7b1d93 |
+ __u = __idx;
|
|
|
7b1d93 |
+ else if (__comparison > 0)
|
|
|
7b1d93 |
+ __l = __idx + 1;
|
|
|
7b1d93 |
+ else
|
|
|
7b1d93 |
+ {
|
|
|
7b1d93 |
+#if __GNUC_PREREQ(4, 6)
|
|
|
7b1d93 |
+# pragma GCC diagnostic push
|
|
|
7b1d93 |
+# pragma GCC diagnostic ignored "-Wcast-qual"
|
|
|
7b1d93 |
+#endif
|
|
|
7b1d93 |
+ return (void *) __p;
|
|
|
7b1d93 |
+#if __GNUC_PREREQ(4, 6)
|
|
|
7b1d93 |
+# pragma GCC diagnostic pop
|
|
|
7b1d93 |
+#endif
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+ }
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+ return NULL;
|
|
|
7b1d93 |
+}
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
+static int cmpdigest(const void *k1, const void *k2, void *data) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_DEBUG, _("reflink: cmpdigest k1=%p k2=%p\n"), k1, k2);
|
|
|
7b1d93 |
+ return memcmp(k1, k2, *(int *)data);
|
|
|
7b1d93 |
+}
|
|
|
7b1d93 |
+
|
|
|
7b1d93 |
static int inodeCmp(rpm_ino_t a, rpm_ino_t b)
|
|
|
7b1d93 |
{
|
|
|
7b1d93 |
return (a != b);
|
|
|
7b1d93 |
@@ -96,51 +137,35 @@ static void reflink_cleanup(rpmPlugin plugin) {
|
|
|
732e02 |
}
|
|
|
732e02 |
|
|
|
732e02 |
static rpmRC reflink_psm_pre(rpmPlugin plugin, rpmte te) {
|
|
|
732e02 |
+ rpmRC rc;
|
|
|
732e02 |
+ size_t len;
|
|
|
732e02 |
+
|
|
|
732e02 |
reflink_state state = rpmPluginGetData(plugin);
|
|
|
732e02 |
state->fd = rpmteFd(te);
|
|
|
732e02 |
if (state->fd == 0) {
|
|
|
732e02 |
rpmlog(RPMLOG_DEBUG, _("reflink: fd = 0, no install\n"));
|
|
|
732e02 |
return RPMRC_OK;
|
|
|
732e02 |
}
|
|
|
732e02 |
+
|
|
|
732e02 |
rpm_loff_t current = Ftell(state->fd);
|
|
|
732e02 |
- uint64_t magic;
|
|
|
732e02 |
- if (Fseek(state->fd, -(sizeof(magic)), SEEK_END) < 0) {
|
|
|
732e02 |
- rpmlog(RPMLOG_ERR, _("reflink: failed to seek for magic\n"));
|
|
|
732e02 |
- if (Fseek(state->fd, current, SEEK_SET) < 0) {
|
|
|
732e02 |
- /* yes this gets a bit repetitive */
|
|
|
732e02 |
- rpmlog(RPMLOG_ERR,
|
|
|
732e02 |
- _("reflink: unable to seek back to original location\n"));
|
|
|
732e02 |
- }
|
|
|
732e02 |
- return RPMRC_FAIL;
|
|
|
732e02 |
- }
|
|
|
732e02 |
- size_t len = sizeof(magic);
|
|
|
732e02 |
- if (Fread(&magic, len, 1, state->fd) != len) {
|
|
|
732e02 |
- rpmlog(RPMLOG_ERR, _("reflink: unable to read magic\n"));
|
|
|
732e02 |
- if (Fseek(state->fd, current, SEEK_SET) < 0) {
|
|
|
732e02 |
- rpmlog(RPMLOG_ERR,
|
|
|
732e02 |
- _("reflink: unable to seek back to original location\n"));
|
|
|
732e02 |
- }
|
|
|
732e02 |
- return RPMRC_FAIL;
|
|
|
732e02 |
- }
|
|
|
732e02 |
- if (magic != MAGIC) {
|
|
|
732e02 |
- rpmlog(RPMLOG_DEBUG, _("reflink: not transcoded\n"));
|
|
|
732e02 |
- if (Fseek(state->fd, current, SEEK_SET) < 0) {
|
|
|
732e02 |
- rpmlog(RPMLOG_ERR,
|
|
|
732e02 |
- _("reflink: unable to seek back to original location\n"));
|
|
|
732e02 |
+ rc = isTranscodedRpm(state->fd);
|
|
|
732e02 |
+
|
|
|
732e02 |
+ switch(rc){
|
|
|
732e02 |
+ // Fail to parse the file, fail the plugin.
|
|
|
732e02 |
+ case RPMRC_FAIL:
|
|
|
732e02 |
return RPMRC_FAIL;
|
|
|
732e02 |
- }
|
|
|
732e02 |
- return RPMRC_OK;
|
|
|
732e02 |
+ // This is not a transcoded file, do nothing.
|
|
|
732e02 |
+ case RPMRC_NOTFOUND:
|
|
|
732e02 |
+ return RPMRC_OK;
|
|
|
732e02 |
+ default:
|
|
|
732e02 |
+ break;
|
|
|
732e02 |
}
|
|
|
732e02 |
rpmlog(RPMLOG_DEBUG, _("reflink: *is* transcoded\n"));
|
|
|
732e02 |
- Header h = rpmteHeader(te);
|
|
|
732e02 |
+ state->transcoded = 1;
|
|
|
732e02 |
|
|
|
732e02 |
- /* replace/add header that main fsm.c can read */
|
|
|
732e02 |
- headerDel(h, RPMTAG_PAYLOADFORMAT);
|
|
|
732e02 |
- headerPutString(h, RPMTAG_PAYLOADFORMAT, "clon");
|
|
|
732e02 |
- headerFree(h);
|
|
|
732e02 |
state->files = rpmteFiles(te);
|
|
|
732e02 |
/* tail of file contains offset_table, offset_checksums then magic */
|
|
|
732e02 |
- if (Fseek(state->fd, -(sizeof(rpm_loff_t) * 2 + sizeof(magic)), SEEK_END) < 0) {
|
|
|
732e02 |
+ if (Fseek(state->fd, -(sizeof(rpm_loff_t) * 2 + sizeof(extents_magic_t)), SEEK_END) < 0) {
|
|
|
732e02 |
rpmlog(RPMLOG_ERR, _("reflink: failed to seek for tail %p\n"),
|
|
|
732e02 |
state->fd);
|
|
|
732e02 |
return RPMRC_FAIL;
|
|
|
7b1d93 |
@@ -182,7 +207,7 @@ static rpmRC reflink_psm_pre(rpmPlugin plugin, rpmte te) {
|
|
|
592a09 |
return RPMRC_FAIL;
|
|
|
592a09 |
}
|
|
|
592a09 |
state->inodeIndexes = inodeIndexHashCreate(
|
|
|
592a09 |
- state->keys, inodeId, inodeCmp, NULL, NULL
|
|
|
592a09 |
+ state->keys, inodeId, inodeCmp, NULL, (inodeIndexHashFreeData)rfree
|
|
|
592a09 |
);
|
|
|
592a09 |
}
|
|
|
592a09 |
|
|
|
7b1d93 |
@@ -217,21 +242,13 @@ static rpmRC reflink_psm_post(rpmPlugin plugin, rpmte te, int res)
|
|
|
7b1d93 |
rpm_loff_t find(const unsigned char *digest, reflink_state state);
|
|
|
7b1d93 |
|
|
|
7b1d93 |
rpm_loff_t find(const unsigned char *digest, reflink_state state) {
|
|
|
7b1d93 |
-# if defined(__GNUC__)
|
|
|
7b1d93 |
- /* GCC nested function because bsearch's comparison function can't access
|
|
|
7b1d93 |
- * state-keysize otherwise
|
|
|
7b1d93 |
- */
|
|
|
7b1d93 |
- int cmpdigest(const void *k1, const void *k2) {
|
|
|
7b1d93 |
- rpmlog(RPMLOG_DEBUG, _("reflink: cmpdigest k1=%p k2=%p\n"), k1, k2);
|
|
|
7b1d93 |
- return memcmp(k1, k2, state->keysize);
|
|
|
7b1d93 |
- }
|
|
|
7b1d93 |
-# endif
|
|
|
7b1d93 |
rpmlog(RPMLOG_DEBUG,
|
|
|
7b1d93 |
- _("reflink: bsearch(key=%p, base=%p, nmemb=%d, size=%lu)\n"),
|
|
|
7b1d93 |
+ _("reflink: bsearch_r(key=%p, base=%p, nmemb=%d, size=%lu)\n"),
|
|
|
7b1d93 |
digest, state->table, state->keys,
|
|
|
7b1d93 |
state->keysize + sizeof(rpm_loff_t));
|
|
|
7b1d93 |
- char *entry = bsearch(digest, state->table, state->keys,
|
|
|
7b1d93 |
- state->keysize + sizeof(rpm_loff_t), cmpdigest);
|
|
|
7b1d93 |
+ char *entry = bsearch_r(digest, state->table, state->keys,
|
|
|
7b1d93 |
+ state->keysize + sizeof(rpm_loff_t), cmpdigest,
|
|
|
7b1d93 |
+ &state->keysize);
|
|
|
7b1d93 |
if (entry == NULL) {
|
|
|
7b1d93 |
return NOT_FOUND;
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
@@ -239,13 +256,13 @@ rpm_loff_t find(const unsigned char *digest, reflink_state state) {
|
|
|
732e02 |
return offset;
|
|
|
732e02 |
}
|
|
|
732e02 |
|
|
|
732e02 |
-static rpmRC reflink_fsm_file_pre(rpmPlugin plugin, rpmfi fi, const char* path,
|
|
|
732e02 |
+static rpmRC reflink_fsm_file_install(rpmPlugin plugin, rpmfi fi, const char* path,
|
|
|
732e02 |
mode_t file_mode, rpmFsmOp op)
|
|
|
732e02 |
{
|
|
|
732e02 |
struct file_clone_range fcr;
|
|
|
592a09 |
rpm_loff_t size;
|
|
|
592a09 |
int dst, rc;
|
|
|
592a09 |
- int *hlix;
|
|
|
592a09 |
+ const char **hl_target = NULL;
|
|
|
592a09 |
|
|
|
592a09 |
reflink_state state = rpmPluginGetData(plugin);
|
|
|
592a09 |
if (state->table == NULL) {
|
|
|
7b1d93 |
@@ -262,18 +279,15 @@ static rpmRC reflink_fsm_file_pre(rpmPlugin plugin, rpmfi fi, const char* path,
|
|
|
592a09 |
/* check for hard link entry in table. GetEntry overwrites hlix with
|
|
|
592a09 |
* the address of the first match.
|
|
|
592a09 |
*/
|
|
|
592a09 |
- if (inodeIndexHashGetEntry(state->inodeIndexes, inode, &hlix, NULL,
|
|
|
592a09 |
- NULL)) {
|
|
|
592a09 |
+ if (inodeIndexHashGetEntry(state->inodeIndexes, inode, &hl_target,
|
|
|
592a09 |
+ NULL, NULL)) {
|
|
|
592a09 |
/* entry is in table, use hard link */
|
|
|
592a09 |
- char *fn = rpmfilesFN(state->files, hlix[0]);
|
|
|
592a09 |
- if (link(fn, path) != 0) {
|
|
|
592a09 |
+ if (link(hl_target[0], path) != 0) {
|
|
|
592a09 |
rpmlog(RPMLOG_ERR,
|
|
|
592a09 |
_("reflink: Unable to hard link %s -> %s due to %s\n"),
|
|
|
592a09 |
- fn, path, strerror(errno));
|
|
|
592a09 |
- free(fn);
|
|
|
592a09 |
+ hl_target[0], path, strerror(errno));
|
|
|
592a09 |
return RPMRC_FAIL;
|
|
|
592a09 |
}
|
|
|
592a09 |
- free(fn);
|
|
|
592a09 |
return RPMRC_PLUGIN_CONTENTS;
|
|
|
592a09 |
}
|
|
|
592a09 |
/* if we didn't hard link, then we'll track this inode as being
|
|
|
7b1d93 |
@@ -281,7 +295,7 @@ static rpmRC reflink_fsm_file_pre(rpmPlugin plugin, rpmfi fi, const char* path,
|
|
|
592a09 |
*/
|
|
|
592a09 |
if (rpmfiFNlink(fi) > 1) {
|
|
|
592a09 |
/* minor optimization: only store files with more than one link */
|
|
|
592a09 |
- inodeIndexHashAddEntry(state->inodeIndexes, inode, rpmfiFX(fi));
|
|
|
592a09 |
+ inodeIndexHashAddEntry(state->inodeIndexes, inode, rstrdup(path));
|
|
|
592a09 |
}
|
|
|
592a09 |
/* derived from wfd_open in fsm.c */
|
|
|
592a09 |
mode_t old_umask = umask(0577);
|
|
|
7b1d93 |
@@ -366,10 +380,21 @@ static rpmRC reflink_fsm_file_pre(rpmPlugin plugin, rpmfi fi, const char* path,
|
|
|
732e02 |
return RPMRC_OK;
|
|
|
732e02 |
}
|
|
|
732e02 |
|
|
|
732e02 |
+static rpmRC reflink_fsm_file_archive_reader(rpmPlugin plugin, FD_t payload,
|
|
|
732e02 |
+ rpmfiles files, rpmfi *fi) {
|
|
|
732e02 |
+ reflink_state state = rpmPluginGetData(plugin);
|
|
|
732e02 |
+ if(state->transcoded) {
|
|
|
732e02 |
+ *fi = rpmfilesIter(files, RPMFI_ITER_FWD);
|
|
|
732e02 |
+ return RPMRC_PLUGIN_CONTENTS;
|
|
|
732e02 |
+ }
|
|
|
732e02 |
+ return RPMRC_OK;
|
|
|
732e02 |
+}
|
|
|
732e02 |
+
|
|
|
732e02 |
struct rpmPluginHooks_s reflink_hooks = {
|
|
|
732e02 |
.init = reflink_init,
|
|
|
732e02 |
.cleanup = reflink_cleanup,
|
|
|
732e02 |
.psm_pre = reflink_psm_pre,
|
|
|
732e02 |
.psm_post = reflink_psm_post,
|
|
|
732e02 |
- .fsm_file_pre = reflink_fsm_file_pre,
|
|
|
732e02 |
+ .fsm_file_install = reflink_fsm_file_install,
|
|
|
732e02 |
+ .fsm_file_archive_reader = reflink_fsm_file_archive_reader,
|
|
|
732e02 |
};
|
|
|
621668 |
diff --git a/rpm2extents.c b/rpm2extents.c
|
|
|
7b1d93 |
index c111be0a2..7dd5128de 100644
|
|
|
621668 |
--- a/rpm2extents.c
|
|
|
621668 |
+++ b/rpm2extents.c
|
|
|
621668 |
@@ -2,7 +2,9 @@
|
|
|
621668 |
|
|
|
621668 |
#include "system.h"
|
|
|
621668 |
|
|
|
621668 |
+#include <rpm/rpmcli.h>
|
|
|
621668 |
#include <rpm/rpmlib.h> /* rpmReadPackageFile .. */
|
|
|
621668 |
+#include <rpm/rpmlog.h>
|
|
|
621668 |
#include <rpm/rpmfi.h>
|
|
|
621668 |
#include <rpm/rpmtag.h>
|
|
|
621668 |
#include <rpm/rpmio.h>
|
|
|
732e02 |
@@ -10,8 +12,10 @@
|
|
|
621668 |
|
|
|
621668 |
#include <rpm/rpmts.h>
|
|
|
621668 |
#include "lib/rpmlead.h"
|
|
|
621668 |
+#include "lib/rpmts.h"
|
|
|
621668 |
#include "lib/signature.h"
|
|
|
621668 |
#include "lib/header_internal.h"
|
|
|
732e02 |
+#include "lib/rpmextents_internal.h"
|
|
|
621668 |
#include "rpmio/rpmio_internal.h"
|
|
|
732e02 |
|
|
|
732e02 |
#include <unistd.h>
|
|
|
732e02 |
@@ -34,11 +38,6 @@
|
|
|
732e02 |
#include "lib/rpmhash.H"
|
|
|
732e02 |
#include "lib/rpmhash.C"
|
|
|
732e02 |
|
|
|
732e02 |
-/* magic value at end of file (64 bits) that indicates this is a transcoded
|
|
|
732e02 |
- * rpm.
|
|
|
732e02 |
- */
|
|
|
732e02 |
-#define MAGIC 3472329499408095051
|
|
|
732e02 |
-
|
|
|
732e02 |
struct digestoffset {
|
|
|
732e02 |
const unsigned char * digest;
|
|
|
732e02 |
rpm_loff_t pos;
|
|
|
7b1d93 |
@@ -51,38 +50,49 @@ rpm_loff_t pad_to(rpm_loff_t pos, rpm_loff_t unit)
|
|
|
621668 |
return (unit - (pos % unit)) % unit;
|
|
|
621668 |
}
|
|
|
621668 |
|
|
|
621668 |
-static int digestor(
|
|
|
621668 |
+static struct poptOption optionsTable[] = {
|
|
|
621668 |
+ { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
|
|
|
621668 |
+ N_("Common options for all rpm modes and executables:"), NULL },
|
|
|
621668 |
+
|
|
|
621668 |
+ POPT_AUTOALIAS
|
|
|
621668 |
+ POPT_AUTOHELP
|
|
|
621668 |
+ POPT_TABLEEND
|
|
|
621668 |
+};
|
|
|
621668 |
+
|
|
|
621668 |
+
|
|
|
621668 |
+static void FDDigestInit(FD_t fdi, uint8_t algos[], uint32_t algos_len){
|
|
|
621668 |
+ int algo;
|
|
|
621668 |
+
|
|
|
621668 |
+ for (algo = 0; algo < algos_len; algo++) {
|
|
|
621668 |
+ fdInitDigest(fdi, algos[algo], 0);
|
|
|
621668 |
+ }
|
|
|
621668 |
+}
|
|
|
621668 |
+
|
|
|
621668 |
+static int FDWriteDigests(
|
|
|
621668 |
FD_t fdi,
|
|
|
621668 |
FD_t fdo,
|
|
|
621668 |
- FD_t validationo,
|
|
|
621668 |
uint8_t algos[],
|
|
|
621668 |
- uint32_t algos_len
|
|
|
621668 |
-)
|
|
|
621668 |
+ uint32_t algos_len)
|
|
|
621668 |
{
|
|
|
621668 |
- ssize_t fdilength;
|
|
|
621668 |
const char *filedigest, *algo_name;
|
|
|
621668 |
size_t filedigest_len, len;
|
|
|
621668 |
uint32_t algo_name_len, algo_digest_len;
|
|
|
621668 |
int algo;
|
|
|
621668 |
rpmRC rc = RPMRC_FAIL;
|
|
|
621668 |
|
|
|
621668 |
- for (algo = 0; algo < algos_len; algo++) {
|
|
|
621668 |
- fdInitDigest(fdi, algos[algo], 0);
|
|
|
621668 |
- }
|
|
|
621668 |
- fdilength = ufdCopy(fdi, fdo);
|
|
|
621668 |
- if (fdilength == -1) {
|
|
|
621668 |
- fprintf(stderr, _("digest cat failed\n"));
|
|
|
621668 |
- goto exit;
|
|
|
621668 |
- }
|
|
|
621668 |
+ ssize_t fdilength = fdOp(fdi, FDSTAT_READ)->bytes;
|
|
|
621668 |
|
|
|
621668 |
len = sizeof(fdilength);
|
|
|
621668 |
- if (Fwrite(&fdilength, len, 1, validationo) != len) {
|
|
|
7b1d93 |
- fprintf(stderr, _("Unable to write input length %zd\n"), fdilength);
|
|
|
621668 |
+ if (Fwrite(&fdilength, len, 1, fdo) != len) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Unable to write input length %zd: %d, %s\n"),
|
|
|
7b1d93 |
+ fdilength, errno, strerror(errno));
|
|
|
621668 |
goto exit;
|
|
|
621668 |
}
|
|
|
621668 |
len = sizeof(algos_len);
|
|
|
621668 |
- if (Fwrite(&algos_len, len, 1, validationo) != len) {
|
|
|
621668 |
- fprintf(stderr, _("Unable to write number of validation digests\n"));
|
|
|
621668 |
+ if (Fwrite(&algos_len, len, 1, fdo) != len) {
|
|
|
621668 |
+ algo_digest_len = (uint32_t)filedigest_len;
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Unable to write number of digests: %d, %s\n"),
|
|
|
7b1d93 |
+ errno, strerror(errno));
|
|
|
621668 |
goto exit;
|
|
|
621668 |
}
|
|
|
621668 |
for (algo = 0; algo < algos_len; algo++) {
|
|
|
7b1d93 |
@@ -93,25 +103,29 @@ static int digestor(
|
|
|
621668 |
algo_digest_len = (uint32_t)filedigest_len;
|
|
|
621668 |
|
|
|
621668 |
len = sizeof(algo_name_len);
|
|
|
621668 |
- if (Fwrite(&algo_name_len, len, 1, validationo) != len) {
|
|
|
7b1d93 |
- fprintf(stderr,
|
|
|
621668 |
- _("Unable to write validation algo name length\n"));
|
|
|
7b1d93 |
+ if (Fwrite(&algo_name_len, len, 1, fdo) != len) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR,
|
|
|
7b1d93 |
+ _("Unable to write digest algo name length: %d, %s\n"),
|
|
|
7b1d93 |
+ errno, strerror(errno));
|
|
|
621668 |
goto exit;
|
|
|
621668 |
}
|
|
|
621668 |
len = sizeof(algo_digest_len);
|
|
|
621668 |
- if (Fwrite(&algo_digest_len, len, 1, validationo) != len) {
|
|
|
7b1d93 |
- fprintf(stderr,
|
|
|
621668 |
- _("Unable to write number of bytes for validation digest\n"));
|
|
|
7b1d93 |
+ if (Fwrite(&algo_digest_len, len, 1, fdo) != len) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR,
|
|
|
7b1d93 |
+ _("Unable to write number of bytes for digest: %d, %s\n"),
|
|
|
7b1d93 |
+ errno, strerror(errno));
|
|
|
621668 |
goto exit;
|
|
|
621668 |
}
|
|
|
621668 |
- if (Fwrite(algo_name, algo_name_len, 1, validationo) != algo_name_len) {
|
|
|
621668 |
- fprintf(stderr, _("Unable to write validation algo name\n"));
|
|
|
621668 |
+ if (Fwrite(algo_name, algo_name_len, 1, fdo) != algo_name_len) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Unable to write digest algo name: %d, %s\n"),
|
|
|
7b1d93 |
+ errno, strerror(errno));
|
|
|
621668 |
goto exit;
|
|
|
621668 |
}
|
|
|
621668 |
- if (Fwrite(filedigest, algo_digest_len, 1, validationo ) != algo_digest_len) {
|
|
|
7b1d93 |
- fprintf(stderr,
|
|
|
621668 |
- _("Unable to write validation digest value %u, %zu\n"),
|
|
|
7b1d93 |
- algo_digest_len, filedigest_len);
|
|
|
7b1d93 |
+ if (Fwrite(filedigest, algo_digest_len, 1, fdo ) != algo_digest_len) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR,
|
|
|
7b1d93 |
+ _("Unable to write digest value %u, %zu: %d, %s\n"),
|
|
|
7b1d93 |
+ algo_digest_len, filedigest_len,
|
|
|
7b1d93 |
+ errno, strerror(errno));
|
|
|
621668 |
goto exit;
|
|
|
621668 |
}
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
@@ -120,7 +134,80 @@ static int digestor(
|
|
|
621668 |
return rc;
|
|
|
621668 |
}
|
|
|
621668 |
|
|
|
621668 |
-static rpmRC process_package(FD_t fdi, FD_t validationi)
|
|
|
621668 |
+static rpmRC FDWriteSignaturesValidation(FD_t fdo, int rpmvsrc, char *msg) {
|
|
|
621668 |
+ size_t len;
|
|
|
621668 |
+ rpmRC rc = RPMRC_FAIL;
|
|
|
621668 |
+
|
|
|
621668 |
+ if(rpmvsrc){
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_WARNING,
|
|
|
7b1d93 |
+ _("Error verifying package signatures:\n%s\n"), msg);
|
|
|
621668 |
+ }
|
|
|
621668 |
+
|
|
|
621668 |
+ len = sizeof(rpmvsrc);
|
|
|
621668 |
+ if (Fwrite(&rpmvsrc, len, 1, fdo) != len) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR,
|
|
|
7b1d93 |
+ _("Unable to write signature verification RC code %d: %d, %s\n"),
|
|
|
7b1d93 |
+ rpmvsrc, errno, strerror(errno));
|
|
|
621668 |
+ goto exit;
|
|
|
621668 |
+ }
|
|
|
621668 |
+ size_t content_len = msg ? strlen(msg) : 0;
|
|
|
621668 |
+ len = sizeof(content_len);
|
|
|
621668 |
+ if (Fwrite(&content_len, len, 1, fdo) != len) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR,
|
|
|
7b1d93 |
+ _("Unable to write signature verification output length %zd: %d, %s\n"),
|
|
|
7b1d93 |
+ content_len, errno, strerror(errno));
|
|
|
621668 |
+ goto exit;
|
|
|
621668 |
+ }
|
|
|
621668 |
+ if (Fwrite(msg, content_len, 1, fdo) != content_len) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR,
|
|
|
7b1d93 |
+ _("Unable to write signature verification output %s: %d, %s\n"),
|
|
|
7b1d93 |
+ msg, errno, strerror(errno));
|
|
|
621668 |
+ goto exit;
|
|
|
621668 |
+ }
|
|
|
621668 |
+
|
|
|
621668 |
+ rc = RPMRC_OK;
|
|
|
621668 |
+exit:
|
|
|
621668 |
+
|
|
|
621668 |
+ return rc;
|
|
|
621668 |
+}
|
|
|
621668 |
+
|
|
|
621668 |
+static rpmRC validator(FD_t fdi, FD_t digesto, FD_t sigo,
|
|
|
621668 |
+ uint8_t algos[],
|
|
|
621668 |
+ uint32_t algos_len){
|
|
|
621668 |
+ int rpmvsrc;
|
|
|
621668 |
+ rpmRC rc = RPMRC_FAIL;
|
|
|
621668 |
+ char *msg = NULL;
|
|
|
621668 |
+ rpmts ts = rpmtsCreate();
|
|
|
621668 |
+
|
|
|
621668 |
+ rpmtsSetRootDir(ts, rpmcliRootDir);
|
|
|
621668 |
+
|
|
|
621668 |
+ FDDigestInit(fdi, algos, algos_len);
|
|
|
621668 |
+
|
|
|
621668 |
+ rpmvsrc = rpmcliVerifySignaturesFD(ts, fdi, &msg;;
|
|
|
621668 |
+
|
|
|
621668 |
+ // Write result of digest computation
|
|
|
621668 |
+ if(FDWriteDigests(fdi, digesto, algos, algos_len) != RPMRC_OK) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Failed to write digests: %d, %s\n"),
|
|
|
7b1d93 |
+ errno, strerror(errno));
|
|
|
621668 |
+ goto exit;
|
|
|
621668 |
+ }
|
|
|
621668 |
+
|
|
|
621668 |
+ // Write result of signature validation.
|
|
|
621668 |
+ if(FDWriteSignaturesValidation(sigo, rpmvsrc, msg)) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR,
|
|
|
7b1d93 |
+ _("Failed to write signature verification result: %d, %s\n"),
|
|
|
7b1d93 |
+ errno, strerror(errno));
|
|
|
621668 |
+ goto exit;
|
|
|
621668 |
+ }
|
|
|
621668 |
+ rc = RPMRC_OK;
|
|
|
621668 |
+exit:
|
|
|
621668 |
+ if(msg) {
|
|
|
621668 |
+ free(msg);
|
|
|
621668 |
+ }
|
|
|
621668 |
+ return rc;
|
|
|
621668 |
+}
|
|
|
621668 |
+
|
|
|
621668 |
+static rpmRC process_package(FD_t fdi, FD_t digestori, FD_t validationi)
|
|
|
621668 |
{
|
|
|
621668 |
uint32_t diglen;
|
|
|
621668 |
/* GNU C extension: can use diglen from outer context */
|
|
|
7b1d93 |
@@ -148,7 +235,7 @@ static rpmRC process_package(FD_t fdi, FD_t validationi)
|
|
|
621668 |
rpm_mode_t mode;
|
|
|
621668 |
char *rpmio_flags = NULL, *zeros;
|
|
|
621668 |
const unsigned char *digest;
|
|
|
621668 |
- rpm_loff_t pos, size, pad, validation_pos;
|
|
|
621668 |
+ rpm_loff_t pos, size, pad, digest_pos, validation_pos, digest_table_pos;
|
|
|
621668 |
uint32_t offset_ix = 0;
|
|
|
621668 |
size_t len;
|
|
|
621668 |
int next = 0;
|
|
|
7b1d93 |
@@ -156,24 +243,24 @@ static rpmRC process_package(FD_t fdi, FD_t validationi)
|
|
|
7b1d93 |
fdo = fdDup(STDOUT_FILENO);
|
|
|
7b1d93 |
|
|
|
7b1d93 |
if (rpmReadPackageRaw(fdi, &sigh, &h)) {
|
|
|
7b1d93 |
- fprintf(stderr, _("Error reading package\n"));
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Error reading package\n"));
|
|
|
7b1d93 |
exit(EXIT_FAILURE);
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
|
|
|
7b1d93 |
if (rpmLeadWrite(fdo, h))
|
|
|
7b1d93 |
{
|
|
|
7b1d93 |
- fprintf(stderr, _("Unable to write package lead: %s\n"),
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Unable to write package lead: %s\n"),
|
|
|
7b1d93 |
Fstrerror(fdo));
|
|
|
7b1d93 |
exit(EXIT_FAILURE);
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
|
|
|
7b1d93 |
if (rpmWriteSignature(fdo, sigh)) {
|
|
|
7b1d93 |
- fprintf(stderr, _("Unable to write signature: %s\n"), Fstrerror(fdo));
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Unable to write signature: %s\n"), Fstrerror(fdo));
|
|
|
7b1d93 |
exit(EXIT_FAILURE);
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
|
|
|
7b1d93 |
if (headerWrite(fdo, h, HEADER_MAGIC_YES)) {
|
|
|
7b1d93 |
- fprintf(stderr, _("Unable to write headers: %s\n"), Fstrerror(fdo));
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Unable to write headers: %s\n"), Fstrerror(fdo));
|
|
|
7b1d93 |
exit(EXIT_FAILURE);
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
|
|
|
7b1d93 |
@@ -187,7 +274,7 @@ static rpmRC process_package(FD_t fdi, FD_t validationi)
|
|
|
7b1d93 |
free(rpmio_flags);
|
|
|
7b1d93 |
|
|
|
7b1d93 |
if (gzdi == NULL) {
|
|
|
7b1d93 |
- fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi));
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("cannot re-open payload: %s\n"), Fstrerror(gzdi));
|
|
|
7b1d93 |
exit(EXIT_FAILURE);
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
|
|
|
7b1d93 |
@@ -230,7 +317,7 @@ static rpmRC process_package(FD_t fdi, FD_t validationi)
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
pad = pad_to(pos, fundamental_block_size);
|
|
|
7b1d93 |
if (Fwrite(zeros, sizeof(char), pad, fdo) != pad) {
|
|
|
7b1d93 |
- fprintf(stderr, _("Unable to write padding\n"));
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Unable to write padding\n"));
|
|
|
7b1d93 |
rc = RPMRC_FAIL;
|
|
|
7b1d93 |
goto exit;
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
@@ -243,7 +330,12 @@ static rpmRC process_package(FD_t fdi, FD_t validationi)
|
|
|
7b1d93 |
size = rpmfiFSize(fi);
|
|
|
7b1d93 |
rc = rpmfiArchiveReadToFile(fi, fdo, 0);
|
|
|
7b1d93 |
if (rc != RPMRC_OK) {
|
|
|
7b1d93 |
- fprintf(stderr, _("rpmfiArchiveReadToFile failed with %d\n"), rc);
|
|
|
7b1d93 |
+ char *errstr = rpmfileStrerror(rc);
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR,
|
|
|
7b1d93 |
+ _("rpmfiArchiveReadToFile failed while extracting "\
|
|
|
7b1d93 |
+ "\"%s\" with RC %d: %s\n"),
|
|
|
7b1d93 |
+ rpmfiFN(fi), rc, errstr);
|
|
|
7b1d93 |
+ free(errstr);
|
|
|
7b1d93 |
goto exit;
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
pos += size;
|
|
|
7b1d93 |
@@ -253,42 +345,53 @@ static rpmRC process_package(FD_t fdi, FD_t validationi)
|
|
|
621668 |
qsort(offsets, (size_t)offset_ix, sizeof(struct digestoffset),
|
|
|
621668 |
digestoffsetCmp);
|
|
|
621668 |
|
|
|
621668 |
+ validation_pos = pos;
|
|
|
621668 |
+ ssize_t validation_len = ufdCopy(validationi, fdo);
|
|
|
621668 |
+ if (validation_len == -1) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("validation output ufdCopy failed\n"));
|
|
|
621668 |
+ rc = RPMRC_FAIL;
|
|
|
621668 |
+ goto exit;
|
|
|
621668 |
+ }
|
|
|
621668 |
+
|
|
|
621668 |
+ digest_table_pos = validation_pos + validation_len;
|
|
|
621668 |
+
|
|
|
621668 |
len = sizeof(offset_ix);
|
|
|
621668 |
if (Fwrite(&offset_ix, len, 1, fdo) != len) {
|
|
|
7b1d93 |
- fprintf(stderr, _("Unable to write length of table\n"));
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Unable to write length of table\n"));
|
|
|
7b1d93 |
rc = RPMRC_FAIL;
|
|
|
7b1d93 |
goto exit;
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
len = sizeof(diglen);
|
|
|
7b1d93 |
if (Fwrite(&diglen, len, 1, fdo) != len) {
|
|
|
7b1d93 |
- fprintf(stderr, _("Unable to write length of digest\n"));
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Unable to write length of digest\n"));
|
|
|
7b1d93 |
rc = RPMRC_FAIL;
|
|
|
7b1d93 |
goto exit;
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
len = sizeof(rpm_loff_t);
|
|
|
7b1d93 |
for (int x = 0; x < offset_ix; x++) {
|
|
|
7b1d93 |
if (Fwrite(offsets[x].digest, diglen, 1, fdo) != diglen) {
|
|
|
7b1d93 |
- fprintf(stderr, _("Unable to write digest\n"));
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Unable to write digest\n"));
|
|
|
7b1d93 |
rc = RPMRC_FAIL;
|
|
|
7b1d93 |
goto exit;
|
|
|
7b1d93 |
}
|
|
|
7b1d93 |
if (Fwrite(&offsets[x].pos, len, 1, fdo) != len) {
|
|
|
7b1d93 |
- fprintf(stderr, _("Unable to write offset\n"));
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Unable to write offset\n"));
|
|
|
7b1d93 |
rc = RPMRC_FAIL;
|
|
|
621668 |
goto exit;
|
|
|
621668 |
}
|
|
|
621668 |
}
|
|
|
621668 |
- validation_pos = (
|
|
|
621668 |
- pos + sizeof(offset_ix) + sizeof(diglen) +
|
|
|
621668 |
+ digest_pos = (
|
|
|
621668 |
+ digest_table_pos + sizeof(offset_ix) + sizeof(diglen) +
|
|
|
621668 |
offset_ix * (diglen + sizeof(rpm_loff_t))
|
|
|
621668 |
);
|
|
|
621668 |
|
|
|
621668 |
- ssize_t validation_len = ufdCopy(validationi, fdo);
|
|
|
621668 |
- if (validation_len == -1) {
|
|
|
7b1d93 |
- fprintf(stderr, _("digest table ufdCopy failed\n"));
|
|
|
621668 |
+ ssize_t digest_len = ufdCopy(digestori, fdo);
|
|
|
621668 |
+ if (digest_len == -1) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("digest table ufdCopy failed\n"));
|
|
|
621668 |
rc = RPMRC_FAIL;
|
|
|
621668 |
goto exit;
|
|
|
621668 |
}
|
|
|
621668 |
+
|
|
|
621668 |
/* add more padding so the last file can be cloned. It doesn't matter that
|
|
|
621668 |
* the table and validation etc are in this space. In fact, it's pretty
|
|
|
621668 |
* efficient if it is.
|
|
|
7b1d93 |
@@ -297,25 +400,15 @@ static rpmRC process_package(FD_t fdi, FD_t validationi)
|
|
|
7b1d93 |
pad = pad_to((validation_pos + validation_len + 2 * sizeof(rpm_loff_t) +
|
|
|
7b1d93 |
sizeof(uint64_t)), fundamental_block_size);
|
|
|
7b1d93 |
if (Fwrite(zeros, sizeof(char), pad, fdo) != pad) {
|
|
|
7b1d93 |
- fprintf(stderr, _("Unable to write final padding\n"));
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Unable to write final padding\n"));
|
|
|
7b1d93 |
rc = RPMRC_FAIL;
|
|
|
621668 |
goto exit;
|
|
|
621668 |
}
|
|
|
621668 |
zeros = _free(zeros);
|
|
|
621668 |
- if (Fwrite(&pos, len, 1, fdo) != len) {
|
|
|
7b1d93 |
- fprintf(stderr, _("Unable to write offset of digest table\n"));
|
|
|
7b1d93 |
- rc = RPMRC_FAIL;
|
|
|
7b1d93 |
- goto exit;
|
|
|
7b1d93 |
- }
|
|
|
621668 |
- if (Fwrite(&validation_pos, len, 1, fdo) != len) {
|
|
|
7b1d93 |
- fprintf(stderr, _("Unable to write offset of validation table\n"));
|
|
|
7b1d93 |
- rc = RPMRC_FAIL;
|
|
|
7b1d93 |
- goto exit;
|
|
|
7b1d93 |
- }
|
|
|
7b1d93 |
- uint64_t magic = MAGIC;
|
|
|
7b1d93 |
- len = sizeof(magic);
|
|
|
7b1d93 |
- if (Fwrite(&magic, len, 1, fdo) != len) {
|
|
|
7b1d93 |
- fprintf(stderr, _("Unable to write magic\n"));
|
|
|
7b1d93 |
+ struct extents_footer_t footer = {.offsets = {validation_pos, digest_table_pos, digest_pos}, .magic = EXTENTS_MAGIC};
|
|
|
7b1d93 |
+ len = sizeof(footer);
|
|
|
7b1d93 |
+ if (Fwrite(&footer, len, 1, fdo) != len) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Unable to write footer\n"));
|
|
|
621668 |
rc = RPMRC_FAIL;
|
|
|
621668 |
goto exit;
|
|
|
732e02 |
}
|
|
|
7b1d93 |
@@ -327,104 +420,202 @@ static rpmRC process_package(FD_t fdi, FD_t validationi)
|
|
|
621668 |
return rc;
|
|
|
621668 |
}
|
|
|
621668 |
|
|
|
621668 |
-int main(int argc, char *argv[]) {
|
|
|
621668 |
- rpmRC rc;
|
|
|
621668 |
- int cprc = 0;
|
|
|
621668 |
- uint8_t algos[argc - 1];
|
|
|
621668 |
- int mainpipefd[2];
|
|
|
621668 |
- int metapipefd[2];
|
|
|
621668 |
- pid_t cpid, w;
|
|
|
621668 |
- int wstatus;
|
|
|
621668 |
+static off_t ufdTee(FD_t sfd, FD_t *fds, int len)
|
|
|
621668 |
+{
|
|
|
621668 |
+ char buf[BUFSIZ];
|
|
|
621668 |
+ ssize_t rdbytes, wrbytes;
|
|
|
621668 |
+ off_t total = 0;
|
|
|
621668 |
+
|
|
|
621668 |
+ while (1) {
|
|
|
621668 |
+ rdbytes = Fread(buf, sizeof(buf[0]), sizeof(buf), sfd);
|
|
|
621668 |
+
|
|
|
621668 |
+ if (rdbytes > 0) {
|
|
|
621668 |
+ for(int i=0; i < len; i++) {
|
|
|
621668 |
+ wrbytes = Fwrite(buf, sizeof(buf[0]), rdbytes, fds[i]);
|
|
|
621668 |
+ if (wrbytes != rdbytes) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR,
|
|
|
7b1d93 |
+ _("Error wriing to FD %d: %s\n"),
|
|
|
7b1d93 |
+ i, Fstrerror(fds[i]));
|
|
|
621668 |
+ total = -1;
|
|
|
621668 |
+ break;
|
|
|
621668 |
+ }
|
|
|
621668 |
+ }
|
|
|
621668 |
+ if(total == -1){
|
|
|
621668 |
+ break;
|
|
|
621668 |
+ }
|
|
|
621668 |
+ total += wrbytes;
|
|
|
621668 |
+ } else {
|
|
|
621668 |
+ if (rdbytes < 0)
|
|
|
621668 |
+ total = -1;
|
|
|
621668 |
+ break;
|
|
|
621668 |
+ }
|
|
|
621668 |
+ }
|
|
|
621668 |
|
|
|
621668 |
- xsetprogname(argv[0]); /* Portability call -- see system.h */
|
|
|
621668 |
- rpmReadConfigFiles(NULL, NULL);
|
|
|
621668 |
+ return total;
|
|
|
621668 |
+}
|
|
|
621668 |
|
|
|
621668 |
- if (argc > 1 && (rstreq(argv[1], "-h") || rstreq(argv[1], "--help"))) {
|
|
|
621668 |
- fprintf(stderr, _("Usage: %s [DIGESTALGO]...\n"), argv[0]);
|
|
|
621668 |
- exit(EXIT_FAILURE);
|
|
|
621668 |
- }
|
|
|
621668 |
+static rpmRC teeRpm(FD_t fdi, uint8_t algos[], uint32_t algos_len) {
|
|
|
621668 |
+ rpmRC rc = RPMRC_FAIL;
|
|
|
621668 |
+ off_t offt = -1;
|
|
|
621668 |
+ // tee-ed stdin
|
|
|
621668 |
+ int processorpipefd[2];
|
|
|
621668 |
+ int validatorpipefd[2];
|
|
|
621668 |
+ // metadata
|
|
|
621668 |
+ int meta_digestpipefd[2];
|
|
|
621668 |
+ int meta_rpmsignpipefd[2];
|
|
|
621668 |
+
|
|
|
621668 |
+ pid_t cpids[2], w;
|
|
|
621668 |
+ int wstatus;
|
|
|
621668 |
+ FD_t fds[2];
|
|
|
621668 |
|
|
|
621668 |
- if (argc == 1) {
|
|
|
621668 |
- fprintf(stderr,
|
|
|
621668 |
- _("Need at least one DIGESTALGO parameter, e.g. 'SHA256'\n"));
|
|
|
621668 |
- exit(EXIT_FAILURE);
|
|
|
621668 |
+ if (pipe(processorpipefd) == -1) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Processor pipe failure\n"));
|
|
|
621668 |
+ return RPMRC_FAIL;
|
|
|
621668 |
}
|
|
|
621668 |
|
|
|
621668 |
- for (int x = 0; x < (argc - 1); x++) {
|
|
|
621668 |
- if (pgpStringVal(PGPVAL_HASHALGO, argv[x + 1], &algos[x]) != 0)
|
|
|
621668 |
- {
|
|
|
621668 |
- fprintf(stderr,
|
|
|
621668 |
- _("Unable to resolve '%s' as a digest algorithm, exiting\n"),
|
|
|
621668 |
- argv[x + 1]);
|
|
|
621668 |
- exit(EXIT_FAILURE);
|
|
|
621668 |
- }
|
|
|
621668 |
+ if (pipe(validatorpipefd) == -1) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Validator pipe failure\n"));
|
|
|
621668 |
+ return RPMRC_FAIL;
|
|
|
621668 |
}
|
|
|
621668 |
|
|
|
621668 |
-
|
|
|
621668 |
- if (pipe(mainpipefd) == -1) {
|
|
|
621668 |
- fprintf(stderr, _("Main pipe failure\n"));
|
|
|
621668 |
- exit(EXIT_FAILURE);
|
|
|
621668 |
+ if (pipe(meta_digestpipefd) == -1) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Meta digest pipe failure\n"));
|
|
|
621668 |
+ return RPMRC_FAIL;
|
|
|
621668 |
}
|
|
|
621668 |
- if (pipe(metapipefd) == -1) {
|
|
|
621668 |
- fprintf(stderr, _("Meta pipe failure\n"));
|
|
|
621668 |
- exit(EXIT_FAILURE);
|
|
|
621668 |
+
|
|
|
621668 |
+ if (pipe(meta_rpmsignpipefd) == -1) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Meta rpm signature pipe failure\n"));
|
|
|
621668 |
+ return RPMRC_FAIL;
|
|
|
621668 |
}
|
|
|
621668 |
- cpid = fork();
|
|
|
621668 |
- if (cpid == 0) {
|
|
|
621668 |
- /* child: digestor */
|
|
|
621668 |
- close(mainpipefd[0]);
|
|
|
621668 |
- close(metapipefd[0]);
|
|
|
621668 |
- FD_t fdi = fdDup(STDIN_FILENO);
|
|
|
621668 |
- FD_t fdo = fdDup(mainpipefd[1]);
|
|
|
621668 |
- FD_t validationo = fdDup(metapipefd[1]);
|
|
|
621668 |
- rc = digestor(fdi, fdo, validationo, algos, argc - 1);
|
|
|
621668 |
- Fclose(validationo);
|
|
|
621668 |
- Fclose(fdo);
|
|
|
621668 |
+
|
|
|
621668 |
+ cpids[0] = fork();
|
|
|
621668 |
+ if (cpids[0] == 0) {
|
|
|
621668 |
+ /* child: validator */
|
|
|
621668 |
+ close(processorpipefd[0]);
|
|
|
621668 |
+ close(processorpipefd[1]);
|
|
|
621668 |
+ close(validatorpipefd[1]);
|
|
|
621668 |
+ close(meta_digestpipefd[0]);
|
|
|
621668 |
+ close(meta_rpmsignpipefd[0]);
|
|
|
621668 |
+ FD_t fdi = fdDup(validatorpipefd[0]);
|
|
|
621668 |
+ FD_t digesto = fdDup(meta_digestpipefd[1]);
|
|
|
621668 |
+ FD_t sigo = fdDup(meta_rpmsignpipefd[1]);
|
|
|
621668 |
+ close(meta_digestpipefd[1]);
|
|
|
621668 |
+ close(meta_rpmsignpipefd[1]);
|
|
|
621668 |
+ rc = validator(fdi, digesto, sigo, algos, algos_len);
|
|
|
621668 |
+ if(rc != RPMRC_OK) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Validator failed with RC %d\n"), rc);
|
|
|
621668 |
+ }
|
|
|
621668 |
Fclose(fdi);
|
|
|
621668 |
+ Fclose(digesto);
|
|
|
621668 |
+ Fclose(sigo);
|
|
|
621668 |
+ if (rc != RPMRC_OK) {
|
|
|
621668 |
+ exit(EXIT_FAILURE);
|
|
|
621668 |
+ }
|
|
|
621668 |
+ exit(EXIT_SUCCESS);
|
|
|
621668 |
} else {
|
|
|
621668 |
/* parent: main program */
|
|
|
621668 |
- close(mainpipefd[1]);
|
|
|
621668 |
- close(metapipefd[1]);
|
|
|
621668 |
- FD_t fdi = fdDup(mainpipefd[0]);
|
|
|
621668 |
- FD_t validationi = fdDup(metapipefd[0]);
|
|
|
621668 |
- rc = process_package(fdi, validationi);
|
|
|
621668 |
- Fclose(validationi);
|
|
|
621668 |
- /* fdi is normally closed through the stacked file gzdi in the
|
|
|
621668 |
- * function.
|
|
|
621668 |
- * Wait for child process (digestor for stdin) to complete.
|
|
|
621668 |
- */
|
|
|
621668 |
- if (rc != RPMRC_OK) {
|
|
|
621668 |
- if (kill(cpid, SIGTERM) != 0) {
|
|
|
621668 |
- fprintf(stderr,
|
|
|
621668 |
- _("Failed to kill digest process when main process failed: %s\n"),
|
|
|
621668 |
- strerror(errno));
|
|
|
621668 |
+ cpids[1] = fork();
|
|
|
621668 |
+ if (cpids[1] == 0) {
|
|
|
621668 |
+ /* child: process_package */
|
|
|
621668 |
+ close(validatorpipefd[0]);
|
|
|
621668 |
+ close(validatorpipefd[1]);
|
|
|
621668 |
+ close(processorpipefd[1]);
|
|
|
621668 |
+ close(meta_digestpipefd[1]);
|
|
|
621668 |
+ close(meta_rpmsignpipefd[1]);
|
|
|
621668 |
+ FD_t fdi = fdDup(processorpipefd[0]);
|
|
|
621668 |
+ close(processorpipefd[0]);
|
|
|
621668 |
+ FD_t sigi = fdDup(meta_rpmsignpipefd[0]);
|
|
|
621668 |
+ close(meta_rpmsignpipefd[0]);
|
|
|
621668 |
+ FD_t digestori = fdDup(meta_digestpipefd[0]);
|
|
|
621668 |
+ close(meta_digestpipefd[0]);
|
|
|
621668 |
+
|
|
|
621668 |
+ rc = process_package(fdi, digestori, sigi);
|
|
|
621668 |
+ if(rc != RPMRC_OK) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Package processor failed: %d\n"), rc);
|
|
|
621668 |
}
|
|
|
621668 |
- }
|
|
|
621668 |
- w = waitpid(cpid, &wstatus, 0);
|
|
|
621668 |
- if (w == -1) {
|
|
|
621668 |
- fprintf(stderr, _("waitpid failed\n"));
|
|
|
621668 |
- cprc = EXIT_FAILURE;
|
|
|
621668 |
- } else if (WIFEXITED(wstatus)) {
|
|
|
621668 |
- cprc = WEXITSTATUS(wstatus);
|
|
|
621668 |
- if (cprc != 0) {
|
|
|
621668 |
- fprintf(stderr,
|
|
|
621668 |
- _("Digest process non-zero exit code %d\n"),
|
|
|
621668 |
- cprc);
|
|
|
621668 |
+ Fclose(digestori);
|
|
|
621668 |
+ Fclose(sigi);
|
|
|
621668 |
+ /* fdi is normally closed through the stacked file gzdi in the
|
|
|
621668 |
+ * function
|
|
|
621668 |
+ */
|
|
|
621668 |
+
|
|
|
621668 |
+ if (rc != RPMRC_OK) {
|
|
|
621668 |
+ exit(EXIT_FAILURE);
|
|
|
621668 |
}
|
|
|
621668 |
- } else if (WIFSIGNALED(wstatus)) {
|
|
|
621668 |
- fprintf(stderr,
|
|
|
621668 |
- _("Digest process was terminated with a signal: %d\n"),
|
|
|
621668 |
- WTERMSIG(wstatus));
|
|
|
621668 |
- cprc = EXIT_FAILURE;
|
|
|
621668 |
+ exit(EXIT_SUCCESS);
|
|
|
621668 |
+
|
|
|
621668 |
+
|
|
|
621668 |
} else {
|
|
|
621668 |
- /* Don't think this can happen, but covering all bases */
|
|
|
621668 |
- fprintf(stderr, _("Unhandled circumstance in waitpid\n"));
|
|
|
621668 |
- cprc = EXIT_FAILURE;
|
|
|
621668 |
+ /* Actual parent. Read from fdi and write to both processes */
|
|
|
621668 |
+ close(processorpipefd[0]);
|
|
|
621668 |
+ close(validatorpipefd[0]);
|
|
|
621668 |
+ fds[0] = fdDup(processorpipefd[1]);
|
|
|
621668 |
+ fds[1] = fdDup(validatorpipefd[1]);
|
|
|
621668 |
+ close(validatorpipefd[1]);
|
|
|
621668 |
+ close(processorpipefd[1]);
|
|
|
621668 |
+ close(meta_digestpipefd[0]);
|
|
|
621668 |
+ close(meta_digestpipefd[1]);
|
|
|
621668 |
+ close(meta_rpmsignpipefd[0]);
|
|
|
621668 |
+ close(meta_rpmsignpipefd[1]);
|
|
|
621668 |
+
|
|
|
621668 |
+ rc = RPMRC_OK;
|
|
|
621668 |
+ offt = ufdTee(fdi, fds, 2);
|
|
|
621668 |
+ if(offt == -1){
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("Failed to tee RPM\n"));
|
|
|
621668 |
+ rc = RPMRC_FAIL;
|
|
|
621668 |
+ }
|
|
|
621668 |
+ Fclose(fds[0]);
|
|
|
621668 |
+ Fclose(fds[1]);
|
|
|
621668 |
+ w = waitpid(cpids[0], &wstatus, 0);
|
|
|
621668 |
+ if (w == -1) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("waitpid cpids[0] failed\n"));
|
|
|
621668 |
+ rc = RPMRC_FAIL;
|
|
|
621668 |
+ }
|
|
|
621668 |
+ w = waitpid(cpids[1], &wstatus, 0);
|
|
|
621668 |
+ if (w == -1) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR, _("waitpid cpids[1] failed\n"));
|
|
|
621668 |
+ rc = RPMRC_FAIL;
|
|
|
621668 |
+ }
|
|
|
621668 |
}
|
|
|
621668 |
- if (cprc != EXIT_SUCCESS) {
|
|
|
621668 |
- rc = RPMRC_FAIL;
|
|
|
621668 |
+ }
|
|
|
621668 |
+
|
|
|
621668 |
+ return rc;
|
|
|
621668 |
+}
|
|
|
621668 |
+
|
|
|
621668 |
+int main(int argc, char *argv[]) {
|
|
|
621668 |
+ rpmRC rc;
|
|
|
621668 |
+ poptContext optCon = NULL;
|
|
|
621668 |
+ const char **args = NULL;
|
|
|
621668 |
+ int nb_algos = 0;
|
|
|
621668 |
+
|
|
|
621668 |
+ xsetprogname(argv[0]); /* Portability call -- see system.h */
|
|
|
621668 |
+ rpmReadConfigFiles(NULL, NULL);
|
|
|
621668 |
+ optCon = rpmcliInit(argc, argv, optionsTable);
|
|
|
621668 |
+ poptSetOtherOptionHelp(optCon, "[OPTIONS]* <DIGESTALGO>");
|
|
|
621668 |
+
|
|
|
621668 |
+ if (poptPeekArg(optCon) == NULL) {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR,
|
|
|
7b1d93 |
+ _("Need at least one DIGESTALGO parameter, e.g. 'SHA256'\n"));
|
|
|
621668 |
+ poptPrintUsage(optCon, stderr, 0);
|
|
|
621668 |
+ exit(EXIT_FAILURE);
|
|
|
621668 |
+ }
|
|
|
621668 |
+
|
|
|
621668 |
+ args = poptGetArgs(optCon);
|
|
|
621668 |
+
|
|
|
621668 |
+ for (nb_algos=0; args[nb_algos]; nb_algos++);
|
|
|
621668 |
+ uint8_t algos[nb_algos];
|
|
|
621668 |
+ for (int x = 0; x < nb_algos; x++) {
|
|
|
621668 |
+ if (pgpStringVal(PGPVAL_HASHALGO, args[x], &algos[x]) != 0)
|
|
|
621668 |
+ {
|
|
|
7b1d93 |
+ rpmlog(RPMLOG_ERR,
|
|
|
7b1d93 |
+ _("Unable to resolve '%s' as a digest algorithm, exiting\n"),
|
|
|
7b1d93 |
+ args[x]);
|
|
|
621668 |
+ exit(EXIT_FAILURE);
|
|
|
621668 |
}
|
|
|
621668 |
}
|
|
|
621668 |
+
|
|
|
621668 |
+ FD_t fdi = fdDup(STDIN_FILENO);
|
|
|
621668 |
+ rc = teeRpm(fdi, algos, nb_algos);
|
|
|
621668 |
if (rc != RPMRC_OK) {
|
|
|
621668 |
/* translate rpmRC into generic failure return code. */
|
|
|
621668 |
return EXIT_FAILURE;
|
|
|
621668 |
diff --git a/scripts/rpm2extents_dump b/scripts/rpm2extents_dump
|
|
|
621668 |
new file mode 100755
|
|
|
621668 |
index 000000000..596a59a49
|
|
|
621668 |
--- /dev/null
|
|
|
621668 |
+++ b/scripts/rpm2extents_dump
|
|
|
621668 |
@@ -0,0 +1,94 @@
|
|
|
621668 |
+#!/usr/bin/env python3
|
|
|
621668 |
+
|
|
|
621668 |
+import argparse
|
|
|
621668 |
+import binascii
|
|
|
621668 |
+import os
|
|
|
621668 |
+import struct
|
|
|
621668 |
+import sys
|
|
|
621668 |
+
|
|
|
621668 |
+MAGIC_SIZE = 8
|
|
|
621668 |
+MAGIC_STR = b'KWTSH100'
|
|
|
621668 |
+
|
|
|
621668 |
+POS_SIZE = 8
|
|
|
621668 |
+
|
|
|
621668 |
+def keep_position(func):
|
|
|
621668 |
+ def wrapper(*args, **kwargs):
|
|
|
621668 |
+ curr = args[0].tell()
|
|
|
621668 |
+ res = func(*args, **kwargs)
|
|
|
621668 |
+ f.seek(curr, os.SEEK_SET)
|
|
|
621668 |
+ return res
|
|
|
621668 |
+ return wrapper
|
|
|
621668 |
+
|
|
|
621668 |
+def read_validation_digest(f, validation_offset):
|
|
|
621668 |
+ digests = []
|
|
|
621668 |
+ # validation
|
|
|
621668 |
+ f.seek(validation_offset, os.SEEK_SET)
|
|
|
621668 |
+ val_content_len, val_digests_num = struct.unpack('=QI', f.read(8+4))
|
|
|
621668 |
+ for i in range(val_digests_num):
|
|
|
621668 |
+ algo_name_len, digest_len = struct.unpack('=II', f.read(8))
|
|
|
621668 |
+ algo_name, digest = struct.unpack(f'{algo_name_len}s{digest_len}s', f.read(algo_name_len+digest_len))
|
|
|
621668 |
+ digests.append((algo_name, binascii.hexlify(digest)))
|
|
|
621668 |
+ return digests
|
|
|
621668 |
+
|
|
|
621668 |
+
|
|
|
621668 |
+def read_digests_table(f, digest_offset):
|
|
|
621668 |
+ digests = []
|
|
|
621668 |
+ # validation
|
|
|
621668 |
+ f.seek(digest_offset, os.SEEK_SET)
|
|
|
621668 |
+ table_len, digest_len = struct.unpack('=II', f.read(8))
|
|
|
621668 |
+
|
|
|
621668 |
+ for i in range(table_len):
|
|
|
621668 |
+ digest, pos = struct.unpack(f'{digest_len}sQ', f.read(digest_len + 8))
|
|
|
621668 |
+ digests.append((pos, binascii.hexlify(digest)))
|
|
|
621668 |
+ return digests
|
|
|
621668 |
+
|
|
|
621668 |
+def read_signature_output(f, signature_offset):
|
|
|
621668 |
+ f.seek(signature_offset, os.SEEK_SET)
|
|
|
621668 |
+ signature_rc, signature_output_len = struct.unpack('=IQ', f.read(12))
|
|
|
621668 |
+ return signature_rc, f.read(signature_output_len)
|
|
|
621668 |
+
|
|
|
621668 |
+@keep_position
|
|
|
621668 |
+def parse_file(f):
|
|
|
621668 |
+ digests = []
|
|
|
621668 |
+ pos_table_offset = f.seek(-8 - 3*POS_SIZE, os.SEEK_END)
|
|
|
621668 |
+ signature_offset, digest_offset, validation_offset = struct.unpack('=QQQ', f.read(3*POS_SIZE))
|
|
|
621668 |
+
|
|
|
621668 |
+ validation_digests = read_validation_digest(f, validation_offset)
|
|
|
621668 |
+ digests_table = read_digests_table(f, digest_offset)
|
|
|
621668 |
+ signature_ouput = read_signature_output(f, signature_offset)
|
|
|
621668 |
+
|
|
|
621668 |
+ return validation_digests, digests_table, signature_ouput
|
|
|
621668 |
+
|
|
|
621668 |
+@keep_position
|
|
|
621668 |
+def is_transcoded(f):
|
|
|
621668 |
+ f.seek(-MAGIC_SIZE, os.SEEK_END)
|
|
|
621668 |
+ magic = f.read(MAGIC_SIZE)
|
|
|
621668 |
+ return magic == MAGIC_STR
|
|
|
621668 |
+
|
|
|
621668 |
+def arg_parse():
|
|
|
621668 |
+ parser = argparse.ArgumentParser()
|
|
|
621668 |
+ parser.add_argument('--dump-signature', action='store_true')
|
|
|
621668 |
+ parser.add_argument('--dump-file-digest-table', action='store_true')
|
|
|
621668 |
+ parser.add_argument('--dump-digests', action='store_true')
|
|
|
621668 |
+ parser.add_argument('file')
|
|
|
621668 |
+
|
|
|
621668 |
+ return parser.parse_args()
|
|
|
621668 |
+
|
|
|
621668 |
+if __name__ == '__main__':
|
|
|
621668 |
+ args = arg_parse()
|
|
|
621668 |
+ f = open(args.file, 'rb')
|
|
|
621668 |
+ if not is_transcoded(f):
|
|
|
621668 |
+ sys.exit(1)
|
|
|
621668 |
+
|
|
|
621668 |
+ validation_digests, digests_table, signature_output = parse_file(f)
|
|
|
621668 |
+ if(args.dump_file_digest_table):
|
|
|
621668 |
+ for digest in digests_table:
|
|
|
621668 |
+ print(f"FileDigest {hex(digest[0])}: {digest[1]}")
|
|
|
621668 |
+
|
|
|
621668 |
+ if(args.dump_digests):
|
|
|
621668 |
+ for validation_digest in validation_digests:
|
|
|
621668 |
+ print(f"HeaderDigest {validation_digest[0]} {validation_digest[1]}")
|
|
|
621668 |
+
|
|
|
621668 |
+ if(args.dump_signature):
|
|
|
621668 |
+ print(f"RPMSignOutput RC {signature_output[0]}\nRPMSignOutput Content {signature_output[1].decode()}")
|
|
|
621668 |
+
|
|
|
621668 |
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
|
|
621668 |
index f78e17c3e..fc8a24a5e 100644
|
|
|
621668 |
--- a/tests/Makefile.am
|
|
|
621668 |
+++ b/tests/Makefile.am
|
|
|
732e02 |
@@ -36,6 +36,7 @@ TESTSUITE_AT += rpmio.at
|
|
|
0c01c9 |
TESTSUITE_AT += rpmio.at
|
|
|
621668 |
TESTSUITE_AT += rpmorder.at
|
|
|
621668 |
TESTSUITE_AT += rpmvfylevel.at
|
|
|
621668 |
+TESTSUITE_AT += rpm2extents.at
|
|
|
621668 |
EXTRA_DIST += $(TESTSUITE_AT)
|
|
|
621668 |
|
|
|
621668 |
## testsuite data
|
|
|
732e02 |
diff --git a/tests/atlocal.in b/tests/atlocal.in
|
|
|
732e02 |
index c3189d327..a110564e2 100644
|
|
|
732e02 |
--- a/tests/atlocal.in
|
|
|
732e02 |
+++ b/tests/atlocal.in
|
|
|
732e02 |
@@ -29,6 +29,19 @@ else
|
|
|
732e02 |
|
|
|
732e02 |
RPM_XFAIL=${RPM_XFAIL-1}
|
|
|
732e02 |
|
|
|
732e02 |
+FSTYPE=$(stat -f -c %T /)
|
|
|
732e02 |
+REFLINKABLE_FS=("xfs" "brtfs")
|
|
|
732e02 |
+
|
|
|
732e02 |
+REFLINK_DISABLED=true;
|
|
|
732e02 |
+for item in "${REFLINKABLE_FS[@]}"
|
|
|
732e02 |
+do
|
|
|
732e02 |
+ if test "${FSTYPE}" = "${item}"
|
|
|
732e02 |
+ then
|
|
|
732e02 |
+ REFLINK_DISABLED=false;
|
|
|
732e02 |
+ break
|
|
|
732e02 |
+ fi
|
|
|
732e02 |
+done
|
|
|
732e02 |
+
|
|
|
732e02 |
function run()
|
|
|
732e02 |
{
|
|
|
732e02 |
"$@" --define "_tmppath ${RPMTEST}/tmp" --define "_topdir ${TOPDIR}" --dbpath="${RPMTEST}/var/lib/rpm/"
|
|
|
732e02 |
@@ -40,6 +53,14 @@ function runroot()
|
|
|
732e02 |
)
|
|
|
732e02 |
}
|
|
|
732e02 |
|
|
|
732e02 |
+function runroot_plugins()
|
|
|
732e02 |
+{
|
|
|
732e02 |
+ (unset RPM_CONFIGDIR RPM_POPTEXEC_PATH; cd ${RPMTEST} && \
|
|
|
732e02 |
+ MAGIC="/magic/magic" FAKECHROOT_BASE="${RPMTEST}" fakechroot "$@" --define "_buildhost testhost" --define "_topdir /build" --nouserns
|
|
|
732e02 |
+ )
|
|
|
732e02 |
+}
|
|
|
732e02 |
+
|
|
|
732e02 |
+
|
|
|
732e02 |
function runroot_other()
|
|
|
732e02 |
{
|
|
|
732e02 |
(unset RPM_CONFIGDIR RPM_POPTEXEC_PATH; cd ${RPMTEST} && \
|
|
|
621668 |
diff --git a/tests/rpm2extents.at b/tests/rpm2extents.at
|
|
|
621668 |
new file mode 100644
|
|
|
7b1d93 |
index 000000000..5135c9cf8
|
|
|
621668 |
--- /dev/null
|
|
|
621668 |
+++ b/tests/rpm2extents.at
|
|
|
7b1d93 |
@@ -0,0 +1,140 @@
|
|
|
621668 |
+# rpm2extents.at: Some very basic checks
|
|
|
621668 |
+#
|
|
|
621668 |
+# Copyright (C) 2022 Manu Bretelle <chantr4@gmail.com>
|
|
|
621668 |
+#
|
|
|
621668 |
+# This program is free software; you can redistribute it and/or modify
|
|
|
621668 |
+# it under the terms of the GNU General Public License as published by
|
|
|
621668 |
+# the Free Software Foundation; either version 2 of the License, or
|
|
|
621668 |
+# (at your option) any later version.
|
|
|
621668 |
+#
|
|
|
621668 |
+# This program is distributed in the hope that it will be useful,
|
|
|
621668 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
621668 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
621668 |
+# GNU General Public License for more details.
|
|
|
621668 |
+#
|
|
|
621668 |
+# You should have received a copy of the GNU General Public License
|
|
|
621668 |
+# along with this program; if not, write to the Free Software
|
|
|
621668 |
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
621668 |
+
|
|
|
621668 |
+AT_BANNER([rpm2extents tests])
|
|
|
621668 |
+
|
|
|
621668 |
+# ------------------------------
|
|
|
621668 |
+
|
|
|
621668 |
+# check that transcoder write magic at the end
|
|
|
621668 |
+AT_SETUP([rpm2extents magic])
|
|
|
621668 |
+AT_KEYWORDS([rpm2extents])
|
|
|
621668 |
+AT_CHECK([runroot_other cat /data/RPMS/hello-2.0-1.x86_64.rpm | runroot_other rpm2extents SHA256 | tail -c8],
|
|
|
621668 |
+[0],
|
|
|
621668 |
+[KWTSH100],
|
|
|
621668 |
+[ignore])
|
|
|
621668 |
+AT_CLEANUP
|
|
|
621668 |
+
|
|
|
621668 |
+# Check that transcoder writes checksig return code and content.
|
|
|
621668 |
+#
|
|
|
621668 |
+AT_SETUP([rpm2extents signature])
|
|
|
592a09 |
+AT_KEYWORDS([rpm2extents])
|
|
|
621668 |
+AT_CHECK([
|
|
|
621668 |
+RPMDB_INIT
|
|
|
621668 |
+
|
|
|
621668 |
+runroot_other cat /data/RPMS/hello-2.0-1.x86_64-signed.rpm | runroot_other rpm2extents SHA256 > /tmp/hello-2.0-1.x86_64-signed.rpm 2> /dev/null
|
|
|
621668 |
+rpm2extents_dump --dump-signature /tmp/hello-2.0-1.x86_64-signed.rpm
|
|
|
621668 |
+runroot rpmkeys --import /data/keys/rpm.org-rsa-2048-test.pub
|
|
|
621668 |
+runroot_other cat /data/RPMS/hello-2.0-1.x86_64-signed.rpm | runroot_other rpm2extents SHA256 > /tmp/hello-2.0-1.x86_64-signed.rpm
|
|
|
621668 |
+rpm2extents_dump --dump-signature /tmp/hello-2.0-1.x86_64-signed.rpm
|
|
|
621668 |
+],
|
|
|
621668 |
+[0],
|
|
|
621668 |
+[RPMSignOutput RC 2
|
|
|
621668 |
+RPMSignOutput Content Header V4 RSA/SHA256 Signature, key ID 1964c5fc: NOKEY
|
|
|
621668 |
+ Header SHA256 digest: OK
|
|
|
621668 |
+ Header SHA1 digest: OK
|
|
|
621668 |
+ Payload SHA256 digest: OK
|
|
|
621668 |
+ V4 RSA/SHA256 Signature, key ID 1964c5fc: NOKEY
|
|
|
621668 |
+ MD5 digest: OK
|
|
|
621668 |
+
|
|
|
621668 |
+RPMSignOutput RC 0
|
|
|
621668 |
+RPMSignOutput Content Header V4 RSA/SHA256 Signature, key ID 1964c5fc: OK
|
|
|
621668 |
+ Header SHA256 digest: OK
|
|
|
621668 |
+ Header SHA1 digest: OK
|
|
|
621668 |
+ Payload SHA256 digest: OK
|
|
|
621668 |
+ V4 RSA/SHA256 Signature, key ID 1964c5fc: OK
|
|
|
621668 |
+ MD5 digest: OK
|
|
|
621668 |
+
|
|
|
621668 |
+],
|
|
|
621668 |
+[])
|
|
|
621668 |
+AT_CLEANUP
|
|
|
621668 |
+
|
|
|
621668 |
+AT_SETUP([rpm2extents signature verification])
|
|
|
592a09 |
+AT_KEYWORDS([rpm2extents])
|
|
|
621668 |
+AT_CHECK([
|
|
|
621668 |
+RPMDB_INIT
|
|
|
621668 |
+
|
|
|
621668 |
+runroot_other cat /data/RPMS/hello-2.0-1.x86_64-signed.rpm | runroot_other rpm2extents SHA256 > ${RPMTEST}/tmp/hello-2.0-1.x86_64-signed.rpm 2> /dev/null
|
|
|
621668 |
+runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64-signed.rpm; echo $?
|
|
|
621668 |
+runroot rpmkeys --import /data/keys/rpm.org-rsa-2048-test.pub
|
|
|
621668 |
+runroot_other cat /data/RPMS/hello-2.0-1.x86_64-signed.rpm | runroot_other rpm2extents SHA256 > ${RPMTEST}/tmp/hello-2.0-1.x86_64-signed.rpm
|
|
|
621668 |
+runroot rpmkeys -Kv /tmp/hello-2.0-1.x86_64-signed.rpm; echo $?
|
|
|
621668 |
+],
|
|
|
621668 |
+[0],
|
|
|
621668 |
+[/tmp/hello-2.0-1.x86_64-signed.rpm:
|
|
|
621668 |
+ Header V4 RSA/SHA256 Signature, key ID 1964c5fc: NOKEY
|
|
|
621668 |
+ Header SHA256 digest: OK
|
|
|
621668 |
+ Header SHA1 digest: OK
|
|
|
621668 |
+ Payload SHA256 digest: OK
|
|
|
621668 |
+ V4 RSA/SHA256 Signature, key ID 1964c5fc: NOKEY
|
|
|
621668 |
+ MD5 digest: OK
|
|
|
621668 |
+1
|
|
|
621668 |
+/tmp/hello-2.0-1.x86_64-signed.rpm:
|
|
|
621668 |
+ Header V4 RSA/SHA256 Signature, key ID 1964c5fc: OK
|
|
|
621668 |
+ Header SHA256 digest: OK
|
|
|
621668 |
+ Header SHA1 digest: OK
|
|
|
621668 |
+ Payload SHA256 digest: OK
|
|
|
621668 |
+ V4 RSA/SHA256 Signature, key ID 1964c5fc: OK
|
|
|
621668 |
+ MD5 digest: OK
|
|
|
621668 |
+0
|
|
|
621668 |
+],
|
|
|
621668 |
+[])
|
|
|
621668 |
+AT_CLEANUP
|
|
|
732e02 |
+
|
|
|
732e02 |
+AT_SETUP([rpm2extents install package])
|
|
|
592a09 |
+AT_KEYWORDS([rpm2extents reflink])
|
|
|
732e02 |
+AT_SKIP_IF([$REFLINK_DISABLED])
|
|
|
732e02 |
+AT_CHECK([
|
|
|
732e02 |
+RPMDB_INIT
|
|
|
732e02 |
+
|
|
|
732e02 |
+runroot_other cat /data/RPMS/hello-2.0-1.x86_64.rpm | runroot_other rpm2extents SHA256 > ${RPMTEST}/tmp/hello-2.0-1.x86_64.rpm 2> /dev/null
|
|
|
7b1d93 |
+runroot_plugins rpm -i --nodeps --undefine=%__transaction_dbus_announce /tmp/hello-2.0-1.x86_64.rpm
|
|
|
7b1d93 |
+test -f ${RPMTEST}/usr/bin/hello
|
|
|
732e02 |
+],
|
|
|
732e02 |
+[0],
|
|
|
732e02 |
+[],
|
|
|
732e02 |
+[])
|
|
|
732e02 |
+AT_CLEANUP
|
|
|
592a09 |
+
|
|
|
7b1d93 |
+AT_SETUP([reflink ignores non-transcoded package])
|
|
|
7b1d93 |
+AT_KEYWORDS([reflink])
|
|
|
592a09 |
+AT_CHECK([
|
|
|
592a09 |
+RPMDB_INIT
|
|
|
592a09 |
+
|
|
|
7b1d93 |
+runroot_plugins rpm -i --nodeps --undefine=%__transaction_dbus_announce /data/RPMS/hello-2.0-1.x86_64.rpm && exit $?
|
|
|
7b1d93 |
+# Check that the file is properly installed in chroot
|
|
|
7b1d93 |
+test -f ${RPMTEST}/usr/bin/hello
|
|
|
592a09 |
+],
|
|
|
592a09 |
+[0],
|
|
|
592a09 |
+[],
|
|
|
592a09 |
+[])
|
|
|
592a09 |
+AT_CLEANUP
|
|
|
592a09 |
+
|
|
|
7b1d93 |
+AT_SETUP([reflink hardlink package])
|
|
|
7b1d93 |
+AT_KEYWORDS([reflink hardlink])
|
|
|
592a09 |
+AT_SKIP_IF([$REFLINK_DISABLED])
|
|
|
592a09 |
+AT_CHECK([
|
|
|
592a09 |
+RPMDB_INIT
|
|
|
592a09 |
+
|
|
|
7b1d93 |
+PKG=hlinktest-1.0-1.noarch.rpm
|
|
|
7b1d93 |
+runroot_other cat /data/RPMS/${PKG} | runroot_other rpm2extents SHA256 > ${RPMTEST}/tmp/${PKG} 2> /dev/null
|
|
|
7b1d93 |
+runroot_plugins rpm -i --nodeps --undefine=%__transaction_dbus_announce /tmp/${PKG}
|
|
|
592a09 |
+],
|
|
|
592a09 |
+[0],
|
|
|
592a09 |
+[],
|
|
|
592a09 |
+[])
|
|
|
592a09 |
+AT_CLEANUP
|
|
|
621668 |
diff --git a/tests/rpmtests.at b/tests/rpmtests.at
|
|
|
621668 |
index a1adab8e0..205fed6a3 100644
|
|
|
621668 |
--- a/tests/rpmtests.at
|
|
|
621668 |
+++ b/tests/rpmtests.at
|
|
|
732e02 |
@@ -21,3 +21,4 @@ m4_include([rpmreplace.at])
|
|
|
0c01c9 |
m4_include([rpmmacro.at])
|
|
|
0c01c9 |
m4_include([rpmpython.at])
|
|
|
0c01c9 |
m4_include([rpmdepmatch.at])
|
|
|
621668 |
+m4_include([rpm2extents.at])
|