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.20 2004/05/27 01:25:37 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 struct openpgp_packet *photo = NULL;
184 photo = getphoto(keys, 0);
186 photof = fopen("keyphoto.jpg", "w");
187 fwrite(photo->data+19,
189 (photo->length - 19),
193 free_publickey(keys);
196 puts("Key not found");
198 } else if (!strcmp("delete", argv[optind])) {
199 delete_key(getfullkeyid(keyid), false);
200 } else if (!strcmp("get", argv[optind])) {
202 puts("Can't get a key on uid text."
203 " You must supply a keyid.");
204 } else if (fetch_key(keyid, &keys, false)) {
205 logthing(LOGTHING_INFO, "Got key.");
206 flatten_publickey(keys,
209 free_publickey(keys);
210 armor_openpgp_stream(stdout_putchar,
213 free_packet_list(packets);
216 puts("Key not found");