Although Windows itself supports the forward slash, some programs may not.
#include <event.h>
#endif
+#ifdef HAVE_MINGW
+#define SLASH "\\"
+#else
+#define SLASH "/"
+#endif
+
#endif /* __TINC_SYSTEM_H__ */
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 */
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);
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");
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);
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);
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))
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");
/* 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");
/* 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");
/* 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");
/* 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");
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));
// 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);
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);
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;
#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;
}
} 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)
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");
} 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)
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");
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);
}
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
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];
// 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;
}
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;
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;
}
}
}
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;
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));
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(!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)
#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");
}
}