2 * lookup.c - CGI to lookup keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
21 #include "onak-conf.h"
29 int putnextchar(void *ctx, size_t count, unsigned char *c)
31 return printf("%.*s", count, c);
34 void find_keys(char *search, uint64_t keyid, bool ishex,
35 bool fingerprint, bool exact, bool verbose)
37 struct openpgp_publickey *publickey = NULL;
41 count = fetch_key(keyid, &publickey, false);
43 count = fetch_key_text(search, &publickey);
45 if (publickey != NULL) {
46 key_index(publickey, verbose, fingerprint, true);
47 free_publickey(publickey);
48 } else if (count == 0) {
49 puts("Key not found.");
51 printf("Found %d keys, but maximum number to return is %d.\n",
54 puts("Try again with a more specific search.");
58 int main(int argc, char *argv[])
63 bool fingerprint = false;
69 struct openpgp_publickey *publickey = NULL;
70 struct openpgp_packet_list *packets = NULL;
71 struct openpgp_packet_list *list_end = NULL;
73 params = getcgivars(argc, argv);
74 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
75 if (!strcmp(params[i], "op")) {
76 if (!strcmp(params[i+1], "get")) {
78 } else if (!strcmp(params[i+1], "index")) {
80 } else if (!strcmp(params[i+1], "vindex")) {
83 } else if (!strcmp(params[i], "search")) {
86 keyid = strtoul(search, &end, 16);
93 } else if (!strcmp(params[i], "fingerprint")) {
94 if (!strcmp(params[i+1], "on")) {
97 } else if (!strcmp(params[i], "exact")) {
98 if (!strcmp(params[i+1], "on")) {
104 // puts("HTTP/1.0 200 OK");
105 // puts("Server: onak 0.0.1");
106 puts("Content-Type: text/html\n");
107 puts("<html>\n<title>Lookup of key</title>");
110 if (op == OP_UNKNOWN) {
111 puts("Error: No operation supplied.");
112 } else if (search == NULL) {
113 puts("Error: No key to search for supplied.");
118 if (fetch_key(keyid, &publickey, false)) {
120 flatten_publickey(publickey,
123 armor_openpgp_stream(putnextchar,
128 puts("Key not found");
132 find_keys(search, keyid, ishex, fingerprint, exact,
136 find_keys(search, keyid, ishex, fingerprint, exact,
140 puts("Unknown operation!");
145 puts("Produced by onak " VERSION " by Jonathan McDowell");
146 puts("</body>\n</html>");
147 return (EXIT_SUCCESS);