2  * gpgwww.c - www interface to path finder.
 
   4  * Copyright 2001-2004 Jonathan McDowell <noodles@earth.li>
 
   6  * This program is free software: you can redistribute it and/or modify it
 
   7  * under the terms of the GNU General Public License as published by the Free
 
   8  * Software Foundation; version 2 of the License.
 
  10  * This program is distributed in the hope that it will be useful, but WITHOUT
 
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
  12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 
  15  * You should have received a copy of the GNU General Public License along with
 
  16  * this program; if not, write to the Free Software Foundation, Inc., 51
 
  17  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
  26 #include "charfuncs.h"
 
  33 #include "onak-conf.h"
 
  41 int parsecgistuff(char **cgiparams, uint64_t *from, uint64_t *to)
 
  46         if (cgiparams != NULL) {
 
  48                 while (cgiparams[i] != NULL) {
 
  49                         if (!strcmp(cgiparams[i], "to")) {
 
  50                                 *to = strtoul(cgiparams[i+1], NULL, 16);
 
  51                         } else if (!strcmp(cgiparams[i], "from")) {
 
  52                                 *from = strtoul(cgiparams[i+1], NULL, 16);
 
  53                         } else if (!strcmp(cgiparams[i], "op")) {
 
  54                                 if (!strcmp(cgiparams[i+1], "get")) {
 
  65 int getkeyspath(uint64_t have, uint64_t want, int count)
 
  67         struct openpgp_publickey *publickey = NULL;
 
  68         struct openpgp_packet_list *packets = NULL;
 
  69         struct openpgp_packet_list *list_end = NULL;
 
  70         struct stats_key *keyinfoa, *keyinfob, *curkey;
 
  71         uint64_t fullhave, fullwant;
 
  74         fullhave = config.dbbackend->getfullkeyid(have);
 
  75         fullwant = config.dbbackend->getfullkeyid(want);
 
  78          * Make sure the keys we have and want are in the cache.
 
  80         config.dbbackend->cached_getkeysigs(fullhave);
 
  81         config.dbbackend->cached_getkeysigs(fullwant);
 
  83         if ((keyinfoa = findinhash(fullhave)) == NULL) {
 
  86         if ((keyinfob = findinhash(fullwant)) == NULL) {
 
  90         while ((!cleanup()) && (pathlen < count)) {
 
  92                  * Fill the tree info up.
 
  95                 findpath(keyinfoa, keyinfob);
 
  97                 if (keyinfoa->colour == 0) {
 
 101                          * Skip the first key, as the remote user will already
 
 104                         curkey = findinhash(keyinfoa->parent);
 
 105                         while (curkey != NULL && curkey->keyid != 0) {
 
 106                                 if (curkey->keyid != fullwant &&
 
 107                                                 config.dbbackend->fetch_key(
 
 109                                                 &publickey, false)) {
 
 110                                         flatten_publickey(publickey,
 
 113                                         free_publickey(publickey);
 
 116                                 if (curkey != keyinfoa && curkey != keyinfob) {
 
 117                                         curkey->disabled = true;
 
 119                                 curkey = findinhash(curkey->parent);
 
 126          * Add the destination key to the list of returned keys.
 
 128         if (config.dbbackend->fetch_key(fullwant, &publickey, false)) {
 
 129                 flatten_publickey(publickey,
 
 132                 free_publickey(publickey);
 
 136         armor_openpgp_stream(stdout_putchar, NULL, packets);
 
 137         free_packet_list(packets);
 
 138         packets = list_end = NULL;
 
 143 int main(int argc, char *argv[])
 
 145         char     **cgiparams = NULL;    /* Our CGI parameter block */
 
 146         uint64_t   from = 0, to = 0;
 
 149         cgiparams = getcgivars(argc, argv);
 
 152         op = parsecgistuff(cgiparams, &from, &to);
 
 155                 start_html("Experimental PGP key path finder results");
 
 157                 puts("Content-Type: text/plain\n");
 
 160         if (from == 0 || to == 0) {
 
 161                 printf("Must pass from & to\n");
 
 167                 printf("<P>Looking for path from 0x%016" PRIX64" to 0x%016"
 
 170                 printf("<A HREF=\"gpgwww?from=0x%016" PRIX64 "&to=0x%016" PRIX64
 
 171                                 "\">Find reverse path</A>\n",
 
 174                 printf("<A HREF=\"gpgwww?from=0x%08" PRIX64 "&to=0x%08" PRIX64
 
 176                                 "Get all keys listed</A></P>\n",
 
 182         initlogthing("gpgwww", config.logfile);
 
 184         config.dbbackend->initdb(true);
 
 186         logthing(LOGTHING_NOTICE, "Looking for path from 0x%016" PRIX64
 
 192                 getkeyspath(from, to, 3);
 
 194                 dofindpath(from, to, true, 3);
 
 197         config.dbbackend->cleanupdb();
 
 203                 puts("Produced by gpgwww " ONAK_VERSION ", part of onak. ");
 
 207         cleanupcgi(cgiparams);