2 * lookup.c - CGI to lookup keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
17 #include "charfuncs.h"
26 #include "onak-conf.h"
38 void find_keys(char *search, uint64_t keyid, bool ishex,
39 bool fingerprint, bool skshash, bool exact, bool verbose,
42 struct openpgp_publickey *publickey = NULL;
46 count = config.dbbackend->fetch_key(keyid, &publickey, false);
48 count = config.dbbackend->fetch_key_text(search, &publickey);
50 if (publickey != NULL) {
52 printf("info:1:%d\n", count);
53 mrkey_index(publickey);
55 key_index(publickey, verbose, fingerprint, skshash,
58 free_publickey(publickey);
59 } else if (count == 0) {
63 puts("Key not found.");
69 printf("Found %d keys, but maximum number to return"
73 puts("Try again with a more specific search.");
78 int main(int argc, char *argv[])
84 bool fingerprint = false;
92 struct openpgp_publickey *publickey = NULL;
93 struct openpgp_packet_list *packets = NULL;
94 struct openpgp_packet_list *list_end = NULL;
98 params = getcgivars(argc, argv);
99 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
100 if (!strcmp(params[i], "op")) {
101 if (!strcmp(params[i+1], "get")) {
103 } else if (!strcmp(params[i+1], "hget")) {
105 } else if (!strcmp(params[i+1], "index")) {
107 } else if (!strcmp(params[i+1], "vindex")) {
109 } else if (!strcmp(params[i+1], "photo")) {
112 } else if (!strcmp(params[i], "search")) {
113 search = params[i+1];
115 if (search != NULL) {
116 keyid = strtoull(search, &end, 16);
123 } else if (!strcmp(params[i], "idx")) {
124 indx = atoi(params[i+1]);
125 } else if (!strcmp(params[i], "fingerprint")) {
126 if (!strcmp(params[i+1], "on")) {
129 } else if (!strcmp(params[i], "hash")) {
130 if (!strcmp(params[i+1], "on")) {
133 } else if (!strcmp(params[i], "exact")) {
134 if (!strcmp(params[i+1], "on")) {
137 } else if (!strcmp(params[i], "options")) {
139 * TODO: We should be smarter about this; options may
140 * have several entries. For now mr is the only valid
143 if (!strcmp(params[i+1], "mr")) {
149 if (params[i+1] != NULL) {
154 if (params != NULL) {
160 puts("Content-Type: text/plain\n");
161 } else if (op == OP_PHOTO) {
162 puts("Content-Type: image/jpeg\n");
164 start_html("Lookup of key");
167 if (op == OP_UNKNOWN) {
168 puts("Error: No operation supplied.");
169 } else if (search == NULL) {
170 puts("Error: No key to search for supplied.");
173 initlogthing("lookup", config.logfile);
175 config.dbbackend->initdb(false);
180 parse_skshash(search, &hash);
181 result = config.dbbackend->fetch_key_skshash(
184 result = config.dbbackend->fetch_key(keyid,
187 result = config.dbbackend->fetch_key_text(
192 logthing(LOGTHING_NOTICE,
193 "Found %d key(s) for search %s",
197 cleankeys(publickey);
198 flatten_publickey(publickey,
201 armor_openpgp_stream(stdout_putchar,
206 logthing(LOGTHING_NOTICE,
207 "Failed to find key for search %s",
209 puts("Key not found");
213 find_keys(search, keyid, ishex, fingerprint, skshash,
214 exact, false, mrhkp);
217 find_keys(search, keyid, ishex, fingerprint, skshash,
221 if (config.dbbackend->fetch_key(keyid, &publickey,
223 unsigned char *photo = NULL;
226 if (getphoto(publickey, indx, &photo,
233 free_publickey(publickey);
238 puts("Unknown operation!");
240 config.dbbackend->cleanupdb();
246 puts("Produced by onak " ONAK_VERSION );
250 if (search != NULL) {
255 return (EXIT_SUCCESS);