tests: Add option "allow-del" to run-threaded

* tests/run-threaded.c (main): Handle allow-del.
(allow-del): New. Variable to allow deletion of keys.
(import): Delete key after import if allow-del is set.
(delete_impres): Delete keys from an import result.
(delete_fpr): Delete a key by fingerprint.

--
This is intended to test write access and locking of the
keyring by repeatedly importing and deleting pubkeys.

It is an option because it might cause keyring corruption
etc. so it should be explicitly enabled.
This commit is contained in:
Andre Heinecke 2019-06-06 09:19:02 +02:00
parent 024a7f75d4
commit e6f2827306
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C

View File

@ -126,6 +126,7 @@ show_usage (int ex)
"Options:\n" "Options:\n"
" --verbose run in verbose mode\n" " --verbose run in verbose mode\n"
" --no-list do not do keylistings\n" " --no-list do not do keylistings\n"
" --allow-del allow to delete keys after import\n"
" --data-type mem function to use one of:\n" " --data-type mem function to use one of:\n"
" 1: fstream\n" " 1: fstream\n"
" 2: posix fd\n" " 2: posix fd\n"
@ -173,6 +174,8 @@ typedef struct keylist_args_s *keylist_args_t;
static volatile int keylists; static volatile int keylists;
static int allow_del;
static THREAD_RET static THREAD_RET
do_keylist (void *keylist_args) do_keylist (void *keylist_args)
{ {
@ -453,6 +456,67 @@ decrypt (const char *fname, gpgme_protocol_t proto)
random_data_close (data); random_data_close (data);
} }
void
delete_key (gpgme_key_t key)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
err = gpgme_new (&ctx);
fail_if_err (err);
gpgme_set_protocol (ctx, key->protocol);
err = gpgme_op_delete (ctx, key, 0);
fail_if_err (err);
gpgme_release (ctx);
}
/* Get the key for the fpr in protocol and call delete_key
on it. */
void
delete_fpr (const char *fpr, gpgme_protocol_t proto)
{
gpgme_ctx_t ctx;
gpgme_error_t err;
gpgme_key_t key = NULL;
err = gpgme_new (&ctx);
fail_if_err (err);
gpgme_set_protocol (ctx, proto);
err = gpgme_get_key (ctx, fpr, &key, 0);
fail_if_err (err);
if (!key)
{
errpoint;
}
delete_key (key);
log ("deleted key %s", fpr);
gpgme_key_unref (key);
gpgme_release (ctx);
}
void
delete_impres (gpgme_import_result_t r, gpgme_protocol_t proto)
{
gpgme_import_status_t st;
if (!r)
{
errpoint;
}
for (st=r->imports; st; st = st->next)
{
delete_fpr (st->fpr, proto);
}
}
void void
import (const char *fname, gpgme_protocol_t proto) import (const char *fname, gpgme_protocol_t proto)
{ {
@ -473,6 +537,11 @@ import (const char *fname, gpgme_protocol_t proto)
err = gpgme_op_import (ctx, data->dh); err = gpgme_op_import (ctx, data->dh);
fail_if_err (err); fail_if_err (err);
if (allow_del)
{
delete_impres (gpgme_op_import_result (ctx), proto);
}
gpgme_release (ctx); gpgme_release (ctx);
log ("Import completed."); log ("Import completed.");
@ -607,6 +676,11 @@ main (int argc, char **argv)
no_list = 1; no_list = 1;
argc--; argv++; argc--; argv++;
} }
else if (!strcmp (*argv, "--allow-del"))
{
allow_del = 1;
argc--; argv++;
}
else if (!strcmp (*argv, "--mem-only")) else if (!strcmp (*argv, "--mem-only"))
{ {
if (data_type) if (data_type)