Skip to content

Commit

Permalink
Add support for RPMKEYRING_MERGE
Browse files Browse the repository at this point in the history
Merge the keys directly in the keyring
  • Loading branch information
ffesti committed Nov 26, 2024
1 parent fe9a914 commit 0d5f27e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/rpm/rpmkeyring.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ extern "C" {
typedef enum rpmKeyringModifyMode_e {
RPMKEYRING_ADD = 1,
RPMKEYRING_REPLACE = 2,
RPMKEYRING_DELETE = 3
RPMKEYRING_DELETE = 3,
RPMKEYRING_MERGE = 4,
} rpmKeyringModifyMode;


Expand Down
24 changes: 23 additions & 1 deletion rpmio/rpmkeyring.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,31 @@ rpmKeyringIterator rpmKeyringIteratorFree(rpmKeyringIterator iterator)
int rpmKeyringModify(rpmKeyring keyring, rpmPubkey key, rpmKeyringModifyMode mode)
{
int rc = 1; /* assume already seen key */
rpmPubkey mergedkey = NULL;
if (keyring == NULL || key == NULL)
return -1;
if (mode != RPMKEYRING_ADD && mode != RPMKEYRING_DELETE && mode != RPMKEYRING_REPLACE)
if (mode < RPMKEYRING_ADD || mode > RPMKEYRING_MERGE)
return -1;

if (mode == RPMKEYRING_MERGE) {
rpmPubkey oldkey = rpmKeyringLookupKey(keyring, key);
if (oldkey) {
if (rpmPubkeyMerge(oldkey, key, &mergedkey) != RPMRC_OK) {
rpmPubkeyFree(oldkey);
return -1;
}
if (!mergedkey) {
mode = RPMKEYRING_ADD;
} else {
key = mergedkey;
mode = RPMKEYRING_REPLACE;
}
rpmPubkeyFree(oldkey);
} else {
mode = RPMKEYRING_ADD;
}
}

/* check if we already have this key, but always wrlock for simplicity */
wrlock lock(keyring->mutex);
auto range = keyring->keys.equal_range(key->keyid);
Expand Down Expand Up @@ -162,6 +182,8 @@ int rpmKeyringModify(rpmKeyring keyring, rpmPubkey key, rpmKeyringModifyMode mod
free(subkeys);
rc = 0;
}
/* strip initial nref */
rpmPubkeyFree(mergedkey);

return rc;
}
Expand Down

0 comments on commit 0d5f27e

Please sign in to comment.