Changeset View
Changeset View
Standalone View
Standalone View
b/g10/getkey.c
Context not available. | |||||
{ | { | ||||
gpg_error_t err = 0; | gpg_error_t err = 0; | ||||
const char *name; | const char *name; | ||||
kbnode_t keyblock; | |||||
struct | struct | ||||
{ | { | ||||
int eof; | int eof; | ||||
Context not available. | |||||
strlist_t sl; | strlist_t sl; | ||||
kbnode_t keyblock; | kbnode_t keyblock; | ||||
kbnode_t node; | kbnode_t node; | ||||
getkey_ctx_t ctx; | |||||
} *c = *context; | } *c = *context; | ||||
if (!c) | if (!c) | ||||
Context not available. | |||||
{ | { | ||||
/* Free the context. */ | /* Free the context. */ | ||||
release_kbnode (c->keyblock); | release_kbnode (c->keyblock); | ||||
getkey_end (c->ctx); | |||||
xfree (c); | xfree (c); | ||||
*context = NULL; | *context = NULL; | ||||
return 0; | return 0; | ||||
Context not available. | |||||
do | do | ||||
{ | { | ||||
name = NULL; | name = NULL; | ||||
keyblock = NULL; | |||||
switch (c->state) | switch (c->state) | ||||
{ | { | ||||
case 0: /* First try to use the --default-key. */ | case 0: /* First try to use the --default-key. */ | ||||
Context not available. | |||||
c->state++; | c->state++; | ||||
break; | break; | ||||
case 3: /* Init search context to try all keys. */ | |||||
if (opt.try_all_secrets) | |||||
{ | |||||
err = getkey_bynames (&c->ctx, NULL, NULL, 1, &keyblock); | |||||
if (err) | |||||
{ | |||||
release_kbnode (keyblock); | |||||
keyblock = NULL; | |||||
getkey_end (c->ctx); | |||||
c->ctx = NULL; | |||||
} | |||||
} | |||||
c->state++; | |||||
break; | |||||
case 4: /* Get next item from the context. */ | |||||
if (c->ctx) | |||||
{ | |||||
err = getkey_next (c->ctx, NULL, &keyblock); | |||||
if (err) | |||||
{ | |||||
release_kbnode (keyblock); | |||||
keyblock = NULL; | |||||
getkey_end (c->ctx); | |||||
c->ctx = NULL; | |||||
} | |||||
} | |||||
else | |||||
c->state++; | |||||
break; | |||||
default: /* No more names to check - stop. */ | default: /* No more names to check - stop. */ | ||||
c->eof = 1; | c->eof = 1; | ||||
return gpg_error (GPG_ERR_EOF); | return gpg_error (GPG_ERR_EOF); | ||||
} | } | ||||
} | } | ||||
while (!name || !*name); | while ((!name || !*name) && !keyblock); | ||||
err = getkey_byname (NULL, NULL, name, 1, &c->keyblock); | if (keyblock) | ||||
if (err) | c->node = c->keyblock = keyblock; | ||||
else | |||||
{ | { | ||||
/* getkey_byname might return a keyblock even in the | err = getkey_byname (NULL, NULL, name, 1, &c->keyblock); | ||||
error case - I have not checked. Thus better release | if (err) | ||||
it. */ | { | ||||
release_kbnode (c->keyblock); | /* getkey_byname might return a keyblock even in the | ||||
c->keyblock = NULL; | error case - I have not checked. Thus better release | ||||
it. */ | |||||
release_kbnode (c->keyblock); | |||||
c->keyblock = NULL; | |||||
} | |||||
else | |||||
c->node = c->keyblock; | |||||
} | } | ||||
else | |||||
c->node = c->keyblock; | |||||
} | } | ||||
/* Get the next key from the current keyblock. */ | /* Get the next key from the current keyblock. */ | ||||
Context not available. |