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
18 #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);
119 if ((argc - optind) < 1) {
121 } else if (!strcmp("dump", argv[optind])) {
125 } else if (!strcmp("add", argv[optind])) {
127 result = read_openpgp_stream(stdin_getchar, NULL,
129 logthing(LOGTHING_INFO,
130 "read_openpgp_stream: %d", result);
132 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
134 if (packets != NULL) {
135 result = parse_keys(packets, &keys);
136 free_packet_list(packets);
138 logthing(LOGTHING_INFO, "Finished reading %d keys.",
141 result = cleankeys(keys);
142 logthing(LOGTHING_INFO, "%d keys cleaned.",
146 logthing(LOGTHING_NOTICE, "Got %d new keys.",
148 if (keys != NULL && update) {
149 flatten_publickey(keys,
153 write_openpgp_stream(stdout_putchar,
157 armor_openpgp_stream(stdout_putchar,
161 free_packet_list(packets);
167 logthing(LOGTHING_NOTICE, "No keys read.");
171 free_publickey(keys);
175 logthing(LOGTHING_NOTICE, "No changes.");
177 } else if (!strcmp("clean", argv[optind])) {
179 result = read_openpgp_stream(stdin_getchar, NULL,
181 logthing(LOGTHING_INFO,
182 "read_openpgp_stream: %d", result);
184 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
187 if (packets != NULL) {
188 result = parse_keys(packets, &keys);
189 free_packet_list(packets);
191 logthing(LOGTHING_INFO, "Finished reading %d keys.",
195 result = cleankeys(keys);
196 logthing(LOGTHING_INFO, "%d keys cleaned.",
199 flatten_publickey(keys,
204 write_openpgp_stream(stdout_putchar,
208 armor_openpgp_stream(stdout_putchar,
212 free_packet_list(packets);
217 logthing(LOGTHING_NOTICE, "No keys read.");
221 free_publickey(keys);
224 } else if ((argc - optind) == 2) {
225 search = argv[optind+1];
226 if (search != NULL) {
227 keyid = strtoul(search, &end, 16);
235 if (!strcmp("index", argv[optind])) {
236 find_keys(search, keyid, ishex, fingerprint,
238 } else if (!strcmp("vindex", argv[optind])) {
239 find_keys(search, keyid, ishex, fingerprint,
241 } else if (!strcmp("getphoto", argv[optind])) {
243 puts("Can't get a key on uid text."
244 " You must supply a keyid.");
245 } else if (fetch_key(keyid, &keys, false)) {
246 unsigned char *photo = NULL;
249 if (getphoto(keys, 0, &photo, &length)) {
255 free_publickey(keys);
258 puts("Key not found");
260 } else if (!strcmp("delete", argv[optind])) {
261 delete_key(getfullkeyid(keyid), false);
262 } else if (!strcmp("get", argv[optind])) {
264 puts("Can't get a key on uid text."
265 " You must supply a keyid.");
266 } else if (fetch_key(keyid, &keys, false)) {
267 logthing(LOGTHING_INFO, "Got key.");
268 flatten_publickey(keys,
271 free_publickey(keys);
272 armor_openpgp_stream(stdout_putchar,
275 free_packet_list(packets);
278 puts("Key not found");