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"
23 #include "onak-conf.h"
26 int stdin_getchar(void *ctx, size_t count, unsigned char *c)
34 } while ((ic != EOF) && (--count > 0));
38 int stdout_putchar(void *ctx, size_t count, unsigned char *c)
42 for (i = 0; i < count; i++) {
48 void find_keys(char *search, uint64_t keyid, bool ishex,
49 bool fingerprint, bool exact, bool verbose)
51 struct openpgp_publickey *publickey = NULL;
55 count = fetch_key(keyid, &publickey, false);
57 count = fetch_key_text(search, &publickey);
59 if (publickey != NULL) {
60 key_index(publickey, verbose, fingerprint, false);
61 free_publickey(publickey);
62 } else if (count == 0) {
63 puts("Key not found.");
65 printf("Found %d keys, but maximum number to return is %d.\n",
68 puts("Try again with a more specific search.");
73 puts("onak " VERSION " - an OpenPGP keyserver.\n");
75 puts("\tonak [options] <command> <parameters>\n");
76 puts("\tCommands:\n");
77 puts("\tadd - read armored OpenPGP keys from stdin and add to the"
79 puts("\tdelete - delete a given key from the keyserver");
80 puts("\tget - retrieves the key requested from the keyserver");
81 puts("\tindex - search for a key and list it");
82 puts("\tvindex - search for a key and list it and its signatures");
85 int main(int argc, char *argv[])
87 struct openpgp_packet_list *packets = NULL;
88 struct openpgp_packet_list *list_end = NULL;
89 struct openpgp_publickey *keys = NULL;
90 int rc = EXIT_SUCCESS;
99 bool fingerprint = false;
102 while ((optchar = getopt(argc, argv, "bfuv")) != -1 ) {
121 if ((argc - optind) < 1) {
123 } else if (!strcmp("dump", argv[optind])) {
127 } else if (!strcmp("add", argv[optind])) {
129 result = read_openpgp_stream(stdin_getchar, NULL,
133 "read_openpgp_stream: %d\n", result);
136 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
138 if (packets != NULL) {
139 result = parse_keys(packets, &keys);
140 free_packet_list(packets);
143 fprintf(stderr, "Finished reading %d keys.\n",
148 fprintf(stderr, "Got %d new keys.\n",
149 update_keys(&keys, verbose));
150 if (keys != NULL && update) {
151 flatten_publickey(keys,
154 armor_openpgp_stream(stdout_putchar,
157 free_packet_list(packets);
163 fprintf(stderr, "No keys read.\n");
167 free_publickey(keys);
171 fprintf(stderr, "No changes.\n");
173 } else if ((argc - optind) == 2) {
174 search = argv[optind+1];
175 if (search != NULL) {
176 keyid = strtoul(search, &end, 16);
184 if (!strcmp("index", argv[optind])) {
185 find_keys(search, keyid, ishex, fingerprint,
187 } else if (!strcmp("vindex", argv[optind])) {
188 find_keys(search, keyid, ishex, fingerprint,
190 } else if (!strcmp("delete", argv[optind])) {
191 delete_key(getfullkeyid(keyid), false);
192 } else if (!strcmp("get", argv[optind])) {
193 if (fetch_key(keyid, &keys, false)) {
195 fprintf(stderr, "Got key.\n");
197 flatten_publickey(keys,
200 armor_openpgp_stream(stdout_putchar,
203 free_packet_list(packets);
206 puts("Key not found");