2 * gpgwww.c - www interface to path finder.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2001-2002 Project Purple.
15 #include "charfuncs.h"
21 #include "onak-conf.h"
28 int parsecgistuff(char **cgiparams, uint64_t *from, uint64_t *to)
33 if (cgiparams != NULL) {
35 while (cgiparams[i] != NULL) {
36 if (!strcmp(cgiparams[i], "to")) {
37 *to = strtoul(cgiparams[i+1], NULL, 16);
38 } else if (!strcmp(cgiparams[i], "from")) {
39 *from = strtoul(cgiparams[i+1], NULL, 16);
40 } else if (!strcmp(cgiparams[i], "op")) {
41 if (!strcmp(cgiparams[i+1], "get")) {
52 int getkeyspath(uint64_t have, uint64_t want, int count)
54 struct openpgp_publickey *publickey = NULL;
55 struct openpgp_packet_list *packets = NULL;
56 struct openpgp_packet_list *list_end = NULL;
57 struct stats_key *keyinfoa, *keyinfob, *curkey;
58 uint64_t fullhave, fullwant;
62 fullhave = getfullkeyid(have);
63 fullwant = getfullkeyid(want);
66 * Make sure the keys we have and want are in the cache.
68 cached_getkeysigs(fullhave);
69 cached_getkeysigs(fullwant);
71 if ((keyinfoa = findinhash(fullhave)) == NULL) {
74 if ((keyinfob = findinhash(fullwant)) == NULL) {
78 while (pathlen < count) {
80 * Fill the tree info up.
83 rec = findpath(keyinfoa, keyinfob);
85 if (keyinfoa->colour == 0) {
89 * Skip the first key, as the remote user will already
92 curkey = findinhash(keyinfoa->parent);
93 while (curkey != NULL && curkey->keyid != 0) {
94 if (curkey->keyid != fullwant && fetch_key(
97 flatten_publickey(publickey,
100 free_publickey(publickey);
103 if (curkey != keyinfoa && curkey != keyinfob) {
104 curkey->disabled = true;
106 curkey = findinhash(curkey->parent);
113 * Add the destination key to the list of returned keys.
115 if (fetch_key(fullwant, &publickey, false)) {
116 flatten_publickey(publickey,
119 free_publickey(publickey);
123 armor_openpgp_stream(stdout_putchar, NULL, packets);
124 free_packet_list(packets);
125 packets = list_end = NULL;
130 int main(int argc, char *argv[])
132 char **cgiparams = NULL; /* Our CGI parameter block */
133 uint64_t from = 0, to = 0;
136 cgiparams = getcgivars(argc, argv);
139 op = parsecgistuff(cgiparams, &from, &to);
142 start_html("Experimental PGP key path finder results");
144 puts("Content-Type: text/plain\n");
147 if (from == 0 || to == 0) {
148 printf("Must pass from & to\n");
154 printf("<P>Looking for path from 0x%llX to 0x%llX.\n",
156 printf("<A HREF=\"gpgwww?from=0x%08llX&to=0x%08llX\">"
157 "Find reverse path</A>\n",
160 printf("<A HREF=\"gpgwww?from=0x%08llX&to=0x%08llX&op=get\">"
161 "Get all keys listed</A></P>\n",
167 initlogthing("gpgwww", config.logfile);
170 logthing(LOGTHING_NOTICE, "Looking for path from 0x%llX to 0x%llX.",
174 getkeyspath(from, to, 3);
176 dofindpath(from, to, true, 3);
185 puts("Produced by gpgwww " VERSION ", part of onak. "
186 "<A HREF=\"mailto:noodles-onak@earth.li\">"
187 "Jonathan McDowell</A>");
191 cleanupcgi(cgiparams);