2 * lookup.c - CGI to lookup keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
8 * $Id: lookup.c,v 1.9 2003/06/04 22:11:41 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, bool mrhkp)
40 struct openpgp_publickey *publickey = NULL;
44 count = fetch_key(keyid, &publickey, false);
46 count = fetch_key_text(search, &publickey);
48 if (publickey != NULL) {
50 printf("info:1:%d\n", count);
51 mrkey_index(publickey);
53 key_index(publickey, verbose, fingerprint, true);
55 free_publickey(publickey);
56 } else if (count == 0) {
60 puts("Key not found.");
66 printf("Found %d keys, but maximum number to return"
70 puts("Try again with a more specific search.");
75 int main(int argc, char *argv[])
80 bool fingerprint = false;
87 struct openpgp_publickey *publickey = NULL;
88 struct openpgp_packet_list *packets = NULL;
89 struct openpgp_packet_list *list_end = NULL;
91 params = getcgivars(argc, argv);
92 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
93 if (!strcmp(params[i], "op")) {
94 if (!strcmp(params[i+1], "get")) {
96 } else if (!strcmp(params[i+1], "index")) {
98 } else if (!strcmp(params[i+1], "vindex")) {
101 } else if (!strcmp(params[i], "search")) {
102 search = params[i+1];
104 if (search != NULL) {
105 keyid = strtoul(search, &end, 16);
112 } else if (!strcmp(params[i], "fingerprint")) {
113 if (!strcmp(params[i+1], "on")) {
116 } else if (!strcmp(params[i], "exact")) {
117 if (!strcmp(params[i+1], "on")) {
120 } else if (!strcmp(params[i], "options")) {
122 * TODO: We should be smarter about this; options may
123 * have several entries. For now mr is the only valid
126 if (!strcmp(params[i+1], "mr")) {
132 if (params[i+1] != NULL) {
137 if (params != NULL) {
143 puts("Content-Type: text/plain\n");
145 start_html("Lookup of key");
148 if (op == OP_UNKNOWN) {
149 puts("Error: No operation supplied.");
150 } else if (search == NULL) {
151 puts("Error: No key to search for supplied.");
154 initlogthing("lookup", config.logfile);
158 if (fetch_key(keyid, &publickey, false)) {
160 flatten_publickey(publickey,
163 armor_openpgp_stream(putnextchar,
168 puts("Key not found");
172 find_keys(search, keyid, ishex, fingerprint, exact,
176 find_keys(search, keyid, ishex, fingerprint, exact,
180 puts("Unknown operation!");
188 puts("Produced by onak " VERSION " by Jonathan McDowell");
192 if (search != NULL) {
197 return (EXIT_SUCCESS);