Use backslashes on Windows.

Although Windows itself supports the forward slash, some programs may not.
This commit is contained in:
Guus Sliepen 2012-07-21 16:26:55 +02:00
parent 09a8ff649c
commit 18237e1f2d
7 changed files with 50 additions and 44 deletions

6
have.h
View file

@ -200,4 +200,10 @@
#include <event.h>
#endif
#ifdef HAVE_MINGW
#define SLASH "\\"
#else
#define SLASH "/"
#endif
#endif /* __TINC_SYSTEM_H__ */

View file

@ -373,7 +373,7 @@ bool read_server_config(void) {
read_config_options(config_tree, NULL);
xasprintf(&fname, "%s/tinc.conf", confbase);
xasprintf(&fname, "%s" SLASH "tinc.conf", confbase);
x = read_config_file(config_tree, fname);
if(!x) { /* System error: complain */
@ -391,7 +391,7 @@ bool read_connection_config(connection_t *c) {
read_config_options(c->config_tree, c->name);
xasprintf(&fname, "%s/hosts/%s", confbase, c->name);
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
x = read_config_file(c->config_tree, fname);
free(fname);
@ -400,7 +400,7 @@ bool read_connection_config(connection_t *c) {
bool append_config_file(const char *name, const char *key, const char *value) {
char *fname;
xasprintf(&fname, "%s/hosts/%s", confbase, name);
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, name);
FILE *fp = fopen(fname, "a");

View file

@ -278,7 +278,7 @@ int reload_configuration(void) {
read_config_options(config_tree, NULL);
xasprintf(&fname, "%s/hosts/%s", confbase, myself->name);
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, myself->name);
read_config_file(config_tree, fname);
free(fname);
@ -303,7 +303,7 @@ int reload_configuration(void) {
c->outgoing = NULL;
}
xasprintf(&fname, "%s/hosts/%s", confbase, c->name);
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
if(stat(fname, &s) || s.st_mtime > last_config_check)
terminate_connection(c, c->status.active);
free(fname);

View file

@ -62,7 +62,7 @@ bool node_read_ecdsa_public_key(node_t *n) {
char *p;
bool result = false;
xasprintf(&fname, "%s/hosts/%s", confbase, n->name);
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, n->name);
init_configuration(&config_tree);
if(!read_config_file(config_tree, fname))
@ -81,7 +81,7 @@ bool node_read_ecdsa_public_key(node_t *n) {
free(fname);
if(!get_config_string(lookup_config(config_tree, "ECDSAPublicKeyFile"), &fname))
xasprintf(&fname, "%s/hosts/%s", confbase, n->name);
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, n->name);
fp = fopen(fname, "r");
@ -116,7 +116,7 @@ bool read_ecdsa_public_key(connection_t *c) {
/* Else, check for ECDSAPublicKeyFile statement and read it */
if(!get_config_string(lookup_config(c->config_tree, "ECDSAPublicKeyFile"), &fname))
xasprintf(&fname, "%s/hosts/%s", confbase, c->name);
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
fp = fopen(fname, "r");
@ -153,7 +153,7 @@ bool read_rsa_public_key(connection_t *c) {
/* Else, check for PublicKeyFile statement and read it */
if(!get_config_string(lookup_config(c->config_tree, "PublicKeyFile"), &fname))
xasprintf(&fname, "%s/hosts/%s", confbase, c->name);
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
fp = fopen(fname, "r");
@ -180,7 +180,7 @@ static bool read_ecdsa_private_key(void) {
/* Check for PrivateKeyFile statement and read it */
if(!get_config_string(lookup_config(config_tree, "ECDSAPrivateKeyFile"), &fname))
xasprintf(&fname, "%s/ecdsa_key.priv", confbase);
xasprintf(&fname, "%s" SLASH "ecdsa_key.priv", confbase);
fp = fopen(fname, "r");
@ -235,7 +235,7 @@ static bool read_rsa_private_key(void) {
/* Else, check for PrivateKeyFile statement and read it */
if(!get_config_string(lookup_config(config_tree, "PrivateKeyFile"), &fname))
xasprintf(&fname, "%s/rsa_key.priv", confbase);
xasprintf(&fname, "%s" SLASH "rsa_key.priv", confbase);
fp = fopen(fname, "r");
@ -299,7 +299,7 @@ void load_all_subnets(void) {
subnet_t *s, *s2;
node_t *n;
xasprintf(&dname, "%s/hosts", confbase);
xasprintf(&dname, "%s" SLASH "hosts", confbase);
dir = opendir(dname);
if(!dir) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", dname, strerror(errno));
@ -317,7 +317,7 @@ void load_all_subnets(void) {
// continue;
#endif
xasprintf(&fname, "%s/hosts/%s", confbase, ent->d_name);
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, ent->d_name);
init_configuration(&config_tree);
read_config_options(config_tree, ent->d_name);
read_config_file(config_tree, fname);
@ -590,7 +590,7 @@ static bool setup_myself(void) {
myself->name = name;
myself->connection->name = xstrdup(name);
xasprintf(&fname, "%s/hosts/%s", confbase, name);
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, name);
read_config_options(config_tree, name);
read_config_file(config_tree, fname);
free(fname);

View file

@ -231,9 +231,9 @@ bool execute_script(const char *name, char **envp) {
int i;
#ifndef HAVE_MINGW
len = xasprintf(&scriptname, "\"%s/%s\"", confbase, name);
len = xasprintf(&scriptname, "\"%s" SLASH "%s\"", confbase, name);
#else
len = xasprintf(&scriptname, "\"%s/%s.bat\"", confbase, name);
len = xasprintf(&scriptname, "\"%s" SLASH "%s.bat\"", confbase, name);
#endif
if(len < 0)
return false;

View file

@ -235,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();
snprintf(buf2, sizeof buf2, "%s/%s", directory, filename);
snprintf(buf2, sizeof buf2, "%s" SLASH "%s", directory, filename);
filename = buf2;
}
@ -270,7 +270,7 @@ static bool ecdsa_keygen() {
} 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)
@ -290,9 +290,9 @@ static bool ecdsa_keygen() {
free(filename);
if(name)
xasprintf(&filename, "%s/hosts/%s", confbase, name);
xasprintf(&filename, "%s" SLASH "hosts" SLASH "%s", confbase, name);
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");
@ -329,7 +329,7 @@ static bool rsa_keygen(int bits) {
} 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)
@ -349,9 +349,9 @@ static bool rsa_keygen(int bits) {
free(filename);
if(name)
xasprintf(&filename, "%s/hosts/%s", confbase, name);
xasprintf(&filename, "%s" SLASH "hosts" SLASH "%s", confbase, name);
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");
@ -389,13 +389,13 @@ static void make_names(void) {
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)
xasprintf(&pidfilename, "%s/pid", confbase);
xasprintf(&pidfilename, "%s" SLASH "pid", confbase);
RegCloseKey(key);
}
@ -404,16 +404,16 @@ static void make_names(void) {
confdir = xstrdup(CONFDIR);
if(!pidfilename)
xasprintf(&pidfilename, "%s/run/%s.pid", LOCALSTATEDIR, identname);
xasprintf(&pidfilename, "%s" SLASH "run" SLASH "%s.pid", LOCALSTATEDIR, identname);
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)
xasprintf(&confbase, CONFDIR "/tinc");
xasprintf(&confbase, CONFDIR SLASH "tinc");
}
#ifdef HAVE_MINGW
@ -421,8 +421,8 @@ static void make_names(void) {
confdir = xstrdup(installdir);
#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];
@ -1160,7 +1160,7 @@ static int cmd_config(int argc, char *argv[]) {
// 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;
@ -1362,7 +1362,7 @@ static int cmd_init(int argc, char *argv[]) {
}
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;
@ -1438,10 +1438,10 @@ static int cmd_edit(int argc, char *argv[]) {
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])) {
xasprintf(&filename, "%s/%s", confbase, argv[1]);
xasprintf(&filename, "%s" SLASH "%s", confbase, argv[1]);
break;
}
}
@ -1450,7 +1450,7 @@ static int cmd_edit(int argc, char *argv[]) {
}
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;
@ -1484,7 +1484,7 @@ static int cmd_edit(int argc, char *argv[]) {
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));
@ -1563,7 +1563,7 @@ static int cmd_import(int argc, char *argv[]) {
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);

View file

@ -258,15 +258,15 @@ static void make_names(void) {
if(!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\tinc", 0, KEY_READ, &key)) {
if(!RegQueryValueEx(key, NULL, 0, 0, installdir, &len)) {
if(!logfilename)
xasprintf(&logfilename, "%s/log/%s.log", identname);
xasprintf(&logfilename, "%s" SLASH "log" SLASH "%s.log", identname);
if(!confbase) {
if(netname)
xasprintf(&confbase, "%s/%s", installdir, netname);
xasprintf(&confbase, "%s" SLASH "%s", installdir, netname);
else
xasprintf(&confbase, "%s", installdir);
}
if(!pidfilename)
xasprintf(&pidfilename, "%s/pid", confbase);
xasprintf(&pidfilename, "%s" SLASH "pid", confbase);
}
RegCloseKey(key);
if(*installdir)
@ -275,19 +275,19 @@ static void make_names(void) {
#endif
if(!logfilename)
xasprintf(&logfilename, LOCALSTATEDIR "/log/%s.log", identname);
xasprintf(&logfilename, LOCALSTATEDIR SLASH "log" SLASH "%s.log", identname);
if(!pidfilename)
xasprintf(&pidfilename, LOCALSTATEDIR "/run/%s.pid", identname);
xasprintf(&pidfilename, LOCALSTATEDIR SLASH "run" SLASH "%s.pid", identname);
if(netname) {
if(!confbase)
xasprintf(&confbase, CONFDIR "/tinc/%s", netname);
xasprintf(&confbase, CONFDIR SLASH "tinc" SLASH "%s", netname);
else
logger(DEBUG_ALWAYS, LOG_INFO, "Both netname and configuration directory given, using the latter...");
} else {
if(!confbase)
xasprintf(&confbase, CONFDIR "/tinc");
xasprintf(&confbase, CONFDIR SLASH "tinc");
}
}