X-Git-Url: http://the.earth.li/gitweb/?a=blobdiff_plain;f=onak.c;h=e79e565a79779c08218101ea0c806f3ccedf6011;hb=fd58db2034c6781399583384055ce69fc300b26b;hp=2a0376e4dbcdfa4a54a6427457912564c77408c1;hpb=b3e534f945ae56605bc5309e7c5af020c797a69b;p=onak.git diff --git a/onak.c b/onak.c index 2a0376e..e79e565 100644 --- a/onak.c +++ b/onak.c @@ -6,10 +6,9 @@ * Jonathan McDowell * * Copyright 2002 Project Purple - * - * $Id: onak.c,v 1.21 2004/05/27 21:58:18 noodles Exp $ */ +#include #include #include #include @@ -17,6 +16,9 @@ #include "armor.h" #include "charfuncs.h" +#include "cleankey.h" +#include "cleanup.h" +#include "config.h" #include "keydb.h" #include "keyid.h" #include "keyindex.h" @@ -53,18 +55,23 @@ void find_keys(char *search, uint64_t keyid, bool ishex, } void usage(void) { - puts("onak " VERSION " - an OpenPGP keyserver.\n"); + puts("onak " PACKAGE_VERSION " - an OpenPGP keyserver.\n"); puts("Usage:\n"); puts("\tonak [options] \n"); puts("\tCommands:\n"); - puts("\tadd - read armored OpenPGP keys from stdin and add to the" + puts("\tadd - read armored OpenPGP keys from stdin and add to the" " keyserver"); - puts("\tdelete - delete a given key from the keyserver"); - puts("\tdump - dump all the keys from the keyserver to a file or" - " files\n\t starting keydump*"); - puts("\tget - retrieves the key requested from the keyserver"); - puts("\tindex - search for a key and list it"); - puts("\tvindex - search for a key and list it and its signatures"); + puts("\tclean - read armored OpenPGP keys from stdin, run the " + " cleaning\n\t routines against them and dump to" + " stdout"); + puts("\tdelete - delete a given key from the keyserver"); + puts("\tdump - dump all the keys from the keyserver to a file or" + " files\n\t starting keydump*"); + puts("\tget - retrieves the key requested from the keyserver"); + puts("\tgetphoto - retrieves the first photoid on the given key and" + " dumps to\n\t stdout"); + puts("\tindex - search for a key and list it"); + puts("\tvindex - search for a key and list it and its signatures"); } int main(int argc, char *argv[]) @@ -108,6 +115,7 @@ int main(int argc, char *argv[]) readconfig(configfile); initlogthing("onak", config.logfile); + catchsignals(); if ((argc - optind) < 1) { usage(); @@ -131,16 +139,26 @@ int main(int argc, char *argv[]) logthing(LOGTHING_INFO, "Finished reading %d keys.", result); + result = cleankeys(keys); + logthing(LOGTHING_INFO, "%d keys cleaned.", + result); + initdb(false); logthing(LOGTHING_NOTICE, "Got %d new keys.", - update_keys(&keys)); + update_keys(&keys, false)); if (keys != NULL && update) { flatten_publickey(keys, &packets, &list_end); - armor_openpgp_stream(stdout_putchar, - NULL, - packets); + if (binary) { + write_openpgp_stream(stdout_putchar, + NULL, + packets); + } else { + armor_openpgp_stream(stdout_putchar, + NULL, + packets); + } free_packet_list(packets); packets = NULL; } @@ -157,6 +175,53 @@ int main(int argc, char *argv[]) rc = 1; logthing(LOGTHING_NOTICE, "No changes."); } + } else if (!strcmp("clean", argv[optind])) { + if (binary) { + result = read_openpgp_stream(stdin_getchar, NULL, + &packets, 0); + logthing(LOGTHING_INFO, + "read_openpgp_stream: %d", result); + } else { + dearmor_openpgp_stream(stdin_getchar, NULL, &packets); + } + + if (packets != NULL) { + result = parse_keys(packets, &keys); + free_packet_list(packets); + packets = NULL; + logthing(LOGTHING_INFO, "Finished reading %d keys.", + result); + + if (keys != NULL) { + result = cleankeys(keys); + logthing(LOGTHING_INFO, "%d keys cleaned.", + result); + + flatten_publickey(keys, + &packets, + &list_end); + + if (binary) { + write_openpgp_stream(stdout_putchar, + NULL, + packets); + } else { + armor_openpgp_stream(stdout_putchar, + NULL, + packets); + } + free_packet_list(packets); + packets = NULL; + } + } else { + rc = 1; + logthing(LOGTHING_NOTICE, "No keys read."); + } + + if (keys != NULL) { + free_publickey(keys); + keys = NULL; + } } else if ((argc - optind) == 2) { search = argv[optind+1]; if (search != NULL) {