Don't ask questions if we are not running interactively.
[tinc] / src / tincctl.c
index 55e14e5..5d37fda 100644 (file)
 #include "tincctl.h"
 #include "top.h"
 
-#ifdef HAVE_MINGW
-#define SCRIPTEXTENSION ".bat"
-#else
-#define SCRIPTEXTENSION ""
-#endif
-
 static char **orig_argv;
 static int orig_argc;
 
@@ -71,10 +65,8 @@ static bool force = false;
 bool tty = true;
 bool confbasegiven = false;
 bool netnamegiven = false;
-
-#ifdef HAVE_MINGW
-static struct WSAData wsa_state;
-#endif
+char *scriptinterpreter = NULL;
+char *scriptextension = "";
 
 static struct option const long_options[] = {
        {"config", required_argument, NULL, 'c'},
@@ -316,8 +308,7 @@ static FILE *ask_and_open(const char *filename, const char *what, const char *mo
        /* Check stdin and stdout */
        if(ask && tty) {
                /* Ask for a file and/or directory name. */
-               fprintf(stdout, "Please enter a file to save %s to [%s]: ", what, filename);
-               fflush(stdout);
+               fprintf(stderr, "Please enter a file to save %s to [%s]: ", what, filename);
 
                if(fgets(buf, sizeof buf, stdin) == NULL) {
                        fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
@@ -686,14 +677,6 @@ bool connect_tincd(bool verbose) {
 
        fclose(f);
 
-#ifdef HAVE_MINGW
-       if(WSAStartup(MAKEWORD(2, 2), &wsa_state)) {
-               if(verbose)
-                       fprintf(stderr, "System call `%s' failed: %s", "WSAStartup", winerror(GetLastError()));
-               return false;
-       }
-#endif
-
 #ifndef HAVE_MINGW
        struct sockaddr_un sa;
        sa.sun_family = AF_UNIX;
@@ -1308,6 +1291,7 @@ const var_t variables[] = {
        {"IffOneQueue", VAR_SERVER},
        {"Interface", VAR_SERVER},
        {"KeyExpire", VAR_SERVER},
+       {"ListenAddress", VAR_SERVER | VAR_MULTIPLE},
        {"LocalDiscovery", VAR_SERVER},
        {"MACExpire", VAR_SERVER},
        {"MaxConnectionBurst", VAR_SERVER},
@@ -1622,7 +1606,7 @@ static int cmd_config(int argc, char *argv[]) {
        if(action < 0 && !removed) {
                remove(tmpfile);
                fprintf(stderr, "No configuration variables deleted.\n");
-               return *value;
+               return *value != 0;
        }
 
        // Replace the configuration file with the new one
@@ -1726,8 +1710,7 @@ static int cmd_init(int argc, char *argv[]) {
        } else if(argc < 2) {
                if(tty) {
                        char buf[1024];
-                       fprintf(stdout, "Enter the Name you want your tinc node to have: ");
-                       fflush(stdout);
+                       fprintf(stderr, "Enter the Name you want your tinc node to have: ");
                        if(!fgets(buf, sizeof buf, stdin)) {
                                fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
                                return 1;
@@ -1755,7 +1738,7 @@ static int cmd_init(int argc, char *argv[]) {
                return 1;
        }
 
-       if(strcmp(confdir, confbase) && mkdir(confdir, 0755) && errno != EEXIST) {
+       if(!confbase_given && mkdir(confdir, 0755) && errno != EEXIST) {
                fprintf(stderr, "Could not create directory %s: %s\n", confdir, strerror(errno));
                return 1;
        }
@@ -1793,7 +1776,7 @@ static int cmd_init(int argc, char *argv[]) {
                        fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
                        return 1;
                }
-               fprintf(f, "#!/bin/sh\n\necho 'Unconfigured tinc-up script, please edit!'\n\n#ifconfig $INTERFACE <your vpn IP address> netmask <netmask of whole VPN>\n");
+               fprintf(f, "#!/bin/sh\n\necho 'Unconfigured tinc-up script, please edit '$0'!'\n\n#ifconfig $INTERFACE <your vpn IP address> netmask <netmask of whole VPN>\n");
                fclose(f);
        }
 #endif
@@ -2370,6 +2353,15 @@ int main(int argc, char *argv[]) {
                return 0;
        }
 
+#ifdef HAVE_MINGW
+       static struct WSAData wsa_state;
+
+       if(WSAStartup(MAKEWORD(2, 2), &wsa_state)) {
+               fprintf(stderr, "System call `%s' failed: %s", "WSAStartup", winerror(GetLastError()));
+               return false;
+       }
+#endif
+
        srand(time(NULL));
        crypto_init();