libalpm: don't use alpm_pgpkey_t in import question

When constructing an import question we never really used a proper gpg
key. We just zero initialize the key, set the uid and fingerprint, and
sent that to the front end.

Instead lets just give the import question a uid and fingerprint field.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
morganamilo 2021-06-03 21:25:04 +01:00 committed by Allan McRae
parent e187aa9b48
commit 625f3d645b
3 changed files with 10 additions and 12 deletions

View file

@ -1074,8 +1074,10 @@ typedef struct _alpm_question_import_key_t {
alpm_question_type_t type;
/** Answer: whether or not to import key */
int import;
/** The key to import */
alpm_pgpkey_t *key;
/** UID of the key to import */
const char *uid;
/** Fingerprint the key to import */
const char *fingerprint;
} alpm_question_import_key_t;
/**

View file

@ -495,7 +495,7 @@ static int email_from_uid(const char *uid, char **email)
int _alpm_key_import(alpm_handle_t *handle, const char *uid, const char *fpr)
{
int ret = -1;
alpm_pgpkey_t fetch_key = {0};
alpm_pgpkey_t fetch_key;
char *email;
if(_alpm_access(handle, handle->gpgdir, "pubring.gpg", W_OK)) {
@ -504,19 +504,15 @@ int _alpm_key_import(alpm_handle_t *handle, const char *uid, const char *fpr)
return -1;
}
STRDUP(fetch_key.uid, uid, return -1);
STRDUP(fetch_key.fingerprint, fpr, free(fetch_key.uid); return -1);
alpm_question_import_key_t question = {
.type = ALPM_QUESTION_IMPORT_KEY,
.import = 0,
.key = &fetch_key
.uid = uid,
.fingerprint = fpr
};
QUESTION(handle, &question);
free(fetch_key.uid);
free(fetch_key.fingerprint);
if(question.import) {
/* Try to import the key from a WKD first */
if(email_from_uid(uid, &email) == 0) {

View file

@ -541,12 +541,12 @@ void cb_question(void *ctx, alpm_question_t *question)
{
alpm_question_import_key_t *q = &question->import_key;
/* the uid is unknown with db signatures */
if (q->key->uid == NULL) {
if (q->uid == NULL) {
q->import = yesno(_("Import PGP key %s?"),
q->key->fingerprint);
q->fingerprint);
} else {
q->import = yesno(_("Import PGP key %s, \"%s\"?"),
q->key->fingerprint, q->key->uid);
q->fingerprint, q->uid);
}
}
break;