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.22 2004/05/31 14:16:49 noodles Exp $
19 #include "charfuncs.h"
24 #include "keystructs.h"
28 #include "onak-conf.h"
32 void find_keys(char *search, uint64_t keyid, bool ishex,
33 bool fingerprint, bool exact, bool verbose)
35 struct openpgp_publickey *publickey = NULL;
39 count = fetch_key(keyid, &publickey, false);
41 count = fetch_key_text(search, &publickey);
43 if (publickey != NULL) {
44 key_index(publickey, verbose, fingerprint, false);
45 free_publickey(publickey);
46 } else if (count == 0) {
47 puts("Key not found.");
49 printf("Found %d keys, but maximum number to return is %d.\n",
52 puts("Try again with a more specific search.");
57 puts("onak " VERSION " - an OpenPGP keyserver.\n");
59 puts("\tonak [options] <command> <parameters>\n");
60 puts("\tCommands:\n");
61 puts("\tadd - read armored OpenPGP keys from stdin and add to the"
63 puts("\tclean - read armored OpenPGP keys from stdin, run the "
64 " cleaning\n\t routines against them and dump to"
66 puts("\tdelete - delete a given key from the keyserver");
67 puts("\tdump - dump all the keys from the keyserver to a file or"
68 " files\n\t starting keydump*");
69 puts("\tget - retrieves the key requested from the keyserver");
70 puts("\tgetphoto - retrieves the first photoid on the given key and"
71 " dumps to\n\t stdout");
72 puts("\tindex - search for a key and list it");
73 puts("\tvindex - search for a key and list it and its signatures");
76 int main(int argc, char *argv[])
78 struct openpgp_packet_list *packets = NULL;
79 struct openpgp_packet_list *list_end = NULL;
80 struct openpgp_publickey *keys = NULL;
81 char *configfile = NULL;
82 int rc = EXIT_SUCCESS;
91 bool fingerprint = false;
94 while ((optchar = getopt(argc, argv, "bc:fuv")) != -1 ) {
100 configfile = strdup(optarg);
110 setlogthreshold(LOGTHING_INFO);
115 readconfig(configfile);
116 initlogthing("onak", config.logfile);
118 if ((argc - optind) < 1) {
120 } else if (!strcmp("dump", argv[optind])) {
124 } else if (!strcmp("add", argv[optind])) {
126 result = read_openpgp_stream(stdin_getchar, NULL,
128 logthing(LOGTHING_INFO,
129 "read_openpgp_stream: %d", result);
131 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
133 if (packets != NULL) {
134 result = parse_keys(packets, &keys);
135 free_packet_list(packets);
137 logthing(LOGTHING_INFO, "Finished reading %d keys.",
140 result = cleankeys(keys);
141 logthing(LOGTHING_INFO, "%d keys cleaned.",
145 logthing(LOGTHING_NOTICE, "Got %d new keys.",
147 if (keys != NULL && update) {
148 flatten_publickey(keys,
152 write_openpgp_stream(stdout_putchar,
156 armor_openpgp_stream(stdout_putchar,
160 free_packet_list(packets);
166 logthing(LOGTHING_NOTICE, "No keys read.");
170 free_publickey(keys);
174 logthing(LOGTHING_NOTICE, "No changes.");
176 } else if (!strcmp("clean", argv[optind])) {
178 result = read_openpgp_stream(stdin_getchar, NULL,
180 logthing(LOGTHING_INFO,
181 "read_openpgp_stream: %d", result);
183 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
186 if (packets != NULL) {
187 result = parse_keys(packets, &keys);
188 free_packet_list(packets);
190 logthing(LOGTHING_INFO, "Finished reading %d keys.",
194 result = cleankeys(keys);
195 logthing(LOGTHING_INFO, "%d keys cleaned.",
198 flatten_publickey(keys,
203 write_openpgp_stream(stdout_putchar,
207 armor_openpgp_stream(stdout_putchar,
211 free_packet_list(packets);
216 logthing(LOGTHING_NOTICE, "No keys read.");
220 free_publickey(keys);
223 } else if ((argc - optind) == 2) {
224 search = argv[optind+1];
225 if (search != NULL) {
226 keyid = strtoul(search, &end, 16);
234 if (!strcmp("index", argv[optind])) {
235 find_keys(search, keyid, ishex, fingerprint,
237 } else if (!strcmp("vindex", argv[optind])) {
238 find_keys(search, keyid, ishex, fingerprint,
240 } else if (!strcmp("getphoto", argv[optind])) {
242 puts("Can't get a key on uid text."
243 " You must supply a keyid.");
244 } else if (fetch_key(keyid, &keys, false)) {
245 unsigned char *photo = NULL;
248 if (getphoto(keys, 0, &photo, &length)) {
254 free_publickey(keys);
257 puts("Key not found");
259 } else if (!strcmp("delete", argv[optind])) {
260 delete_key(getfullkeyid(keyid), false);
261 } else if (!strcmp("get", argv[optind])) {
263 puts("Can't get a key on uid text."
264 " You must supply a keyid.");
265 } else if (fetch_key(keyid, &keys, false)) {
266 logthing(LOGTHING_INFO, "Got key.");
267 flatten_publickey(keys,
270 free_publickey(keys);
271 armor_openpgp_stream(stdout_putchar,
274 free_packet_list(packets);
277 puts("Key not found");