projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Rename tincctl to tinc.
[tinc]
/
src
/
tincctl.c
diff --git
a/src/tincctl.c
b/src/tincctl.c
index
afaeda3
..
cb9740e
100644
(file)
--- a/
src/tincctl.c
+++ b/
src/tincctl.c
@@
-1,6
+1,6
@@
/*
tincctl.c -- Controlling a running tincd
/*
tincctl.c -- Controlling a running tincd
- Copyright (C) 2007-201
2
Guus Sliepen <guus@tinc-vpn.org>
+ Copyright (C) 2007-201
3
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
@@
-112,11
+112,10
@@
static void usage(bool status) {
"\n"
"Valid commands are:\n"
" init [name] Create initial configuration files.\n"
"\n"
"Valid commands are:\n"
" init [name] Create initial configuration files.\n"
- " config Change configuration:\n"
- " [get] VARIABLE - print current value of VARIABLE\n"
- " [set] VARIABLE VALUE - set VARIABLE to VALUE\n"
- " add VARIABLE VALUE - add VARIABLE with the given VALUE\n"
- " del VARIABLE [VALUE] - remove VARIABLE [only ones with watching VALUE]\n"
+ " get VARIABLE Print current value of VARIABLE\n"
+ " set VARIABLE VALUE Set VARIABLE to VALUE\n"
+ " add VARIABLE VALUE Add VARIABLE with the given VALUE\n"
+ " del VARIABLE [VALUE] Remove VARIABLE [only ones with watching VALUE]\n"
" start [tincd options] Start tincd.\n"
" stop Stop tincd.\n"
" restart Restart tincd.\n"
" start [tincd options] Start tincd.\n"
" stop Stop tincd.\n"
" restart Restart tincd.\n"
@@
-834,16
+833,10
@@
static int cmd_stop(int argc, char *argv[]) {
}
sendline(fd, "%d %d", CONTROL, REQ_STOP);
}
sendline(fd, "%d %d", CONTROL, REQ_STOP);
- if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &req, &result) != 3 || code != CONTROL || req != REQ_STOP || result) {
- 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);
+ while(recvline(fd, line, sizeof line)) {
+ // Wait for tincd to close the connection...
+ }
#else
if(!remove_service())
return 1;
#else
if(!remove_service())
return 1;
@@
-1154,7
+1147,7
@@
static int cmd_top(int argc, char *argv[]) {
top(fd);
return 0;
#else
top(fd);
return 0;
#else
- fprintf(stderr, "This version of tinc
ctl
was compiled without support for the curses library.\n");
+ fprintf(stderr, "This version of tinc was compiled without support for the curses library.\n");
return 1;
#endif
}
return 1;
#endif
}
@@
-1205,10
+1198,11
@@
static int rstrip(char *value) {
return len;
}
return len;
}
-static char *get_my_name() {
+static char *get_my_name(
bool verbose
) {
FILE *f = fopen(tinc_conf, "r");
if(!f) {
FILE *f = fopen(tinc_conf, "r");
if(!f) {
- fprintf(stderr, "Could not open %s: %s\n", tinc_conf, strerror(errno));
+ if(verbose)
+ fprintf(stderr, "Could not open %s: %s\n", tinc_conf, strerror(errno));
return NULL;
}
return NULL;
}
@@
-1234,7
+1228,8
@@
static char *get_my_name() {
}
fclose(f);
}
fclose(f);
- fprintf(stderr, "Could not find Name in %s.\n", tinc_conf);
+ if(verbose)
+ fprintf(stderr, "Could not find Name in %s.\n", tinc_conf);
return NULL;
}
return NULL;
}
@@
-1315,6
+1310,9
@@
static int cmd_config(int argc, char *argv[]) {
return 1;
}
return 1;
}
+ if(strcasecmp(argv[0], "config"))
+ argv--, argc++;
+
int action = -2;
if(!strcasecmp(argv[1], "get")) {
argv++, argc--;
int action = -2;
if(!strcasecmp(argv[1], "get")) {
argv++, argc--;
@@
-1408,7
+1406,7
@@
static int cmd_config(int argc, char *argv[]) {
/* Should this go into our own host config file? */
if(!node && !(variables[i].type & VAR_SERVER)) {
/* Should this go into our own host config file? */
if(!node && !(variables[i].type & VAR_SERVER)) {
- node = get_my_name();
+ node = get_my_name(
true
);
if(!node)
return 1;
}
if(!node)
return 1;
}
@@
-1698,6
+1696,9
@@
static int cmd_generate_keys(int argc, char *argv[]) {
return 1;
}
return 1;
}
+ if(!name)
+ name = get_my_name(false);
+
return !(rsa_keygen(argc > 1 ? atoi(argv[1]) : 2048, true) && ecdsa_keygen(true));
}
return !(rsa_keygen(argc > 1 ? atoi(argv[1]) : 2048, true) && ecdsa_keygen(true));
}
@@
-1707,6
+1708,9
@@
static int cmd_generate_rsa_keys(int argc, char *argv[]) {
return 1;
}
return 1;
}
+ if(!name)
+ name = get_my_name(false);
+
return !rsa_keygen(argc > 1 ? atoi(argv[1]) : 2048, true);
}
return !rsa_keygen(argc > 1 ? atoi(argv[1]) : 2048, true);
}
@@
-1716,6
+1720,9
@@
static int cmd_generate_ecdsa_keys(int argc, char *argv[]) {
return 1;
}
return 1;
}
+ if(!name)
+ name = get_my_name(false);
+
return !ecdsa_keygen(true);
}
return !ecdsa_keygen(true);
}
@@
-1837,13
+1844,15
@@
static int cmd_export(int argc, char *argv[]) {
return 1;
}
return 1;
}
- char *name = get_my_name();
+ char *name = get_my_name(
true
);
if(!name)
return 1;
int result = export(name, stdout);
if(!tty)
fclose(stdout);
if(!name)
return 1;
int result = export(name, stdout);
if(!tty)
fclose(stdout);
+
+ free(name);
return result;
}
return result;
}
@@
-1981,6
+1990,12
@@
static const struct {
{"log", cmd_log},
{"pid", cmd_pid},
{"config", cmd_config},
{"log", cmd_log},
{"pid", cmd_pid},
{"config", cmd_config},
+ {"add", cmd_config},
+ {"del", cmd_config},
+ {"get", cmd_config},
+ {"set", cmd_config},
+ {"change", cmd_config},
+ {"replace", cmd_config},
{"init", cmd_init},
{"generate-keys", cmd_generate_keys},
{"generate-rsa-keys", cmd_generate_rsa_keys},
{"init", cmd_init},
{"generate-keys", cmd_generate_keys},
{"generate-rsa-keys", cmd_generate_rsa_keys},