2 * lookup.c - CGI to lookup keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
8 * $Id: lookup.c,v 1.16 2004/05/27 21:58:18 noodles Exp $
19 #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);
163 logthing(LOGTHING_NOTICE, "Getting keyid 0x%llX",
165 if (fetch_key(keyid, &publickey, false)) {
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);