Everything will be contained in a single directory specified by confbase.
list.c list.h \
logger.c logger.h \
meta.c meta.h \
- names.c names.h \
net.c net.h \
net_packet.c \
net_setup.c \
#include "conf.h"
#include "list.h"
#include "logger.h"
-#include "names.h"
#include "netutl.h" /* for str2address */
#include "protocol.h"
#include "utils.h" /* for cp */
#include "graph.h"
#include "list.h"
#include "logger.h"
-#include "names.h"
#include "netutl.h"
#include "node.h"
#include "protocol.h"
#include "ecdsa.h"
#include "ecdsagen.h"
#include "invitation.h"
-#include "names.h"
#include "netutl.h"
#include "rsagen.h"
#include "sptps.h"
char temp_netname[32];
make_names:
- if(!confbasegiven) {
- free(confbase);
- confbase = NULL;
- }
-
- make_names();
-
free(tinc_conf);
free(hosts_dir);
free(newbase);
netname = line;
- make_names();
}
fprintf(stderr, "Configuration stored in: %s\n", confbase);
}
// Make sure confbase exists and is accessible.
- if(!confbase_given && mkdir(confdir, 0755) && errno != EEXIST) {
- fprintf(stderr, "Could not create directory %s: %s\n", confdir, strerror(errno));
- return 1;
- }
-
if(mkdir(confbase, 0777) && errno != EEXIST) {
fprintf(stderr, "Could not create directory %s: %s\n", confbase, strerror(errno));
return 1;
}
//tinc_setup() should basically do what cmd_init() from src/tincctl.c does, except it doesn't have to generate a tinc-up script.
bool tinc_setup(const char* confbaseapi, const char* name) {
- confbase = confbaseapi;
- make_names();
+ confbase = xstrdup(confbaseapi);
xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase);
xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase);
if(!access(tinc_conf, F_OK)) {
return false;
}
- if(!confbase_given && mkdir(confdir, 0755) && errno != EEXIST) {
- fprintf(stderr, "Could not create directory %s: %s\n", confdir, strerror(errno));
- return false;
- }
-
if(mkdir(confbase, 0777) && errno != EEXIST) {
fprintf(stderr, "Could not create directory %s: %s\n", confbase, strerror(errno));
return false;
}
bool tinc_main_thread(void * in) {
+ static bool status = false;
-static bool status = false;
-
-/* If nonzero, write log entries to a separate file. */
-bool use_logfile = false;
+ /* If nonzero, write log entries to a separate file. */
+ bool use_logfile = false;
-confbase = (char*) in;
+ confbase = (char*) in;
- openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR);
+ openlogger("tinc", LOGMODE_STDERR);
init_configuration(&config_tree);
exit_configuration(&config_tree);
free(cmdline_conf);
- free_names();
return status;
#include "system.h"
#include "node.h"
-#include "names.h"
//#include "tincctl.h"
#include "xalloc.h"
#include "logger.h"
#include "conf.h"
#include "meta.h"
-#include "names.h"
#include "logger.h"
#include "connection.h"
#include "sptps.h"
debug_t debug_level = DEBUG_NOTHING;
static logmode_t logmode = LOGMODE_STDERR;
static pid_t logpid;
-static FILE *logfile = NULL;
#ifdef HAVE_MINGW
static HANDLE loghandle = NULL;
#endif
fprintf(stderr, "%s\n", message);
fflush(stderr);
break;
- case LOGMODE_FILE:
- if(!now.tv_sec)
- gettimeofday(&now, NULL);
- time_t now_sec = now.tv_sec;
- strftime(timestr, sizeof timestr, "%Y-%m-%d %H:%M:%S", localtime(&now_sec));
- fprintf(logfile, "%s %s[%ld]: %s\n", timestr, logident, (long)logpid, message);
- fflush(logfile);
- break;
case LOGMODE_SYSLOG:
#ifdef HAVE_MINGW
{
case LOGMODE_STDERR:
logpid = getpid();
break;
- case LOGMODE_FILE:
- logpid = getpid();
- logfile = fopen(logfilename, "a");
- if(!logfile) {
- fprintf(stderr, "Could not open log file %s: %s\n", logfilename, strerror(errno));
- logmode = LOGMODE_NULL;
- }
- break;
case LOGMODE_SYSLOG:
#ifdef HAVE_MINGW
loghandle = RegisterEventSource(NULL, logident);
sptps_log = sptps_log_quiet;
}
-void reopenlogger() {
- if(logmode != LOGMODE_FILE)
- return;
-
- fflush(logfile);
- FILE *newfile = fopen(logfilename, "a");
- if(!newfile) {
- logger(DEBUG_ALWAYS, LOG_ERR, "Unable to reopen log file %s: %s", logfilename, strerror(errno));
- return;
- }
- fclose(logfile);
- logfile = newfile;
-}
-
-
void closelogger(void) {
switch(logmode) {
- case LOGMODE_FILE:
- fclose(logfile);
- break;
case LOGMODE_SYSLOG:
#ifdef HAVE_MINGW
DeregisterEventSource(loghandle);
typedef enum logmode_t {
LOGMODE_NULL,
LOGMODE_STDERR,
- LOGMODE_FILE,
LOGMODE_SYSLOG
} logmode_t;
extern debug_t debug_level;
extern bool logcontrol;
extern void openlogger(const char *, logmode_t);
-extern void reopenlogger(void);
extern void logger(int, int, const char *, ...) __attribute__ ((__format__(printf, 3, 4)));
extern void closelogger(void);
+++ /dev/null
-/*
- names.c -- generate commonly used (file)names
- Copyright (C) 1998-2005 Ivo Timmermans
- 2000-2013 Guus Sliepen <guus@tinc-vpn.org>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#include "system.h"
-
-#include "logger.h"
-#include "xalloc.h"
-
-char *netname = NULL;
-char *confdir = NULL; /* base configuration directory */
-char *confbase = NULL; /* base configuration directory for this instance of tinc */
-bool confbase_given;
-char *identname = NULL; /* program name for syslog */
-char *unixsocketname = NULL; /* UNIX socket location */
-char *logfilename = NULL; /* log file location */
-char *pidfilename = NULL;
-char *program_name = NULL;
-
-/*
- Set all files and paths according to netname
-*/
-void make_names(void) {
-#ifdef HAVE_MINGW
- HKEY key;
- char installdir[1024] = "";
- DWORD len = sizeof installdir;
-#endif
- confbase_given = confbase;
-
- if(netname && confbase)
- logger(DEBUG_ALWAYS, LOG_INFO, "Both netname and configuration directory given, using the latter...");
-
- if(netname)
- xasprintf(&identname, "tinc.%s", netname);
- else
- identname = xstrdup("tinc");
-
-#ifdef HAVE_MINGW
- if(!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\tinc", 0, KEY_READ, &key)) {
- if(!RegQueryValueEx(key, NULL, 0, 0, (LPBYTE)installdir, &len)) {
- confdir = xstrdup(installdir);
- if(!logfilename)
- xasprintf(&logfilename, "%s" SLASH "log" SLASH "%s.log", installdir, identname);
- if(!confbase) {
- if(netname)
- xasprintf(&confbase, "%s" SLASH "%s", installdir, netname);
- else
- xasprintf(&confbase, "%s", installdir);
- }
- if(!pidfilename)
- xasprintf(&pidfilename, "%s" SLASH "pid", confbase);
- }
- RegCloseKey(key);
- }
-#endif
- if(!confdir)
- confdir = xstrdup(CONFDIR SLASH "tinc");
-
- if(!logfilename)
- xasprintf(&logfilename, LOCALSTATEDIR SLASH "log" SLASH "%s.log", identname);
-
- if(!pidfilename)
- xasprintf(&pidfilename, SLASH "tmp" SLASH "%s.pid", identname);
-
- if(!unixsocketname) {
- int len = strlen(pidfilename);
- unixsocketname = xmalloc(len + 8);
- strcpy(unixsocketname, pidfilename);
- if(len > 4 && !strcmp(pidfilename + len - 4, ".pid"))
- strcpy(unixsocketname + len - 4, ".socket");
- else
- strcpy(unixsocketname + len, ".socket");
- }
-
- if(!confbase) {
- if(netname)
- xasprintf(&confbase, CONFDIR SLASH "tinc" SLASH "%s", netname);
- else
- xasprintf(&confbase, CONFDIR SLASH "tinc");
- }
-}
-
-void free_names(void) {
- free(identname);
- free(netname);
- free(unixsocketname);
- free(pidfilename);
- free(logfilename);
- free(confbase);
- free(confdir);
-}
+++ /dev/null
-/*
- names.h -- header for names.c
- Copyright (C) 1998-2005 Ivo Timmermans
- 2000-2013 Guus Sliepen <guus@tinc-vpn.org>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#ifndef __TINC_NAMES_H__
-#define __TINC_NAMES_H__
-
-extern char *confdir;
-extern char *confbase;
-extern bool confbase_given;
-extern char *netname;
-extern char *identname;
-extern char *unixsocketname;
-extern char *logfilename;
-extern char *pidfilename;
-extern char *program_name;
-
-extern void make_names(void);
-extern void free_names(void);
-
-#endif /* __TINC_NAMES_H__ */
#include "graph.h"
#include "logger.h"
#include "meta.h"
-#include "names.h"
#include "net.h"
#include "netutl.h"
#include "protocol.h"
static timeout_t pingtimer;
static timeout_t periodictimer;
+//TODO: move this to a better place
+char *confbase;
+
/* Purge edges of unreachable nodes. Use carefully. */
// TODO: remove
static void sighup_handler(void *data) {
logger(DEBUG_ALWAYS, LOG_NOTICE, "Got %s signal", strsignal(((signal_t *)data)->signum));
- reopenlogger();
if(reload_configuration())
exit(1);
}
extern CRITICAL_SECTION mutex;
#endif
+//TODO: move this to a better place
+extern char *confbase;
+
#endif /* __TINC_NET_H__ */
#include "ecdsa.h"
#include "graph.h"
#include "logger.h"
-#include "names.h"
#include "net.h"
#include "netutl.h"
#include "protocol.h"
if(!fp) {
logger(DEBUG_ALWAYS, LOG_ERR, "Error reading ECDSA private key file `%s': %s", fname, strerror(errno));
if(errno == ENOENT)
- logger(DEBUG_ALWAYS, LOG_INFO, "Create an ECDSA keypair with `tinc -n %s generate-ecdsa-keys'.", netname ?: ".");
+ logger(DEBUG_ALWAYS, LOG_INFO, "Create an ECDSA keypair with `tinc generate-ecdsa-keys'.");
free(fname);
return false;
}
#include "list.h"
#include "logger.h"
#include "meta.h"
-#include "names.h"
#include "net.h"
#include "netutl.h"
#include "protocol.h"
setenv("REMOTEPORT", port, true);
setenv("NODE", c->name, true);
setenv("NAME", myself->name, true);
- if(netname)
- setenv("NETNAME", netname, true);
int result = system(command);
if(result < 0)
#include "graph.h"
#include "logger.h"
#include "meta.h"
-#include "names.h"
#include "net.h"
#include "netutl.h"
#include "node.h"
#include "ecdsagen.h"
#include "info.h"
#include "invitation.h"
-#include "names.h"
#include "rsagen.h"
#include "utils.h"
#include "tincctl.h"
free(netname);
netname = strcmp(name, ".") ? xstrdup(name) : NULL;
- make_names();
xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase);
xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase);
xasprintf(&prompt, "%s> ", identname);
if(!parse_options(argc, argv))
return 1;
- make_names();
xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase);
xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase);
#include "conf.h"
#include "crypto.h"
#include "logger.h"
-#include "names.h"
#include "net.h"
#include "netutl.h"
#include "protocol.h"
static const char *switchuser = NULL;
#endif
-/* If nonzero, write log entries to a separate file. */
-bool use_logfile = false;
-
char **g_argv; /* a copy of the cmdline arguments */
static int status = 1;
{"mlock", no_argument, NULL, 'L'},
{"chroot", no_argument, NULL, 'R'},
{"user", required_argument, NULL, 'U'},
- {"logfile", optional_argument, NULL, 4},
- {"pidfile", required_argument, NULL, 5},
{"option", required_argument, NULL, 'o'},
{NULL, 0, NULL, 0}
};
static void usage(bool status) {
if(status)
- fprintf(stderr, "Try `%s --help\' for more information.\n",
- program_name);
+ fprintf(stderr, "Try `tincd --help\' for more information.\n");
else {
- printf("Usage: %s [option]...\n\n", program_name);
+ printf("Usage: tincd [option]...\n\n");
printf( " -c, --config=DIR Read configuration options from DIR.\n"
" -D, --no-detach Don't fork and detach.\n"
" -d, --debug[=LEVEL] Increase debug level or set it to LEVEL.\n"
#ifdef HAVE_MLOCKALL
" -L, --mlock Lock tinc into main memory.\n"
#endif
- " --logfile[=FILENAME] Write log entries to a logfile.\n"
- " --pidfile=FILENAME Write PID and control socket cookie to FILENAME.\n"
" --bypass-security Disables meta protocol security, for debugging.\n"
" -o, --option[HOST.]KEY=VALUE Set global/host configuration value.\n"
#ifndef HAVE_MINGW
debug_level++;
break;
- case 'n': /* net name given */
- netname = xstrdup(optarg);
- break;
-
case 'o': /* option */
cfg = parse_config_line(optarg, NULL, ++lineno);
if (!cfg)
bypass_security = true;
break;
- case 4: /* write log entries to a file */
- use_logfile = true;
- if(!optarg && optind < argc && *argv[optind] != '-')
- optarg = argv[optind++];
- if(optarg)
- logfilename = xstrdup(optarg);
- break;
-
- case 5: /* open control socket here */
- pidfilename = xstrdup(optarg);
- break;
-
case '?': /* wrong options */
usage(true);
return false;
return false;
}
- if(!netname && (netname = getenv("NETNAME")))
- netname = xstrdup(netname);
-
- /* netname "." is special: a "top-level name" */
-
- if(netname && (!*netname || !strcmp(netname, "."))) {
- free(netname);
- netname = NULL;
- }
-
- if(netname && (strpbrk(netname, "\\/") || *netname == '.')) {
- fprintf(stderr, "Invalid character in netname!\n");
- return false;
- }
-
return true;
}
#endif
int main(int argc, char **argv) {
- program_name = argv[0];
-
if(!parse_options(argc, argv))
return 1;
- make_names();
-
if(show_version) {
printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE,
VERSION, __DATE__, __TIME__, PROT_MAJOR, PROT_MINOR);
}
#endif
- openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR);
+ openlogger("tinc", LOGMODE_STDERR);
g_argv = argv;
exit_configuration(&config_tree);
free(cmdline_conf);
- free_names();
return status;
}