]> git.sommitrealweird.co.uk Git - onak.git/commitdiff
cscvs to tla changeset 49
authorJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:47:21 +0000 (23:47 +0000)
committerJonathan McDowell <noodles@earth.li>
Mon, 31 May 2004 23:47:21 +0000 (23:47 +0000)
Author: noodles
Date: 2002/11/26 17:29:26
Added sixdegrees and cleaned out code from gpgstats that's already in use.

Makefile
gpgstats-0.0.2/dotrees.c
gpgstats-0.0.2/filt.pl [deleted file]
gpgstats-0.0.2/gpgpre [deleted file]
gpgstats-0.0.2/gpgprecolons [deleted file]
gpgstats-0.0.2/gpgstats.c
sixdegrees.c [new file with mode: 0644]

index dc8d5cedd57e0de542e5cafd1b98f317ec793922..35f1674f3c4b74302a5d6cefbd7fefa9cc8204a3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ SRCS = armor.c parsekey.c merge.c keyid.c md5.c sha.c main.c getcgi.c stats.c \
        keyindex.c mem.c lookup.c add.c keydb_$(DBTYPE).c ll.c hash.c \
        gpgwww.c onak-conf.c charfuncs.c sendsync.c
 
-all: $(PROGS) testparse maxpath
+all: $(PROGS) testparse maxpath sixdegrees
 
 testparse: main.o $(OBJS)
        $(LINK) -o testparse main.o $(OBJS) $(LIBS)
@@ -26,6 +26,9 @@ testparse: main.o $(OBJS)
 maxpath: maxpath.o $(OBJS)
        $(LINK) -o maxpath maxpath.o $(OBJS) $(LIBS)
 
+sixdegrees: sixdegrees.o $(OBJS)
+       $(LINK) -o sixdegrees sixdegrees.o $(OBJS) $(LIBS)
+
 gpgwww: gpgwww.o $(OBJS)
        $(LINK) -o gpgwww gpgwww.o $(OBJS) $(LIBS)
 
index 0dec450b8d5061e7b45b4bb9437bc420292725b2..de4e7a880f4494646ff471354d28a31692c7f59c 100644 (file)
@@ -259,144 +259,6 @@ void printtrees(int minsize)
 }
 
 
