2 * lookup.c - CGI to lookup keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
8 * $Id: lookup.c,v 1.8 2003/06/04 20:57:10 noodles Exp $
24 #include "onak-conf.h"
32 int putnextchar(void *ctx, size_t count, unsigned char *c)
34 return printf("%.*s", (int) count, c);
37 void find_keys(char *search, uint64_t keyid, bool ishex,
38 bool fingerprint, bool exact, bool verbose)
40 struct openpgp_publickey *publickey = NULL;
44 count = fetch_key(keyid, &publickey, false);
46 count = fetch_key_text(search, &publickey);
48 if (publickey != NULL) {
49 key_index(publickey, verbose, fingerprint, true);
50 free_publickey(publickey);
51 } else if (count == 0) {
52 puts("Key not found.");
54 printf("Found %d keys, but maximum number to return is %d.\n",
57 puts("Try again with a more specific search.");
61 int main(int argc, char *argv[])
66 bool fingerprint = false;
72 struct openpgp_publickey *publickey = NULL;
73 struct openpgp_packet_list *packets = NULL;
74 struct openpgp_packet_list *list_end = NULL;
76 params = getcgivars(argc, argv);
77 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
78 if (!strcmp(params[i], "op")) {
79 if (!strcmp(params[i+1], "get")) {
81 } else if (!strcmp(params[i+1], "index")) {
83 } else if (!strcmp(params[i+1], "vindex")) {
86 } else if (!strcmp(params[i], "search")) {
90 keyid = strtoul(search, &end, 16);
97 } else if (!strcmp(params[i], "fingerprint")) {
98 if (!strcmp(params[i+1], "on")) {
101 } else if (!strcmp(params[i], "exact")) {
102 if (!strcmp(params[i+1], "on")) {
108 if (params[i+1] != NULL) {
113 if (params != NULL) {
118 start_html("Lookup of key");
120 if (op == OP_UNKNOWN) {
121 puts("Error: No operation supplied.");
122 } else if (search == NULL) {
123 puts("Error: No key to search for supplied.");
126 initlogthing("lookup", config.logfile);
130 if (fetch_key(keyid, &publickey, false)) {
132 flatten_publickey(publickey,
135 armor_openpgp_stream(putnextchar,
140 puts("Key not found");
144 find_keys(search, keyid, ishex, fingerprint, exact,
148 find_keys(search, keyid, ishex, fingerprint, exact,
152 puts("Unknown operation!");
159 puts("Produced by onak " VERSION " by Jonathan McDowell");
162 if (search != NULL) {
167 return (EXIT_SUCCESS);