X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ftincctl.c;h=619b90ece9328a0785907222d48df5a1cb0f6188;hb=248d300f1be0d5f2aae39202041699ab2b46c56b;hp=f519e78d37792b07b3182a767e970f84336ba243;hpb=18237e1f2d9dd5eef4a4e0d746d016bf94a42ad4;p=tinc diff --git a/src/tincctl.c b/src/tincctl.c index f519e78d..619b90ec 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -1361,8 +1361,6 @@ static int cmd_init(int argc, char *argv[]) { return 1; } - char *hosts_dir = NULL; - xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase); if(mkdir(hosts_dir, 0755) && errno != EEXIST) { fprintf(stderr, "Could not create directory %s: %s\n", hosts_dir, strerror(errno)); return 1; @@ -1379,9 +1377,24 @@ static int cmd_init(int argc, char *argv[]) { fclose(stdin); if(!rsa_keygen(2048) || !ecdsa_keygen()) - return false; + return 1; - return true; +#ifndef HAVE_MINGW + char *filename; + xasprintf(&filename, "%s" SLASH "tinc-up", confbase); + if(access(filename, F_OK)) { + FILE *f = fopen(filename, "w"); + if(!f) { + fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno)); + return 1; + } + fchmod(fileno(f), 0755); + fprintf(f, "#!/bin/sh\n\necho 'Unconfigured tinc-up script, please edit!'\n\n#ifconfig $INTERFACE netmask \n"); + fclose(f); + } +#endif + + return 0; } @@ -1461,14 +1474,12 @@ static int cmd_edit(int argc, char *argv[]) { } } + char *command; #ifndef HAVE_MINGW - char *editor = getenv("VISUAL") ?: getenv("EDITOR") ?: "vi"; + xasprintf(&command, "\"%s\" \"%s\"", getenv("VISUAL") ?: getenv("EDITOR") ?: "vi", filename); #else - char *editor = "edit"; + xasprintf(&command, "edit \"%s\"", filename); #endif - - char *command; - xasprintf(&command, "\"%s\" \"%s\"", editor, filename); int result = system(command); if(result) return result;