Skip to contentSkip to conversation

Remove inetd support from OpenVPN

PATCH In review Arne Schwabe 2 participants 2 messages Dec 14, 2020 – Jan 30, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove inetd support from OpenVPN

This code is from another time and has almost no relevance today.

---
 Changes.rst                                   |   7 +
 doc/man-sections/link-options.rst             |   4 -
 doc/man-sections/log-options.rst              |   4 +-
 doc/man-sections/server-options.rst           |  31 ---
 .../sample-config-files/xinetd-client-config  |  11 -
 .../sample-config-files/xinetd-server-config  |  25 ---
 src/openvpn/error.c                           |   4 +-
 src/openvpn/forward.c                         |  18 +-
 src/openvpn/init.c                            |  22 --
 src/openvpn/misc.c                            |  20 --
 src/openvpn/misc.h                            |   7 -
 src/openvpn/options.c                         | 121 -----------
 src/openvpn/options.h                         |   3 -
 src/openvpn/socket.c                          | 191 +++++-------------
 src/openvpn/socket.h                          |   6 -
 15 files changed, 70 insertions(+), 404 deletions(-)
 delete mode 100644 sample/sample-config-files/xinetd-client-config
 delete mode 100644 sample/sample-config-files/xinetd-server-config
Changes.rst +7 -0
index 2a2829e7..2a847564 100644
@@ -9,6 +9,13 @@ Keying Material Exporters (RFC 5705) based key generation
     the RFC5705 based key material generation to the current custom
     OpenVPN PRF. This feature requires OpenSSL or mbed TLS 2.18+.
 
+Deprecated features
+-------------------
+``inetd`` has been removed
+    This was a very limited and not-well-tested way to run OpenVPN, on TCP
+    and TAP mode only.
+
+
 Overview of changes in 2.5
 ==========================
 
doc/man-sections/link-options.rst +0 -4
index c132a623..b8a72d7a 100644
@@ -366,10 +366,6 @@ the local and the remote host.
   Persist replay-protection state across sessions using ``file`` to save
   and reload the state.
 
-  This option will strengthen protection against replay attacks,
-  especially when you are using OpenVPN in a dynamic context (such as with
-  ``--inetd``) when OpenVPN sessions are frequently started and stopped.
-
   This option will keep a disk copy of the current replay protection state
   (i.e. the most recent packet timestamp and sequence number received from
   the remote peer), so that if an OpenVPN session is stopped and
doc/man-sections/log-options.rst +2 -2
index e385d180..d2451d8a 100644
@@ -15,8 +15,8 @@ Log options
   Output logging messages to ``file``, including output to stdout/stderr
   which is generated by called scripts. If ``file`` already exists it will
   be truncated. This option takes effect immediately when it is parsed in
-  the command line and will supersede syslog output if ``--daemon`` or
-  ``--inetd`` is also specified. This option is persistent over the entire
+  the command line and will supersede syslog output if ``--daemon``
+  is also specified. This option is persistent over the entire
   course of an OpenVPN instantiation and will not be reset by
   :code:`SIGHUP`, :code:`SIGUSR1`, or ``--ping-restart``.
 
doc/man-sections/server-options.rst +0 -31
index 5a689452..37ea8d43 100644
@@ -286,37 +286,6 @@ fast hardware. SSL/TLS authentication must be used in this mode.
 
      ifconfig-ipv6-push ipv6addr/bits ipv6remote
 
