Replace hard-code with new ScriptsInterpreter configuration property.
authorVilbrekin <vilbrekin@gmail.com>
Sat, 25 Aug 2012 17:14:00 +0000 (19:14 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Mon, 24 Sep 2012 11:55:24 +0000 (13:55 +0200)
This new setting allows choosing a custom script interpreter used for the various tinc callbacks.
If none is specified, the script itself is called as executable (as before).
This is particularly useful when storing tinc configuration and script on a mount point with no-exec attribute.

src/process.c

index 41a1468..a682226 100644 (file)
@@ -358,6 +358,7 @@ bool execute_script(const char *name, char **envp) {
        int status, len;
        char *scriptname;
        int i;
+    char *aInterpreter = NULL;
 
 #ifndef HAVE_MINGW
        len = xasprintf(&scriptname, "\"%s/%s\"", confbase, name);
@@ -376,17 +377,21 @@ bool execute_script(const char *name, char **envp) {
                free(scriptname);
                return true;
        }
-    else
+#endif
+
+    // Custom scripts interpreter
+    if(get_config_string(lookup_config(config_tree, "ScriptsInterpreter"), &aInterpreter))
     {
-        // Ugly hard-code allowing execution of scripts on android without execution flag (such as on /sdcard)
+        // Force custom scripts interpreter allowing execution of scripts on android without execution flag (such as on /sdcard)
         free(scriptname);
-        len = xasprintf(&scriptname, "/system/bin/sh \"%s/%s\"", confbase, name);
+        len = xasprintf(&scriptname, "%s \"%s/%s\"", aInterpreter, confbase, name);
         if(len < 0)
         {
+            free(aInterpreter);
             return false;
         }
     }
-#endif
+    free(aInterpreter);
 
        ifdebug(STATUS) logger(LOG_INFO, "Executing script %s", name);