X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ftincd.c;h=d8ab0ac06e40c70ed8ce6ba791389a647b79e536;hb=7208397398f7e08d741bfa83594a88e5d01b6220;hp=3a3703ca57e82dff96844513eeb7cd7efc6b9e62;hpb=0f18410ebaf1c503e5d0ca9624b24df930561d7d;p=tinc diff --git a/src/tincd.c b/src/tincd.c index 3a3703ca..d8ab0ac0 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -159,6 +159,7 @@ static bool parse_options(int argc, char **argv) { break; case 'c': /* config file */ + free(confbase); confbase = xstrdup(optarg); break; @@ -169,7 +170,7 @@ static bool parse_options(int argc, char **argv) { case 'L': /* no detach */ #ifndef HAVE_MLOCKALL logger(DEBUG_ALWAYS, LOG_ERR, "The %s option is not supported on this platform.", argv[optind - 1]); - return false; + goto exit_fail; #else do_mlock = true; break; @@ -189,6 +190,7 @@ static bool parse_options(int argc, char **argv) { break; case 'n': /* net name given */ + free(netname); netname = xstrdup(optarg); break; @@ -201,7 +203,7 @@ static bool parse_options(int argc, char **argv) { cfg = parse_config_line(optarg, NULL, ++lineno); if(!cfg) { - return false; + goto exit_fail; } list_insert_tail(cmdline_conf, cfg); @@ -212,7 +214,7 @@ static bool parse_options(int argc, char **argv) { case 'R': case 'U': logger(DEBUG_ALWAYS, LOG_ERR, "The %s option is not supported on this platform.", argv[optind - 1]); - return false; + goto exit_fail; #else case 'R': /* chroot to NETNAME dir */ @@ -245,18 +247,20 @@ static bool parse_options(int argc, char **argv) { } if(optarg) { + free(logfilename); logfilename = xstrdup(optarg); } break; case 5: /* open control socket here */ + free(pidfilename); pidfilename = xstrdup(optarg); break; case '?': /* wrong options */ usage(true); - return false; + goto exit_fail; default: break; @@ -266,7 +270,7 @@ static bool parse_options(int argc, char **argv) { if(optind < argc) { fprintf(stderr, "%s: unrecognized argument '%s'\n", argv[0], argv[optind]); usage(true); - return false; + goto exit_fail; } if(!netname && (netname = getenv("NETNAME"))) { @@ -282,7 +286,7 @@ static bool parse_options(int argc, char **argv) { if(netname && !check_netname(netname, false)) { fprintf(stderr, "Invalid character in netname!\n"); - return false; + goto exit_fail; } if(netname && !check_netname(netname, true)) { @@ -290,6 +294,12 @@ static bool parse_options(int argc, char **argv) { } return true; + +exit_fail: + free_names(); + list_delete_list(cmdline_conf); + cmdline_conf = NULL; + return false; } static bool drop_privs(void) { @@ -372,6 +382,15 @@ static BOOL WINAPI console_ctrl_handler(DWORD type) { # define setpriority(level) (setpriority(PRIO_PROCESS, 0, (level))) #endif +static void cleanup() { + if(config_tree) { + exit_configuration(&config_tree); + } + + list_delete_list(cmdline_conf); + free_names(); +} + int main(int argc, char **argv) { program_name = argv[0]; @@ -382,6 +401,41 @@ int main(int argc, char **argv) { if(show_version) { printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE, BUILD_VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR); + printf("Features:" +#ifdef HAVE_OPENSSL + " openssl" +#endif +#ifdef HAVE_LIBGCRYPT + " libgcrypt" +#endif +#ifdef HAVE_LZO + " comp_lzo" +#endif +#ifdef HAVE_ZLIB + " comp_zlib" +#endif +#ifdef HAVE_LZ4 + " comp_lz4" +#endif +#ifndef DISABLE_LEGACY + " legacy_protocol" +#endif +#ifdef ENABLE_JUMBOGRAMS + " jumbograms" +#endif +#ifdef ENABLE_TUNEMU + " tunemu" +#endif +#ifdef HAVE_MINIUPNPC + " miniupnpc" +#endif +#ifdef ENABLE_UML + " uml" +#endif +#ifdef ENABLE_VDE + " vde" +#endif + "\n\n"); printf("Copyright (C) 1998-2021 Ivo Timmermans, Guus Sliepen and others.\n" "See the AUTHORS file for a complete list.\n\n" "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" @@ -397,6 +451,8 @@ int main(int argc, char **argv) { } make_names(true); + atexit(cleanup); + chdir(confbase); #ifdef HAVE_MINGW @@ -448,7 +504,7 @@ int main(int argc, char **argv) { srand(now.tv_sec + now.tv_usec); crypto_init(); - if(!read_server_config()) { + if(!read_server_config(config_tree)) { return 1; } @@ -572,9 +628,5 @@ end: crypto_exit(); - exit_configuration(&config_tree); - free(cmdline_conf); - free_names(); - return status; }