---inetd args
-  Valid syntaxes:
-  ::
-
-     inetd
-     inetd wait
-     inetd nowait
-     inetd wait progname
-
-  Use this option when OpenVPN is being run from the inetd or ``xinetd``\(8)
-  server.
-
-  The :code:`wait` and :code:`nowait` option must match what is specified
-  in the inetd/xinetd config file. The :code:`nowait` mode can only be used
-  with ``--proto tcp-server`` The default is :code:`wait`.  The
-  :code:`nowait` mode can be used to instantiate the OpenVPN daemon as a
-  classic TCP server, where client connection requests are serviced on a
-  single port number. For additional information on this kind of
-  configuration, see the OpenVPN FAQ:
-  https://community.openvpn.net/openvpn/wiki/325-openvpn-as-a--forking-tcp-server-which-can-service-multiple-clients-over-a-single-tcp-port
-
-  This option precludes the use of ``--daemon``, ``--local`` or
-  ``--remote``.  Note that this option causes message and error output to
-  be handled in the same way as the ``--daemon`` option. The optional
-  ``progname`` parameter is also handled exactly as in ``--daemon``.
-
-  Also note that in ``wait`` mode, each OpenVPN tunnel requires a separate
-  TCP/UDP port and a separate inetd or xinetd entry. See the OpenVPN 1.x
-  HOWTO for an example on using OpenVPN with xinetd:
-  https://openvpn.net/community-resources/1xhowto/
-
 --multihome
   Configure a multi-homed UDP server. This option needs to be used when a
   server has more than one IP address (e.g. multiple interfaces, or
sample/sample-config-files/xinetd-client-config deleted +0 -11
deleted file mode 100644
index 03c5c1fa..00000000
@@ -1,11 +0,0 @@
-# This OpenVPN config file
-# is the client side counterpart
-# of xinetd-server-config
-
-dev tun
-ifconfig 10.4.0.1 10.4.0.2
-remote my-server
-port 1194
-user nobody
-secret /root/openvpn/key
-inactive 600
sample/sample-config-files/xinetd-server-config deleted +0 -25
deleted file mode 100644
index 803a6f8f..00000000
@@ -1,25 +0,0 @@
-# An xinetd configuration file for OpenVPN.
-#
-# This file should be renamed to openvpn or something suitably
-# descriptive and copied to the /etc/xinetd.d directory.
-# xinetd can then be made aware of this file by restarting
-# it or sending it a SIGHUP signal.
-#
-# For each potential incoming client, create a separate version
-# of this configuration file on a unique port number.  Also note
-# that the key file and ifconfig endpoints should be unique for
-# each client.  This configuration assumes that the OpenVPN
-# executable and key live in /root/openvpn.  Change this to fit
-# your environment.
-
-service openvpn_1
-{
-        type            = UNLISTED
-        port            = 1194
-        socket_type     = dgram
-        protocol        = udp
-        wait            = yes
-        user            = root
-        server          = /root/openvpn/openvpn
-        server_args     = --inetd --dev tun --ifconfig 10.4.0.2 10.4.0.1 --secret /root/openvpn/key --inactive 600 --user nobody
-}
src/openvpn/error.c +2 -2
index 7d0fcb2d..0ecbfc33 100644
@@ -62,7 +62,7 @@ static int mute_category;   /* GLOBAL */
  * Output mode priorities are as follows:
  *
  *  (1) --log-x overrides everything
- *  (2) syslog is used if --daemon or --inetd is defined and not --log-x
+ *  (2) syslog is used if --daemon is defined and not --log-x
  *  (3) if OPENVPN_DEBUG_COMMAND_LINE is defined, output
  *      to constant logfile name.
  *  (4) Output to stdout.
@@ -476,7 +476,7 @@ open_syslog(const char *pgmname, bool stdio_to_null)
         }
     }
 #else  /* if SYSLOG_CAPABILITY */
-    msg(M_WARN, "Warning on use of --daemon/--inetd: this operating system lacks daemon logging features, therefore when I become a daemon, I won't be able to log status or error messages");
+    msg(M_WARN, "Warning on use of --daemon: this operating system lacks daemon logging features, therefore when I become a daemon, I won't be able to log status or error messages");
 #endif
 }
 
src/openvpn/forward.c +5 -13
index 67615a6b..17a2699d 100644
@@ -834,23 +834,15 @@ read_incoming_link(struct context *c)
 #endif
         {
             /* received a disconnect from a connection-oriented protocol */
-            if (c->options.inetd)
+            if (event_timeout_defined(&c->c2.explicit_exit_notification_interval))
             {
-                register_signal(c, SIGTERM, "connection-reset-inetd");
-                msg(D_STREAM_ERRORS, "Connection reset, inetd/xinetd exit [%d]", status);
+                msg(D_STREAM_ERRORS, "Connection reset during exit notification period, ignoring [%d]", status);
+                management_sleep(1);
             }
             else
             {
-                if (event_timeout_defined(&c->c2.explicit_exit_notification_interval))
-                {
-                    msg(D_STREAM_ERRORS, "Connection reset during exit notification period, ignoring [%d]", status);
-                    management_sleep(1);
-                }
-                else
-                {
-                    register_signal(c, SIGUSR1, "connection-reset"); /* SOFT-SIGUSR1 -- TCP connection reset */
-                    msg(D_STREAM_ERRORS, "Connection reset, restarting [%d]", status);
-                }
+                register_signal(c, SIGUSR1, "connection-reset"); /* SOFT-SIGUSR1 -- TCP connection reset */
+                msg(D_STREAM_ERRORS, "Connection reset, restarting [%d]", status);
             }
         }
         perf_pop();
src/openvpn/init.c +0 -22
index c3493c42..d234729c 100644
@@ -1236,7 +1236,6 @@ possibly_become_daemon(const struct options *options)
 
     if (options->daemon)
     {
-        ASSERT(!options->inetd);
         /* Don't chdir immediately, but the end of the init sequence, if needed */
 
 #if defined(__APPLE__) && defined(__clang__)
@@ -3449,7 +3448,6 @@ do_init_socket_1(struct context *c, const int mode)
 #endif
                             c->options.ce.bind_local,
                             c->options.ce.remote_float,
-                            c->options.inetd,
                             &c->c1.link_socket_addr,
                             c->options.ipchange,
                             c->plugins,
@@ -3552,23 +3550,6 @@ do_init_first_time(struct context *c)
     }
 }
 
