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 = config.dbbackend->fetch_key(keyid, &publickey, false);
 
  45                 count = config.dbbackend->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 = strtoull(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);
 
 162                 config.dbbackend->initdb(true);
 
 165                         logthing(LOGTHING_NOTICE, "Getting keyid 0x%llX",
 
 167                         if (config.dbbackend->fetch_key(keyid, &publickey,
 
 170                                 cleankeys(publickey);
 
 171                                 flatten_publickey(publickey,
 
 174                                 armor_openpgp_stream(stdout_putchar,
 
 179                                 logthing(LOGTHING_NOTICE,
 
 180                                         "Failed to fetch key.");
 
 181                                 puts("Key not found");
 
 185                         find_keys(search, keyid, ishex, fingerprint, exact,
 
 189                         find_keys(search, keyid, ishex, fingerprint, exact,
 
 193                         if (config.dbbackend->fetch_key(keyid, &publickey,
 
 195                                 unsigned char *photo = NULL;
 
 198                                 if (getphoto(publickey, 0, &photo, &length)) {
 
 204                                 free_publickey(publickey);
 
 209                         puts("Unknown operation!");
 
 211                 config.dbbackend->cleanupdb();
 
 217                 puts("Produced by onak " PACKAGE_VERSION 
 
 218                                 " by Jonathan McDowell");
 
 222         if (search != NULL) {
 
 227         return (EXIT_SUCCESS);