catchsignals();
dbctx = config.dbinit(config.backend, false);
- count = cleankeys(&keys, config.clean_policies);
+ count = cleankeys(dbctx, &keys, config.clean_policies);
logthing(LOGTHING_INFO, "%d keys cleaned.",
count);
result,
search);
puts("<pre>");
- cleankeys(&publickey, config.clean_policies);
+ cleankeys(dbctx, &publickey,
+ config.clean_policies);
flatten_publickey(publickey,
&packets,
&list_end);
* made, otherwise the number of keys cleaned. Note that some options
* may result in keys being removed entirely from the list.
*/
-int cleankeys(struct openpgp_publickey **keys, uint64_t policies)
+int cleankeys(struct onak_dbctx *dbctx, struct openpgp_publickey **keys,
+ uint64_t policies)
{
struct openpgp_publickey **curkey, *tmp;
int changed = 0, count = 0;
#ifndef __CLEANKEY_H__
#define __CLEANKEY_H__
+#include "keydb.h"
#include "keystructs.h"
#define ONAK_CLEAN_CHECK_SIGHASH (1 << 0)
/**
* cleankeys - Apply all available cleaning options on a list of keys.
+ * @dbctx: A database context suitable for looking up signing keys
* @publickey: The list of keys to clean.
* @policies: The cleaning policies to apply.
*
* made, otherwise the number of keys cleaned. Note that some options
* may result in keys being removed entirely from the list.
*/
-int cleankeys(struct openpgp_publickey **keys, uint64_t policies);
+int cleankeys(struct onak_dbctx *dbctx, struct openpgp_publickey **keys,
+ uint64_t policies);
#endif
(struct onak_dbctx *) privctx->backends->object;
struct openpgp_publickey *curkey;
- cleankeys(&publickey, config.clean_policies);
+ cleankeys(backend, &publickey, config.clean_policies);
/*
* If we walked the stack at all, store the key in the first
* backend if configured to do so. It's not an update as we
logthing(LOGTHING_INFO, "Finished reading %d keys.",
result);
- result = cleankeys(&keys, config.clean_policies);
+ dbctx = config.dbinit(config.backend, false);
+ result = cleankeys(dbctx, &keys,
+ config.clean_policies);
logthing(LOGTHING_INFO, "%d keys cleaned.",
result);
- dbctx = config.dbinit(config.backend, false);
logthing(LOGTHING_NOTICE, "Got %d new keys.",
dbctx->update_keys(dbctx, &keys,
&config.blacklist,
logthing(LOGTHING_NOTICE, "No changes.");
}
} else if (!strcmp("clean", argv[optind])) {
+ dbctx = config.dbinit(config.backend, true);
if (binary) {
result = read_openpgp_stream(stdin_getchar, NULL,
&packets, 0);
result);
if (keys != NULL) {
- result = cleankeys(&keys,
+ result = cleankeys(dbctx, &keys,
config.clean_policies);
logthing(LOGTHING_INFO, "%d keys cleaned.",
result);
free_publickey(keys);
keys = NULL;
}
+ dbctx->cleanupdb(dbctx);
} else if (!strcmp("dumpconfig", argv[optind])) {
if ((argc - optind) == 2) {
writeconfig(argv[optind + 1]);
if (dbctx->fetch_key_id(dbctx, keyid, &keys, true)) {
get_fingerprint(keys->publickey, &fingerprint);
dbctx->delete_key(dbctx, &fingerprint, true);
- cleankeys(&keys, config.clean_policies);
+ cleankeys(dbctx, &keys, config.clean_policies);
dbctx->store_key(dbctx, keys, true, false);
} else {
puts("Key not found");
parse_keys( packets, &keys );
free_packet_list(packets);
packets = NULL;
- cleankeys(&keys, ONAK_CLEAN_ALL);
+ cleankeys(NULL, &keys, ONAK_CLEAN_ALL);
/* Iterate over the keys... */
for( key = keys; key; key = key->next ) {
uint64_t keyid;