]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Added --management-signal option to signal SIGUSR1 when the management
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Mon, 22 Oct 2007 19:12:54 +0000 (19:12 +0000)
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>
Mon, 22 Oct 2007 19:12:54 +0000 (19:12 +0000)
interface disconnects (Alon Bar-Lev).

git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@2413 e7ae566f-a301-0410-adde-c780ea21d3b5

init.c
manage.c
manage.h
openvpn.8
options.c
options.h

diff --git a/init.c b/init.c
index 2cff87c2c2b501d3e12c6bda9b57f5dbf86d5333..65796af7f57631c4955efd46f9b9e5f4eb95883b 100644 (file)
--- a/init.c
+++ b/init.c
@@ -2468,6 +2468,7 @@ open_management (struct context *c)
                               c->options.management_echo_buffer_size,
                               c->options.management_state_buffer_size,
                               c->options.management_hold,
+                              c->options.management_signal,
                               c->options.management_client,
                               c->options.management_write_peer_info_file,
                               c->options.remap_sigusr1))
index 7323dd6f784c9867d8b8f2cf50649ad37d4b3794..b6f8bcfae99290920f9bef6bd960071e48b84919 100644 (file)
--- a/manage.c
+++ b/manage.c
@@ -1080,6 +1080,15 @@ man_reset_client_socket (struct management *man, const bool exiting)
     }
   if (!exiting)
     {
+      if (man->settings.signal_on_disconnect) {
+         int mysig = man_mod_signal (man, SIGUSR1);
+         if (mysig >= 0)
+           {
+             msg (D_MANAGEMENT, "MANAGEMENT: Triggering management signal");
+             throw_signal_soft (mysig, "management-disconnect");
+           }
+      }
+
       if (man->settings.connect_as_client)
        {
          msg (D_MANAGEMENT, "MANAGEMENT: Triggering management exit");
@@ -1323,6 +1332,7 @@ man_settings_init (struct man_settings *ms,
                   const int echo_buffer_size,
                   const int state_buffer_size,
                   const bool hold,
+                  const bool signal_on_disconnect,
                   const bool connect_as_client,
                   const char *write_peer_info_file,
                   const int remap_sigusr1)
@@ -1354,6 +1364,12 @@ man_settings_init (struct man_settings *ms,
        */
       ms->hold = hold;
 
+      /*
+       * Should OpenVPN be signaled if management
+       * disconnects?
+       */
+      ms->signal_on_disconnect = signal_on_disconnect;
+
       /*
        * Should OpenVPN connect to management interface as a client
        * rather than a server?
@@ -1496,6 +1512,7 @@ management_open (struct management *man,
                 const int echo_buffer_size,
                 const int state_buffer_size,
                 const bool hold,
+                const bool signal_on_disconnect,
                 const bool connect_as_client,
                 const char *write_peer_info_file,
                 const int remap_sigusr1)
@@ -1516,6 +1533,7 @@ management_open (struct management *man,
                     echo_buffer_size,
                     state_buffer_size,
                     hold,
+                    signal_on_disconnect,
                     connect_as_client,
                     write_peer_info_file,
                     remap_sigusr1);
index 445f710283f74c49463fa75ffab8070ad86e5a66..20b15d26ea02cd32b397f0aa23966b1e54c85628 100644 (file)
--- a/manage.h
+++ b/manage.h
@@ -205,6 +205,7 @@ struct man_settings {
   int state_buffer_size;
   bool server;
   bool hold;
+  bool signal_on_disconnect;
   bool connect_as_client;
   char *write_peer_info_file;
 
@@ -281,6 +282,7 @@ bool management_open (struct management *man,
                      const int echo_buffer_size,
                      const int state_buffer_size,
                      const bool hold,
+                     const bool signal_on_disconnect,
                      const bool connect_as_client,
                      const char *write_peer_info_file,
                      const int remap_sigusr1);
index c52d1c14757cedf3eaba5e0bc556b0999d0af60f..aa48e70a3cbe1923e97a9ac92921c1dbe34a02f5 100644 (file)
--- a/openvpn.8
+++ b/openvpn.8
@@ -178,6 +178,7 @@ openvpn \- secure IP tunnel daemon.
 [\ \fB\-\-lport\fR\ \fIport\fR\ ]
 [\ \fB\-\-management\-hold\fR\ ]
 [\ \fB\-\-management\-log\-cache\fR\ \fIn\fR\ ]
+[\ \fB\-\-management\-signal\fR\ ]
 [\ \fB\-\-management\-query\-passwords\fR\ ]
 [\ \fB\-\-management\fR\ \fIIP\ port\ [pw\-file]\fR\ ]
 [\ \fB\-\-max\-clients\fR\ \fIn\fR\ ]
@@ -2327,6 +2328,12 @@ with the
 command.
 .\"*********************************************************
 .TP
+.B --management-signal
+Send SIGUSR1 signal to OpenVPN if management session disconnects.
+This is useful when you wish to disconnect an OpenVPN session on
+user logoff.
+.\"*********************************************************
+.TP
 .B --management-log-cache n
 Cache the most recent
 .B n
index 46aad6d91c50ef0c82b6da322491b89e9a7fc45f..f2310fca866bb07535cfddf245811834cd67dc64 100644 (file)
--- a/options.c
+++ b/options.c
@@ -311,6 +311,7 @@ static const char usage_message[] =
   "                  and auth-user-pass passwords.\n"
   "--management-hold : Start " PACKAGE_NAME " in a hibernating state, until a client\n"
   "                    of the management interface explicitly starts it.\n"
+  "--management-signal : Issue SIGUSR1 when management disconnect event occurs.\n"
   "--management-log-cache n : Cache n lines of log file history for usage\n"
   "                  by the management channel.\n"
 #endif
@@ -1200,6 +1201,7 @@ show_settings (const struct options *o)
   SHOW_BOOL (management_query_passwords);
   SHOW_BOOL (management_hold);
   SHOW_BOOL (management_client);
+  SHOW_BOOL (management_signal);
   SHOW_STR (management_write_peer_info_file);
 #endif
 #ifdef ENABLE_PLUGIN
@@ -1527,7 +1529,7 @@ options_postprocess (struct options *options, bool first_time)
    */
 #ifdef ENABLE_MANAGEMENT
   if (!options->management_addr &&
-      (options->management_query_passwords || options->management_hold
+      (options->management_query_passwords || options->management_hold || options->management_signal
        || 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");
@@ -3164,6 +3166,11 @@ add_option (struct options *options,
       VERIFY_PERMISSION (OPT_P_GENERAL);
       options->management_hold = true;
     }
+  else if (streq (p[0], "management-signal"))
+    {
+      VERIFY_PERMISSION (OPT_P_GENERAL);
+      options->management_signal = true;
+    }
   else if (streq (p[0], "management-client"))
     {
       VERIFY_PERMISSION (OPT_P_GENERAL);
index 21d131ed5888e5cfa8b1c075bf3fb36aab48a371..ee13c8de3c15a492fb9065fd3615dc9665a8cf5c 100644 (file)
--- a/options.h
+++ b/options.h
@@ -283,6 +283,7 @@ struct options
   int management_state_buffer_size;
   bool management_query_passwords;
   bool management_hold;
+  bool management_signal;
   bool management_client;
   const char *management_write_peer_info_file;
 #endif