projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
C99 extravaganza.
[tinc]
/
src
/
tincctl.c
diff --git
a/src/tincctl.c
b/src/tincctl.c
index
0d773e4
..
4dc1ff2
100644
(file)
--- 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;
static bool ecdsa_keygen(bool ask) {
ecdsa_t key;
FILE *f;
- char *
file
name;
+ char *
pubname, *priv
name;
fprintf(stderr, "Generating ECDSA keypair:\n");
fprintf(stderr, "Generating ECDSA keypair:\n");
@@
-365,8
+365,9
@@
static bool ecdsa_keygen(bool ask) {
} else
fprintf(stderr, "Done.\n");
} 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;
if(!f)
return false;
@@
-379,14
+380,14
@@
static bool ecdsa_keygen(bool ask) {
ecdsa_write_pem_private_key(&key, f);
fclose(f);
ecdsa_write_pem_private_key(&key, f);
fclose(f);
- free(filename);
if(name)
if(name)
- xasprintf(&
file
name, "%s" SLASH "hosts" SLASH "%s", confbase, name);
+ xasprintf(&
pub
name, "%s" SLASH "hosts" SLASH "%s", confbase, name);
else
else
- xasprintf(&
file
name, "%s" SLASH "ecdsa_key.pub", confbase);
+ xasprintf(&
pub
name, "%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;
if(!f)
return false;
@@
-396,7
+397,6
@@
static bool ecdsa_keygen(bool ask) {
free(pubkey);
fclose(f);
free(pubkey);
fclose(f);
- free(filename);
return true;
}
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;
static bool rsa_keygen(int bits, bool ask) {
rsa_t key;
FILE *f;
- char *
file
name;
+ char *
pubname, *priv
name;
fprintf(stderr, "Generating %d bits keys:\n", bits);
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");
} 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;
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);
rsa_write_pem_private_key(&key, f);
fclose(f);
- free(filename);
if(name)
if(name)
- xasprintf(&
file
name, "%s" SLASH "hosts" SLASH "%s", confbase, name);
+ xasprintf(&
pub
name, "%s" SLASH "hosts" SLASH "%s", confbase, name);
else
else
- xasprintf(&
file
name, "%s" SLASH "rsa_key.pub", confbase);
+ xasprintf(&
pub
name, "%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;
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);
rsa_write_pem_public_key(&key, f);
fclose(f);
- free(filename);
return true;
}
return true;
}
@@
-817,9
+817,10
@@
static int cmd_start(int argc, char *argv[]) {
c = "tincd";
int nargc = 0;
c = "tincd";
int nargc = 0;
- char **nargv = xmalloc_and_zero((o
rig_argc
+ argc) * sizeof *nargv);
+ char **nargv = xmalloc_and_zero((o
ptind
+ 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];
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));
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));
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);
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) {
#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;
return 1;
+ }
+
fprintf(stderr, "Sent TERM signal to process with PID %u.\n", pid);
fprintf(stderr, "Sent TERM signal to process with PID %u.\n", pid);
+ waitpid(pid, NULL, 0);
return 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;
}
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;
#else
if(!remove_service())
return 1;
@@
-1215,7
+1229,7
@@
static struct {
{"ECDSAPrivateKeyFile", VAR_SERVER},
{"ExperimentalProtocol", VAR_SERVER},
{"Forwarding", VAR_SERVER},
{"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},
{"Hostnames", VAR_SERVER},
{"IffOneQueue", VAR_SERVER},
{"Interface", VAR_SERVER},
@@
-1234,6
+1248,8
@@
static struct {
{"ProcessPriority", VAR_SERVER},
{"Proxy", VAR_SERVER},
{"ReplayWindow", VAR_SERVER},
{"ProcessPriority", VAR_SERVER},
{"Proxy", VAR_SERVER},
{"ReplayWindow", VAR_SERVER},
+ {"ScriptsExtension", VAR_SERVER},
+ {"ScriptsInterpreter", VAR_SERVER},
{"StrictSubnets", VAR_SERVER},
{"TunnelServer", VAR_SERVER},
{"UDPRcvBuf", 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);
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];
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;
if(tty)
printf("\n");
return result;