2 * lookup.c - CGI to lookup keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
8 * $Id: lookup.c,v 1.15 2004/05/27 01:25:37 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 %llX",
165 if (fetch_key(keyid, &publickey, false)) {
167 flatten_publickey(publickey,
170 armor_openpgp_stream(stdout_putchar,
175 puts("Key not found");
179 find_keys(search, keyid, ishex, fingerprint, exact,
183 find_keys(search, keyid, ishex, fingerprint, exact,
187 if (fetch_key(keyid, &publickey, false)) {
188 struct openpgp_packet *photo = NULL;
189 photo = getphoto(publickey, 0);
191 fwrite(photo->data+19,
193 (photo->length - 19),
196 free_publickey(publickey);
201 puts("Unknown operation!");
209 puts("Produced by onak " VERSION " by Jonathan McDowell");
213 if (search != NULL) {
218 return (EXIT_SUCCESS);