/*
tincd.c -- the main file for tincd
Copyright (C) 1998-2005 Ivo Timmermans
- 2000-2018 Guus Sliepen <guus@tinc-vpn.org>
+ 2000-2021 Guus Sliepen <guus@tinc-vpn.org>
2008 Max Rijevski <maksuf@gmail.com>
2009 Michael Tokarev <mjt@tls.msk.ru>
2010 Julien Muchembled <jm@jmuchemb.eu>
#include LZO1X_H
#endif
+#ifdef LZ4_H
+#include LZ4_H
+#endif
+
#ifndef HAVE_MINGW
#include <pwd.h>
#include <grp.h>
break;
case 'c': /* config file */
+ free(confbase);
confbase = xstrdup(optarg);
break;
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;
break;
case 'n': /* net name given */
+ free(netname);
netname = xstrdup(optarg);
break;
cfg = parse_config_line(optarg, NULL, ++lineno);
if(!cfg) {
- return false;
+ goto exit_fail;
}
list_insert_tail(cmdline_conf, cfg);
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 */
}
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;
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"))) {
if(netname && !check_netname(netname, false)) {
fprintf(stderr, "Invalid character in netname!\n");
- return false;
+ goto exit_fail;
}
if(netname && !check_netname(netname, true)) {
}
return true;
+
+exit_fail:
+ free_names();
+ free(cmdline_conf);
+ cmdline_conf = NULL;
+ return false;
}
static bool drop_privs(void) {
# define setpriority(level) !SetPriorityClass(GetCurrentProcess(), (level))
static void stop_handler(void *data, int flags) {
+ (void)data;
+ (void)flags;
+
event_exit();
}
static BOOL WINAPI console_ctrl_handler(DWORD type) {
+ (void)type;
+
logger(DEBUG_ALWAYS, LOG_NOTICE, "Got console shutdown request");
if(WSASetEvent(stop_io.event) == FALSE) {
# define setpriority(level) (setpriority(PRIO_PROCESS, 0, (level)))
#endif
+static void cleanup() {
+ if(config_tree) {
+ exit_configuration(&config_tree);
+ }
+
+ free(cmdline_conf);
+ free_names();
+}
+
int main(int argc, char **argv) {
program_name = argv[0];
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("Copyright (C) 1998-2018 Ivo Timmermans, Guus Sliepen and others.\n"
+ 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"
"and you are welcome to redistribute it under certain conditions;\n"
}
make_names(true);
+ atexit(cleanup);
+
chdir(confbase);
#ifdef HAVE_MINGW
}
int main2(int argc, char **argv) {
+ (void)argc;
+ (void)argv;
#endif
char *priority = NULL;
crypto_exit();
- exit_configuration(&config_tree);
- free(cmdline_conf);
- free_names();
-
return status;
}