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("\tget - retrieves the key requested from the keyserver");
82 puts("\tindex - search for a key and list it");
83 puts("\tvindex - search for a key and list it and its signatures");
86 int main(int argc, char *argv[])
88 struct openpgp_packet_list *packets = NULL;
89 struct openpgp_packet_list *list_end = NULL;
90 struct openpgp_publickey *keys = NULL;
91 int rc = EXIT_SUCCESS;
100 bool fingerprint = false;
103 while ((optchar = getopt(argc, argv, "bfuv")) != -1 ) {
116 setlogthreshold(LOGTHING_INFO);
122 initlogthing("onak", config.logfile);
124 if ((argc - optind) < 1) {
126 } else if (!strcmp("dump", argv[optind])) {
130 } else if (!strcmp("add", argv[optind])) {
132 result = read_openpgp_stream(stdin_getchar, NULL,
134 logthing(LOGTHING_INFO,
135 "read_openpgp_stream: %d", result);
137 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
139 if (packets != NULL) {
140 result = parse_keys(packets, &keys);
141 free_packet_list(packets);
143 logthing(LOGTHING_INFO, "Finished reading %d keys.",
147 logthing(LOGTHING_NOTICE, "Got %d new keys.",
149 if (keys != NULL && update) {
150 flatten_publickey(keys,
153 armor_openpgp_stream(stdout_putchar,
156 free_packet_list(packets);
162 logthing(LOGTHING_NOTICE, "No keys read.");
166 free_publickey(keys);
170 logthing(LOGTHING_NOTICE, "No changes.");
172 } else if ((argc - optind) == 2) {
173 search = argv[optind+1];
174 if (search != NULL) {
175 keyid = strtoul(search, &end, 16);
183 if (!strcmp("index", argv[optind])) {
184 find_keys(search, keyid, ishex, fingerprint,
186 } else if (!strcmp("vindex", argv[optind])) {
187 find_keys(search, keyid, ishex, fingerprint,
189 } else if (!strcmp("delete", argv[optind])) {
190 delete_key(getfullkeyid(keyid), false);
191 } else if (!strcmp("get", argv[optind])) {
192 if (fetch_key(keyid, &keys, false)) {
193 logthing(LOGTHING_INFO, "Got key.");
194 flatten_publickey(keys,
197 armor_openpgp_stream(stdout_putchar,
200 free_packet_list(packets);
203 puts("Key not found");