2 * onak.c - An OpenPGP keyserver.
4 * This is the main swiss army knife binary.
6 * Jonathan McDowell <noodles@earth.li>
8 * Copyright 2002 Project Purple
10 * $Id: onak.c,v 1.17 2003/09/30 20:40:11 noodles Exp $
19 #include "charfuncs.h"
23 #include "keystructs.h"
27 #include "onak-conf.h"
30 void find_keys(char *search, uint64_t keyid, bool ishex,
31 bool fingerprint, bool exact, bool verbose)
33 struct openpgp_publickey *publickey = NULL;
37 count = fetch_key(keyid, &publickey, false);
39 count = fetch_key_text(search, &publickey);
41 if (publickey != NULL) {
42 key_index(publickey, verbose, fingerprint, false);
43 free_publickey(publickey);
44 } else if (count == 0) {
45 puts("Key not found.");
47 printf("Found %d keys, but maximum number to return is %d.\n",
50 puts("Try again with a more specific search.");
55 puts("onak " VERSION " - an OpenPGP keyserver.\n");
57 puts("\tonak [options] <command> <parameters>\n");
58 puts("\tCommands:\n");
59 puts("\tadd - read armored OpenPGP keys from stdin and add to the"
61 puts("\tdelete - delete a given key from the keyserver");
62 puts("\tdump - dump all the keys from the keyserver to a file or"
63 " files\n\t starting keydump*");
64 puts("\tget - retrieves the key requested from the keyserver");
65 puts("\tindex - search for a key and list it");
66 puts("\tvindex - search for a key and list it and its signatures");
69 int main(int argc, char *argv[])
71 struct openpgp_packet_list *packets = NULL;
72 struct openpgp_packet_list *list_end = NULL;
73 struct openpgp_publickey *keys = NULL;
74 int rc = EXIT_SUCCESS;
83 bool fingerprint = false;
86 while ((optchar = getopt(argc, argv, "bfuv")) != -1 ) {
99 setlogthreshold(LOGTHING_INFO);
105 initlogthing("onak", config.logfile);
107 if ((argc - optind) < 1) {
109 } else if (!strcmp("dump", argv[optind])) {
113 } else if (!strcmp("add", argv[optind])) {
115 result = read_openpgp_stream(stdin_getchar, NULL,
117 logthing(LOGTHING_INFO,
118 "read_openpgp_stream: %d", result);
120 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
122 if (packets != NULL) {
123 result = parse_keys(packets, &keys);
124 free_packet_list(packets);
126 logthing(LOGTHING_INFO, "Finished reading %d keys.",
130 logthing(LOGTHING_NOTICE, "Got %d new keys.",
132 if (keys != NULL && update) {
133 flatten_publickey(keys,
136 armor_openpgp_stream(stdout_putchar,
139 free_packet_list(packets);
145 logthing(LOGTHING_NOTICE, "No keys read.");
149 free_publickey(keys);
153 logthing(LOGTHING_NOTICE, "No changes.");
155 } else if ((argc - optind) == 2) {
156 search = argv[optind+1];
157 if (search != NULL) {
158 keyid = strtoul(search, &end, 16);
166 if (!strcmp("index", argv[optind])) {
167 find_keys(search, keyid, ishex, fingerprint,
169 } else if (!strcmp("vindex", argv[optind])) {
170 find_keys(search, keyid, ishex, fingerprint,
172 } else if (!strcmp("delete", argv[optind])) {
173 delete_key(getfullkeyid(keyid), false);
174 } else if (!strcmp("get", argv[optind])) {
176 puts("Can't get a key on uid text."
177 " You must supply a keyid.");
178 } else if (fetch_key(keyid, &keys, false)) {
179 logthing(LOGTHING_INFO, "Got key.");
180 flatten_publickey(keys,
183 free_publickey(keys);
184 armor_openpgp_stream(stdout_putchar,
187 free_packet_list(packets);
190 puts("Key not found");