diff --git a/lib/rpmte.cc b/lib/rpmte.cc index 70b1d8520f..f923e12845 100644 --- a/lib/rpmte.cc +++ b/lib/rpmte.cc @@ -167,6 +167,11 @@ static int addTE(rpmte p, Header h, fnpyKey key, rpmRelocation * relocs) } } + if (p->type != TR_REMOVED && rstreq(p->name, "gpg-pubkey")) { + rpmlog(RPMLOG_ERR, _("public keys can not be installed as gpg-pubkey packages; use rpmkeys --import for that\n")); + goto exit; + } + p->isSource = headerIsSource(h); p->NEVR = headerGetAsString(h, RPMTAG_NEVR); diff --git a/tests/rpmpython.at b/tests/rpmpython.at index 4ab4fdc245..a9dc8e3177 100644 --- a/tests/rpmpython.at +++ b/tests/rpmpython.at @@ -360,6 +360,23 @@ adding upgrade to transaction failed ], []) +RPMPY_TEST([add bogus package to transaction 4],[ + +h = ts.hdrFromFdno('${RPMDATA}/RPMS/hello-1.0-1.ppc64.rpm') +del h["name"] +h["name"] = "gpg-pubkey" +try: + ts.addInstall(h, 'foo', 'u') +except rpm.error as err: + myprint(err) +for e in ts: + myprint(e.NEVRA()) +], +[adding upgrade to transaction failed +], +[error: public keys can not be installed as gpg-pubkey packages; use rpmkeys --import for that +]) + RPMPY_TEST([transaction element userdata],[ mydata = { 'foo': 'bar', 'capstest': 'lock' } ts.addInstall('${RPMDATA}/RPMS/foo-1.0-1.noarch.rpm', 'u')