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"
25 #include "keystructs.h"
29 #include "onak-conf.h"
33 void find_keys(char *search, uint64_t keyid, bool ishex,
34 bool fingerprint, bool exact, bool verbose)
36 struct openpgp_publickey *publickey = NULL;
40 count = fetch_key(keyid, &publickey, false);
42 count = fetch_key_text(search, &publickey);
44 if (publickey != NULL) {
45 key_index(publickey, verbose, fingerprint, false);
46 free_publickey(publickey);
47 } else if (count == 0) {
48 puts("Key not found.");
50 printf("Found %d keys, but maximum number to return is %d.\n",
53 puts("Try again with a more specific search.");
58 puts("onak " PACKAGE_VERSION " - an OpenPGP keyserver.\n");
60 puts("\tonak [options] <command> <parameters>\n");
61 puts("\tCommands:\n");
62 puts("\tadd - read armored OpenPGP keys from stdin and add to the"
64 puts("\tclean - read armored OpenPGP keys from stdin, run the "
65 " cleaning\n\t routines against them and dump to"
67 puts("\tdelete - delete a given key from the keyserver");
68 puts("\tdump - dump all the keys from the keyserver to a file or"
69 " files\n\t starting keydump*");
70 puts("\tget - retrieves the key requested from the keyserver");
71 puts("\tgetphoto - retrieves the first photoid on the given key and"
72 " dumps to\n\t stdout");
73 puts("\tindex - search for a key and list it");
74 puts("\tvindex - search for a key and list it and its signatures");
77 int main(int argc, char *argv[])
79 struct openpgp_packet_list *packets = NULL;
80 struct openpgp_packet_list *list_end = NULL;
81 struct openpgp_publickey *keys = NULL;
82 char *configfile = NULL;
83 int rc = EXIT_SUCCESS;
92 bool fingerprint = false;
95 while ((optchar = getopt(argc, argv, "bc:fuv")) != -1 ) {
101 configfile = strdup(optarg);
111 setlogthreshold(LOGTHING_INFO);
116 readconfig(configfile);
117 initlogthing("onak", config.logfile);
120 if ((argc - optind) < 1) {
122 } else if (!strcmp("dump", argv[optind])) {
126 } else if (!strcmp("add", argv[optind])) {
128 result = read_openpgp_stream(stdin_getchar, NULL,
130 logthing(LOGTHING_INFO,
131 "read_openpgp_stream: %d", result);
133 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
135 if (packets != NULL) {
136 result = parse_keys(packets, &keys);
137 free_packet_list(packets);
139 logthing(LOGTHING_INFO, "Finished reading %d keys.",
142 result = cleankeys(keys);
143 logthing(LOGTHING_INFO, "%d keys cleaned.",
147 logthing(LOGTHING_NOTICE, "Got %d new keys.",
148 update_keys(&keys, false));
149 if (keys != NULL && update) {
150 flatten_publickey(keys,
154 write_openpgp_stream(stdout_putchar,
158 armor_openpgp_stream(stdout_putchar,
162 free_packet_list(packets);
168 logthing(LOGTHING_NOTICE, "No keys read.");
172 free_publickey(keys);
176 logthing(LOGTHING_NOTICE, "No changes.");
178 } else if (!strcmp("clean", argv[optind])) {
180 result = read_openpgp_stream(stdin_getchar, NULL,
182 logthing(LOGTHING_INFO,
183 "read_openpgp_stream: %d", result);
185 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
188 if (packets != NULL) {
189 result = parse_keys(packets, &keys);
190 free_packet_list(packets);
192 logthing(LOGTHING_INFO, "Finished reading %d keys.",
196 result = cleankeys(keys);
197 logthing(LOGTHING_INFO, "%d keys cleaned.",
200 flatten_publickey(keys,
205 write_openpgp_stream(stdout_putchar,
209 armor_openpgp_stream(stdout_putchar,
213 free_packet_list(packets);
218 logthing(LOGTHING_NOTICE, "No keys read.");
222 free_publickey(keys);
225 } else if ((argc - optind) == 2) {
226 search = argv[optind+1];
227 if (search != NULL) {
228 keyid = strtoul(search, &end, 16);
236 if (!strcmp("index", argv[optind])) {
237 find_keys(search, keyid, ishex, fingerprint,
239 } else if (!strcmp("vindex", argv[optind])) {
240 find_keys(search, keyid, ishex, fingerprint,
242 } else if (!strcmp("getphoto", argv[optind])) {
244 puts("Can't get a key on uid text."
245 " You must supply a keyid.");
246 } else if (fetch_key(keyid, &keys, false)) {
247 unsigned char *photo = NULL;
250 if (getphoto(keys, 0, &photo, &length)) {
256 free_publickey(keys);
259 puts("Key not found");
261 } else if (!strcmp("delete", argv[optind])) {
262 delete_key(getfullkeyid(keyid), false);
263 } else if (!strcmp("get", argv[optind])) {
265 puts("Can't get a key on uid text."
266 " You must supply a keyid.");
267 } else if (fetch_key(keyid, &keys, false)) {
268 logthing(LOGTHING_INFO, "Got key.");
269 flatten_publickey(keys,
272 free_publickey(keys);
273 armor_openpgp_stream(stdout_putchar,
276 free_packet_list(packets);
279 puts("Key not found");