Skip to content

Commit

Permalink
Return rpmRC from rpmKeystoreLoad() too
Browse files Browse the repository at this point in the history
This used to return number of keys loaded but it didn't really mean
anything, and so nothing was checking the results either. So for
now keystore load simply always returns success, that's how it has
technically always behaved anyway.
  • Loading branch information
pmatilai authored and ffesti committed Oct 28, 2024
1 parent 79b26f1 commit 43f3720
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 9 additions & 13 deletions lib/keystore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ using std::string;

static int makePubkeyHeader(rpmts ts, rpmPubkey key, Header * hdrp);

static int rpmtsLoadKeyringFromFiles(rpmtxn txn, rpmKeyring keyring)
static rpmRC rpmtsLoadKeyringFromFiles(rpmtxn txn, rpmKeyring keyring)
{
ARGV_t files = NULL;
/* XXX TODO: deal with chroot path issues */
char *pkpath = rpmGetPath(rpmtxnRootDir(txn), "%{_keyringpath}/*.key", NULL);
int nkeys = 0;

rpmlog(RPMLOG_DEBUG, "loading keyring from pubkeys in %s\n", pkpath);
if (rpmGlob(pkpath, NULL, &files)) {
Expand All @@ -47,14 +46,13 @@ static int rpmtsLoadKeyringFromFiles(rpmtxn txn, rpmKeyring keyring)

if (rpmKeyringAddKey(keyring, key) == 0) {
rpmlog(RPMLOG_DEBUG, "Loaded key %s\n", *f);
nkeys++;
}
rpmPubkeyFree(key);
}
exit:
free(pkpath);
argvFree(files);
return nkeys;
return RPMRC_OK;
}

static rpmRC rpmtsDeleteFSKey(rpmtxn txn, const string & keyid, const string & newname = "")
Expand Down Expand Up @@ -133,11 +131,10 @@ static rpmRC rpmtsImportFSKey(rpmtxn txn, rpmPubkey key, rpmFlags flags, int rep
return rc;
}

static int rpmtsLoadKeyringFromDB(rpmtxn txn, rpmKeyring keyring)
static rpmRC rpmtsLoadKeyringFromDB(rpmtxn txn, rpmKeyring keyring)
{
Header h;
rpmdbMatchIterator mi;
int nkeys = 0;

rpmlog(RPMLOG_DEBUG, "loading keyring from rpmdb\n");
mi = rpmtsInitIterator(rpmtxnTs(txn), RPMDBI_NAME, "gpg-pubkey", 0);
Expand All @@ -159,7 +156,6 @@ static int rpmtsLoadKeyringFromDB(rpmtxn txn, rpmKeyring keyring)
if (key) {
if (rpmKeyringAddKey(keyring, key) == 0) {
rpmlog(RPMLOG_DEBUG, "Loaded key %s\n", nevr);
nkeys++;
}
rpmPubkeyFree(key);
}
Expand All @@ -171,7 +167,7 @@ static int rpmtsLoadKeyringFromDB(rpmtxn txn, rpmKeyring keyring)
}
rpmdbFreeIterator(mi);

return nkeys;
return RPMRC_OK;
}

static rpmRC rpmtsDeleteDBKey(rpmtxn txn, const string & keyid, unsigned int newinstance = 0)
Expand Down Expand Up @@ -405,15 +401,15 @@ rpmRC rpmKeystoreDeletePubkey(rpmtxn txn, rpmPubkey key)
return rc;
}

int rpmKeystoreLoad(rpmtxn txn, rpmKeyring keyring)
rpmRC rpmKeystoreLoad(rpmtxn txn, rpmKeyring keyring)
{
int nkeys = 0;
rpmRC rc = RPMRC_FAIL;
rpmts ts = rpmtxnTs(txn);
if (ts->keyringtype == KEYRING_FS) {
nkeys = rpmtsLoadKeyringFromFiles(txn, keyring);
rc = rpmtsLoadKeyringFromFiles(txn, keyring);
} else {
nkeys = rpmtsLoadKeyringFromDB(txn, keyring);
rc = rpmtsLoadKeyringFromDB(txn, keyring);
}
return nkeys;
return rc;
}

2 changes: 1 addition & 1 deletion lib/keystore.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum {
};

RPM_GNUC_INTERNAL
int rpmKeystoreLoad(rpmtxn txn, rpmKeyring keyring);
rpmRC rpmKeystoreLoad(rpmtxn txn, rpmKeyring keyring);

RPM_GNUC_INTERNAL
rpmRC rpmKeystoreImportPubkey(rpmtxn txn, rpmPubkey key, int replace = 0);
Expand Down

0 comments on commit 43f3720

Please sign in to comment.