/* Dimension size to use for empty array declaration */
#define EMPTY_ARRAY_SIZE 0
+/* Define to 1 if you have the `getsockname' function. */
+#define HAVE_GETSOCKNAME 1
+
/* Define to 1 if you have the <openssl/engine.h> header file. */
#define HAVE_OPENSSL_ENGINE_H 1
getpass strerror syslog openlog mlockall getgrnam setgid dnl
setgroups stat flock readv writev setsockopt getsockopt dnl
setsid chdir gettimeofday putenv getpeername unlink dnl
- poll chsize ftruncate sendmsg recvmsg)
+ poll chsize ftruncate sendmsg recvmsg getsockname)
AC_CACHE_SAVE
dnl Required library functions
return BSTR (&out);
}
+#ifdef ENABLE_DEBUG
+void
+crash (void)
+{
+ char *null = NULL;
+ *null = 0;
+}
+#endif
+
#ifdef WIN32
const char *
void assert_failed (const char *filename, int line);
+#ifdef ENABLE_DEBUG
+void crash (void); // force a segfault (debugging only)
+#endif
+
/* Inline functions */
static inline bool
c->options.management_echo_buffer_size,
c->options.management_state_buffer_size,
c->options.management_hold,
- c->options.management_client))
+ c->options.management_client,
+ c->options.management_write_peer_info_file))
{
management_set_state (management,
OPENVPN_STATE_CONNECTING,
return;
sig:
- c->sig->signal_text = "init_instance";
+ if (!c->sig->signal_text)
+ c->sig->signal_text = "init_instance";
close_context (c, -1, flags);
return;
}
output_list_push (man->connection.out, (const unsigned char *) str);
man_update_io_state (man);
if (!man->persist.standalone_disabled)
- man_output_standalone (man, NULL);
+ {
+ volatile int signal_received = 0;
+ man_output_standalone (man, &signal_received);
+ }
}
}
#endif
+static void
+man_record_peer_info (struct management *man)
+{
+ struct gc_arena gc = gc_new ();
+ if (man->settings.write_peer_info_file)
+ {
+ bool success = false;
+#ifdef HAVE_GETSOCKNAME
+ if (socket_defined (man->connection.sd_cli))
+ {
+ struct sockaddr_in addr;
+ socklen_t addrlen = sizeof (addr);
+ int status;
+
+ CLEAR (addr);
+ status = getsockname (man->connection.sd_cli, (struct sockaddr *)&addr, &addrlen);
+ if (!status && addrlen == sizeof (addr))
+ {
+ const in_addr_t a = ntohl (addr.sin_addr.s_addr);
+ const int p = ntohs (addr.sin_port);
+ FILE *fp = fopen (man->settings.write_peer_info_file, "w");
+ if (fp)
+ {
+ fprintf (fp, "%s\n%d\n", print_in_addr_t (a, 0, &gc), p);
+ if (!fclose (fp))
+ success = true;
+ }
+ }
+ }
+#endif
+ if (!success)
+ {
+ msg (D_MANAGEMENT, "MANAGEMENT: failed to write peer info to file %s",
+ man->settings.write_peer_info_file);
+ throw_signal_soft (SIGTERM, "management-connect-failed");
+ }
+ }
+ gc_free (&gc);
+}
+
static void
man_connection_settings_reset (struct management *man)
{
goto done;
}
+ man_record_peer_info (man);
man_new_connection_post (man, "Connected to management server at");
done:
if (!exiting)
{
if (man->settings.connect_as_client)
- throw_signal_soft (SIGTERM, "management-exit");
+ {
+ msg (D_MANAGEMENT, "MANAGEMENT: Triggering management exit");
+ throw_signal_soft (SIGTERM, "management-exit");
+ }
else
man_listen (man);
}
const int echo_buffer_size,
const int state_buffer_size,
const bool hold,
- const bool connect_as_client)
+ const bool connect_as_client,
+ const char *write_peer_info_file)
{
if (!ms->defined)
{
* rather than a server?
*/
ms->connect_as_client = connect_as_client;
+ ms->write_peer_info_file = string_alloc (write_peer_info_file, NULL);
/*
* Initialize socket address
static void
man_settings_close (struct man_settings *ms)
{
+ free (ms->write_peer_info_file);
CLEAR (*ms);
}
const int echo_buffer_size,
const int state_buffer_size,
const bool hold,
- const bool connect_as_client)
+ const bool connect_as_client,
+ const char *write_peer_info_file)
{
bool ret = false;
echo_buffer_size,
state_buffer_size,
hold,
- connect_as_client);
+ connect_as_client,
+ write_peer_info_file);
/*
* The log is initially sized to MANAGEMENT_LOG_HISTORY_INITIAL_SIZE,
return !man->settings.management_over_tunnel && man->connection.state != MS_INITIAL;
}
+static bool
+man_check_for_signals (volatile int *signal_received)
+{
+ if (signal_received)
+ {
+ get_signal (signal_received);
+ if (*signal_received)
+ return true;
+ }
+ return false;
+}
+
/*
* Wait for socket I/O when outside primary event loop
*/
management_socket_set (man, man->connection.es, NULL, NULL);
tv.tv_usec = 0;
tv.tv_sec = 1;
+ if (man_check_for_signals (signal_received))
+ {
+ status = -1;
+ break;
+ }
status = event_wait (man->connection.es, &tv, &esr, 1);
update_time ();
- if (signal_received)
+ if (man_check_for_signals (signal_received))
{
- get_signal (signal_received);
- if (*signal_received)
- {
- status = -1;
- break;
- }
+ status = -1;
+ break;
}
/* set SIGINT signal if expiration time exceeded */
if (expire && now >= expire)
bool server;
bool hold;
bool connect_as_client;
+ char *write_peer_info_file;
};
/* up_query modes */
const int echo_buffer_size,
const int state_buffer_size,
const bool hold,
- const bool connect_as_client);
-
+ const bool connect_as_client,
+ const char *write_peer_info_file);
void management_close (struct management *man);
SHOW_BOOL (management_query_passwords);
SHOW_BOOL (management_hold);
SHOW_BOOL (management_client);
+ SHOW_STR (management_write_peer_info_file);
#endif
#ifdef ENABLE_PLUGIN
if (o->plugin_list)
*/
#ifdef ENABLE_MANAGEMENT
if (!options->management_addr &&
- (options->management_query_passwords || options->management_hold || options->management_client
+ (options->management_query_passwords || options->management_hold
+ || options->management_client || options->management_write_peer_info_file
|| options->management_log_history_cache != defaults.management_log_history_cache))
msg (M_USAGE, "--management is not specified, however one or more options which modify the behavior of --management were specified");
#endif
{
VERIFY_PERMISSION (OPT_P_GENERAL);
options->management_client = true;
+ options->management_write_peer_info_file = p[1];
}
else if (streq (p[0], "management-log-cache") && p[1])
{
bool management_query_passwords;
bool management_hold;
bool management_client;
+ const char *management_write_peer_info_file;
#endif
#ifdef ENABLE_PLUGIN
---- service.c.orig Mon Sep 5 14:38:41 2005
-+++ service.c Tue Sep 6 13:58:52 2005
+--- service.c.orig Mon Jan 30 10:03:35 2006
++++ service.c Mon Jan 30 10:16:33 2006
@@ -16,6 +16,7 @@
service_main(DWORD dwArgc, LPTSTR *lpszArgv);
CmdInstallService();
+
+ schService = OpenService(
+ schSCManager, // SCM database
-+ "MeetrixService", // service name
++ SZSERVICENAME, // service name
+ SERVICE_ALL_ACCESS);
-+
++
+ if (schService == NULL) {
+ _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256));
+ ret = 1;
}
if ( lpszTemp )
---- service.h.orig Mon Sep 5 14:38:41 2005
-+++ service.h Tue Sep 6 13:58:59 2005
+--- service.h.orig Mon Jan 30 10:03:35 2006
++++ service.h Mon Jan 30 10:03:35 2006
@@ -62,13 +62,13 @@
//// todo: change to desired strings
////