2 * lookup.c - CGI to lookup keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
22 #include "onak-conf.h"
30 int putnextchar(void *ctx, size_t count, unsigned char *c)
32 return printf("%.*s", (int) count, c);
35 void find_keys(char *search, uint64_t keyid, bool ishex,
36 bool fingerprint, bool exact, bool verbose)
38 struct openpgp_publickey *publickey = NULL;
42 count = fetch_key(keyid, &publickey, false);
44 count = fetch_key_text(search, &publickey);
46 if (publickey != NULL) {
47 key_index(publickey, verbose, fingerprint, true);
48 free_publickey(publickey);
49 } else if (count == 0) {
50 puts("Key not found.");
52 printf("Found %d keys, but maximum number to return is %d.\n",
55 puts("Try again with a more specific search.");
59 int main(int argc, char *argv[])
64 bool fingerprint = false;
70 struct openpgp_publickey *publickey = NULL;
71 struct openpgp_packet_list *packets = NULL;
72 struct openpgp_packet_list *list_end = NULL;
74 params = getcgivars(argc, argv);
75 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
76 if (!strcmp(params[i], "op")) {
77 if (!strcmp(params[i+1], "get")) {
79 } else if (!strcmp(params[i+1], "index")) {
81 } else if (!strcmp(params[i+1], "vindex")) {
84 } else if (!strcmp(params[i], "search")) {
88 keyid = strtoul(search, &end, 16);
95 } else if (!strcmp(params[i], "fingerprint")) {
96 if (!strcmp(params[i+1], "on")) {
99 } else if (!strcmp(params[i], "exact")) {
100 if (!strcmp(params[i+1], "on")) {
106 if (params[i+1] != NULL) {
111 if (params != NULL) {
116 start_html("Lookup of key");
118 if (op == OP_UNKNOWN) {
119 puts("Error: No operation supplied.");
120 } else if (search == NULL) {
121 puts("Error: No key to search for supplied.");
124 initlogthing("lookup", config.logfile);
128 if (fetch_key(keyid, &publickey, false)) {
130 flatten_publickey(publickey,
133 armor_openpgp_stream(putnextchar,
138 puts("Key not found");
142 find_keys(search, keyid, ishex, fingerprint, exact,
146 find_keys(search, keyid, ishex, fingerprint, exact,
150 puts("Unknown operation!");
157 puts("Produced by onak " VERSION " by Jonathan McDowell");
160 if (search != NULL) {
165 return (EXIT_SUCCESS);