Skip to content

Commit 662c231

Browse files
committed
Pass rpmPubkey instance to rpmtxnDeletePubkey
Use the matchingKeys() in rpmkeys to acquire those rpmPubkey instances. Use EXIT_FAILURE as exit code for rpmkeys --delete instead of the count of errors.
1 parent 52c675f commit 662c231

File tree

4 files changed

+18
-30
lines changed

4 files changed

+18
-30
lines changed

include/rpm/rpmts.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <rpm/rpmsw.h>
1515
#include <rpm/rpmfi.h>
1616
#include <rpm/rpmcallback.h>
17+
#include <rpm/rpmkeyring.h>
1718

1819
#ifdef __cplusplus
1920
extern "C" {
@@ -353,13 +354,12 @@ rpmRC rpmtxnImportPubkey(rpmtxn txn, const unsigned char * pkt, size_t pktlen);
353354
/** \ingroup rpmts
354355
* Delete public key from transaction keystore.
355356
* @param txn transaction handle
356-
* @param keyid key fingerprint or keyid (in hex)
357+
* @param key public key
357358
* @return RPMRC_OK on success
358359
* RPMRC_NOTFOUND if key not found
359-
* RPMRC_NOKEY on invalid keyid
360360
* RPMRC_FAIL on other failure
361361
*/
362-
rpmRC rpmtxnDeletePubkey(rpmtxn txn, const char *keyid);
362+
rpmRC rpmtxnDeletePubkey(rpmtxn txn, rpmPubkey key);
363363

364364
/** \ingroup rpmts
365365
* Retrieve handle for keyring used for this transaction set

lib/rpmts.cc

+5-11
Original file line numberDiff line numberDiff line change
@@ -774,17 +774,10 @@ rpmRC rpmtxnImportPubkey(rpmtxn txn, const unsigned char * pkt, size_t pktlen)
774774
return rc;
775775
}
776776

777-
rpmRC rpmtxnDeletePubkey(rpmtxn txn, const char *keyid)
777+
rpmRC rpmtxnDeletePubkey(rpmtxn txn, rpmPubkey key)
778778
{
779779
rpmRC rc = RPMRC_FAIL;
780-
size_t klen = strlen(keyid);
781-
782-
/* Allow short keyid while we're transitioning */
783-
if (klen != 40 && klen != 16 && klen != 8)
784-
return RPMRC_NOKEY;
785-
786-
if (!rpmIsValidHex(keyid, klen))
787-
return RPMRC_NOKEY;
780+
char * keyid = rpmPubkeyKeyIDAsHex(key);
788781

789782
if (txn) {
790783
/* force keyring load */
@@ -797,12 +790,13 @@ rpmRC rpmtxnDeletePubkey(rpmtxn txn, const char *keyid)
797790
rc = RPMRC_OK;
798791
if (!(rpmtsFlags(txn->ts) & RPMTRANS_FLAG_TEST)) {
799792
if (txn->ts->keyringtype == KEYRING_FS)
800-
rc = rpmtsDeleteFSKey(txn, keyid);
793+
rc = rpmtsDeleteFSKey(txn, keyid+8);
801794
else
802-
rc = rpmtsDeleteDBKey(txn, keyid);
795+
rc = rpmtsDeleteDBKey(txn, keyid+8);
803796
}
804797
rpmKeyringFree(keyring);
805798
}
799+
free(keyid);
806800
return rc;
807801
}
808802

tests/rpmsigdig.at

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ runroot rpmkeys -Kv /data/RPMS/hello-2.0-1.x86_64-signed-with-new-subkey.rpm
7878
RPMTEST_CHECK([
7979
runroot rpmkeys --delete abcd gimmekey 1111aaaa2222bbbb
8080
],
81-
[3],
81+
[1],
8282
[],
8383
[error: invalid key id: abcd
8484
error: invalid key id: gimmekey
@@ -147,7 +147,7 @@ runroot rpmkeys -Kv /data/RPMS/hello-2.0-1.x86_64-signed-with-new-subkey.rpm
147147
RPMTEST_CHECK([
148148
runroot rpmkeys --delete abcd gimmekey 1111aaaa2222bbbb
149149
],
150-
[3],
150+
[1],
151151
[],
152152
[error: invalid key id: abcd
153153
error: invalid key id: gimmekey

tools/rpmkeys.cc

+8-14
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ static int printKey(rpmPubkey key, void * data)
122122
return 0;
123123
}
124124

125+
static int deleteKey(rpmPubkey key, void * data)
126+
{
127+
rpmtxn txn = (rpmtxn) data;
128+
rpmtxnDeletePubkey(txn, key);
129+
return 0;
130+
}
131+
125132
int main(int argc, char *argv[])
126133
{
127134
int ec = EXIT_FAILURE;
@@ -157,20 +164,7 @@ int main(int argc, char *argv[])
157164
{
158165
rpmtxn txn = rpmtxnBegin(ts, RPMTXN_WRITE);
159166
if (txn) {
160-
int nfail = 0;
161-
for (char const * const *arg = args; *arg && **arg; arg++) {
162-
rpmRC delrc = rpmtxnDeletePubkey(txn, *arg);
163-
if (delrc) {
164-
if (delrc == RPMRC_NOTFOUND)
165-
rpmlog(RPMLOG_ERR, ("key not found: %s\n"), *arg);
166-
else if (delrc == RPMRC_NOKEY)
167-
rpmlog(RPMLOG_ERR, ("invalid key id: %s\n"), *arg);
168-
else if (delrc == RPMRC_FAIL)
169-
rpmlog(RPMLOG_ERR, ("failed to delete key: %s\n"), *arg);
170-
nfail++;
171-
}
172-
}
173-
ec = nfail;
167+
ec = matchingKeys(ts, args, deleteKey, txn);
174168
rpmtxnEnd(txn);
175169
}
176170
break;

0 commit comments

Comments
 (0)