X-Git-Url: http://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ftincctl.c;h=c1654186bea9b9eb6a75b6cbfb2172390446af09;hb=36dee4c539521578005eed5e58b4803b73f0c889;hp=523bbb4ec8e7bd98103995425ccf6a01267dcacb;hpb=cedfeccb247abb00063316068d7d2ade880f9d09;p=tinc diff --git a/src/tincctl.c b/src/tincctl.c index 523bbb4e..c1654186 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -655,6 +655,9 @@ static bool connect_tincd() { static int cmd_start(int argc, char *argv[]) { int i, j; char *c; + + argc += optind; + argv -= optind; char *slash = strrchr(argv[0], '/'); #ifdef HAVE_MINGW @@ -1163,6 +1166,12 @@ static int cmd_config(int argc, char *argv[]) { return 1; } + // Silently try notifying a running tincd of changes. + fclose(stderr); + + if(connect_tincd()) + sendline(fd, "%d %d", CONTROL, REQ_RELOAD); + return 0; } @@ -1269,6 +1278,69 @@ static int cmd_version(int argc, char *argv[]) { return 0; } +static const char *conffiles[] = { + "tinc.conf", + "tinc-up", + "tinc-down", + "subnet-up", + "subnet-down", + "host-up", + "host-down", + NULL, +}; + +static int cmd_edit(int argc, char *argv[]) { + if(argc != 2) { + fprintf(stderr, "Invalid number of arguments.\n"); + return 1; + } + + char *filename = NULL; + + if(strncmp(argv[1], "hosts/", 6)) { + for(int i = 0; conffiles[i]; i++) { + if(!strcmp(argv[1], conffiles[i])) { + xasprintf(&filename, "%s/%s", confbase, argv[1]); + break; + } + } + } else { + argv[1] += 6; + } + + if(!filename) { + xasprintf(&filename, "%s/%s", hosts_dir, argv[1]); + char *dash = strchr(argv[1], '-'); + if(dash) { + *dash++ = 0; + if((strcmp(dash, "up") && strcmp(dash, "down")) || !check_id(argv[1])) { + fprintf(stderr, "Invalid configuration filename.\n"); + return 1; + } + } + } + +#ifndef HAVE_MINGW + char *editor = getenv("VISUAL") ?: getenv("EDITOR") ?: "vi"; +#else + char *editor = "edit" +#endif + + char *command; + xasprintf(&command, "\"%s\" \"%s\"", editor, filename); + int result = system(command); + if(result) + return result; + + // Silently try notifying a running tincd of changes. + fclose(stderr); + + if(connect_tincd()) + sendline(fd, "%d %d", CONTROL, REQ_RELOAD); + + return 0; +} + static const struct { const char *command; int (*function)(int argc, char *argv[]); @@ -1294,6 +1366,7 @@ static const struct { {"generate-ecdsa-keys", cmd_generate_ecdsa_keys}, {"help", cmd_help}, {"version", cmd_version}, + {"edit", cmd_edit}, {NULL, NULL}, };