2 * lookup.c - CGI to lookup keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
17 #include "charfuncs.h"
25 #include "onak-conf.h"
35 void find_keys(char *search, uint64_t keyid, bool ishex,
36 bool fingerprint, bool exact, bool verbose, bool mrhkp)
38 struct openpgp_publickey *publickey = NULL;
42 count = fetch_key(keyid, &publickey, false);
44 count = fetch_key_text(search, &publickey);
46 if (publickey != NULL) {
48 printf("info:1:%d\n", count);
49 mrkey_index(publickey);
51 key_index(publickey, verbose, fingerprint, true);
53 free_publickey(publickey);
54 } else if (count == 0) {
58 puts("Key not found.");
64 printf("Found %d keys, but maximum number to return"
68 puts("Try again with a more specific search.");
73 int main(int argc, char *argv[])
79 bool fingerprint = false;
86 struct openpgp_publickey *publickey = NULL;
87 struct openpgp_packet_list *packets = NULL;
88 struct openpgp_packet_list *list_end = NULL;
90 params = getcgivars(argc, argv);
91 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
92 if (!strcmp(params[i], "op")) {
93 if (!strcmp(params[i+1], "get")) {
95 } else if (!strcmp(params[i+1], "index")) {
97 } else if (!strcmp(params[i+1], "vindex")) {
99 } else if (!strcmp(params[i+1], "photo")) {
102 } else if (!strcmp(params[i], "search")) {
103 search = params[i+1];
105 if (search != NULL) {
106 keyid = strtoul(search, &end, 16);
113 } else if (!strcmp(params[i], "idx")) {
114 indx = atoi(params[i+1]);
115 } else if (!strcmp(params[i], "fingerprint")) {
116 if (!strcmp(params[i+1], "on")) {
119 } else if (!strcmp(params[i], "exact")) {
120 if (!strcmp(params[i+1], "on")) {
123 } else if (!strcmp(params[i], "options")) {
125 * TODO: We should be smarter about this; options may
126 * have several entries. For now mr is the only valid
129 if (!strcmp(params[i+1], "mr")) {
135 if (params[i+1] != NULL) {
140 if (params != NULL) {
146 puts("Content-Type: text/plain\n");
147 } else if (op == OP_PHOTO) {
148 puts("Content-Type: image/jpeg\n");
150 start_html("Lookup of key");
153 if (op == OP_UNKNOWN) {
154 puts("Error: No operation supplied.");
155 } else if (search == NULL) {
156 puts("Error: No key to search for supplied.");
159 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);