Added feature to --management-client to confirm connection

by writing IP addr and port to a file.


git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@885 e7ae566f-a301-0410-adde-c780ea21d3b5
This commit is contained in:
james 2006-02-03 09:04:52 +00:00
parent 4f404ad36d
commit 8d33c06028
10 changed files with 112 additions and 24 deletions

View File

@ -98,6 +98,9 @@ typedef unsigned long in_addr_t;
/* Dimension size to use for empty array declaration */ /* Dimension size to use for empty array declaration */
#define EMPTY_ARRAY_SIZE 0 #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 to 1 if you have the <openssl/engine.h> header file. */
#define HAVE_OPENSSL_ENGINE_H 1 #define HAVE_OPENSSL_ENGINE_H 1

View File

@ -378,7 +378,7 @@ AC_CHECK_FUNCS(daemon chroot getpwnam setuid nice system getpid dup dup2 dnl
getpass strerror syslog openlog mlockall getgrnam setgid dnl getpass strerror syslog openlog mlockall getgrnam setgid dnl
setgroups stat flock readv writev setsockopt getsockopt dnl setgroups stat flock readv writev setsockopt getsockopt dnl
setsid chdir gettimeofday putenv getpeername unlink dnl setsid chdir gettimeofday putenv getpeername unlink dnl
poll chsize ftruncate sendmsg recvmsg) poll chsize ftruncate sendmsg recvmsg getsockname)
AC_CACHE_SAVE AC_CACHE_SAVE
dnl Required library functions dnl Required library functions

View File

@ -705,6 +705,15 @@ msg_flags_string (const unsigned int flags, struct gc_arena *gc)
return BSTR (&out); return BSTR (&out);
} }
#ifdef ENABLE_DEBUG
void
crash (void)
{
char *null = NULL;
*null = 0;
}
#endif
#ifdef WIN32 #ifdef WIN32
const char * const char *

View File

@ -195,6 +195,10 @@ FILE *msg_fp(void);
void assert_failed (const char *filename, int line); void assert_failed (const char *filename, int line);
#ifdef ENABLE_DEBUG
void crash (void); // force a segfault (debugging only)
#endif
/* Inline functions */ /* Inline functions */
static inline bool static inline bool

6
init.c
View File

