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"
23 #include "keystructs.h"
27 #include "onak-conf.h"
31 void find_keys(char *search, uint64_t keyid, bool ishex,
32 bool fingerprint, bool exact, bool verbose)
34 struct openpgp_publickey *publickey = NULL;
38 count = fetch_key(keyid, &publickey, false);
40 count = fetch_key_text(search, &publickey);
42 if (publickey != NULL) {
43 key_index(publickey, verbose, fingerprint, false);
44 free_publickey(publickey);
45 } else if (count == 0) {
46 puts("Key not found.");
48 printf("Found %d keys, but maximum number to return is %d.\n",
51 puts("Try again with a more specific search.");
56 puts("onak " VERSION " - an OpenPGP keyserver.\n");
58 puts("\tonak [options] <command> <parameters>\n");
59 puts("\tCommands:\n");
60 puts("\tadd - read armored OpenPGP keys from stdin and add to the"
62 puts("\tclean - read armored OpenPGP keys from stdin, run the "
63 " cleaning\n\t routines against them and dump to"
65 puts("\tdelete - delete a given key from the keyserver");
66 puts("\tdump - dump all the keys from the keyserver to a file or"
67 " files\n\t starting keydump*");
68 puts("\tget - retrieves the key requested from the keyserver");
69 puts("\tgetphoto - retrieves the first photoid on the given key and"
70 " dumps to\n\t stdout");
71 puts("\tindex - search for a key and list it");
72 puts("\tvindex - search for a key and list it and its signatures");
75 int main(int argc, char *argv[])
77 struct openpgp_packet_list *packets = NULL;
78 struct openpgp_packet_list *list_end = NULL;
79 struct openpgp_publickey *keys = NULL;
80 char *configfile = NULL;
81 int rc = EXIT_SUCCESS;
90 bool fingerprint = false;
93 while ((optchar = getopt(argc, argv, "bc:fuv")) != -1 ) {
99 configfile = strdup(optarg);
109 setlogthreshold(LOGTHING_INFO);
114 readconfig(configfile);
115 initlogthing("onak", config.logfile);
117 if ((argc - optind) < 1) {
119 } else if (!strcmp("dump", argv[optind])) {
123 } else if (!strcmp("add", argv[optind])) {
125 result = read_openpgp_stream(stdin_getchar, NULL,
127 logthing(LOGTHING_INFO,
128 "read_openpgp_stream: %d", result);
130 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
132 if (packets != NULL) {
133 result = parse_keys(packets, &keys);
134 free_packet_list(packets);
136 logthing(LOGTHING_INFO, "Finished reading %d keys.",
139 result = cleankeys(keys);
140 logthing(LOGTHING_INFO, "%d keys cleaned.",
144 logthing(LOGTHING_NOTICE, "Got %d new keys.",
146 if (keys != NULL && update) {
147 flatten_publickey(keys,
151 write_openpgp_stream(stdout_putchar,
155 armor_openpgp_stream(stdout_putchar,
159 free_packet_list(packets);
165 logthing(LOGTHING_NOTICE, "No keys read.");
169 free_publickey(keys);
173 logthing(LOGTHING_NOTICE, "No changes.");
175 } else if (!strcmp("clean", argv[optind])) {
177 result = read_openpgp_stream(stdin_getchar, NULL,
179 logthing(LOGTHING_INFO,
180 "read_openpgp_stream: %d", result);
182 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
185 if (packets != NULL) {
186 result = parse_keys(packets, &keys);
187 free_packet_list(packets);
189 logthing(LOGTHING_INFO, "Finished reading %d keys.",
193 result = cleankeys(keys);
194 logthing(LOGTHING_INFO, "%d keys cleaned.",
197 flatten_publickey(keys,
202 write_openpgp_stream(stdout_putchar,
206 armor_openpgp_stream(stdout_putchar,
210 free_packet_list(packets);
215 logthing(LOGTHING_NOTICE, "No keys read.");
219 free_publickey(keys);
222 } else if ((argc - optind) == 2) {
223 search = argv[optind+1];
224 if (search != NULL) {
225 keyid = strtoul(search, &end, 16);
233 if (!strcmp("index", argv[optind])) {
234 find_keys(search, keyid, ishex, fingerprint,
236 } else if (!strcmp("vindex", argv[optind])) {
237 find_keys(search, keyid, ishex, fingerprint,
239 } else if (!strcmp("getphoto", argv[optind])) {
241 puts("Can't get a key on uid text."
242 " You must supply a keyid.");
243 } else if (fetch_key(keyid, &keys, false)) {
244 unsigned char *photo = NULL;
247 if (getphoto(keys, 0, &photo, &length)) {
253 free_publickey(keys);
256 puts("Key not found");
258 } else if (!strcmp("delete", argv[optind])) {
259 delete_key(getfullkeyid(keyid), false);
260 } else if (!strcmp("get", argv[optind])) {
262 puts("Can't get a key on uid text."
263 " You must supply a keyid.");
264 } else if (fetch_key(keyid, &keys, false)) {
265 logthing(LOGTHING_INFO, "Got key.");
266 flatten_publickey(keys,
269 free_publickey(keys);
270 armor_openpgp_stream(stdout_putchar,
273 free_packet_list(packets);
276 puts("Key not found");