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", (int) 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")) {
87 keyid = strtoul(search, &end, 16);
94 } else if (!strcmp(params[i], "fingerprint")) {
95 if (!strcmp(params[i+1], "on")) {
98 } else if (!strcmp(params[i], "exact")) {
99 if (!strcmp(params[i+1], "on")) {
105 if (params[i+1] != NULL) {
110 if (params != NULL) {
115 start_html("Lookup of key");
117 if (op == OP_UNKNOWN) {
118 puts("Error: No operation supplied.");
119 } else if (search == NULL) {
120 puts("Error: No key to search for supplied.");
126 if (fetch_key(keyid, &publickey, false)) {
128 flatten_publickey(publickey,
131 armor_openpgp_stream(putnextchar,
136 puts("Key not found");
140 find_keys(search, keyid, ishex, fingerprint, exact,
144 find_keys(search, keyid, ishex, fingerprint, exact,
148 puts("Unknown operation!");
153 puts("Produced by onak " VERSION " by Jonathan McDowell");
156 if (search != NULL) {
161 return (EXIT_SUCCESS);