2  * lookup.c - CGI to lookup keys.
 
   4  * Jonathan McDowell <noodles@earth.li>
 
   6  * Copyright 2002 Project Purple
 
   8  * $Id: lookup.c,v 1.12 2003/10/15 21:15:21 noodles Exp $
 
  19 #include "charfuncs.h"
 
  25 #include "onak-conf.h"
 
  33 void find_keys(char *search, uint64_t keyid, bool ishex,
 
  34                 bool fingerprint, bool exact, bool verbose, bool mrhkp)
 
  36         struct openpgp_publickey *publickey = NULL;
 
  40                 count = fetch_key(keyid, &publickey, false);
 
  42                 count = fetch_key_text(search, &publickey);
 
  44         if (publickey != NULL) {
 
  46                         printf("info:1:%d\n", count);
 
  47                         mrkey_index(publickey);
 
  49                         key_index(publickey, verbose, fingerprint, true);
 
  51                 free_publickey(publickey);
 
  52         } else if (count == 0) {
 
  56                         puts("Key not found.");
 
  62                         printf("Found %d keys, but maximum number to return"
 
  66                         puts("Try again with a more specific search.");
 
  71 int main(int argc, char *argv[])
 
  76         bool fingerprint = false;
 
  83         struct openpgp_publickey *publickey = NULL;
 
  84         struct openpgp_packet_list *packets = NULL;
 
  85         struct openpgp_packet_list *list_end = NULL;
 
  87         params = getcgivars(argc, argv);
 
  88         for (i = 0; params != NULL && params[i] != NULL; i += 2) {
 
  89                 if (!strcmp(params[i], "op")) {
 
  90                         if (!strcmp(params[i+1], "get")) {
 
  92                         } else if (!strcmp(params[i+1], "index")) {
 
  94                         } else if (!strcmp(params[i+1], "vindex")) {
 
  97                 } else if (!strcmp(params[i], "search")) {
 
 100                         if (search != NULL) {
 
 101                                 keyid = strtoul(search, &end, 16);
 
 108                 } else if (!strcmp(params[i], "fingerprint")) {
 
 109                         if (!strcmp(params[i+1], "on")) {
 
 112                 } else if (!strcmp(params[i], "exact")) {
 
 113                         if (!strcmp(params[i+1], "on")) {
 
 116                 } else if (!strcmp(params[i], "options")) {
 
 118                          * TODO: We should be smarter about this; options may
 
 119                          * have several entries. For now mr is the only valid
 
 122                         if (!strcmp(params[i+1], "mr")) {
 
 128                 if (params[i+1] != NULL) {
 
 133         if (params != NULL) {
 
 139                 puts("Content-Type: text/plain\n");
 
 141                 start_html("Lookup of key");
 
 144         if (op == OP_UNKNOWN) {
 
 145                 puts("Error: No operation supplied.");
 
 146         } else if (search == NULL) {
 
 147                 puts("Error: No key to search for supplied.");
 
 150                 initlogthing("lookup", config.logfile);
 
 154                         if (fetch_key(keyid, &publickey, false)) {
 
 156                                 flatten_publickey(publickey,
 
 159                                 armor_openpgp_stream(stdout_putchar,
 
 164                                 puts("Key not found");
 
 168                         find_keys(search, keyid, ishex, fingerprint, exact,
 
 172                         find_keys(search, keyid, ishex, fingerprint, exact,
 
 176                         puts("Unknown operation!");
 
 184                 puts("Produced by onak " VERSION " by Jonathan McDowell");
 
 188         if (search != NULL) {
 
 193         return (EXIT_SUCCESS);