Skip to content

Commit

Permalink
Refactor lower level keystore load to separate function
Browse files Browse the repository at this point in the history
Paving way for next steps, no functional changes.
  • Loading branch information
pmatilai authored and ffesti committed Oct 23, 2024
1 parent 16ef3ee commit 5e5e614
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions lib/rpmts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ int rpmtsSetKeyring(rpmts ts, rpmKeyring keyring)
return 0;
}

static int rpmtsLoadKeyringFromFiles(rpmts ts)
static int rpmtsLoadKeyringFromFiles(rpmts ts, rpmKeyring keyring)
{
ARGV_t files = NULL;
/* XXX TODO: deal with chroot path issues */
Expand All @@ -291,7 +291,7 @@ static int rpmtsLoadKeyringFromFiles(rpmts ts)
rpmlog(RPMLOG_ERR, _("%s: reading of public key failed.\n"), *f);
continue;
}
if (rpmKeyringAddKey(ts->keyring, key) == 0) {
if (rpmKeyringAddKey(keyring, key) == 0) {
nkeys++;
rpmlog(RPMLOG_DEBUG, "added key %s to keyring\n", *f);
}
Expand All @@ -301,7 +301,7 @@ static int rpmtsLoadKeyringFromFiles(rpmts ts)
for (i = 0; i < subkeysCount; i++) {
rpmPubkey subkey = subkeys[i];

if (rpmKeyringAddKey(ts->keyring, subkey) == 0) {
if (rpmKeyringAddKey(keyring, subkey) == 0) {
rpmlog(RPMLOG_DEBUG,
"added subkey %d of main key %s to keyring\n",
i, *f);
Expand All @@ -318,7 +318,7 @@ static int rpmtsLoadKeyringFromFiles(rpmts ts)
return nkeys;
}

static int rpmtsLoadKeyringFromDB(rpmts ts)
static int rpmtsLoadKeyringFromDB(rpmts ts, rpmKeyring keyring)
{
Header h;
rpmdbMatchIterator mi;
Expand All @@ -342,7 +342,7 @@ static int rpmtsLoadKeyringFromDB(rpmts ts)
int subkeysCount, i;
rpmPubkey *subkeys = rpmGetSubkeys(key, &subkeysCount);

if (rpmKeyringAddKey(ts->keyring, key) == 0) {
if (rpmKeyringAddKey(keyring, key) == 0) {
char *nvr = headerGetAsString(h, RPMTAG_NVR);
rpmlog(RPMLOG_DEBUG, "added key %s to keyring\n", nvr);
free(nvr);
Expand All @@ -353,7 +353,7 @@ static int rpmtsLoadKeyringFromDB(rpmts ts)
for (i = 0; i < subkeysCount; i++) {
rpmPubkey subkey = subkeys[i];

if (rpmKeyringAddKey(ts->keyring, subkey) == 0) {
if (rpmKeyringAddKey(keyring, subkey) == 0) {
char *nvr = headerGetAsString(h, RPMTAG_NVR);
rpmlog(RPMLOG_DEBUG,
"added subkey %d of main key %s to keyring\n",
Expand Down Expand Up @@ -392,19 +392,26 @@ static int getKeyringType(void)
return kt;
}

static int rpmKeystoreLoad(rpmts ts, rpmKeyring keyring)
{
int nkeys = 0;
if (!ts->keyringtype)
ts->keyringtype = getKeyringType();
if (ts->keyringtype == KEYRING_FS) {
nkeys = rpmtsLoadKeyringFromFiles(ts, keyring);
} else {
nkeys = rpmtsLoadKeyringFromDB(ts, keyring);
}
return nkeys;
}

static void loadKeyring(rpmts ts)
{
/* Never load the keyring if signature checking is disabled */
if ((rpmtsVSFlags(ts) & RPMVSF_MASK_NOSIGNATURES) !=
RPMVSF_MASK_NOSIGNATURES) {
ts->keyring = rpmKeyringNew();
if (!ts->keyringtype)
ts->keyringtype = getKeyringType();
if (ts->keyringtype == KEYRING_FS) {
rpmtsLoadKeyringFromFiles(ts);
} else {
rpmtsLoadKeyringFromDB(ts);
}
rpmKeystoreLoad(ts, ts->keyring);
}
}

Expand Down

0 comments on commit 5e5e614

Please sign in to comment.