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 = 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);
165 logthing(LOGTHING_NOTICE, "Getting keyid 0x%llX",
167 if (fetch_key(keyid, &publickey, false)) {
169 cleankeys(publickey);
170 flatten_publickey(publickey,
173 armor_openpgp_stream(stdout_putchar,
178 logthing(LOGTHING_NOTICE,
179 "Failed to fetch key.");
180 puts("Key not found");
184 find_keys(search, keyid, ishex, fingerprint, exact,
188 find_keys(search, keyid, ishex, fingerprint, exact,
192 if (fetch_key(keyid, &publickey, false)) {
193 unsigned char *photo = NULL;
196 if (getphoto(publickey, 0, &photo, &length)) {
202 free_publickey(publickey);
207 puts("Unknown operation!");
215 puts("Produced by onak " PACKAGE_VERSION
216 " by Jonathan McDowell");
220 if (search != NULL) {
225 return (EXIT_SUCCESS);