@ -2393,7 +2393,8 @@ open_management (struct context *c)
c->options.management_echo_buffer_size, c->options.management_echo_buffer_size,
c->options.management_state_buffer_size, c->options.management_state_buffer_size,
c->options.management_hold, c->options.management_hold,
c->options.management_client)) c->options.management_client,
c->options.management_write_peer_info_file))
{ {
management_set_state (management, management_set_state (management,
OPENVPN_STATE_CONNECTING, OPENVPN_STATE_CONNECTING,
@ -2665,7 +2666,8 @@ init_instance (struct context *c, const struct env_set *env, const unsigned int
return; return;
sig: sig:
c->sig->signal_text = "init_instance"; if (!c->sig->signal_text)
c->sig->signal_text = "init_instance";
close_context (c, -1, flags); close_context (c, -1, flags);
return; return;
} }

View File

@ -187,7 +187,10 @@ man_output_list_push (struct management *man, const char *str)
output_list_push (man->connection.out, (const unsigned char *) str); output_list_push (man->connection.out, (const unsigned char *) str);
man_update_io_state (man); man_update_io_state (man);
if (!man->persist.standalone_disabled) if (!man->persist.standalone_disabled)
man_output_standalone (man, NULL); {
volatile int signal_received = 0;
man_output_standalone (man, &signal_received);
}
} }
} }
@ -791,6 +794,46 @@ man_stop_ne32 (struct management *man)
#endif #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 static void
man_connection_settings_reset (struct management *man) man_connection_settings_reset (struct management *man)
{ {
@ -937,6 +980,7 @@ man_connect (struct management *man)
goto done; goto done;
} }
man_record_peer_info (man);
man_new_connection_post (man, "Connected to management server at"); man_new_connection_post (man, "Connected to management server at");
done: done:
@ -960,7 +1004,10 @@ man_reset_client_socket (struct management *man, const bool exiting)
if (!exiting) if (!exiting)
{ {
if (man->settings.connect_as_client) 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 else
man_listen (man); man_listen (man);
} }
@ -1199,7 +1246,8 @@ man_settings_init (struct man_settings *ms,
const int echo_buffer_size, const int echo_buffer_size,
const int state_buffer_size, const int state_buffer_size,
const bool hold, const bool hold,
const bool connect_as_client) const bool connect_as_client,
const char *write_peer_info_file)
{ {
if (!ms->defined) if (!ms->defined)
{ {
@ -1233,6 +1281,7 @@ man_settings_init (struct man_settings *ms,
* rather than a server? * rather than a server?
*/ */
ms->connect_as_client = connect_as_client; ms->connect_as_client = connect_as_client;
ms->write_peer_info_file = string_alloc (write_peer_info_file, NULL);
/* /*
* Initialize socket address * Initialize socket address
@ -1269,6 +1318,7 @@ man_settings_init (struct man_settings *ms,
static void static void
man_settings_close (struct man_settings *ms) man_settings_close (struct man_settings *ms)
{ {
free (ms->write_peer_info_file);
CLEAR (*ms); CLEAR (*ms);
} }
@ -1360,7 +1410,8 @@ management_open (struct management *man,
const int echo_buffer_size, const int echo_buffer_size,
const int state_buffer_size, const int state_buffer_size,
const bool hold, const bool hold,
const bool connect_as_client) const bool connect_as_client,
const char *write_peer_info_file)
{ {
bool ret = false; bool ret = false;
@ -1378,7 +1429,8 @@ management_open (struct management *man,
echo_buffer_size, echo_buffer_size,
state_buffer_size, state_buffer_size,
hold, hold,
connect_as_client); connect_as_client,
write_peer_info_file);
/* /*
* The log is initially sized to MANAGEMENT_LOG_HISTORY_INITIAL_SIZE, * The log is initially sized to MANAGEMENT_LOG_HISTORY_INITIAL_SIZE,
@ -1678,6 +1730,18 @@ man_standalone_ok (const struct management *man)
return !man->settings.management_over_tunnel && man->connection.state != MS_INITIAL; 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 * Wait for socket I/O when outside primary event loop
*/ */
@ -1696,16 +1760,17 @@ man_block (struct management *man, volatile int *signal_received, const time_t e
management_socket_set (man, man->connection.es, NULL, NULL); management_socket_set (man, man->connection.es, NULL, NULL);
tv.tv_usec = 0; tv.tv_usec = 0;
tv.tv_sec = 1; tv.tv_sec = 1;
if (man_check_for_signals (signal_received))
{
status = -1;
break;
}
status = event_wait (man->connection.es, &tv, &esr, 1); status = event_wait (man->connection.es, &tv, &esr, 1);
update_time (); update_time ();
if (signal_received) if (man_check_for_signals (signal_received))
{ {
get_signal (signal_received); status = -1;
if (*signal_received) break;
{
status = -1;
break;
}
} }
/* set SIGINT signal if expiration time exceeded */ /* set SIGINT signal if expiration time exceeded */
if (expire && now >= expire) if (expire && now >= expire)

View File

@ -201,6 +201,7 @@ struct man_settings {
bool server; bool server;
bool hold; bool hold;
bool connect_as_client; bool connect_as_client;
char *write_peer_info_file;
}; };
/* up_query modes */ /* up_query modes */
@ -267,8 +268,8 @@ bool management_open (struct management *man,
const int echo_buffer_size, const int echo_buffer_size,
const int state_buffer_size, const int state_buffer_size,
const bool hold, 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); void management_close (struct management *man);

View File

@ -1184,6 +1184,7 @@ show_settings (const struct options *o)
SHOW_BOOL (management_query_passwords); SHOW_BOOL (management_query_passwords);
SHOW_BOOL (management_hold); SHOW_BOOL (management_hold);
SHOW_BOOL (management_client); SHOW_BOOL (management_client);
SHOW_STR (management_write_peer_info_file);
#endif #endif
#ifdef ENABLE_PLUGIN #ifdef ENABLE_PLUGIN
if (o->plugin_list) if (o->plugin_list)
@ -1498,7 +1499,8 @@ options_postprocess (struct options *options, bool first_time)
*/ */
#ifdef ENABLE_MANAGEMENT #ifdef ENABLE_MANAGEMENT
if (!options->management_addr && 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)) || 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"); msg (M_USAGE, "--management is not specified, however one or more options which modify the behavior of --management were specified");
#endif #endif
@ -3129,6 +3131,7 @@ add_option (struct options *options,
{ {
VERIFY_PERMISSION (OPT_P_GENERAL); VERIFY_PERMISSION (OPT_P_GENERAL);
options->management_client = true; options->management_client = true;
options->management_write_peer_info_file = p[1];
} }
else if (streq (p[0], "management-log-cache") && p[1]) else if (streq (p[0], "management-log-cache") && p[1])
{ {

View File

@ -280,6 +280,7 @@ struct options
bool management_query_passwords; bool management_query_passwords;
bool management_hold; bool management_hold;
bool management_client; bool management_client;
const char *management_write_peer_info_file;
#endif #endif
#ifdef ENABLE_PLUGIN #ifdef ENABLE_PLUGIN

View File

@ -1,5 +1,5 @@
--- service.c.orig Mon Sep 5 14:38:41 2005 --- service.c.orig Mon Jan 30 10:03:35 2006
+++ service.c Tue Sep 6 13:58:52 2005 +++ service.c Mon Jan 30 10:16:33 2006
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
service_main(DWORD dwArgc, LPTSTR *lpszArgv); service_main(DWORD dwArgc, LPTSTR *lpszArgv);
CmdInstallService(); CmdInstallService();
@ -221,7 +221,7 @@
+ +
+ schService = OpenService( + schService = OpenService(
+ schSCManager, // SCM database + schSCManager, // SCM database
+ "MeetrixService", // service name + SZSERVICENAME, // service name
+ SERVICE_ALL_ACCESS); + SERVICE_ALL_ACCESS);
+ +
+ if (schService == NULL) { + if (schService == NULL) {
@ -319,8 +319,8 @@
} }
if ( lpszTemp ) if ( lpszTemp )
--- service.h.orig Mon Sep 5 14:38:41 2005 --- service.h.orig Mon Jan 30 10:03:35 2006
+++ service.h Tue Sep 6 13:58:59 2005 +++ service.h Mon Jan 30 10:03:35 2006
@@ -62,13 +62,13 @@ @@ -62,13 +62,13 @@
//// todo: change to desired strings //// todo: change to desired strings
//// ////