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.19 2004/03/23 12:33:47 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 char *configfile = NULL;
75 int rc = EXIT_SUCCESS;
84 bool fingerprint = false;
87 while ((optchar = getopt(argc, argv, "bc:fuv")) != -1 ) {
93 configfile = strdup(optarg);
103 setlogthreshold(LOGTHING_INFO);
108 readconfig(configfile);
109 initlogthing("onak", config.logfile);
111 if ((argc - optind) < 1) {
113 } else if (!strcmp("dump", argv[optind])) {
117 } else if (!strcmp("add", argv[optind])) {
119 result = read_openpgp_stream(stdin_getchar, NULL,
121 logthing(LOGTHING_INFO,
122 "read_openpgp_stream: %d", result);
124 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
126 if (packets != NULL) {
127 result = parse_keys(packets, &keys);
128 free_packet_list(packets);
130 logthing(LOGTHING_INFO, "Finished reading %d keys.",
134 logthing(LOGTHING_NOTICE, "Got %d new keys.",
136 if (keys != NULL && update) {
137 flatten_publickey(keys,
140 armor_openpgp_stream(stdout_putchar,
143 free_packet_list(packets);
149 logthing(LOGTHING_NOTICE, "No keys read.");
153 free_publickey(keys);
157 logthing(LOGTHING_NOTICE, "No changes.");
159 } else if ((argc - optind) == 2) {
160 search = argv[optind+1];
161 if (search != NULL) {
162 keyid = strtoul(search, &end, 16);
170 if (!strcmp("index", argv[optind])) {
171 find_keys(search, keyid, ishex, fingerprint,
173 } else if (!strcmp("vindex", argv[optind])) {
174 find_keys(search, keyid, ishex, fingerprint,
176 } else if (!strcmp("delete", argv[optind])) {
177 delete_key(getfullkeyid(keyid), false);
178 } else if (!strcmp("get", argv[optind])) {
180 puts("Can't get a key on uid text."
181 " You must supply a keyid.");
182 } else if (fetch_key(keyid, &keys, false)) {
183 logthing(LOGTHING_INFO, "Got key.");
184 flatten_publickey(keys,
187 free_publickey(keys);
188 armor_openpgp_stream(stdout_putchar,
191 free_packet_list(packets);
194 puts("Key not found");