]> git.ipfire.org Git - thirdparty/openvpn.git/commit
clean up / rewrite sample-plugins/defer/simple.c
authorGert Doering <gert@greenie.muc.de>
Thu, 21 Jan 2021 17:25:36 +0000 (18:25 +0100)
committerGert Doering <gert@greenie.muc.de>
Sat, 23 Jan 2021 13:28:43 +0000 (14:28 +0100)
commit452e016cba977cb1c109e74977029b9c0de33de2
tree44c42edb04d78f62ed69e2c1b53af27722b45d80
parent6a0c51baaa4d2b329183601ec35d3d16f127519e
clean up / rewrite sample-plugins/defer/simple.c

If we ship something that we consider a form of documentation
"this is how to write an OpenVPN plugin" it should meet our standards
for secure and modern code.  This plugin did neither.

  - get rid of system() calls, especially those that enabled a
    remote-root exploit if this code was used "as is"

  - change logging from printf() to OpenVPN's plugin_log()

  - this requires changing to openvpn_plugin_open_v3() to get
    to the function pointers

  - change wacky "background and sleep in the shell call" to the
    double-fork/waitpid model we use in plugins/auth-pam
    (copy-paste code reuse)

  - OpenVPN 2.5 and later react badly to OPENVPN_PLUGIN_FUNC_ERROR
    returns to OPENVPN_PLUGIN_ENABLE_PF calls (SIGSEGV crash), so
    always return SUCCESS.  Only hook ENABLE_PF if that functionality
    is actually requested ("setenv test_packet_filter NN").

  - change deeply-nested functions auth_user_pass_verify() and
    tls_final() to use early-return style

  - actually make defered PF setup *work* with recent OpenVPNs
    (pre-creating temp files broke this, so unlink() the pre-created
    file in the ENABLE_PF hook, and re-create asyncronously later)

  - add lots of comments explaining why we do things this way

Security issue reported by "oxr463" on HackerOne.

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20210121172536.32500-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg21466.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
sample/sample-plugins/defer/simple.c