mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-17 15:44:34 +02:00
gpg: Make the get_pubkey_byname interface easier to understand.
* g10/keydb.h (enum get_pubkey_modes): New. * g10/getkey.c (get_pubkey_byname): Repalce no_akl by a mode arg and change all callers. -- This change prepares the implementation of GET_PUBKEY_NO_LOCAL. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
8b113bb148
commit
9980f81da7
@ -2174,10 +2174,10 @@ export_ssh_key (ctrl_t ctrl, const char *userid)
|
|||||||
{
|
{
|
||||||
getkey_ctx_t getkeyctx;
|
getkey_ctx_t getkeyctx;
|
||||||
|
|
||||||
err = get_pubkey_byname (ctrl, &getkeyctx, NULL, userid, &keyblock,
|
err = get_pubkey_byname (ctrl, GET_PUBKEY_NO_AKL,
|
||||||
|
&getkeyctx, NULL, userid, &keyblock,
|
||||||
NULL,
|
NULL,
|
||||||
0 /* Only usable keys or given exact. */,
|
0 /* Only usable keys or given exact. */);
|
||||||
1 /* No AKL lookup. */);
|
|
||||||
if (!err)
|
if (!err)
|
||||||
{
|
{
|
||||||
err = getkey_next (ctrl, getkeyctx, NULL, NULL);
|
err = getkey_next (ctrl, getkeyctx, NULL, NULL);
|
||||||
|
41
g10/getkey.c
41
g10/getkey.c
@ -843,11 +843,21 @@ key_byname (ctrl_t ctrl, GETKEY_CTX *retctx, strlist_t namelist,
|
|||||||
|
|
||||||
/* Find a public key identified by NAME.
|
/* Find a public key identified by NAME.
|
||||||
*
|
*
|
||||||
* If name appears to be a valid RFC822 mailbox (i.e., email
|
* If name appears to be a valid RFC822 mailbox (i.e., email address)
|
||||||
* address) and auto key lookup is enabled (no_akl == 0), then the
|
* and auto key lookup is enabled (mode != GET_PUBKEY_NO_AKL), then
|
||||||
* specified auto key lookup methods (--auto-key-lookup) are used to
|
* the specified auto key lookup methods (--auto-key-lookup) are used
|
||||||
* import the key into the local keyring. Otherwise, just the local
|
* to import the key into the local keyring. Otherwise, just the
|
||||||
* keyring is consulted.
|
* local keyring is consulted.
|
||||||
|
*
|
||||||
|
* MODE can be one of:
|
||||||
|
* GET_PUBKEY_NORMAL - The standard mode
|
||||||
|
* GET_PUBKEY_NO_AKL - The auto key locate functionality is
|
||||||
|
* disabled and only the local key ring is
|
||||||
|
* considered. Note: the local key ring is
|
||||||
|
* consulted even if local is not in the
|
||||||
|
* auto-key-locate option list!
|
||||||
|
* GET_PUBKEY_NO_LOCAL - Only the auto key locate functionaly is
|
||||||
|
* used and no local search is done.
|
||||||
*
|
*
|
||||||
* If RETCTX is not NULL, then the constructed context is returned in
|
* If RETCTX is not NULL, then the constructed context is returned in
|
||||||
* *RETCTX so that getpubkey_next can be used to get subsequent
|
* *RETCTX so that getpubkey_next can be used to get subsequent
|
||||||
@ -883,18 +893,14 @@ key_byname (ctrl_t ctrl, GETKEY_CTX *retctx, strlist_t namelist,
|
|||||||
* documentation for skip_unusable for an exact definition) are
|
* documentation for skip_unusable for an exact definition) are
|
||||||
* skipped unless they are looked up by key id or by fingerprint.
|
* skipped unless they are looked up by key id or by fingerprint.
|
||||||
*
|
*
|
||||||
* If NO_AKL is set, then the auto key locate functionality is
|
|
||||||
* disabled and only the local key ring is considered. Note: the
|
|
||||||
* local key ring is consulted even if local is not in the
|
|
||||||
* --auto-key-locate option list!
|
|
||||||
*
|
|
||||||
* This function returns 0 on success. Otherwise, an error code is
|
* This function returns 0 on success. Otherwise, an error code is
|
||||||
* returned. In particular, GPG_ERR_NO_PUBKEY or GPG_ERR_NO_SECKEY
|
* returned. In particular, GPG_ERR_NO_PUBKEY or GPG_ERR_NO_SECKEY
|
||||||
* (if want_secret is set) is returned if the key is not found. */
|
* (if want_secret is set) is returned if the key is not found. */
|
||||||
int
|
int
|
||||||
get_pubkey_byname (ctrl_t ctrl, GETKEY_CTX * retctx, PKT_public_key * pk,
|
get_pubkey_byname (ctrl_t ctrl, enum get_pubkey_modes mode,
|
||||||
|
GETKEY_CTX * retctx, PKT_public_key * pk,
|
||||||
const char *name, KBNODE * ret_keyblock,
|
const char *name, KBNODE * ret_keyblock,
|
||||||
KEYDB_HANDLE * ret_kdbhd, int include_unusable, int no_akl)
|
KEYDB_HANDLE * ret_kdbhd, int include_unusable)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
strlist_t namelist = NULL;
|
strlist_t namelist = NULL;
|
||||||
@ -930,7 +936,7 @@ get_pubkey_byname (ctrl_t ctrl, GETKEY_CTX * retctx, PKT_public_key * pk,
|
|||||||
* Note: we only save the search context in RETCTX if the local
|
* Note: we only save the search context in RETCTX if the local
|
||||||
* method is the first method tried (either explicitly or
|
* method is the first method tried (either explicitly or
|
||||||
* implicitly). */
|
* implicitly). */
|
||||||
if (!no_akl)
|
if (mode != GET_PUBKEY_NO_AKL)
|
||||||
{
|
{
|
||||||
/* auto-key-locate is enabled. */
|
/* auto-key-locate is enabled. */
|
||||||
|
|
||||||
@ -980,7 +986,9 @@ get_pubkey_byname (ctrl_t ctrl, GETKEY_CTX * retctx, PKT_public_key * pk,
|
|||||||
|
|
||||||
/* If the requested name resembles a valid mailbox and automatic
|
/* If the requested name resembles a valid mailbox and automatic
|
||||||
retrieval has been enabled, we try to import the key. */
|
retrieval has been enabled, we try to import the key. */
|
||||||
if (gpg_err_code (rc) == GPG_ERR_NO_PUBKEY && !no_akl && is_mbox)
|
if (gpg_err_code (rc) == GPG_ERR_NO_PUBKEY
|
||||||
|
&& mode != GET_PUBKEY_NO_AKL
|
||||||
|
&& is_mbox)
|
||||||
{
|
{
|
||||||
/* NAME wasn't present in the local keyring (or we didn't try
|
/* NAME wasn't present in the local keyring (or we didn't try
|
||||||
* the local keyring). Since the auto key locate feature is
|
* the local keyring). Since the auto key locate feature is
|
||||||
@ -1325,8 +1333,9 @@ get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
|
|||||||
getkey_end (ctrl, ctx);
|
getkey_end (ctrl, ctx);
|
||||||
ctx = NULL;
|
ctx = NULL;
|
||||||
}
|
}
|
||||||
err = get_pubkey_byname (ctrl, &ctx, pk, name, ret_keyblock,
|
err = get_pubkey_byname (ctrl, GET_PUBKEY_NORMAL,
|
||||||
NULL, include_unusable, 0);
|
&ctx, pk, name, ret_keyblock,
|
||||||
|
NULL, include_unusable);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
getkey_end (ctrl, ctx);
|
getkey_end (ctrl, ctx);
|
||||||
|
@ -1200,7 +1200,8 @@ sig_revocation_key (const char *option, int argc, char *argv[], void *cookie)
|
|||||||
option, argv[0]);
|
option, argv[0]);
|
||||||
|
|
||||||
pk.req_usage = PUBKEY_USAGE_SIG;
|
pk.req_usage = PUBKEY_USAGE_SIG;
|
||||||
err = get_pubkey_byname (NULL, NULL, &pk, argv[1], NULL, NULL, 1, 1);
|
err = get_pubkey_byname (NULL, GET_PUBKEY_NO_AKL,
|
||||||
|
NULL, &pk, argv[1], NULL, NULL, 1);
|
||||||
if (err)
|
if (err)
|
||||||
log_fatal ("looking up key %s: %s\n", argv[1], gpg_strerror (err));
|
log_fatal ("looking up key %s: %s\n", argv[1], gpg_strerror (err));
|
||||||
|
|
||||||
@ -2457,7 +2458,8 @@ pk_esk (const char *option, int argc, char *argv[], void *cookie)
|
|||||||
|
|
||||||
memset (&pk, 0, sizeof (pk));
|
memset (&pk, 0, sizeof (pk));
|
||||||
pk.req_usage = PUBKEY_USAGE_ENC;
|
pk.req_usage = PUBKEY_USAGE_ENC;
|
||||||
err = get_pubkey_byname (NULL, NULL, &pk, pi.keyid, NULL, NULL, 1, 1);
|
err = get_pubkey_byname (NULL, GET_PUBKEY_NO_AKL,
|
||||||
|
NULL, &pk, pi.keyid, NULL, NULL, 1);
|
||||||
if (err)
|
if (err)
|
||||||
log_fatal ("%s: looking up key %s: %s\n",
|
log_fatal ("%s: looking up key %s: %s\n",
|
||||||
option, pi.keyid, gpg_strerror (err));
|
option, pi.keyid, gpg_strerror (err));
|
||||||
|
13
g10/keydb.h
13
g10/keydb.h
@ -345,12 +345,21 @@ typedef struct pubkey_s *pubkey_t;
|
|||||||
/* Free a list of public keys. */
|
/* Free a list of public keys. */
|
||||||
void pubkeys_free (pubkey_t keys);
|
void pubkeys_free (pubkey_t keys);
|
||||||
|
|
||||||
|
|
||||||
|
/* Mode flags for get_pubkey_byname. */
|
||||||
|
enum get_pubkey_modes
|
||||||
|
{
|
||||||
|
GET_PUBKEY_NORMAL = 0,
|
||||||
|
GET_PUBKEY_NO_AKL = 1,
|
||||||
|
GET_PUBKEY_NO_LOCAL = 2
|
||||||
|
};
|
||||||
|
|
||||||
/* Find a public key identified by NAME. */
|
/* Find a public key identified by NAME. */
|
||||||
int get_pubkey_byname (ctrl_t ctrl,
|
int get_pubkey_byname (ctrl_t ctrl, enum get_pubkey_modes mode,
|
||||||
GETKEY_CTX *retctx, PKT_public_key *pk,
|
GETKEY_CTX *retctx, PKT_public_key *pk,
|
||||||
const char *name,
|
const char *name,
|
||||||
KBNODE *ret_keyblock, KEYDB_HANDLE *ret_kdbhd,
|
KBNODE *ret_keyblock, KEYDB_HANDLE *ret_kdbhd,
|
||||||
int include_unusable, int no_akl );
|
int include_unusable);
|
||||||
|
|
||||||
/* Likewise, but only return the best match if NAME resembles a mail
|
/* Likewise, but only return the best match if NAME resembles a mail
|
||||||
* address. */
|
* address. */
|
||||||
|
@ -1438,7 +1438,8 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Get the public key */
|
/* Get the public key */
|
||||||
err = get_pubkey_byname (ctrl, NULL, NULL, username, &keyblock, &kdbhd, 1, 1);
|
err = get_pubkey_byname (ctrl, GET_PUBKEY_NO_AKL,
|
||||||
|
NULL, NULL, username, &keyblock, &kdbhd, 1);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
log_error (_("key \"%s\" not found: %s\n"), username, gpg_strerror (err));
|
log_error (_("key \"%s\" not found: %s\n"), username, gpg_strerror (err));
|
||||||
@ -2571,7 +2572,8 @@ find_by_primary_fpr (ctrl_t ctrl, const char *fpr,
|
|||||||
err = gpg_error (GPG_ERR_INV_NAME);
|
err = gpg_error (GPG_ERR_INV_NAME);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
err = get_pubkey_byname (ctrl, NULL, NULL, fpr, &keyblock, &kdbhd, 1, 1);
|
err = get_pubkey_byname (ctrl, GET_PUBKEY_NO_AKL,
|
||||||
|
NULL, NULL, fpr, &keyblock, &kdbhd, 1);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
log_error (_("key \"%s\" not found: %s\n"), fpr, gpg_strerror (err));
|
log_error (_("key \"%s\" not found: %s\n"), fpr, gpg_strerror (err));
|
||||||
@ -4290,7 +4292,8 @@ menu_addrevoker (ctrl_t ctrl, kbnode_t pub_keyblock, int sensitive)
|
|||||||
primary keys only, but some casual testing shows that PGP and
|
primary keys only, but some casual testing shows that PGP and
|
||||||
GnuPG both can handle a designated revocation from a subkey. */
|
GnuPG both can handle a designated revocation from a subkey. */
|
||||||
revoker_pk->req_usage = PUBKEY_USAGE_CERT;
|
revoker_pk->req_usage = PUBKEY_USAGE_CERT;
|
||||||
rc = get_pubkey_byname (ctrl, NULL, revoker_pk, answer, NULL, NULL, 1, 1);
|
rc = get_pubkey_byname (ctrl, GET_PUBKEY_NO_AKL,
|
||||||
|
NULL, revoker_pk, answer, NULL, NULL, 1);
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
log_error (_("key \"%s\" not found: %s\n"), answer,
|
log_error (_("key \"%s\" not found: %s\n"), answer,
|
||||||
|
@ -975,8 +975,8 @@ build_pk_list (ctrl_t ctrl, strlist_t rcpts, PK_LIST *ret_pk_list)
|
|||||||
r->pk = xmalloc_clear (sizeof *r->pk);
|
r->pk = xmalloc_clear (sizeof *r->pk);
|
||||||
r->pk->req_usage = PUBKEY_USAGE_ENC;
|
r->pk->req_usage = PUBKEY_USAGE_ENC;
|
||||||
|
|
||||||
rc = get_pubkey_byname (ctrl, NULL, r->pk, default_key,
|
rc = get_pubkey_byname (ctrl, GET_PUBKEY_NO_AKL,
|
||||||
NULL, NULL, 0, 1);
|
NULL, r->pk, default_key, NULL, NULL, 0);
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
xfree (r->pk);
|
xfree (r->pk);
|
||||||
@ -1041,8 +1041,8 @@ build_pk_list (ctrl_t ctrl, strlist_t rcpts, PK_LIST *ret_pk_list)
|
|||||||
/* We explicitly allow encrypt-to to an disabled key; thus
|
/* We explicitly allow encrypt-to to an disabled key; thus
|
||||||
we pass 1 for the second last argument and 1 as the last
|
we pass 1 for the second last argument and 1 as the last
|
||||||
argument to disable AKL. */
|
argument to disable AKL. */
|
||||||
if ( (rc = get_pubkey_byname (ctrl,
|
if ((rc = get_pubkey_byname (ctrl, GET_PUBKEY_NO_AKL,
|
||||||
NULL, pk, rov->d, NULL, NULL, 1, 1)) )
|
NULL, pk, rov->d, NULL, NULL, 1)))
|
||||||
{
|
{
|
||||||
free_public_key ( pk ); pk = NULL;
|
free_public_key ( pk ); pk = NULL;
|
||||||
log_error (_("%s: skipped: %s\n"), rov->d, gpg_strerror (rc) );
|
log_error (_("%s: skipped: %s\n"), rov->d, gpg_strerror (rc) );
|
||||||
@ -1179,7 +1179,8 @@ build_pk_list (ctrl_t ctrl, strlist_t rcpts, PK_LIST *ret_pk_list)
|
|||||||
free_public_key (pk);
|
free_public_key (pk);
|
||||||
pk = xmalloc_clear( sizeof *pk );
|
pk = xmalloc_clear( sizeof *pk );
|
||||||
pk->req_usage = PUBKEY_USAGE_ENC;
|
pk->req_usage = PUBKEY_USAGE_ENC;
|
||||||
rc = get_pubkey_byname (ctrl, NULL, pk, answer, NULL, NULL, 0, 0 );
|
rc = get_pubkey_byname (ctrl, GET_PUBKEY_NORMAL,
|
||||||
|
NULL, pk, answer, NULL, NULL, 0);
|
||||||
if (rc)
|
if (rc)
|
||||||
tty_printf(_("No such user ID.\n"));
|
tty_printf(_("No such user ID.\n"));
|
||||||
else if ( !(rc=openpgp_pk_test_algo2 (pk->pubkey_algo,
|
else if ( !(rc=openpgp_pk_test_algo2 (pk->pubkey_algo,
|
||||||
@ -1257,7 +1258,8 @@ build_pk_list (ctrl_t ctrl, strlist_t rcpts, PK_LIST *ret_pk_list)
|
|||||||
|
|
||||||
/* The default recipient is allowed to be disabled; thus pass 1
|
/* The default recipient is allowed to be disabled; thus pass 1
|
||||||
as second last argument. We also don't want an AKL. */
|
as second last argument. We also don't want an AKL. */
|
||||||
rc = get_pubkey_byname (ctrl, NULL, pk, def_rec, NULL, NULL, 1, 1);
|
rc = get_pubkey_byname (ctrl, GET_PUBKEY_NO_AKL,
|
||||||
|
NULL, pk, def_rec, NULL, NULL, 1);
|
||||||
if (rc)
|
if (rc)
|
||||||
log_error(_("unknown default recipient \"%s\"\n"), def_rec );
|
log_error(_("unknown default recipient \"%s\"\n"), def_rec );
|
||||||
else if ( !(rc=openpgp_pk_test_algo2(pk->pubkey_algo,
|
else if ( !(rc=openpgp_pk_test_algo2(pk->pubkey_algo,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user