X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ftincctl.c;h=033739263f15610d80cfd250b0a6a7af939b3c6d;hb=09a8ff649cc7aa51d291c89e1556526a6265cc81;hp=b944e5c451c8753dd6b28660c8f111e6cfdc950d;hpb=dea722c4aca9a8cfa463807d279aa10cc6a0fc64;p=tinc diff --git a/src/tincctl.c b/src/tincctl.c index b944e5c4..03373926 100644 --- 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 *confdir = 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; } @@ -396,6 +401,7 @@ static void make_names(void) { if(!*installdir) { #endif + confdir = xstrdup(CONFDIR); if(!pidfilename) xasprintf(&pidfilename, "%s/run/%s.pid", LOCALSTATEDIR, identname); @@ -411,7 +417,8 @@ static void make_names(void) { } #ifdef HAVE_MINGW - } + } else + confdir = xstrdup(installdir); #endif xasprintf(&tinc_conf, "%s/tinc.conf", confbase); @@ -1190,7 +1197,7 @@ static int cmd_config(int argc, char *argv[]) { while(fgets(buf1, sizeof buf1, f)) { buf1[sizeof buf1 - 1] = 0; - strcpy(buf2, buf1); + strncpy(buf2, buf1, sizeof buf2); // 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; } + + // 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... @@ -1336,7 +1351,7 @@ static int cmd_init(int argc, char *argv[]) { 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; }