2 * lookup.c - CGI to lookup keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
17 #include "charfuncs.h"
24 #include "onak-conf.h"
34 void find_keys(char *search, uint64_t keyid, bool ishex,
35 bool fingerprint, bool exact, bool verbose, bool mrhkp)
37 struct openpgp_publickey *publickey = NULL;
41 count = fetch_key(keyid, &publickey, false);
43 count = fetch_key_text(search, &publickey);
45 if (publickey != NULL) {
47 printf("info:1:%d\n", count);
48 mrkey_index(publickey);
50 key_index(publickey, verbose, fingerprint, true);
52 free_publickey(publickey);
53 } else if (count == 0) {
57 puts("Key not found.");
63 printf("Found %d keys, but maximum number to return"
67 puts("Try again with a more specific search.");
72 int main(int argc, char *argv[])
78 bool fingerprint = false;
85 struct openpgp_publickey *publickey = NULL;
86 struct openpgp_packet_list *packets = NULL;
87 struct openpgp_packet_list *list_end = NULL;
89 params = getcgivars(argc, argv);
90 for (i = 0; params != NULL && params[i] != NULL; i += 2) {
91 if (!strcmp(params[i], "op")) {
92 if (!strcmp(params[i+1], "get")) {
94 } else if (!strcmp(params[i+1], "index")) {
96 } else if (!strcmp(params[i+1], "vindex")) {
98 } else if (!strcmp(params[i+1], "photo")) {
101 } else if (!strcmp(params[i], "search")) {
102 search = params[i+1];
104 if (search != NULL) {
105 keyid = strtoul(search, &end, 16);
112 } else if (!strcmp(params[i], "idx")) {
113 indx = atoi(params[i+1]);
114 } else if (!strcmp(params[i], "fingerprint")) {
115 if (!strcmp(params[i+1], "on")) {
118 } else if (!strcmp(params[i], "exact")) {
119 if (!strcmp(params[i+1], "on")) {
122 } else if (!strcmp(params[i], "options")) {
124 * TODO: We should be smarter about this; options may
125 * have several entries. For now mr is the only valid
128 if (!strcmp(params[i+1], "mr")) {
134 if (params[i+1] != NULL) {
139 if (params != NULL) {
145 puts("Content-Type: text/plain\n");
146 } else if (op == OP_PHOTO) {
147 puts("Content-Type: image/jpeg\n");
149 start_html("Lookup of key");
152 if (op == OP_UNKNOWN) {
153 puts("Error: No operation supplied.");
154 } else if (search == NULL) {
155 puts("Error: No key to search for supplied.");
158 initlogthing("lookup", config.logfile);
162 logthing(LOGTHING_NOTICE, "Getting keyid 0x%llX",
164 if (fetch_key(keyid, &publickey, false)) {
166 cleankeys(publickey);
167 flatten_publickey(publickey,
170 armor_openpgp_stream(stdout_putchar,
175 logthing(LOGTHING_NOTICE,
176 "Failed to fetch key.");
177 puts("Key not found");
181 find_keys(search, keyid, ishex, fingerprint, exact,
185 find_keys(search, keyid, ishex, fingerprint, exact,
189 if (fetch_key(keyid, &publickey, false)) {
190 unsigned char *photo = NULL;
193 if (getphoto(publickey, 0, &photo, &length)) {
199 free_publickey(publickey);
204 puts("Unknown operation!");
212 puts("Produced by onak " VERSION " by Jonathan McDowell");
216 if (search != NULL) {
221 return (EXIT_SUCCESS);