-unsigned long size2degree(struct ll *curll, struct key *prev, int sigs, int curdegree, int maxdegree, int *rec)
-{
-       unsigned long count=0;
-       struct ll *nextll;
-
-       ++curdegree;
-       ++(*rec);
-
-       nextll=NULL;
-       while (curll!=NULL) {
-               if (((struct key *) curll->object)->revoked==1) {
-                       /* It's revoked. Ignore it. */
-               } else if (((struct key *) curll->object)->colour==0) {
-                       /* We've never seen it. Count it, mark it and
-                               explore its subtree */
-                       count++;
-                       printf("0x%08lX (%s)\n", ((struct key *) curll->object)->keyid,
-                               ((struct key *) curll->object)->name);
-                       ((struct key *)curll->object)->colour=curdegree;
-                       ((struct key *)curll->object)->pi=(struct ll *) prev;
-                       nextll=lladd(nextll, curll->object);
-               } else if (((struct key *) curll->object)->colour>curdegree) {
-                       /* We've seen it, but it it's closer to us than we
-                               thought. Re-evaluate, but don't count it
-                               again */
-                       ((struct key *)curll->object)->colour=curdegree;
-                       ((struct key *)curll->object)->pi=(struct ll *) prev;
-                       nextll=lladd(nextll, curll->object);
-               }
-               curll=curll->next;
-       }
-       /* Now we've marked, let's recurse */
-       if (curdegree<maxdegree) curll=nextll; else curll=NULL;
-       while (curll!=NULL) {
-               if (sigs) {
-                       count += size2degree(((struct key *)curll->object)->sigs, curll->object, sigs, curdegree, maxdegree, rec);
-               } else {
-                       count += size2degree(((struct key *)curll->object)->signs, curll->object, sigs, curdegree, maxdegree, rec);
-               }
-               nextll=curll->next;
-               free(curll);
-               curll=nextll;
-       }
-
-       return count;
-}
-
-
-void sixdegrees(unsigned long keyid)
-{
-       struct key *keyinfo, key;
-       int loop;
-       int rec;
-
-       key.keyid=keyid;
-
-       if ((keyinfo=findinhash(&key))==NULL) {
-               printf("Couldn't find key 0x%08lX.\n", keyid);
-               return;
-       }
-
-       printf("Six degrees for 0x%08lX (%s):\n", keyinfo->keyid, keyinfo->name);
-
-       puts("\t\t   Signs       Signed by");
-       for (loop=1; loop<7; loop++) {
-               initcolour(0);
-               rec=0;
-               printf("Degree %d:\t%8ld", loop, size2degree(keyinfo->signs, NULL, 0, 0, loop, &rec));
-               printf(" (%d)", rec);
-               initcolour(0);
-               rec=0;
-               printf("\t%8ld", size2degree(keyinfo->sigs, NULL, 1, 0, loop, &rec));
-               printf(" (%d)\n", rec);
-       }
-}
-
-
-void showkeysigs(unsigned long keyid, int sigs)
-{
-       struct key *keyinfo, key;
-       struct ll *cursig;
-
-       key.keyid=keyid;
-
-       if ((keyinfo=findinhash(&key))==NULL) {
-               printf("Couldn't find key 0x%08lX.\n", keyid);
-               return;
-       }
-
-       printf("0x%08lX (%s) %s:\n", keyinfo->keyid, keyinfo->name,
-                       sigs ? "is signed by" : "signs");
-
-       if (sigs) cursig=keyinfo->sigs; else cursig=keyinfo->signs;
-       while (cursig!=NULL) {
-               printf("\t0x%08lX (%s)\n", ((struct key *)cursig->object)->keyid,
-                               ((struct key *)cursig->object)->name);
-               cursig=cursig->next;
-       }
-}
-
-
-void findpath(unsigned long keyida, unsigned long keyidb)
-{
-       struct key *keyinfoa, *keyinfob, *curkey, keya, keyb;
-       int rec;
-
-       keya.keyid=keyida;
-       keyb.keyid=keyidb;
-
-       if ((keyinfoa=findinhash(&keya))==NULL) {
-               printf("Couldn't find key 0x%08lX.\n", keyida);
-               return;
-       }
-       if ((keyinfob=findinhash(&keyb))==NULL) {
-               printf("Couldn't find key 0x%08lX.\n", keyidb);
-               return;
-       }
-
-       /* Fill the tree info up */
-       initcolour(1);
-       rec=0;
-       size2degree(keyinfoa->signs, keyinfoa, 0, 0, 1000, &rec);
-       keyinfoa->pi=NULL;
-
-       printf("%d recursions required.\n", rec);
-       if (keyinfob->colour==0) {
-               printf("Can't find a link from 0x%08lX to 0x%08lX\n", keyida, keyidb);
-       } else {
-               printf("%d steps from 0x%08lX to 0x%08lX\n", keyinfob->colour, keyida, keyidb);
-               curkey=keyinfob;
-               while (curkey!=NULL) {
-                       printf("0x%08lX (%s)\n", curkey->keyid, curkey->name);
-                       curkey=(struct key *)curkey->pi;
-               }
-       }
-}
-
-
 int main(int argc, char *argv[])
 {
        struct key *keyinfo,foo;
@@ -406,9 +268,7 @@ int main(int argc, char *argv[])
        puts("Copyright 2000 Project Purple. Released under the GPL.");
        puts("A simple program to do stats on a GPG keyring.\n");
        inithash();
-//     readkeys("keyfile");
        readkeys("keyfile.debian");
-//     readkeys("../keyfile.big");
        printf("%ld selfsigned.\n", checkselfsig());
        printf("%ld distinct keys.\n", hashelements());
 
@@ -418,15 +278,4 @@ int main(int argc, char *argv[])
        printf("Starting second DFS.\n");
        DFSsorted();
        printtrees(2);
-
-//     foo.keyid=0xC7A966DD; /* Phil Zimmerman himself */
-//     if ((keyinfo=findinhash(&foo))==NULL) {
-//             printf("Couldn't find key 0x%08lX.\n", foo.keyid);
-//             return 1;
-//     }
-
-//     initcolour(0);
-//     rec=0;
-//     printf("%ld\n", size2degree(keyinfo->sigs, NULL, 0, 0, 1000, &rec));
-//     return 0;
 }