-/*
- * If xinetd/inetd mode, don't allow restart.
- */
-static void
-do_close_check_if_restart_permitted(struct context *c)
-{
-    if (c->options.inetd
-        && (c->sig->signal_received == SIGHUP
-            || c->sig->signal_received == SIGUSR1))
-    {
-        c->sig->signal_received = SIGTERM;
-        msg(M_INFO,
-            PACKAGE_NAME
-            " started by inetd/xinetd cannot restart... Exiting.");
-    }
-}
-
 /*
  * free buffers
  */
@@ -4462,9 +4443,6 @@ close_instance(struct context *c)
         || c->mode == CM_CHILD_UDP
         || c->mode == CM_TOP)
     {
-        /* if xinetd/inetd mode, don't allow restart */
-        do_close_check_if_restart_permitted(c);
-
 #ifdef USE_COMP
         if (c->c2.comp_context)
         {
src/openvpn/misc.c +0 -20
index c0c72dd7..feaefb3b 100644
@@ -75,26 +75,6 @@ set_std_files_to_null(bool stdin_only)
 #endif
 }
 
-/*
- *  dup inetd/xinetd socket descriptor and save
- */
-
-int inetd_socket_descriptor = SOCKET_UNDEFINED; /* GLOBAL */
-
-void
-save_inetd_socket_descriptor(void)
-{
-    inetd_socket_descriptor = INETD_SOCKET_DESCRIPTOR;
-#if defined(HAVE_DUP) && defined(HAVE_DUP2)
-    /* use handle passed by inetd/xinetd */
-    if ((inetd_socket_descriptor = dup(INETD_SOCKET_DESCRIPTOR)) < 0)
-    {
-        msg(M_ERR, "INETD_SOCKET_DESCRIPTOR dup(%d) failed", INETD_SOCKET_DESCRIPTOR);
-    }
-    set_std_files_to_null(true);
-#endif
-}
-
 /*
  * Prepend a random string to hostname to prevent DNS caching.
  * For example, foo.bar.gov would be modified to <random-chars>.foo.bar.gov.
src/openvpn/misc.h +0 -7
index e4342b0d..9b018eb5 100644
@@ -32,9 +32,6 @@
 #include "buffer.h"
 #include "platform.h"
 
-/* socket descriptor passed by inetd/xinetd server to us */
-#define INETD_SOCKET_DESCRIPTOR 0
-
 /* forward declarations */
 struct plugin_list;
 
@@ -42,10 +39,6 @@ struct plugin_list;
 /* Set standard file descriptors to /dev/null */
 void set_std_files_to_null(bool stdin_only);
 
-/* dup inetd/xinetd socket descriptor and save */
-extern int inetd_socket_descriptor;
-void save_inetd_socket_descriptor(void);
-
 /* Make arrays of strings */
 
 const char **make_arg_array(const char *first, const char *parms, struct gc_arena *gc);
src/openvpn/options.c +0 -121

158 lines not on this page · raw message

src/openvpn/options.h +0 -3
index 5b6d9441..56228668 100644
@@ -319,9 +319,6 @@ struct options
 
     int remap_sigusr1;
 
-    /* inetd modes defined in socket.h */
-    int inetd;
-
     bool log;
     bool suppress_timestamps;
     bool machine_readable_output;
src/openvpn/socket.c +54 -137

259 lines not on this page · raw message

src/openvpn/socket.h +0 -6
index 7aeae527..4099f6ea 100644
@@ -188,11 +188,6 @@ struct link_socket
     struct cached_dns_entry *dns_cache;
     bool bind_local;
 
-#define INETD_NONE   0
-#define INETD_WAIT   1
-#define INETD_NOWAIT 2
-    int inetd;
-
 #define LS_MODE_DEFAULT           0
 #define LS_MODE_TCP_LISTEN        1
 #define LS_MODE_TCP_ACCEPT_FROM   2
@@ -318,7 +313,6 @@ link_socket_init_phase1(struct link_socket *sock,
 #endif
                         bool bind_local,
                         bool remote_float,
-                        int inetd,
                         struct link_socket_addr *lsa,
                         const char *ipchange_command,
                         const struct plugin_list *plugins,
Signature · 1 line
2.26.2
Acked-by on v1 1/1
#1 lore raw

stared-at-code (which is quite a lot of changes, some of which want "-w"), ran on the client and server test rigs (breaks --inetd mode, whoa, but everything else works :-) ). Looks good!

Removal of --inetd has been pending for multiple months now (since before the release of 2.5.0) and nobody has ever asked for it to stay - so, gone it is, now.

Your patch has been applied to the master branch.

commit ce652e7d3865dcdebfdc9233d9f46dfbcc2a6e2b

Author: Arne Schwabe
Date:   Mon Dec 14 18:24:07 2020 +0100
     Remove inetd support from OpenVPN

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg21360.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering