]> git.meshlink.io Git - meshlink/commitdiff
Remove support for calling external scripts.
authorGuus Sliepen <guus@meshlink.io>
Sat, 12 Apr 2014 12:28:18 +0000 (14:28 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sat, 12 Apr 2014 12:28:18 +0000 (14:28 +0200)
These will be replaced by callbacks to the application.

src/Makefile.am
src/graph.c
src/invitation.c
src/net_setup.c
src/protocol_auth.c
src/script.c [deleted file]
src/script.h [deleted file]

index 1cb2b6ac49f79663b73e2c6443971051159440ae..153ffb69e54e5bc8456730d0439a6ed53f2a6e24 100644 (file)
@@ -69,7 +69,6 @@ libmeshlink_la_SOURCES = \
        route.c route.h \
        rsa.h \
        rsagen.h \
-       script.c script.h \
        splay_tree.c splay_tree.h \
        sptps.c sptps.h \
        system.h \
index b7ace49756efe0c51df5f025e301362d6a3fd63e..67fe99f7f9bc393350621108cf34230308e7fc0e 100644 (file)
@@ -53,7 +53,6 @@
 #include "netutl.h"
 #include "node.h"
 #include "protocol.h"
-#include "script.h"
 #include "utils.h"
 #include "xalloc.h"
 #include "graph.h"
@@ -230,29 +229,7 @@ static void check_reachability(void) {
 
                        timeout_del(&n->mtutimeout);
 
-                       char *name;
-                       char *address;
-                       char *port;
-                       char *envp[8] = {NULL};
-
-                       xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
-                       xasprintf(&envp[3], "NODE=%s", n->name);
-                       sockaddr2str(&n->address, &address, &port);
-                       xasprintf(&envp[4], "REMOTEADDRESS=%s", address);
-                       xasprintf(&envp[5], "REMOTEPORT=%s", port);
-                       xasprintf(&envp[6], "NAME=%s", myself->name);
-
-                       execute_script(n->status.reachable ? "host-up" : "host-down", envp);
-
-                       xasprintf(&name, n->status.reachable ? "hosts/%s-up" : "hosts/%s-down", n->name);
-                       execute_script(name, envp);
-
-                       free(name);
-                       free(address);
-                       free(port);
-
-                       for(int i = 0; i < 7; i++)
-                               free(envp[i]);
+                       //TODO: callback to application to inform of this node going up/down
 
                        if(!n->status.reachable) {
                                update_node_udp(n, NULL);
index cdef3d0480efa04278ecb834156ef9332de99ec0..3e05d8c7d7c95cbee46ceb1fc0247a6cdb3b49be 100644 (file)
@@ -27,7 +27,6 @@
 #include "names.h"
 #include "netutl.h"
 #include "rsagen.h"
-#include "script.h"
 #include "sptps.h"
 #include "tincctl.h"
 #include "utils.h"
@@ -434,22 +433,6 @@ int cmd_invite(int argc, char *argv[]) {
        char *url;
        xasprintf(&url, "%s/%s%s", address, hash, cookie);
 
-       // Call the inviation-created script
-       char *envp[6] = {};
-       xasprintf(&envp[0], "NAME=%s", myname);
-       xasprintf(&envp[1], "NETNAME=%s", netname);
-       xasprintf(&envp[2], "NODE=%s", argv[1]);
-       xasprintf(&envp[3], "INVITATION_FILE=%s", filename);
-       xasprintf(&envp[4], "INVITATION_URL=%s", url);
-       execute_script("invitation-created", envp);
-       for(int i = 0; i < 6 && envp[i]; i++)
-               free(envp[i]);
-
-       puts(url);
-       free(url);
-       free(filename);
-       free(address);
-
        return 0;
 }
 
index b311ecad74b9fd3125106e93a68a7904bdf89bf9..a4cc2367bfb2cd3757fe7395f38a508d6a2ce364 100644 (file)
@@ -37,7 +37,6 @@
 #include "protocol.h"
 #include "route.h"
 #include "rsa.h"
-#include "script.h"
 #include "utils.h"
 #include "xalloc.h"
 
@@ -51,9 +50,6 @@ proxytype_t proxytype;
 int autoconnect;
 bool disablebuggypeers;
 
-char *scriptinterpreter;
-char *scriptextension;
-
 bool node_read_ecdsa_public_key(node_t *n) {
        if(ecdsa_active(n->ecdsa))
                return true;
@@ -388,15 +384,6 @@ bool setup_myself_reloadable(void) {
        char *space;
        bool choice;
 
-       free(scriptinterpreter);
-       scriptinterpreter = NULL;
-       get_config_string(lookup_config(config_tree, "ScriptsInterpreter"), &scriptinterpreter);
-
-
-       free(scriptextension);
-       if(!get_config_string(lookup_config(config_tree, "ScriptsExtension"), &scriptextension))
-               scriptextension = xstrdup("");
-
        get_config_string(lookup_config(config_tree, "Proxy"), &proxy);
        if(proxy) {
                if((space = strchr(proxy, ' ')))
@@ -939,17 +926,6 @@ bool setup_network(void) {
        if(!init_control())
                return false;
 
-       /* Run tinc-up script to further initialize the tap interface */
-
-       char *envp[5] = {NULL};
-       xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
-       xasprintf(&envp[3], "NAME=%s", myself->name);
-
-       execute_script("tinc-up", envp);
-
-       for(int i = 0; i < 4; i++)
-               free(envp[i]);
-
        return true;
 }
 
@@ -982,22 +958,13 @@ void close_network_connections(void) {
                close(listen_socket[i].udp.fd);
        }
 
-       char *envp[5] = {NULL};
-       xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
-       xasprintf(&envp[3], "NAME=%s", myself->name);
-
        exit_requests();
        exit_edges();
        exit_nodes();
        exit_connections();
 
-       execute_script("tinc-down", envp);
-
        if(myport) free(myport);
 
-       for(int i = 0; i < 4; i++)
-               free(envp[i]);
-
        exit_control();
 
        return;
index a1395b715e0169f2defb668338ac7fe28bb5ab69..703b670adbbc8d73e7514bd0a86f303e318017c5 100644 (file)
@@ -39,7 +39,6 @@
 #include "prf.h"
 #include "protocol.h"
 #include "rsa.h"
-#include "script.h"
 #include "sptps.h"
 #include "utils.h"
 #include "xalloc.h"
@@ -176,20 +175,7 @@ static bool finalize_invitation(connection_t *c, const char *data, uint16_t len)
 
        logger(DEBUG_CONNECTIONS, LOG_INFO, "Key succesfully received from %s (%s)", c->name, c->hostname);
 
-       // Call invitation-accepted script
-       char *envp[7] = {NULL};
-       char *address, *port;
-
-       xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
-        xasprintf(&envp[3], "NODE=%s", c->name);
-       sockaddr2str(&c->address, &address, &port);
-       xasprintf(&envp[4], "REMOTEADDRESS=%s", address);
-       xasprintf(&envp[5], "NAME=%s", myself->name);
-
-       execute_script("invitation-accepted", envp);
-
-       for(int i = 0; envp[i] && i < 7; i++)
-               free(envp[i]);
+       //TODO: callback to application to inform of an accepted invitation
 
        sptps_send_record(&c->sptps, 2, data, 0);
        return true;
@@ -755,7 +741,7 @@ bool ack_h(connection_t *c, const char *request) {
                        }
 
                        terminate_connection(n->connection, false);
-                       /* Run graph algorithm to purge key and make sure up/down scripts are rerun with new IP addresses and stuff */
+                       /* Run graph algorithm to keep things in sync */
                        graph();
                }
        }
diff --git a/src/script.c b/src/script.c
deleted file mode 100644 (file)
index e441dcf..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
-    script.c -- call an external script
-    Copyright (C) 1999-2005 Ivo Timmermans,
-                  2000-2013 Guus Sliepen <guus@tinc-vpn.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License along
-    with this program; if not, write to the Free Software Foundation, Inc.,
-    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#include "system.h"
-
-#include "conf.h"
-#include "logger.h"
-#include "names.h"
-#include "net.h"
-#include "script.h"
-#include "xalloc.h"
-
-bool execute_script(const char *name, char **envp) {
-#ifdef HAVE_SYSTEM
-       char *scriptname;
-       char *command;
-
-       xasprintf(&scriptname, "%s" SLASH "%s%s", confbase, name, scriptextension);
-
-       /* First check if there is a script */
-
-#ifdef HAVE_MINGW
-       if(!*scriptextension) {
-               const char *pathext = getenv("PATHEXT") ?: ".COM;.EXE;.BAT;.CMD";
-               char fullname[strlen(scriptname) + strlen(pathext)];
-               char *ext = fullname + strlen(scriptname);
-               strcpy(fullname, scriptname);
-
-               const char *p = pathext;
-               bool found = false;
-               while(p && *p) {
-                       const char *q = strchr(p, ';');
-                       if(q) {
-                               memcpy(ext, p, q - p);
-                               ext[q - p] = 0;
-                               *q++;
-                       } else {
-                               strcpy(ext, p);
-                       }
-                       if((found = !access(fullname, F_OK)))
-                               break;
-                       p = q;
-               }
-               if(!found) {
-                       free(scriptname);
-                       return true;
-               }
-       } else
-#endif
-
-       if(access(scriptname, F_OK)) {
-               free(scriptname);
-               return true;
-       }
-
-       logger(DEBUG_STATUS, LOG_INFO, "Executing script %s", name);
-
-#ifdef HAVE_PUTENV
-       /* Set environment */
-
-       for(int i = 0; envp[i]; i++)
-               putenv(envp[i]);
-#endif
-
-       if(scriptinterpreter)
-               xasprintf(&command, "%s \"%s\"", scriptinterpreter, scriptname);
-       else
-               xasprintf(&command, "\"%s\"", scriptname);
-
-       int status = system(command);
-
-       free(command);
-       free(scriptname);
-
-       /* Unset environment */
-
-       for(int i = 0; envp[i]; i++) {
-               char *e = strchr(envp[i], '=');
-               if(e) {
-                       char p[e - envp[i] + 1];
-                       strncpy(p, envp[i], e - envp[i]);
-                       p[e - envp[i]] = '\0';
-                       putenv(p);
-               }
-       }
-
-       if(status != -1) {
-#ifdef WEXITSTATUS
-               if(WIFEXITED(status)) {          /* Child exited by itself */
-                       if(WEXITSTATUS(status)) {
-                               logger(DEBUG_ALWAYS, LOG_ERR, "Script %s exited with non-zero status %d",
-                                          name, WEXITSTATUS(status));
-                               return false;
-                       }
-               } else if(WIFSIGNALED(status)) { /* Child was killed by a signal */
-                       logger(DEBUG_ALWAYS, LOG_ERR, "Script %s was killed by signal %d (%s)",
-                                  name, WTERMSIG(status), strsignal(WTERMSIG(status)));
-                       return false;
-               } else {                         /* Something strange happened */
-                       logger(DEBUG_ALWAYS, LOG_ERR, "Script %s terminated abnormally", name);
-                       return false;
-               }
-#endif
-       } else {
-               logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "system", strerror(errno));
-               return false;
-       }
-#endif
-       return true;
-}
diff --git a/src/script.h b/src/script.h
deleted file mode 100644 (file)
index 446a3b9..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-    script.h -- header file for script.c
-    Copyright (C) 1999-2005 Ivo Timmermans,
-                  2000-2013 Guus Sliepen <guus@tinc-vpn.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License along
-    with this program; if not, write to the Free Software Foundation, Inc.,
-    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#ifndef __TINC_SCRIPT_H__
-#define __TINC_SCRIPT_H__
-
-extern bool execute_script(const char *, char **);
-
-#endif /* __TINC_SCRIPT_H__ */