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.21 2004/05/27 21:58:18 noodles Exp $
19 #include "charfuncs.h"
23 #include "keystructs.h"
27 #include "onak-conf.h"
31 void find_keys(char *search, uint64_t keyid, bool ishex,
32 bool fingerprint, bool exact, bool verbose)
34 struct openpgp_publickey *publickey = NULL;
38 count = fetch_key(keyid, &publickey, false);
40 count = fetch_key_text(search, &publickey);
42 if (publickey != NULL) {
43 key_index(publickey, verbose, fingerprint, false);
44 free_publickey(publickey);
45 } else if (count == 0) {
46 puts("Key not found.");
48 printf("Found %d keys, but maximum number to return is %d.\n",
51 puts("Try again with a more specific search.");
56 puts("onak " VERSION " - an OpenPGP keyserver.\n");
58 puts("\tonak [options] <command> <parameters>\n");
59 puts("\tCommands:\n");
60 puts("\tadd - read armored OpenPGP keys from stdin and add to the"
62 puts("\tdelete - delete a given key from the keyserver");
63 puts("\tdump - dump all the keys from the keyserver to a file or"
64 " files\n\t starting keydump*");
65 puts("\tget - retrieves the key requested from the keyserver");
66 puts("\tindex - search for a key and list it");
67 puts("\tvindex - search for a key and list it and its signatures");
70 int main(int argc, char *argv[])
72 struct openpgp_packet_list *packets = NULL;
73 struct openpgp_packet_list *list_end = NULL;
74 struct openpgp_publickey *keys = NULL;
75 char *configfile = NULL;
76 int rc = EXIT_SUCCESS;
85 bool fingerprint = false;
88 while ((optchar = getopt(argc, argv, "bc:fuv")) != -1 ) {
94 configfile = strdup(optarg);
104 setlogthreshold(LOGTHING_INFO);
109 readconfig(configfile);
110 initlogthing("onak", config.logfile);
112 if ((argc - optind) < 1) {
114 } else if (!strcmp("dump", argv[optind])) {
118 } else if (!strcmp("add", argv[optind])) {
120 result = read_openpgp_stream(stdin_getchar, NULL,
122 logthing(LOGTHING_INFO,
123 "read_openpgp_stream: %d", result);
125 dearmor_openpgp_stream(stdin_getchar, NULL, &packets);
127 if (packets != NULL) {
128 result = parse_keys(packets, &keys);
129 free_packet_list(packets);
131 logthing(LOGTHING_INFO, "Finished reading %d keys.",
135 logthing(LOGTHING_NOTICE, "Got %d new keys.",
137 if (keys != NULL && update) {
138 flatten_publickey(keys,
141 armor_openpgp_stream(stdout_putchar,
144 free_packet_list(packets);
150 logthing(LOGTHING_NOTICE, "No keys read.");
154 free_publickey(keys);
158 logthing(LOGTHING_NOTICE, "No changes.");
160 } else if ((argc - optind) == 2) {
161 search = argv[optind+1];
162 if (search != NULL) {
163 keyid = strtoul(search, &end, 16);
171 if (!strcmp("index", argv[optind])) {
172 find_keys(search, keyid, ishex, fingerprint,
174 } else if (!strcmp("vindex", argv[optind])) {
175 find_keys(search, keyid, ishex, fingerprint,
177 } else if (!strcmp("getphoto", argv[optind])) {
179 puts("Can't get a key on uid text."
180 " You must supply a keyid.");
181 } else if (fetch_key(keyid, &keys, false)) {
182 unsigned char *photo = NULL;
185 if (getphoto(keys, 0, &photo, &length)) {
191 free_publickey(keys);
194 puts("Key not found");
196 } else if (!strcmp("delete", argv[optind])) {
197 delete_key(getfullkeyid(keyid), false);
198 } else if (!strcmp("get", argv[optind])) {
200 puts("Can't get a key on uid text."
201 " You must supply a keyid.");
202 } else if (fetch_key(keyid, &keys, false)) {
203 logthing(LOGTHING_INFO, "Got key.");
204 flatten_publickey(keys,
207 free_publickey(keys);
208 armor_openpgp_stream(stdout_putchar,
211 free_packet_list(packets);
214 puts("Key not found");