2 * gpgwww.c - www interface to path finder.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2001-2002 Project Purple.
15 #include "charfuncs.h"
22 #include "onak-conf.h"
30 int parsecgistuff(char **cgiparams, uint64_t *from, uint64_t *to)
35 if (cgiparams != NULL) {
37 while (cgiparams[i] != NULL) {
38 if (!strcmp(cgiparams[i], "to")) {
39 *to = strtoul(cgiparams[i+1], NULL, 16);
40 } else if (!strcmp(cgiparams[i], "from")) {
41 *from = strtoul(cgiparams[i+1], NULL, 16);
42 } else if (!strcmp(cgiparams[i], "op")) {
43 if (!strcmp(cgiparams[i+1], "get")) {
54 int getkeyspath(uint64_t have, uint64_t want, int count)
56 struct openpgp_publickey *publickey = NULL;
57 struct openpgp_packet_list *packets = NULL;
58 struct openpgp_packet_list *list_end = NULL;
59 struct stats_key *keyinfoa, *keyinfob, *curkey;
60 uint64_t fullhave, fullwant;
64 fullhave = config.dbbackend->getfullkeyid(have);
65 fullwant = config.dbbackend->getfullkeyid(want);
68 * Make sure the keys we have and want are in the cache.
70 config.dbbackend->cached_getkeysigs(fullhave);
71 config.dbbackend->cached_getkeysigs(fullwant);
73 if ((keyinfoa = findinhash(fullhave)) == NULL) {
76 if ((keyinfob = findinhash(fullwant)) == NULL) {
80 while ((!cleanup()) && (pathlen < count)) {
82 * Fill the tree info up.
85 rec = findpath(keyinfoa, keyinfob);
87 if (keyinfoa->colour == 0) {
91 * Skip the first key, as the remote user will already
94 curkey = findinhash(keyinfoa->parent);
95 while (curkey != NULL && curkey->keyid != 0) {
96 if (curkey->keyid != fullwant &&
97 config.dbbackend->fetch_key(
100 flatten_publickey(publickey,
103 free_publickey(publickey);
106 if (curkey != keyinfoa && curkey != keyinfob) {
107 curkey->disabled = true;
109 curkey = findinhash(curkey->parent);
116 * Add the destination key to the list of returned keys.
118 if (config.dbbackend->fetch_key(fullwant, &publickey, false)) {
119 flatten_publickey(publickey,
122 free_publickey(publickey);
126 armor_openpgp_stream(stdout_putchar, NULL, packets);
127 free_packet_list(packets);
128 packets = list_end = NULL;
133 int main(int argc, char *argv[])
135 char **cgiparams = NULL; /* Our CGI parameter block */
136 uint64_t from = 0, to = 0;
139 cgiparams = getcgivars(argc, argv);
142 op = parsecgistuff(cgiparams, &from, &to);
145 start_html("Experimental PGP key path finder results");
147 puts("Content-Type: text/plain\n");
150 if (from == 0 || to == 0) {
151 printf("Must pass from & to\n");
157 printf("<P>Looking for path from 0x%016" PRIX64" to 0x%016"
160 printf("<A HREF=\"gpgwww?from=0x%016" PRIX64 "&to=0x%016" PRIX64
161 "\">Find reverse path</A>\n",
164 printf("<A HREF=\"gpgwww?from=0x%08" PRIX64 "&to=0x%08" PRIX64
166 "Get all keys listed</A></P>\n",
172 initlogthing("gpgwww", config.logfile);
174 config.dbbackend->initdb(true);
176 logthing(LOGTHING_NOTICE, "Looking for path from 0x%016" PRIX64
182 getkeyspath(from, to, 3);
184 dofindpath(from, to, true, 3);
187 config.dbbackend->cleanupdb();
193 puts("Produced by gpgwww " ONAK_VERSION ", part of onak. "
194 "<A HREF=\"mailto:noodles-onak@earth.li\">"
195 "Jonathan McDowell</A>");
199 cleanupcgi(cgiparams);