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"
29 int parsecgistuff(char **cgiparams, uint64_t *from, uint64_t *to)
34 if (cgiparams != NULL) {
36 while (cgiparams[i] != NULL) {
37 if (!strcmp(cgiparams[i], "to")) {
38 *to = strtoul(cgiparams[i+1], NULL, 16);
39 } else if (!strcmp(cgiparams[i], "from")) {
40 *from = strtoul(cgiparams[i+1], NULL, 16);
41 } else if (!strcmp(cgiparams[i], "op")) {
42 if (!strcmp(cgiparams[i+1], "get")) {
53 int getkeyspath(uint64_t have, uint64_t want, int count)
55 struct openpgp_publickey *publickey = NULL;
56 struct openpgp_packet_list *packets = NULL;
57 struct openpgp_packet_list *list_end = NULL;
58 struct stats_key *keyinfoa, *keyinfob, *curkey;
59 uint64_t fullhave, fullwant;
63 fullhave = getfullkeyid(have);
64 fullwant = getfullkeyid(want);
67 * Make sure the keys we have and want are in the cache.
69 cached_getkeysigs(fullhave);
70 cached_getkeysigs(fullwant);
72 if ((keyinfoa = findinhash(fullhave)) == NULL) {
75 if ((keyinfob = findinhash(fullwant)) == NULL) {
79 while ((!cleanup()) && (pathlen < count)) {
81 * Fill the tree info up.
84 rec = findpath(keyinfoa, keyinfob);
86 if (keyinfoa->colour == 0) {
90 * Skip the first key, as the remote user will already
93 curkey = findinhash(keyinfoa->parent);
94 while (curkey != NULL && curkey->keyid != 0) {
95 if (curkey->keyid != fullwant && fetch_key(
98 flatten_publickey(publickey,
101 free_publickey(publickey);
104 if (curkey != keyinfoa && curkey != keyinfob) {
105 curkey->disabled = true;
107 curkey = findinhash(curkey->parent);
114 * Add the destination key to the list of returned keys.
116 if (fetch_key(fullwant, &publickey, false)) {
117 flatten_publickey(publickey,
120 free_publickey(publickey);
124 armor_openpgp_stream(stdout_putchar, NULL, packets);
125 free_packet_list(packets);
126 packets = list_end = NULL;
131 int main(int argc, char *argv[])
133 char **cgiparams = NULL; /* Our CGI parameter block */
134 uint64_t from = 0, to = 0;
137 cgiparams = getcgivars(argc, argv);
140 op = parsecgistuff(cgiparams, &from, &to);
143 start_html("Experimental PGP key path finder results");
145 puts("Content-Type: text/plain\n");
148 if (from == 0 || to == 0) {
149 printf("Must pass from & to\n");
155 printf("<P>Looking for path from 0x%llX to 0x%llX.\n",
157 printf("<A HREF=\"gpgwww?from=0x%08llX&to=0x%08llX\">"
158 "Find reverse path</A>\n",
161 printf("<A HREF=\"gpgwww?from=0x%08llX&to=0x%08llX&op=get\">"
162 "Get all keys listed</A></P>\n",
168 initlogthing("gpgwww", config.logfile);
172 logthing(LOGTHING_NOTICE, "Looking for path from 0x%llX to 0x%llX.",
176 getkeyspath(from, to, 3);
178 dofindpath(from, to, true, 3);
187 puts("Produced by gpgwww " VERSION ", part of onak. "
188 "<A HREF=\"mailto:noodles-onak@earth.li\">"
189 "Jonathan McDowell</A>");
193 cleanupcgi(cgiparams);