X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ftincctl.c;h=4dc1ff24c7adff2d61a181e1f60e669eb0c00030;hb=0b8b23e0dd7219344543f135ca0aeba8a4a42d48;hp=0d773e423916c16b870923d6b9300a062aa44c72;hpb=e971130b601064090815c31c90b876e3d0d1d5b1;p=tinc diff --git a/src/tincctl.c b/src/tincctl.c index 0d773e42..4dc1ff24 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -355,7 +355,7 @@ static FILE *ask_and_open(const char *filename, const char *what, const char *mo static bool ecdsa_keygen(bool ask) { ecdsa_t key; FILE *f; - char *filename; + char *pubname, *privname; fprintf(stderr, "Generating ECDSA keypair:\n"); @@ -365,8 +365,9 @@ static bool ecdsa_keygen(bool ask) { } else fprintf(stderr, "Done.\n"); - xasprintf(&filename, "%s" SLASH "ecdsa_key.priv", confbase); - f = ask_and_open(filename, "private ECDSA key", "a", ask); + xasprintf(&privname, "%s" SLASH "ecdsa_key.priv", confbase); + f = ask_and_open(privname, "private ECDSA key", "a", ask); + free(privname); if(!f) return false; @@ -379,14 +380,14 @@ static bool ecdsa_keygen(bool ask) { ecdsa_write_pem_private_key(&key, f); fclose(f); - free(filename); if(name) - xasprintf(&filename, "%s" SLASH "hosts" SLASH "%s", confbase, name); + xasprintf(&pubname, "%s" SLASH "hosts" SLASH "%s", confbase, name); else - xasprintf(&filename, "%s" SLASH "ecdsa_key.pub", confbase); + xasprintf(&pubname, "%s" SLASH "ecdsa_key.pub", confbase); - f = ask_and_open(filename, "public ECDSA key", "a", ask); + f = ask_and_open(pubname, "public ECDSA key", "a", ask); + free(pubname); if(!f) return false; @@ -396,7 +397,6 @@ static bool ecdsa_keygen(bool ask) { free(pubkey); fclose(f); - free(filename); return true; } @@ -408,7 +408,7 @@ static bool ecdsa_keygen(bool ask) { static bool rsa_keygen(int bits, bool ask) { rsa_t key; FILE *f; - char *filename; + char *pubname, *privname; fprintf(stderr, "Generating %d bits keys:\n", bits); @@ -418,8 +418,9 @@ static bool rsa_keygen(int bits, bool ask) { } else fprintf(stderr, "Done.\n"); - xasprintf(&filename, "%s" SLASH "rsa_key.priv", confbase); - f = ask_and_open(filename, "private RSA key", "a", ask); + xasprintf(&privname, "%s" SLASH "rsa_key.priv", confbase); + f = ask_and_open(privname, "private RSA key", "a", ask); + free(privname); if(!f) return false; @@ -432,14 +433,14 @@ static bool rsa_keygen(int bits, bool ask) { rsa_write_pem_private_key(&key, f); fclose(f); - free(filename); if(name) - xasprintf(&filename, "%s" SLASH "hosts" SLASH "%s", confbase, name); + xasprintf(&pubname, "%s" SLASH "hosts" SLASH "%s", confbase, name); else - xasprintf(&filename, "%s" SLASH "rsa_key.pub", confbase); + xasprintf(&pubname, "%s" SLASH "rsa_key.pub", confbase); - f = ask_and_open(filename, "public RSA key", "a", ask); + f = ask_and_open(pubname, "public RSA key", "a", ask); + free(pubname); if(!f) return false; @@ -447,7 +448,6 @@ static bool rsa_keygen(int bits, bool ask) { rsa_write_pem_public_key(&key, f); fclose(f); - free(filename); return true; } @@ -817,9 +817,10 @@ static int cmd_start(int argc, char *argv[]) { c = "tincd"; int nargc = 0; - char **nargv = xmalloc_and_zero((orig_argc + argc) * sizeof *nargv); + char **nargv = xmalloc_and_zero((optind + argc) * sizeof *nargv); - for(int i = 0; i < orig_argc; i++) + nargv[nargc++] = c; + for(int i = 1; i < optind; i++) nargv[nargc++] = orig_argv[i]; for(int i = 1; i < argc; i++) nargv[nargc++] = argv[i]; @@ -832,12 +833,15 @@ static int cmd_start(int argc, char *argv[]) { pid_t pid = fork(); if(pid == -1) { fprintf(stderr, "Could not fork: %s\n", strerror(errno)); + free(nargv); return 1; } if(!pid) exit(execvp(c, nargv)); + free(nargv); + int status = -1; if(waitpid(pid, &status, 0) != pid || !WIFEXITED(status) || WEXITSTATUS(status)) { fprintf(stderr, "Error starting %s\n", c); @@ -852,9 +856,13 @@ static int cmd_stop(int argc, char *argv[]) { #ifndef HAVE_MINGW if(!connect_tincd(true)) { if(pid) { - if(kill(pid, SIGTERM)) + if(kill(pid, SIGTERM)) { + fprintf(stderr, "Could not send TERM signal to process with PID %u: %s\n", pid, strerror(errno)); return 1; + } + fprintf(stderr, "Sent TERM signal to process with PID %u.\n", pid); + waitpid(pid, NULL, 0); return 0; } @@ -866,6 +874,12 @@ static int cmd_stop(int argc, char *argv[]) { fprintf(stderr, "Could not stop tinc daemon.\n"); return 1; } + + // Wait for tincd to close the connection... + fd_set r; + FD_ZERO(&r); + FD_SET(fd, &r); + select(fd + 1, &r, NULL, NULL, NULL); #else if(!remove_service()) return 1; @@ -1215,7 +1229,7 @@ static struct { {"ECDSAPrivateKeyFile", VAR_SERVER}, {"ExperimentalProtocol", VAR_SERVER}, {"Forwarding", VAR_SERVER}, - {"GraphDumpFile", VAR_SERVER}, + {"GraphDumpFile", VAR_SERVER | VAR_OBSOLETE}, {"Hostnames", VAR_SERVER}, {"IffOneQueue", VAR_SERVER}, {"Interface", VAR_SERVER}, @@ -1234,6 +1248,8 @@ static struct { {"ProcessPriority", VAR_SERVER}, {"Proxy", VAR_SERVER}, {"ReplayWindow", VAR_SERVER}, + {"ScriptsExtension", VAR_SERVER}, + {"ScriptsInterpreter", VAR_SERVER}, {"StrictSubnets", VAR_SERVER}, {"TunnelServer", VAR_SERVER}, {"UDPRcvBuf", VAR_SERVER}, @@ -2037,7 +2053,6 @@ static int cmd_shell(int argc, char *argv[]) { char *line = NULL; int maxargs = argc + 16; char **nargv = xmalloc(maxargs * sizeof *nargv); - optind = argc; for(int i = 0; i < argc; i++) nargv[i] = argv[i]; @@ -2123,6 +2138,8 @@ static int cmd_shell(int argc, char *argv[]) { } } + free(nargv); + if(tty) printf("\n"); return result;