projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Windows doesn't like quotes around "edit" when calling it through system().
[tinc]
/
src
/
tincctl.c
diff --git
a/src/tincctl.c
b/src/tincctl.c
index
b944e5c
..
5f24ae4
100644
(file)
--- a/
src/tincctl.c
+++ b/
src/tincctl.c
@@
-47,6
+47,7
@@
static bool show_version = false;
static char *name = NULL;
static char *identname = NULL; /* program name for syslog */
static char *pidfilename = NULL; /* pid file location */
static char *name = NULL;
static char *identname = NULL; /* program name for syslog */
static char *pidfilename = NULL; /* pid file location */
+static char *confdir = NULL;
static char controlcookie[1024];
char *netname = NULL;
char *confbase = NULL;
static char controlcookie[1024];
char *netname = NULL;
char *confbase = NULL;
@@
-187,11
+188,15
@@
static bool parse_options(int argc, char **argv) {
}
}
}
}
- if(!netname) {
- netname = getenv("NETNAME");
- if(netname)
- netname = xstrdup(netname);
- }
+ if(!netname && (netname = getenv("NETNAME")))
+ netname = xstrdup(netname);
+
+ /* netname "." is special: a "top-level name" */
+
+ if(netname && !strcmp(netname, ".")) {
+ free(netname);
+ netname = NULL;
+ }
return true;
}
return true;
}
@@
-230,7
+235,7
@@
static FILE *ask_and_open(const char *filename, const char *what, const char *mo
#endif
/* The directory is a relative path or a filename. */
directory = get_current_dir_name();
#endif
/* The directory is a relative path or a filename. */
directory = get_current_dir_name();
- snprintf(buf2, sizeof buf2, "%s
/
%s", directory, filename);
+ snprintf(buf2, sizeof buf2, "%s
" SLASH "
%s", directory, filename);
filename = buf2;
}
filename = buf2;
}
@@
-265,7
+270,7
@@
static bool ecdsa_keygen() {
} else
fprintf(stderr, "Done.\n");
} else
fprintf(stderr, "Done.\n");
- xasprintf(&filename, "%s
/
ecdsa_key.priv", confbase);
+ xasprintf(&filename, "%s
" SLASH "
ecdsa_key.priv", confbase);
f = ask_and_open(filename, "private ECDSA key", "a");
if(!f)
f = ask_and_open(filename, "private ECDSA key", "a");
if(!f)
@@
-285,9
+290,9
@@
static bool ecdsa_keygen() {
free(filename);
if(name)
free(filename);
if(name)
- xasprintf(&filename, "%s
/hosts/
%s", confbase, name);
+ xasprintf(&filename, "%s
" SLASH "hosts" SLASH "
%s", confbase, name);
else
else
- xasprintf(&filename, "%s
/
ecdsa_key.pub", confbase);
+ xasprintf(&filename, "%s
" SLASH "
ecdsa_key.pub", confbase);
f = ask_and_open(filename, "public ECDSA key", "a");
f = ask_and_open(filename, "public ECDSA key", "a");
@@
-324,7
+329,7
@@
static bool rsa_keygen(int bits) {
} else
fprintf(stderr, "Done.\n");
} else
fprintf(stderr, "Done.\n");
- xasprintf(&filename, "%s
/
rsa_key.priv", confbase);
+ xasprintf(&filename, "%s
" SLASH "
rsa_key.priv", confbase);
f = ask_and_open(filename, "private RSA key", "a");
if(!f)
f = ask_and_open(filename, "private RSA key", "a");
if(!f)
@@
-344,9
+349,9
@@
static bool rsa_keygen(int bits) {
free(filename);
if(name)
free(filename);
if(name)
- xasprintf(&filename, "%s
/hosts/
%s", confbase, name);
+ xasprintf(&filename, "%s
" SLASH "hosts" SLASH "
%s", confbase, name);
else
else
- xasprintf(&filename, "%s
/
rsa_key.pub", confbase);
+ xasprintf(&filename, "%s
" SLASH "
rsa_key.pub", confbase);
f = ask_and_open(filename, "public RSA key", "a");
f = ask_and_open(filename, "public RSA key", "a");
@@
-384,38
+389,40
@@
static void make_names(void) {
if(!RegQueryValueEx(key, NULL, 0, 0, installdir, &len)) {
if(!confbase) {
if(netname)
if(!RegQueryValueEx(key, NULL, 0, 0, installdir, &len)) {
if(!confbase) {
if(netname)
- xasprintf(&confbase, "%s
/
%s", installdir, netname);
+ xasprintf(&confbase, "%s
" SLASH "
%s", installdir, netname);
else
xasprintf(&confbase, "%s", installdir);
}
}
if(!pidfilename)
else
xasprintf(&confbase, "%s", installdir);
}
}
if(!pidfilename)
- xasprintf(&pidfilename, "%s
/
pid", confbase);
+ xasprintf(&pidfilename, "%s
" SLASH "
pid", confbase);
RegCloseKey(key);
}
if(!*installdir) {
#endif
RegCloseKey(key);
}
if(!*installdir) {
#endif
+ confdir = xstrdup(CONFDIR);
if(!pidfilename)
if(!pidfilename)
- xasprintf(&pidfilename, "%s
/run/
%s.pid", LOCALSTATEDIR, identname);
+ xasprintf(&pidfilename, "%s
" SLASH "run" SLASH "
%s.pid", LOCALSTATEDIR, identname);
if(netname) {
if(!confbase)
if(netname) {
if(!confbase)
- xasprintf(&confbase, CONFDIR
"/tinc/
%s", netname);
+ xasprintf(&confbase, CONFDIR
SLASH "tinc" SLASH "
%s", netname);
else
fprintf(stderr, "Both netname and configuration directory given, using the latter...\n");
} else {
if(!confbase)
else
fprintf(stderr, "Both netname and configuration directory given, using the latter...\n");
} else {
if(!confbase)
- xasprintf(&confbase, CONFDIR
"/
tinc");
+ xasprintf(&confbase, CONFDIR
SLASH "
tinc");
}
#ifdef HAVE_MINGW
}
#ifdef HAVE_MINGW
- }
+ } else
+ confdir = xstrdup(installdir);
#endif
#endif
- xasprintf(&tinc_conf, "%s
/
tinc.conf", confbase);
- xasprintf(&hosts_dir, "%s
/
hosts", confbase);
+ xasprintf(&tinc_conf, "%s
" SLASH "
tinc.conf", confbase);
+ xasprintf(&hosts_dir, "%s
" SLASH "
hosts", confbase);
}
static char buffer[4096];
}
static char buffer[4096];
@@
-1153,7
+1160,7
@@
static int cmd_config(int argc, char *argv[]) {
// Open the right configuration file.
char *filename;
if(node)
// Open the right configuration file.
char *filename;
if(node)
- xasprintf(&filename, "%s
/
%s", hosts_dir, node);
+ xasprintf(&filename, "%s
" SLASH "
%s", hosts_dir, node);
else
filename = tinc_conf;
else
filename = tinc_conf;
@@
-1190,7
+1197,7
@@
static int cmd_config(int argc, char *argv[]) {
while(fgets(buf1, sizeof buf1, f)) {
buf1[sizeof buf1 - 1] = 0;
while(fgets(buf1, sizeof buf1, f)) {
buf1[sizeof buf1 - 1] = 0;
- str
cpy(buf2, buf1
);
+ str
ncpy(buf2, buf1, sizeof buf2
);
// Parse line in a simple way
char *bvalue;
// Parse line in a simple way
char *bvalue;
@@
-1234,6
+1241,14
@@
static int cmd_config(int argc, char *argv[]) {
fprintf(stderr, "Error writing to temporary file %s: %s\n", tmpfile, strerror(errno));
return 1;
}
fprintf(stderr, "Error writing to temporary file %s: %s\n", tmpfile, strerror(errno));
return 1;
}
+
+ // Add newline if it is missing...
+ if(*buf1 && buf1[strlen(buf1) - 1] != '\n') {
+ if(fputc('\n', tf) < 0) {
+ fprintf(stderr, "Error writing to temporary file %s: %s\n", tmpfile, strerror(errno));
+ return 1;
+ }
+ }
}
// Make sure we read everything...
}
// Make sure we read everything...
@@
-1336,7
+1351,7
@@
static int cmd_init(int argc, char *argv[]) {
return 1;
}
return 1;
}
- if(mkdir(
CONFDIR
, 0755) && errno != EEXIST) {
+ if(mkdir(
confdir
, 0755) && errno != EEXIST) {
fprintf(stderr, "Could not create directory %s: %s\n", CONFDIR, strerror(errno));
return 1;
}
fprintf(stderr, "Could not create directory %s: %s\n", CONFDIR, strerror(errno));
return 1;
}
@@
-1347,7
+1362,7
@@
static int cmd_init(int argc, char *argv[]) {
}
char *hosts_dir = NULL;
}
char *hosts_dir = NULL;
- xasprintf(&hosts_dir, "%s
/
hosts", confbase);
+ 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;
if(mkdir(hosts_dir, 0755) && errno != EEXIST) {
fprintf(stderr, "Could not create directory %s: %s\n", hosts_dir, strerror(errno));
return 1;
@@
-1423,10
+1438,10
@@
static int cmd_edit(int argc, char *argv[]) {
char *filename = NULL;
char *filename = NULL;
- if(strncmp(argv[1], "hosts
/"
, 6)) {
+ if(strncmp(argv[1], "hosts
" SLASH
, 6)) {
for(int i = 0; conffiles[i]; i++) {
if(!strcmp(argv[1], conffiles[i])) {
for(int i = 0; conffiles[i]; i++) {
if(!strcmp(argv[1], conffiles[i])) {
- xasprintf(&filename, "%s
/
%s", confbase, argv[1]);
+ xasprintf(&filename, "%s
" SLASH "
%s", confbase, argv[1]);
break;
}
}
break;
}
}
@@
-1435,7
+1450,7
@@
static int cmd_edit(int argc, char *argv[]) {
}
if(!filename) {
}
if(!filename) {
- xasprintf(&filename, "%s
/
%s", hosts_dir, argv[1]);
+ xasprintf(&filename, "%s
" SLASH "
%s", hosts_dir, argv[1]);
char *dash = strchr(argv[1], '-');
if(dash) {
*dash++ = 0;
char *dash = strchr(argv[1], '-');
if(dash) {
*dash++ = 0;
@@
-1446,14
+1461,12
@@
static int cmd_edit(int argc, char *argv[]) {
}
}
}
}
+ char *command;
#ifndef HAVE_MINGW
#ifndef HAVE_MINGW
-
char *editor = getenv("VISUAL") ?: getenv("EDITOR") ?: "vi"
;
+
xasprintf(&command, "\"%s\" \"%s\"", getenv("VISUAL") ?: getenv("EDITOR") ?: "vi", filename)
;
#else
#else
-
char *editor = "edit"
;
+
xasprintf(&command, "edit \"%s\"", filename)
;
#endif
#endif
-
- char *command;
- xasprintf(&command, "\"%s\" \"%s\"", editor, filename);
int result = system(command);
if(result)
return result;
int result = system(command);
if(result)
return result;
@@
-1469,7
+1482,7
@@
static int cmd_edit(int argc, char *argv[]) {
static int export(const char *name, FILE *out) {
char *filename;
static int export(const char *name, FILE *out) {
char *filename;
- xasprintf(&filename, "%s
/
%s", hosts_dir, name);
+ xasprintf(&filename, "%s
" SLASH "
%s", hosts_dir, name);
FILE *in = fopen(filename, "r");
if(!in) {
fprintf(stderr, "Could not open configuration file %s: %s\n", filename, strerror(errno));
FILE *in = fopen(filename, "r");
if(!in) {
fprintf(stderr, "Could not open configuration file %s: %s\n", filename, strerror(errno));
@@
-1548,7
+1561,7
@@
static int cmd_import(int argc, char *argv[]) {
fclose(out);
free(filename);
fclose(out);
free(filename);
- xasprintf(&filename, "%s
/
%s", hosts_dir, name);
+ xasprintf(&filename, "%s
" SLASH "
%s", hosts_dir, name);
if(!force && !access(filename, F_OK)) {
fprintf(stderr, "Host configuration file %s already exists, skipping.\n", filename);
if(!force && !access(filename, F_OK)) {
fprintf(stderr, "Host configuration file %s already exists, skipping.\n", filename);