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
20 #include "keystructs.h"
24 #include "onak-conf.h"
27 int stdin_getchar(void *ctx, size_t count, unsigned char *c)
35 } while ((ic != EOF) && (--count > 0));
39 int stdout_putchar(void *ctx, size_t count, unsigned char *c)
43 for (i = 0; i < count; i++) {
49 void find_keys(char *search, uint64_t keyid, bool ishex,
50 bool fingerprint, bool exact, bool verbose)
52 struct openpgp_publickey *publickey = NULL;
56 count = fetch_key(keyid, &publickey, false);
58 count = fetch_key_text(search, &publickey);
60 if (publickey != NULL) {
61 key_index(publickey, verbose, fingerprint, false);
62 free_publickey(publickey);
63 } else if (count == 0) {
64 puts("Key not found.");
66 printf("Found %d keys, but maximum number to return is %d.\n",
69 puts("Try again with a more specific search.");
74 puts("onak " VERSION " - an OpenPGP keyserver.\n");
76 puts("\tonak [options] <command> <parameters>\n");
77 puts("\tCommands:\n");
78 puts("\tadd - read armored OpenPGP keys from stdin and add to the"
80 puts("\tdelete - delete a given key from the keyserver");
81 puts("\tdump - dump all the keys from the keyserver to a file or"
82 " files\n\t starting keydump*");
83 puts("\tget - retrieves the key requested from the keyserver");
84 puts("\tindex - search for a key and list it");
85 puts("\tvindex - search for a key and list it and its signatures");
88 int main(int argc, char *argv[])
90 struct openpgp_packet_list *packets = NULL;
91 struct openpgp_packet_list *list_end = NULL;
92 struct openpgp_publickey *keys = NULL;
93 int rc = EXIT_SUCCESS;
102 bool fingerprint = false;
105 while ((optchar = getopt(argc, argv, "bfuv")) != -1 ) {
118 setlogthreshold(LOGTHING_INFO);
124 initlogthing("onak", config.logfile);
126 if ((argc - optind) < 1) {
128 } else if (!strcmp("dump", argv[optind])) {
132 } else if (!strcmp("add", argv[optind])) {
134 result = read_openpgp_stream(stdin_getchar, NULL,
136 logthing(LOGTHING_INFO,
137 "read_openpgp_stream: %d", result);
139 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
141 if (packets != NULL) {
142 result = parse_keys(packets, &keys);
143 free_packet_list(packets);
145 logthing(LOGTHING_INFO, "Finished reading %d keys.",
149 logthing(LOGTHING_NOTICE, "Got %d new keys.",
151 if (keys != NULL && update) {
152 flatten_publickey(keys,
155 armor_openpgp_stream(stdout_putchar,
158 free_packet_list(packets);
164 logthing(LOGTHING_NOTICE, "No keys read.");
168 free_publickey(keys);
172 logthing(LOGTHING_NOTICE, "No changes.");
174 } else if ((argc - optind) == 2) {
175 search = argv[optind+1];
176 if (search != NULL) {
177 keyid = strtoul(search, &end, 16);
185 if (!strcmp("index", argv[optind])) {
186 find_keys(search, keyid, ishex, fingerprint,
188 } else if (!strcmp("vindex", argv[optind])) {
189 find_keys(search, keyid, ishex, fingerprint,
191 } else if (!strcmp("delete", argv[optind])) {
192 delete_key(getfullkeyid(keyid), false);
193 } else if (!strcmp("get", argv[optind])) {
194 if (fetch_key(keyid, &keys, false)) {
195 logthing(LOGTHING_INFO, "Got key.");
196 flatten_publickey(keys,
199 free_publickey(keys);
200 armor_openpgp_stream(stdout_putchar,
203 free_packet_list(packets);
206 puts("Key not found");