diff --git a/gpgstats-0.0.2/filt.pl b/gpgstats-0.0.2/filt.pl
deleted file mode 100755 (executable)
index a7e4353..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/perl
-
-@keyfile=<>;
-
-$count=0;
-
-while ($count<scalar(@keyfile)) {
-       if ($keyfile[$count] =~ /^P/ &&
-               $keyfile[$count+1] =~ /^N/ &&
-               $keyfile[$count+2] =~ /^S/ &&
-               $keyfile[$count+3] =~ /^P/) {
-               $count = $count + 3;
-       } else {
-               print $keyfile[$count++];
-       }
-}
diff --git a/gpgstats-0.0.2/gpgpre b/gpgstats-0.0.2/gpgpre
deleted file mode 100755 (executable)
index 9f81af3..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/perl -Tw
-# Written by Jonathan McDowell <noodles@earth.li>
-# Copyright 2000 Project Purple.
-# Dedicated to linguists called Simon everywhere.
-#
-# Processes the output of gpg -v --list-keys to a format gpgstats likes.
-#
-# Try:
-# gpg -v --list-keys | ./gpgpre | uniq > keyfile
-#
-# I should really include the uniq in the code.
-
-use strict;
-
-my ($curline);
-
-while ($curline = <>) {
-       chomp $curline;
-
-       if ($curline =~ /^pub.*\/([0-9a-fA-F]{8}) [0-9-\/]{10} (.*)/) {
-               print "P$1\n";
-               print "N$2\n";
-       } elsif ($curline =~ /^sig *([0-9a-fA-F]{8})/) {
-               print "S$1\n";
-       }
-}
diff --git a/gpgstats-0.0.2/gpgprecolons b/gpgstats-0.0.2/gpgprecolons
deleted file mode 100755 (executable)
index 94ba88a..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/perl -Tw
-# Written by Jonathan McDowell <noodles@earth.li>
-# Dedicated to linguists called Simon everywhere.
-#
-# An attempt at parsing the output of gpg -v --with-colons --list-keys
-# Not completed yet. Will replace gpgpre and allow info on keysize/type.
-
-use strict;
-
-my ($curline, $rsa, $dsa, $elg, $elgeo);
-
-$rsa=$dsa=$elg=$elgeo=0;
-
-while ($curline = <>) {
-       chomp $curline;
-
-       if ($curline =~ /^pub:.*:\d*:(\d*):([0-9a-fA-F]*):.*:.*:.*:.*:(.*):/) {
-               if ($1 == 1) {
-                       $rsa++;
-               } elsif ($1 == 16) {
-                       $elgeo++;
-               } elsif ($1 == 17) {
-                       $dsa++;
-               } elsif ($1 == 20) {
-                       $elg++;
-               }
-#              print "P$2\n";
-#              print "N$3\n";
-       } elsif ($curline =~ /^sig:.*:\d*:(\d*):([0-9a-fA-F]*):.*:.*:.*:.*:.*/) {
-#              print "S$2\n";
-       } elsif ($curline =~ /^uid:/) {
-               # Extra uid. Ignore.
-       } elsif ($curline =~ /^sub:/) {
-               # Subkey. Ignore.
-       } elsif ($curline =~ /^rev:/) {
-               # Unsure. Ignore.
-       } else {
-               print "$curline\n";
-       }
-}
-
-print "RSA keys: $rsa, DSA keys: $dsa, ELG encrypt-only: $elgeo, ELG: $elg\n";
index a72879945e4f89526517f70b59239b9723fd2cf6..c3d0a4b43e8cebdb2a0a8a497aed9ce4d4049652 100644 (file)
@@ -66,33 +66,6 @@ void printtrees(int minsize)
 //     log(LOG_INFO, "Total of %ld trees.\n", total);
 }
 
-
-void sixdegrees(uint64_t keyid)
-{
-       struct stats_key *keyinfo;
-       int loop;
-       long degree;
-
-       if ((keyinfo = findinhash(keyid)) == NULL) {
-               printf("Couldn't find key 0x%llX.\n", keyid);
-               return;
-       }
-
-       printf("Six degrees for 0x%llX (%s):\n", keyinfo->keyid,
-                                                keyid2uid(keyinfo->keyid));
-
-       puts("\t\t   Signs       Signed by");
-       for (loop = 1; loop < 7; loop++) {
-               initcolour(false);
-               degree = countdegree(keyinfo, 0, loop);
-               printf("Degree %d:\t%8ld", loop, degree);
-               initcolour(false);
-               degree = countdegree(keyinfo, 1, loop);
-               printf("\t%8ld\n", degree);
-       }
-}
-
-
 void showkeysigs(uint64_t keyid, bool sigs)
 {
        struct stats_key *keyinfo = NULL;
@@ -198,35 +171,6 @@ void showmostsigns(int sigs)
        }
 }
 
