Allow dumping a list of outstanding invitations.
authorGuus Sliepen <guus@tinc-vpn.org>
Tue, 19 May 2015 22:12:01 +0000 (00:12 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Tue, 19 May 2015 22:12:01 +0000 (00:12 +0200)
This dumps the name of the invitation file, as well as the name of the
node that is being invited. This can make it easier to find the
invitation file belonging to a given node.

bash_completion.d/tinc
doc/tinc.8.in
doc/tinc.texi
src/tincctl.c

index 7fdbf20..48512dd 100644 (file)
@@ -58,7 +58,7 @@ _tinc() {
                return 0
                ;;
                dump|list|reachable)
                return 0
                ;;
                dump|list|reachable)
-               COMPREPLY=( $(compgen -W "reachable nodes edges subnets connections graph" -- ${cur}) )
+               COMPREPLY=( $(compgen -W "reachable nodes edges subnets connections graph invitations" -- ${cur}) )
                return 0
                ;;
                network)
                return 0
                ;;
                network)
index b9bd2d4..016053b 100644 (file)
@@ -172,6 +172,9 @@ format.
 Nodes are colored according to their reachability:
 red nodes are unreachable, orange nodes are indirectly reachable, green nodes are directly reachable.
 Black nodes are either directly or indirectly reachable, but direct reachability has not been tried yet.
 Nodes are colored according to their reachability:
 red nodes are unreachable, orange nodes are indirectly reachable, green nodes are directly reachable.
 Black nodes are either directly or indirectly reachable, but direct reachability has not been tried yet.
+.It dump invitations
+Dump a list of outstanding invitations.
+The filename of the invitation, as well as the name of the node that is being invited is shown for each invitation.
 .It info Ar node | subnet | address
 Show information about a particular node, subnet or address.
 If an address is given, any matching subnet will be shown.
 .It info Ar node | subnet | address
 Show information about a particular node, subnet or address.
 If an address is given, any matching subnet will be shown.
index 05760d9..f386b83 100644 (file)
@@ -2408,6 +2408,10 @@ Nodes are colored according to their reachability:
 red nodes are unreachable, orange nodes are indirectly reachable, green nodes are directly reachable.
 Black nodes are either directly or indirectly reachable, but direct reachability has not been tried yet.
 
 red nodes are unreachable, orange nodes are indirectly reachable, green nodes are directly reachable.
 Black nodes are either directly or indirectly reachable, but direct reachability has not been tried yet.
 
+@item dump invitations
+Dump a list of outstanding invitations.
+The filename of the invitation, as well as the name of the node that is being invited is shown for each invitation.
+
 @cindex info
 @item info @var{node} | @var{subnet} | @var{address}
 Show information about a particular @var{node}, @var{subnet} or @var{address}.
 @cindex info
 @item info @var{node} | @var{subnet} | @var{address}
 Show information about a particular @var{node}, @var{subnet} or @var{address}.
index 8d3d7a5..e0a6086 100644 (file)
@@ -1,6 +1,6 @@
 /*
     tincctl.c -- Controlling a running tincd
 /*
     tincctl.c -- Controlling a running tincd
-    Copyright (C) 2007-2014 Guus Sliepen <guus@tinc-vpn.org>
+    Copyright (C) 2007-2015 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -134,6 +134,7 @@ static void usage(bool status) {
                                "    subnets                  - all known subnets in the VPN\n"
                                "    connections              - all meta connections with ourself\n"
                                "    [di]graph                - graph of the VPN in dotty format\n"
                                "    subnets                  - all known subnets in the VPN\n"
                                "    connections              - all meta connections with ourself\n"
                                "    [di]graph                - graph of the VPN in dotty format\n"
+                               "    invitations              - outstanding invitations\n"
                                "  info NODE|SUBNET|ADDRESS   Give information about a particular NODE, SUBNET or ADDRESS.\n"
                                "  purge                      Purge unreachable nodes\n"
                                "  debug N                    Set debug level\n"
                                "  info NODE|SUBNET|ADDRESS   Give information about a particular NODE, SUBNET or ADDRESS.\n"
                                "  purge                      Purge unreachable nodes\n"
                                "  debug N                    Set debug level\n"
@@ -943,6 +944,65 @@ static int cmd_reload(int argc, char *argv[]) {
 
 }
 
 
 }
 
+static int dump_invitations(void) {
+       char dname[PATH_MAX];
+       snprintf(dname, sizeof dname, "%s" SLASH "invitations", confbase);
+       DIR *dir = opendir(dname);
+       if(!dir) {
+               if(errno == ENOENT) {
+                       fprintf(stderr, "No outstanding invitations.\n");
+                       return 0;
+               }
+
+               fprintf(stderr, "Cannot not read directory %s: %s\n", dname, strerror(errno));
+               return 1;
+       }
+
+       struct dirent *ent;
+       bool found = false;
+
+       while((ent = readdir(dir))) {
+               char buf[MAX_STRING_SIZE];
+               if(b64decode(ent->d_name, buf, 24) != 18)
+                       continue;
+
+               char fname[PATH_MAX];
+               snprintf(fname, sizeof fname, "%s" SLASH "%s", dname, ent->d_name);
+               FILE *f = fopen(fname, "r");
+               if(!f) {
+                       fprintf(stderr, "Cannot open %s: %s\n", fname, strerror(errno));
+                       fclose(f);
+                       continue;
+               }
+
+               buf[0] = 0;
+               if(!fgets(buf, sizeof buf, f)) {
+                       fprintf(stderr, "Invalid invitation file %s", fname);
+                       fclose(f);
+                       continue;
+               }
+               fclose(f);
+
+               char *eol = buf + strlen(buf);
+               while(strchr("\t \r\n", *--eol))
+                       *eol = 0;
+               if(strncmp(buf, "Name = ", 7) || !check_id(buf + 7)) {
+                       fprintf(stderr, "Invalid invitation file %s", fname);
+                       continue;
+               }
+
+               found = true;
+               printf("%s %s\n", ent->d_name, buf + 7);
+       }
+
+       closedir(dir);
+
+       if(!found)
+               fprintf(stderr, "No outstanding invitations.\n");
+
+       return 0;
+}
+
 static int cmd_dump(int argc, char *argv[]) {
        bool only_reachable = false;
 
 static int cmd_dump(int argc, char *argv[]) {
        bool only_reachable = false;
 
@@ -963,6 +1023,9 @@ static int cmd_dump(int argc, char *argv[]) {
                return 1;
        }
 
                return 1;
        }
 
+       if(!strcasecmp(argv[1], "invitations"))
+               return dump_invitations();
+
        if(!connect_tincd(true))
                return 1;
 
        if(!connect_tincd(true))
                return 1;