2 * lookup.c - CGI to lookup keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
8 * $Id: lookup.c,v 1.17 2004/05/31 14:16:49 noodles Exp $
19 #include "charfuncs.h"
26 #include "onak-conf.h"
36 void find_keys(char *search, uint64_t keyid, bool ishex,
37 bool fingerprint, bool exact, bool verbose, bool mrhkp)
39 struct openpgp_publickey *publickey = NULL;
43 count = fetch_key(keyid, &publickey, false);
45 count = fetch_key_text(search, &publickey);
47 if (publickey != NULL) {
49 printf("info:1:%d\n", count);
50 mrkey_index(publickey);
52 key_index(publickey, verbose, fingerprint, true);
54 free_publickey(publickey);
55 } else if (count == 0) {
59 puts("Key not found.");
65 printf("Found %d keys, but maximum number to return"
69 puts("Try again with a more specific search.");
74 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")) {
100 } else if (!strcmp(params[i+1], "photo")) {
103 } else if (!strcmp(params[i], "search")) {
104 search = params[i+1];
106 if (search != NULL) {
107 keyid = strtoul(search, &end, 16);
114 } else if (!strcmp(params[i], "idx")) {
115 indx = atoi(params[i+1]);
116 } else if (!strcmp(params[i], "fingerprint")) {
117 if (!strcmp(params[i+1], "on")) {
120 } else if (!strcmp(params[i], "exact")) {
121 if (!strcmp(params[i+1], "on")) {
124 } else if (!strcmp(params[i], "options")) {
126 * TODO: We should be smarter about this; options may
127 * have several entries. For now mr is the only valid
130 if (!strcmp(params[i+1], "mr")) {
136 if (params[i+1] != NULL) {
141 if (params != NULL) {
147 puts("Content-Type: text/plain\n");
148 } else if (op == OP_PHOTO) {
149 puts("Content-Type: image/jpeg\n");
151 start_html("Lookup of key");
154 if (op == OP_UNKNOWN) {
155 puts("Error: No operation supplied.");
156 } else if (search == NULL) {
157 puts("Error: No key to search for supplied.");
160 initlogthing("lookup", config.logfile);
164 logthing(LOGTHING_NOTICE, "Getting keyid 0x%llX",
166 if (fetch_key(keyid, &publickey, false)) {
168 cleankeys(publickey);
169 flatten_publickey(publickey,
172 armor_openpgp_stream(stdout_putchar,
177 logthing(LOGTHING_NOTICE,
178 "Failed to fetch key.");
179 puts("Key not found");
183 find_keys(search, keyid, ishex, fingerprint, exact,
187 find_keys(search, keyid, ishex, fingerprint, exact,
191 if (fetch_key(keyid, &publickey, false)) {
192 unsigned char *photo = NULL;
195 if (getphoto(publickey, 0, &photo, &length)) {
201 free_publickey(publickey);
206 puts("Unknown operation!");
214 puts("Produced by onak " VERSION " by Jonathan McDowell");
218 if (search != NULL) {
223 return (EXIT_SUCCESS);