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.14 2003/06/07 13:37:33 noodles Exp $
22 #include "keystructs.h"
26 #include "onak-conf.h"
29 int stdin_getchar(void *ctx, size_t count, unsigned char *c)
37 } while ((ic != EOF) && (--count > 0));
41 int stdout_putchar(void *ctx, size_t count, unsigned char *c)
45 for (i = 0; i < count; i++) {
51 void find_keys(char *search, uint64_t keyid, bool ishex,
52 bool fingerprint, bool exact, bool verbose)
54 struct openpgp_publickey *publickey = NULL;
58 count = fetch_key(keyid, &publickey, false);
60 count = fetch_key_text(search, &publickey);
62 if (publickey != NULL) {
63 key_index(publickey, verbose, fingerprint, false);
64 free_publickey(publickey);
65 } else if (count == 0) {
66 puts("Key not found.");
68 printf("Found %d keys, but maximum number to return is %d.\n",
71 puts("Try again with a more specific search.");
76 puts("onak " VERSION " - an OpenPGP keyserver.\n");
78 puts("\tonak [options] <command> <parameters>\n");
79 puts("\tCommands:\n");
80 puts("\tadd - read armored OpenPGP keys from stdin and add to the"
82 puts("\tdelete - delete a given key from the keyserver");
83 puts("\tdump - dump all the keys from the keyserver to a file or"
84 " files\n\t starting keydump*");
85 puts("\tget - retrieves the key requested from the keyserver");
86 puts("\tindex - search for a key and list it");
87 puts("\tvindex - search for a key and list it and its signatures");
90 int main(int argc, char *argv[])
92 struct openpgp_packet_list *packets = NULL;
93 struct openpgp_packet_list *list_end = NULL;
94 struct openpgp_publickey *keys = NULL;
95 int rc = EXIT_SUCCESS;
101 bool verbose = false;
104 bool fingerprint = false;
107 while ((optchar = getopt(argc, argv, "bfuv")) != -1 ) {
120 setlogthreshold(LOGTHING_INFO);
126 initlogthing("onak", config.logfile);
128 if ((argc - optind) < 1) {
130 } else if (!strcmp("dump", argv[optind])) {
134 } else if (!strcmp("add", argv[optind])) {
136 result = read_openpgp_stream(stdin_getchar, NULL,
138 logthing(LOGTHING_INFO,
139 "read_openpgp_stream: %d", result);
141 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
143 if (packets != NULL) {
144 result = parse_keys(packets, &keys);
145 free_packet_list(packets);
147 logthing(LOGTHING_INFO, "Finished reading %d keys.",
151 logthing(LOGTHING_NOTICE, "Got %d new keys.",
153 if (keys != NULL && update) {
154 flatten_publickey(keys,
157 armor_openpgp_stream(stdout_putchar,
160 free_packet_list(packets);
166 logthing(LOGTHING_NOTICE, "No keys read.");
170 free_publickey(keys);
174 logthing(LOGTHING_NOTICE, "No changes.");
176 } else if ((argc - optind) == 2) {
177 search = argv[optind+1];
178 if (search != NULL) {
179 keyid = strtoul(search, &end, 16);
187 if (!strcmp("index", argv[optind])) {
188 find_keys(search, keyid, ishex, fingerprint,
190 } else if (!strcmp("vindex", argv[optind])) {
191 find_keys(search, keyid, ishex, fingerprint,
193 } else if (!strcmp("delete", argv[optind])) {
194 delete_key(getfullkeyid(keyid), false);
195 } else if (!strcmp("get", argv[optind])) {
197 puts("Can't get a key on uid text."
198 " You must supply a keyid.");
199 } else if (fetch_key(keyid, &keys, false)) {
200 logthing(LOGTHING_INFO, "Got key.");
201 flatten_publickey(keys,
204 free_publickey(keys);
205 armor_openpgp_stream(stdout_putchar,
208 free_packet_list(packets);
211 puts("Key not found");