-void findmaxpath(unsigned long max)
-{
-       struct key *from, *to, *tmp;
-       struct ll *curkey;
-       unsigned long distance, loop;
-
-       printf("In findmaxpath\n");
-       distance=0;
-       from=to=NULL;
-       for (loop=0; loop<HASHSIZE && distance<max; loop++) {
-               curkey=gethashtableentry(loop);
-               while (curkey!=NULL && distance<max) {
-                       initcolour(false);
-                       tmp=furthestkey((struct key *)curkey->object);
-                       if (tmp->colour>distance) {
-                               from=(struct key *)curkey->object;
-                               to=tmp;
-                               distance=to->colour;
-                               printf("Current max path (#%ld) is from %08lX to %08lX (%ld steps)\n", loop, from->keyid, to->keyid, distance);
-                       }
-                       curkey=curkey->next;
-               }
-       }
-       printf("Max path is from %08lX to %08lX (%ld steps)\n",
-                       from->keyid,
-                       to->keyid,
-                       distance);
-}
-
 void showhelp(void)
 {
        printf("gpgstats %s by Jonathan McDowell\n", VERSION);
@@ -283,9 +227,6 @@ void commandloop(void)
                case 2:
                        readkeys(param);
                        break;
-               case 3:
-                       sixdegrees(strtoul(param, NULL, 16));
-                       break;
                case 4:
                        //dofindpath(strtoul(param, NULL, 16),
                        //      strtoul(strchr(param, ' ')+1, NULL, 16));
@@ -321,9 +262,6 @@ void commandloop(void)
                case 12:
                        memstats();
                        break;
-               case 13:
-                       findmaxpath(atoi(param));
-                       break;
                }
        } while (cmd!=1);
 }
diff --git a/sixdegrees.c b/sixdegrees.c
new file mode 100644 (file)
index 0000000..1afbf77
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * sixdegrees.c - List the size of the six degrees of trust away from a key.
+ * 
+ * Jonathan McDowell <noodles@earth.li>
+ *
+ * Copyright 2001-2002 Project Purple.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "hash.h"
+#include "keydb.h"
+#include "keystructs.h"
+#include "ll.h"
+#include "onak-conf.h"
+#include "stats.h"
+
+unsigned long countdegree(struct stats_key *have, int maxdegree)
+{
+       unsigned long count = 0, curdegree = 0;
+       struct ll *curll, *nextll, *sigll, *tmp;
+
+       ++curdegree;
+
+       nextll = NULL;
+       curll = lladd(NULL, have);
+
+       while (curll != NULL && curdegree <= maxdegree) {
+               sigll = cached_getkeysigs(((struct stats_key *)
+                               curll->object)->keyid);
+               while (sigll != NULL) {
+                       if (((struct stats_key *) sigll->object)->colour==0) {
+                               /* We've never seen it. Count it, mark it and
+                                       explore its subtree */
+                               count++;
+                               ((struct stats_key *)sigll->object)->colour = 
+                                       curdegree;
+                               ((struct stats_key *)sigll->object)->parent = 
+                                       ((struct stats_key *)
+                                        curll->object)->keyid;
+                               nextll=lladd(nextll, sigll->object);
+                       }
+                       sigll = sigll->next;
+               }
+               tmp = curll->next;
+               free(curll);
+               curll = tmp;
+               if (curll == NULL) {
+                       curll = nextll;
+                       nextll = NULL;
+                       ++curdegree;
+               };
+       }
+       if (curll != NULL) {
+               llfree(curll, NULL);
+               curll = NULL;
+       }
+       if (nextll != NULL) {
+               llfree(nextll, NULL);
+               nextll = NULL;
+       }
+
+       return count;
+}
+
+void sixdegrees(uint64_t keyid)
+{
+       struct stats_key *keyinfo;
+       int loop;
+       long degree;
+       char *uid;
+
+       cached_getkeysigs(keyid);
+
+       if ((keyinfo = findinhash(keyid)) == NULL) {
+               printf("Couldn't find key 0x%llX.\n", keyid);
+               return;
+       }
+
+       uid = keyid2uid(keyinfo->keyid);
+       printf("Six degrees for 0x%llX (%s):\n", keyinfo->keyid, uid);
+       free(uid);
+       uid = NULL;
+
+       puts("\t\tSigned by");
+       for (loop = 1; loop < 7; loop++) {
+               initcolour(false);
+               degree = countdegree(keyinfo, loop);
+               printf("Degree %d:\t%8ld\n", loop, degree);
+               /*
+                * TODO: Used to have keys we signed as well but this takes a
+                * lot of resource and isn't quite appropriate for something
+                * intended to be run on the fly. Given this isn't a CGI at
+                * present perhaps should be readded.
+                */
+       }
+}
+
+int main(int argc, char *argv[])
+{
+       readconfig();
+       initdb();
+       inithash();
+       sixdegrees(0x5B430367);
+       destroyhash();
+       cleanupdb();
+       cleanupconfig();
+
+       return 0;
+}