X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ftincd.c;h=539f527473e96da11bdb7a58dfc742ca77dc6620;hb=72091d5c770856870bb8cd51bcc5641078c7562c;hp=06e6713056c4c0b09027920eae32bdf0f4b2c702;hpb=3d787920d51a35e74e442c7265be3b13b69ad8e4;p=tinc diff --git a/src/tincd.c b/src/tincd.c index 06e67130..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; @@ -130,7 +131,7 @@ static void usage(bool status) { fprintf(stderr, "Try `%s --help\' for more information.\n", program_name); else { - static const char *message = + fprintf(stdout, "Usage: %s [option]...\n" "\n" " -c, --config=DIR Read configuration options from DIR.\n" @@ -152,9 +153,8 @@ static void usage(bool status) { " --help Display this help and exit.\n" " --version Output version information and exit.\n" "\n" - "Report bugs to tinc@tinc-vpn.org.\n"; - - printf(message, program_name); + "Report bugs to tinc@tinc-vpn.org.\n", + program_name); } } @@ -323,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; @@ -374,7 +412,8 @@ static bool drop_privs(void) { } #endif - return true; + + return sandbox_enter(); } #ifdef HAVE_WINDOWS @@ -419,7 +458,7 @@ int main(int argc, char **argv) { } if(show_version) { - static const char *message = + fprintf(stdout, "%s version %s (built %s %s, protocol %d.%d)\n" "Features:" #ifdef HAVE_OPENSSL @@ -449,6 +488,9 @@ int main(int argc, char **argv) { #ifdef HAVE_MINIUPNPC " miniupnpc" #endif +#ifdef HAVE_SANDBOX + " sandbox" +#endif #ifdef ENABLE_UML " uml" #endif @@ -461,9 +503,8 @@ int main(int argc, char **argv) { "\n" "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" "and you are welcome to redistribute it under certain conditions;\n" - "see the file COPYING for details.\n"; - - printf(message, PACKAGE, BUILD_VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR); + "see the file COPYING for details.\n", + PACKAGE, BUILD_VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR); return 0; } @@ -532,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;