X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ftincd.c;h=539f527473e96da11bdb7a58dfc742ca77dc6620;hb=4436af55e55e79b496264fe114039fbc1198d71f;hp=edb03f51993bbfc282164639693537e59e6ae2b4;hpb=bc4df95a48857aa4ab65fb47eabd48c48d650ca0;p=tinc diff --git a/src/tincd.c b/src/tincd.c index edb03f51..539f5274 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -55,6 +55,7 @@ #include "xalloc.h" #include "version.h" #include "random.h" +#include "sandbox.h" /* If nonzero, display usage information and exit. */ static bool show_help = false; @@ -322,6 +323,44 @@ exit_fail: return false; } +static bool read_sandbox_level(void) { + sandbox_level_t level; + char *value = NULL; + + if(get_config_string(lookup_config(&config_tree, "Sandbox"), &value)) { + if(!strcasecmp("off", value)) { + level = SANDBOX_NONE; + } else if(!strcasecmp("normal", value)) { + level = SANDBOX_NORMAL; + } else if(!strcasecmp("high", value)) { + level = SANDBOX_HIGH; + } else { + logger(DEBUG_ALWAYS, LOG_ERR, "Bad sandbox value %s!", value); + free(value); + return false; + } + + free(value); + } else { +#ifdef HAVE_SANDBOX + level = SANDBOX_NORMAL; +#else + level = SANDBOX_NONE; +#endif + } + +#ifndef HAVE_SANDBOX + + if(level > SANDBOX_NONE) { + logger(DEBUG_ALWAYS, LOG_ERR, "Sandbox is used but is not supported on this platform"); + return false; + } + +#endif + sandbox_set_level(level); + return true; +} + static bool drop_privs(void) { #ifndef HAVE_WINDOWS uid_t uid = 0; @@ -373,7 +412,8 @@ static bool drop_privs(void) { } #endif - return true; + + return sandbox_enter(); } #ifdef HAVE_WINDOWS @@ -448,6 +488,9 @@ int main(int argc, char **argv) { #ifdef HAVE_MINIUPNPC " miniupnpc" #endif +#ifdef HAVE_SANDBOX + " sandbox" +#endif #ifdef ENABLE_UML " uml" #endif @@ -530,6 +573,10 @@ int main(int argc, char **argv) { return 1; } + if(!read_sandbox_level()) { + return 1; + } + if(debug_level == DEBUG_NOTHING) { int level = 0;