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"
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 = config.dbbackend->fetch_key(keyid, &publickey, false);
45 count = config.dbbackend->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;
92 params = getcgivars(argc, argv);
93 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
94 if (!strcmp(params[i], "op")) {
95 if (!strcmp(params[i+1], "get")) {
97 } else if (!strcmp(params[i+1], "index")) {
99 } else if (!strcmp(params[i+1], "vindex")) {
101 } else if (!strcmp(params[i+1], "photo")) {
104 } else if (!strcmp(params[i], "search")) {
105 search = params[i+1];
107 if (search != NULL) {
108 keyid = strtoull(search, &end, 16);
115 } else if (!strcmp(params[i], "idx")) {
116 indx = atoi(params[i+1]);
117 } else if (!strcmp(params[i], "fingerprint")) {
118 if (!strcmp(params[i+1], "on")) {
121 } else if (!strcmp(params[i], "exact")) {
122 if (!strcmp(params[i+1], "on")) {
125 } else if (!strcmp(params[i], "options")) {
127 * TODO: We should be smarter about this; options may
128 * have several entries. For now mr is the only valid
131 if (!strcmp(params[i+1], "mr")) {
137 if (params[i+1] != NULL) {
142 if (params != NULL) {
148 puts("Content-Type: text/plain\n");
149 } else if (op == OP_PHOTO) {
150 puts("Content-Type: image/jpeg\n");
152 start_html("Lookup of key");
155 if (op == OP_UNKNOWN) {
156 puts("Error: No operation supplied.");
157 } else if (search == NULL) {
158 puts("Error: No key to search for supplied.");
161 initlogthing("lookup", config.logfile);
163 config.dbbackend->initdb(true);
167 logthing(LOGTHING_NOTICE,
168 "Getting keyid 0x%llX",
170 result = config.dbbackend->fetch_key(keyid,
173 logthing(LOGTHING_NOTICE,
174 "Getting key(s) for search text %s",
176 result = config.dbbackend->fetch_key_text(
182 cleankeys(publickey);
183 flatten_publickey(publickey,
186 armor_openpgp_stream(stdout_putchar,
191 logthing(LOGTHING_NOTICE,
192 "Failed to fetch key.");
193 puts("Key not found");
197 find_keys(search, keyid, ishex, fingerprint, exact,
201 find_keys(search, keyid, ishex, fingerprint, exact,
205 if (config.dbbackend->fetch_key(keyid, &publickey,
207 unsigned char *photo = NULL;
210 if (getphoto(publickey, indx, &photo,
217 free_publickey(publickey);
222 puts("Unknown operation!");
224 config.dbbackend->cleanupdb();
230 puts("Produced by onak " PACKAGE_VERSION
231 " by Jonathan McDowell");
235 if (search != NULL) {
240 return (EXIT_SUCCESS);