projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix compiler warnings.
[tinc]
/
src
/
tincd.c
diff --git
a/src/tincd.c
b/src/tincd.c
index
48f5faf
..
9c6009e
100644
(file)
--- a/
src/tincd.c
+++ b/
src/tincd.c
@@
-2,6
+2,8
@@
tincd.c -- the main file for tincd
Copyright (C) 1998-2005 Ivo Timmermans
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
tincd.c -- the main file for tincd
Copyright (C) 1998-2005 Ivo Timmermans
2000-2009 Guus Sliepen <guus@tinc-vpn.org>
+ 2008 Max Rijevski <maksuf@gmail.com>
+ 2009 Michael Tokarev <mjt@tls.msk.ru>
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
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
@@
-13,11
+15,9
@@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- $Id$
+ 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 "system.h"
@@
-78,8
+78,8
@@
static const char *switchuser = NULL;
bool use_logfile = false;
char *identname = NULL; /* program name for syslog */
bool use_logfile = false;
char *identname = NULL; /* program name for syslog */
-char *controlsocketname = NULL; /* control socket location */
char *logfilename = NULL; /* log file location */
char *logfilename = NULL; /* log file location */
+char *controlcookiename = NULL;
char **g_argv; /* a copy of the cmdline arguments */
static int status;
char **g_argv; /* a copy of the cmdline arguments */
static int status;
@@
-96,7
+96,7
@@
static struct option const long_options[] = {
{"chroot", no_argument, NULL, 'R'},
{"user", required_argument, NULL, 'U'},
{"logfile", optional_argument, NULL, 4},
{"chroot", no_argument, NULL, 'R'},
{"user", required_argument, NULL, 'U'},
{"logfile", optional_argument, NULL, 4},
- {"control
socket
", required_argument, NULL, 5},
+ {"control
cookie
", required_argument, NULL, 5},
{NULL, 0, NULL, 0}
};
{NULL, 0, NULL, 0}
};
@@
-105,30
+105,28
@@
static struct WSAData wsa_state;
CRITICAL_SECTION mutex;
#endif
CRITICAL_SECTION mutex;
#endif
-static void usage(bool status)
-{
+static void usage(bool status) {
if(status)
if(status)
- fprintf(stderr,
_("Try `%s --help\' for more information.\n")
,
+ fprintf(stderr,
"Try `%s --help\' for more information.\n"
,
program_name);
else {
program_name);
else {
- printf(
_("Usage: %s [option]...\n\n")
, program_name);
- printf(
_(
" -c, --config=DIR Read configuration options from DIR.\n"
+ printf(
"Usage: %s [option]...\n\n"
, program_name);
+ 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"
" -n, --net=NETNAME Connect to net NETNAME.\n"
" -L, --mlock Lock tinc into main memory.\n"
" --logfile[=FILENAME] Write log entries to a logfile.\n"
" -D, --no-detach Don't fork and detach.\n"
" -d, --debug[=LEVEL] Increase debug level or set it to LEVEL.\n"
" -n, --net=NETNAME Connect to net NETNAME.\n"
" -L, --mlock Lock tinc into main memory.\n"
" --logfile[=FILENAME] Write log entries to a logfile.\n"
- " --control
socket=FILENAME Open control socket at
FILENAME.\n"
+ " --control
cookie=FILENAME Write control socket cookie to
FILENAME.\n"
" --bypass-security Disables meta protocol security, for debugging.\n"
" -R, --chroot chroot to NET dir at startup.\n"
" -U, --user=USER setuid to given USER at startup.\n" " --help Display this help and exit.\n"
" --bypass-security Disables meta protocol security, for debugging.\n"
" -R, --chroot chroot to NET dir at startup.\n"
" -U, --user=USER setuid to given USER at startup.\n" " --help Display this help and exit.\n"
- " --version Output version information and exit.\n\n")
)
;
- printf(
_("Report bugs to tinc@tinc-vpn.org.\n")
);
+ " --version Output version information and exit.\n\n");
+ printf(
"Report bugs to tinc@tinc-vpn.org.\n"
);
}
}
}
}
-static bool parse_options(int argc, char **argv)
-{
+static bool parse_options(int argc, char **argv) {
int r;
int option_index = 0;
int r;
int option_index = 0;
@@
-147,7
+145,7
@@
static bool parse_options(int argc, char **argv)
case 'L': /* no detach */
#ifndef HAVE_MLOCKALL
case 'L': /* no detach */
#ifndef HAVE_MLOCKALL
- logger(LOG_ERR,
_("%s not supported on this platform")
, "mlockall()");
+ logger(LOG_ERR,
"%s not supported on this platform"
, "mlockall()");
return false;
#else
do_mlock = true;
return false;
#else
do_mlock = true;
@@
-192,7
+190,7
@@
static bool parse_options(int argc, char **argv)
break;
case 5: /* open control socket here */
break;
case 5: /* open control socket here */
- control
socket
name = xstrdup(optarg);
+ control
cookie
name = xstrdup(optarg);
break;
case '?':
break;
case '?':
@@
-210,8
+208,7
@@
static bool parse_options(int argc, char **argv)
/*
Set all files and paths according to netname
*/
/*
Set all files and paths according to netname
*/
-static void make_names(void)
-{
+static void make_names(void) {
#ifdef HAVE_MINGW
HKEY key;
char installdir[1024] = "";
#ifdef HAVE_MINGW
HKEY key;
char installdir[1024] = "";
@@
-234,6
+231,8
@@
static void make_names(void)
else
xasprintf(&confbase, "%s", installdir);
}
else
xasprintf(&confbase, "%s", installdir);
}
+ if(!controlcookiename)
+ xasprintf(&controlcookiename, "%s/cookie", confbase);
}
RegCloseKey(key);
if(*installdir)
}
RegCloseKey(key);
if(*installdir)
@@
-241,17
+240,17
@@
static void make_names(void)
}
#endif
}
#endif
- if(!controlsocketname)
- xasprintf(&controlsocketname, "%s/run/%s.control/socket", LOCALSTATEDIR, identname);
-
if(!logfilename)
xasprintf(&logfilename, LOCALSTATEDIR "/log/%s.log", identname);
if(!logfilename)
xasprintf(&logfilename, LOCALSTATEDIR "/log/%s.log", identname);
+ if(!controlcookiename)
+ xasprintf(&controlcookiename, LOCALSTATEDIR "/run/%s.cookie", identname);
+
if(netname) {
if(!confbase)
xasprintf(&confbase, CONFDIR "/tinc/%s", netname);
else
if(netname) {
if(!confbase)
xasprintf(&confbase, CONFDIR "/tinc/%s", netname);
else
- logger(LOG_INFO,
_("Both netname and configuration directory given, using the latter...")
);
+ logger(LOG_INFO,
"Both netname and configuration directory given, using the latter..."
);
} else {
if(!confbase)
xasprintf(&confbase, CONFDIR "/tinc");
} else {
if(!confbase)
xasprintf(&confbase, CONFDIR "/tinc");
@@
-261,7
+260,7
@@
static void make_names(void)
static void free_names() {
if (identname) free(identname);
if (netname) free(netname);
static void free_names() {
if (identname) free(identname);
if (netname) free(netname);
- if (control
socketname) free(controlsocket
name);
+ if (control
cookiename) free(controlcookie
name);
if (logfilename) free(logfilename);
if (confbase) free(confbase);
}
if (logfilename) free(logfilename);
if (confbase) free(confbase);
}
@@
-269,11
+268,11
@@
static void free_names() {
static bool drop_privs() {
#ifdef HAVE_MINGW
if (switchuser) {
static bool drop_privs() {
#ifdef HAVE_MINGW
if (switchuser) {
- logger(LOG_ERR,
_("%s not supported on this platform")
, "-U");
+ logger(LOG_ERR,
"%s not supported on this platform"
, "-U");
return false;
}
if (do_chroot) {
return false;
}
if (do_chroot) {
- logger(LOG_ERR,
_("%s not supported on this platform")
, "-R");
+ logger(LOG_ERR,
"%s not supported on this platform"
, "-R");
return false;
}
#else
return false;
}
#else
@@
-281,13
+280,13
@@
static bool drop_privs() {
if (switchuser) {
struct passwd *pw = getpwnam(switchuser);
if (!pw) {
if (switchuser) {
struct passwd *pw = getpwnam(switchuser);
if (!pw) {
- logger(LOG_ERR,
_("unknown user `%s'")
, switchuser);
+ logger(LOG_ERR,
"unknown user `%s'"
, switchuser);
return false;
}
uid = pw->pw_uid;
if (initgroups(switchuser, pw->pw_gid) != 0 ||
setgid(pw->pw_gid) != 0) {
return false;
}
uid = pw->pw_uid;
if (initgroups(switchuser, pw->pw_gid) != 0 ||
setgid(pw->pw_gid) != 0) {
- logger(LOG_ERR,
_("System call `%s' failed: %s")
,
+ logger(LOG_ERR,
"System call `%s' failed: %s"
,
"initgroups", strerror(errno));
return false;
}
"initgroups", strerror(errno));
return false;
}
@@
-297,7
+296,7
@@
static bool drop_privs() {
if (do_chroot) {
tzset(); /* for proper timestamps in logs */
if (chroot(confbase) != 0 || chdir("/") != 0) {
if (do_chroot) {
tzset(); /* for proper timestamps in logs */
if (chroot(confbase) != 0 || chdir("/") != 0) {
- logger(LOG_ERR,
_("System call `%s' failed: %s")
,
+ logger(LOG_ERR,
"System call `%s' failed: %s"
,
"chroot", strerror(errno));
return false;
}
"chroot", strerror(errno));
return false;
}
@@
-306,7
+305,7
@@
static bool drop_privs() {
}
if (switchuser)
if (setuid(uid) != 0) {
}
if (switchuser)
if (setuid(uid) != 0) {
- logger(LOG_ERR,
_("System call `%s' failed: %s")
,
+ logger(LOG_ERR,
"System call `%s' failed: %s"
,
"setuid", strerror(errno));
return false;
}
"setuid", strerror(errno));
return false;
}
@@
-323,27
+322,22
@@
static bool drop_privs() {
# define setpriority(level) nice(level)
#endif
# define setpriority(level) nice(level)
#endif
-int main(int argc, char **argv)
-{
+int main(int argc, char **argv) {
program_name = argv[0];
program_name = argv[0];
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
if(!parse_options(argc, argv))
return 1;
make_names();
if(show_version) {
if(!parse_options(argc, argv))
return 1;
make_names();
if(show_version) {
- printf(
_("%s version %s (built %s %s, protocol %d)\n")
, PACKAGE,
+ printf(
"%s version %s (built %s %s, protocol %d)\n"
, PACKAGE,
VERSION, __DATE__, __TIME__, PROT_CURRENT);
VERSION, __DATE__, __TIME__, PROT_CURRENT);
- printf(
_(
"Copyright (C) 1998-2009 Ivo Timmermans, Guus Sliepen and others.\n"
+ printf("Copyright (C) 1998-2009 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"
"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"
- "see the file COPYING for details.\n")
)
;
+ "see the file COPYING for details.\n");
return 0;
}
return 0;
}
@@
-353,16
+347,20
@@
int main(int argc, char **argv)
return 0;
}
return 0;
}
+#ifdef HAVE_MINGW
+ if(WSAStartup(MAKEWORD(2, 2), &wsa_state)) {
+ logger(LOG_ERR, "System call `%s' failed: %s", "WSAStartup", winerror(GetLastError()));
+ return 1;
+ }
+#endif
+
openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR);
if(!event_init()) {
openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR);
if(!event_init()) {
- logger(LOG_ERR,
_("Error initializing libevent!")
);
+ logger(LOG_ERR,
"Error initializing libevent!"
);
return 1;
}
return 1;
}
- if(!init_control())
- return 1;
-
g_argv = argv;
init_configuration(&config_tree);
g_argv = argv;
init_configuration(&config_tree);
@@
-376,24
+374,18
@@
int main(int argc, char **argv)
return 1;
if(lzo_init() != LZO_E_OK) {
return 1;
if(lzo_init() != LZO_E_OK) {
- logger(LOG_ERR,
_("Error initializing LZO compressor!")
);
+ logger(LOG_ERR,
"Error initializing LZO compressor!"
);
return 1;
}
#ifdef HAVE_MINGW
return 1;
}
#ifdef HAVE_MINGW
- if(WSAStartup(MAKEWORD(2, 2), &wsa_state)) {
- logger(LOG_ERR, _("System call `%s' failed: %s"), "WSAStartup", winerror(GetLastError()));
- return 1;
- }
-
if(!do_detach || !init_service())
return main2(argc, argv);
else
return 1;
}
if(!do_detach || !init_service())
return main2(argc, argv);
else
return 1;
}
-int main2(int argc, char **argv)
-{
+int main2(int argc, char **argv) {
InitializeCriticalSection(&mutex);
EnterCriticalSection(&mutex);
#endif
InitializeCriticalSection(&mutex);
EnterCriticalSection(&mutex);
#endif
@@
-406,7
+398,7
@@
int main2(int argc, char **argv)
* This has to be done after daemon()/fork() so it works for child.
* No need to do that in parent as it's very short-lived. */
if(do_mlock && mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
* This has to be done after daemon()/fork() so it works for child.
* No need to do that in parent as it's very short-lived. */
if(do_mlock && mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
- logger(LOG_ERR,
_("System call `%s' failed: %s")
, "mlockall",
+ logger(LOG_ERR,
"System call `%s' failed: %s"
, "mlockall",
strerror(errno));
return 1;
}
strerror(errno));
return 1;
}
@@
-417,6
+409,9
@@
int main2(int argc, char **argv)
if(!setup_network())
goto end;
if(!setup_network())
goto end;
+ if(!init_control())
+ return 1;
+
/* Initiate all outgoing connections. */
try_outgoing_connections();
/* Initiate all outgoing connections. */
try_outgoing_connections();
@@
-433,7
+428,7
@@
int main2(int argc, char **argv)
else if(!strcasecmp(priority, "High"))
setpriority(HIGH_PRIORITY_CLASS);
else {
else if(!strcasecmp(priority, "High"))
setpriority(HIGH_PRIORITY_CLASS);
else {
- logger(LOG_ERR,
_("Invalid priority `%s`!")
, priority);
+ logger(LOG_ERR,
"Invalid priority `%s`!"
, priority);
goto end;
}
}
goto end;
}
}
@@
-454,11
+449,9
@@
int main2(int argc, char **argv)
close_network_connections();
end:
close_network_connections();
end:
- logger(LOG_NOTICE,
_("Terminating")
);
+ logger(LOG_NOTICE,
"Terminating"
);
-#ifndef HAVE_MINGW
exit_control();
exit_control();
-#endif
crypto_exit();
crypto_exit();