X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;f=onak.c;h=a588b51d2fc667c668b4aa3106dabc9a2d7794be;hb=refs%2Fheads%2Fmain;hp=a27ff983e78908d6de2e57013173d7b97d7118cf;hpb=a2979c20e1ab2d52e3a961ac7dad45fee9d6345a;p=onak.git diff --git a/onak.c b/onak.c index a27ff98..a588b51 100644 --- a/onak.c +++ b/onak.c @@ -187,6 +187,9 @@ int main(int argc, char *argv[]) binary = true; break; case 'c': + if (configfile != NULL) { + free(configfile); + } configfile = strdup(optarg); break; case 'e': @@ -215,6 +218,12 @@ int main(int argc, char *argv[]) usage(); } else if (!strcmp("dump", argv[optind])) { dbctx = config.dbinit(config.backend, true); + if (dbctx == NULL) { + logthing(LOGTHING_ERROR, + "Failed to open key database."); + rc = EXIT_FAILURE; + goto err; + } dumpstate.count = dumpstate.filenum = 0; dumpstate.maxcount = 100000; dumpstate.fd = -1; @@ -242,6 +251,12 @@ int main(int argc, char *argv[]) result); dbctx = config.dbinit(config.backend, false); + if (dbctx == NULL) { + logthing(LOGTHING_ERROR, + "Failed to open key database."); + rc = EXIT_FAILURE; + goto err; + } result = cleankeys(dbctx, &keys, config.clean_policies); logthing(LOGTHING_INFO, "%d keys cleaned.", @@ -284,6 +299,12 @@ int main(int argc, char *argv[]) } } else if (!strcmp("clean", argv[optind])) { dbctx = config.dbinit(config.backend, true); + if (dbctx == NULL) { + logthing(LOGTHING_ERROR, + "Failed to open key database."); + rc = EXIT_FAILURE; + goto err; + } if (binary) { result = read_openpgp_stream(stdin_getchar, NULL, &packets, 0); @@ -370,6 +391,12 @@ int main(int argc, char *argv[]) } } dbctx = config.dbinit(config.backend, false); + if (dbctx == NULL) { + logthing(LOGTHING_ERROR, + "Failed to open key database."); + rc = EXIT_FAILURE; + goto err; + } if (!strcmp("index", argv[optind])) { find_keys(dbctx, search, keyid, &fingerprint, ishex, isfp, dispfp, skshash, @@ -484,6 +511,7 @@ int main(int argc, char *argv[]) usage(); } +err: cleanuplogthing(); cleanupconfig(); free(configfile);