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.15 2003/09/28 20:33:34 noodles Exp $
22 #include "keystructs.h"
26 #include "onak-conf.h"
29 int stdin_getchar(void *ctx, size_t count, unsigned char *c)
33 while ((count > 0) && (ic != EOF)) {
43 int stdout_putchar(void *ctx, size_t count, unsigned char *c)
47 for (i = 0; i < count; i++) {
53 void find_keys(char *search, uint64_t keyid, bool ishex,
54 bool fingerprint, bool exact, bool verbose)
56 struct openpgp_publickey *publickey = NULL;
60 count = fetch_key(keyid, &publickey, false);
62 count = fetch_key_text(search, &publickey);
64 if (publickey != NULL) {
65 key_index(publickey, verbose, fingerprint, false);
66 free_publickey(publickey);
67 } else if (count == 0) {
68 puts("Key not found.");
70 printf("Found %d keys, but maximum number to return is %d.\n",
73 puts("Try again with a more specific search.");
78 puts("onak " VERSION " - an OpenPGP keyserver.\n");
80 puts("\tonak [options] <command> <parameters>\n");
81 puts("\tCommands:\n");
82 puts("\tadd - read armored OpenPGP keys from stdin and add to the"
84 puts("\tdelete - delete a given key from the keyserver");
85 puts("\tdump - dump all the keys from the keyserver to a file or"
86 " files\n\t starting keydump*");
87 puts("\tget - retrieves the key requested from the keyserver");
88 puts("\tindex - search for a key and list it");
89 puts("\tvindex - search for a key and list it and its signatures");
92 int main(int argc, char *argv[])
94 struct openpgp_packet_list *packets = NULL;
95 struct openpgp_packet_list *list_end = NULL;
96 struct openpgp_publickey *keys = NULL;
97 int rc = EXIT_SUCCESS;
103 bool verbose = false;
106 bool fingerprint = false;
109 while ((optchar = getopt(argc, argv, "bfuv")) != -1 ) {
122 setlogthreshold(LOGTHING_INFO);
128 initlogthing("onak", config.logfile);
130 if ((argc - optind) < 1) {
132 } else if (!strcmp("dump", argv[optind])) {
136 } else if (!strcmp("add", argv[optind])) {
138 result = read_openpgp_stream(stdin_getchar, NULL,
140 logthing(LOGTHING_INFO,
141 "read_openpgp_stream: %d", result);
143 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
145 if (packets != NULL) {
146 result = parse_keys(packets, &keys);
147 free_packet_list(packets);
149 logthing(LOGTHING_INFO, "Finished reading %d keys.",
153 logthing(LOGTHING_NOTICE, "Got %d new keys.",
155 if (keys != NULL && update) {
156 flatten_publickey(keys,
159 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 ((argc - optind) == 2) {
179 search = argv[optind+1];
180 if (search != NULL) {
181 keyid = strtoul(search, &end, 16);
189 if (!strcmp("index", argv[optind])) {
190 find_keys(search, keyid, ishex, fingerprint,
192 } else if (!strcmp("vindex", argv[optind])) {
193 find_keys(search, keyid, ishex, fingerprint,
195 } else if (!strcmp("delete", argv[optind])) {
196 delete_key(getfullkeyid(keyid), false);
197 } else if (!strcmp("get", argv[optind])) {
199 puts("Can't get a key on uid text."
200 " You must supply a keyid.");
201 } else if (fetch_key(keyid, &keys, false)) {
202 logthing(LOGTHING_INFO, "Got key.");
203 flatten_publickey(keys,
206 free_publickey(keys);
207 armor_openpgp_stream(stdout_putchar,
210 free_packet_list(packets);
213 puts("Key not found");