We don't depend on ECDH functions from OpenSSL anymore.
[tinc] / src / net_setup.c
index 665e3c6..29f1212 100644 (file)
@@ -44,6 +44,7 @@
 #include "xalloc.h"
 
 char *myport;
+static char *myname;
 static io_t device_io;
 devops_t devops;
 bool device_standby = false;
@@ -276,6 +277,8 @@ static bool read_rsa_private_key(void) {
        if(!fp) {
                logger(DEBUG_ALWAYS, LOG_ERR, "Error reading RSA private key file `%s': %s",
                           fname, strerror(errno));
+               if(errno == ENOENT)
+                       logger(DEBUG_ALWAYS, LOG_INFO, "Create an RSA keypair with `tinc -n %s generate-rsa-keys'.", netname ?: ".");
                free(fname);
                return false;
        }
@@ -715,7 +718,7 @@ void device_enable(void) {
        xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
        xasprintf(&envp[1], "DEVICE=%s", device ? : "");
        xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
-       xasprintf(&envp[3], "NAME=%s", myself->name);
+       xasprintf(&envp[3], "NAME=%s", myname);
 
        execute_script("tinc-up", envp);
 
@@ -728,7 +731,7 @@ void device_disable(void) {
        xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
        xasprintf(&envp[1], "DEVICE=%s", device ? : "");
        xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
-       xasprintf(&envp[3], "NAME=%s", myself->name);
+       xasprintf(&envp[3], "NAME=%s", myname);
 
        execute_script("tinc-down", envp);
 
@@ -752,6 +755,7 @@ static bool setup_myself(void) {
                return false;
        }
 
+       myname = xstrdup(name);
        myself = new_node();
        myself->connection = new_connection();
        myself->name = name;
@@ -778,8 +782,14 @@ static bool setup_myself(void) {
                        return false;
        }
 
-       if(!read_rsa_private_key())
-               return false;
+       if(!read_rsa_private_key()) {
+               if(experimental) {
+                       logger(DEBUG_ALWAYS, LOG_WARNING, "Support for legacy protocol disabled.");
+               } else {
+                       logger(DEBUG_ALWAYS, LOG_ERR, "No private keys available, cannot start tinc!");
+                       return false;
+               }
+       }
 
        /* Ensure myport is numeric */
 
@@ -1112,7 +1122,7 @@ void close_network_connections(void) {
        if (!device_standby)
                device_disable();
 
-       if(myport) free(myport);
+       free(myport);
 
        if (device_fd >= 0)
                io_del(&device_io);
@@ -1121,5 +1131,9 @@ void close_network_connections(void) {
 
        exit_control();
 
+       free(myname);
+       free(scriptextension);
+       free(scriptinterpreter);
+
        return;
 }