From: Michael Tremer Date: Sat, 23 Mar 2024 14:03:36 +0000 (+0100) Subject: openvpnctrl: Rewrite the entire thing X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3fc65c5c1981f11a241c76b33eef75d922f423db;p=people%2Fms%2Fipfire-2.x.git openvpnctrl: Rewrite the entire thing This binary because a major headache as it has been changed so many times by so many people neglegting the code quality. Therefore, the logic has now been moved into initscripts and the binary changed so that it only serves as a SUID wrapper to call the initscripts. Signed-off-by: Michael Tremer --- diff --git a/html/cgi-bin/ovpnmain.cgi b/html/cgi-bin/ovpnmain.cgi index a79ed4d44..b5a8fd6df 100755 --- a/html/cgi-bin/ovpnmain.cgi +++ b/html/cgi-bin/ovpnmain.cgi @@ -936,10 +936,10 @@ sub writecollectdconf { ### if ($cgiparams{'ACTION'} eq $Lang::tr{'start ovpn server'}) { - &General::system("/usr/local/bin/openvpnctrl", "-s"); + &General::system("/usr/local/bin/openvpnctrl", "rw", "start"); } elsif ($cgiparams{'ACTION'} eq $Lang::tr{'stop ovpn server'}) { - &General::system("/usr/local/bin/openvpnctrl", "-k"); + &General::system("/usr/local/bin/openvpnctrl", "rw", "stop"); } ### @@ -1399,8 +1399,8 @@ SETTINGS_ERROR: my $file = ''; &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); - # Kill all N2N connections - &General::system("/usr/local/bin/openvpnctrl", "-kn2n"); + # Stop all N2N connections + &General::system("/usr/local/bin/openvpnctrl", "n2n", "stop"); foreach my $key (keys %confighash) { my $name = $confighash{$cgiparams{'$key'}}[1]; @@ -1409,7 +1409,7 @@ SETTINGS_ERROR: delete $confighash{$cgiparams{'$key'}}; } - &General::system("/usr/local/bin/openvpnctrl", "-drrd", "$name"); + &General::system("/usr/local/bin/openvpnctrl", "n2n", "delete", "$name"); } while ($file = glob("${General::swroot}/ovpn/ca/*")) { unlink $file; @@ -2167,7 +2167,7 @@ END &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ - &General::system("/usr/local/bin/openvpnctrl", "-sn2n", "$confighash{$cgiparams{'KEY'}}[1]"); + &General::system("/usr/local/bin/openvpnctrl", "n2n", "start", "$confighash{$cgiparams{'KEY'}}[1]"); &writecollectdconf(); } } else { @@ -2177,7 +2177,7 @@ END if ($confighash{$cgiparams{'KEY'}}[3] eq 'net'){ if ($n2nactive ne '') { - &General::system("/usr/local/bin/openvpnctrl", "-kn2n", "$confighash{$cgiparams{'KEY'}}[1]"); + &General::system("/usr/local/bin/openvpnctrl", "n2n", "stop", "$confighash{$cgiparams{'KEY'}}[1]"); &writecollectdconf(); } } @@ -2535,7 +2535,7 @@ else if ($confighash{$cgiparams{'KEY'}}[3] eq 'net') { # Stop the N2N connection before it is removed - &General::system("/usr/local/bin/openvpnctrl", "-kn2n", "$confighash{$cgiparams{'KEY'}}[1]"); + &General::system("/usr/local/bin/openvpnctrl", "n2n", "stop", "$confighash{$cgiparams{'KEY'}}[1]"); my $conffile = glob("${General::swroot}/ovpn/n2nconf/$confighash{$cgiparams{'KEY'}}[1]/$confighash{$cgiparams{'KEY'}}[1].conf"); my $certfile = glob("${General::swroot}/ovpn/certs/$confighash{$cgiparams{'KEY'}}[1].p12"); @@ -2576,7 +2576,7 @@ else # Update collectd configuration and delete all RRD files of the removed connection &writecollectdconf(); - &General::system("/usr/local/bin/openvpnctrl", "-drrd", "$confighash{$cgiparams{'KEY'}}[1]"); + &General::system("/usr/local/bin/openvpnctrl", "n2n", "delete", "$confighash{$cgiparams{'KEY'}}[1]"); delete $confighash{$cgiparams{'KEY'}}; &General::system("/usr/bin/openssl", "ca", "-gencrl", "-out", "${General::swroot}/ovpn/crls/cacrl.pem", "-config", "${General::swroot}/ovpn/openssl/ovpn.cnf"); @@ -4548,7 +4548,7 @@ if ($cgiparams{'TYPE'} eq 'net') { if ($cgiparams{'TYPE'} eq 'net') { if (-e "/var/run/$confighash{$key}[1]n2n.pid") { - &General::system("/usr/local/bin/openvpnctrl", "-kn2n", "$confighash{$cgiparams{'KEY'}}[1]"); + &General::system("/usr/local/bin/openvpnctrl", "n2n", "stop", "$confighash{$cgiparams{'KEY'}}[1]"); &General::readhasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); my $key = $cgiparams{'KEY'}; @@ -4562,7 +4562,7 @@ if ($cgiparams{'TYPE'} eq 'net') { $confighash{$key}[0] = 'on'; &General::writehasharray("${General::swroot}/ovpn/ovpnconfig", \%confighash); - &General::system("/usr/local/bin/openvpnctrl", "-sn2n", "$confighash{$cgiparams{'KEY'}}[1]"); + &General::system("/usr/local/bin/openvpnctrl", "n2n", "start", "$confighash{$cgiparams{'KEY'}}[1]"); } } diff --git a/src/misc-progs/openvpnctrl.c b/src/misc-progs/openvpnctrl.c index cb5855015..cd2a9ca4d 100644 --- a/src/misc-progs/openvpnctrl.c +++ b/src/misc-progs/openvpnctrl.c @@ -1,647 +1,41 @@ -#define _XOPEN_SOURCE 500 -#include +/* This file is part of the IPFire Firewall. + * + * This program is distributed under the terms of the GNU General Public + * Licence. See the file COPYING for details. + * + */ + #include #include -#include -#include -#include -#include -#include -#include -#include -#include "setuid.h" -#include "netutil.h" -#include "libsmooth.h" - -#define noovpndebug - -// global vars - struct keyvalue *kv = NULL; - -// consts -char OVPNINPUT[STRING_SIZE] = "OVPNINPUT"; -char OVPNBLOCK[STRING_SIZE] = "OVPNBLOCK"; -char OVPNNAT[STRING_SIZE] = "OVPNNAT"; -char WRAPPERVERSION[STRING_SIZE] = "ipfire-2.2.4"; - -struct connection_struct { - char name[STRING_SIZE]; - char type[STRING_SIZE]; - char proto[STRING_SIZE]; - char status[STRING_SIZE]; - char local_subnet[STRING_SIZE]; - char transfer_subnet[STRING_SIZE]; - char role[STRING_SIZE]; - char port[STRING_SIZE]; - struct connection_struct *next; -}; - -typedef struct connection_struct connection; - -static int recursive_remove_callback(const char* fpath, const struct stat* sb, int typeflag, struct FTW* ftwbuf) { - int rv = remove(fpath); - if (rv) - perror(fpath); - - return rv; -} - -static int recursive_remove(const char* path) { - return nftw(path, recursive_remove_callback, 64, FTW_DEPTH | FTW_PHYS); -} - -void exithandler(void) -{ - if(kv) - freekeyvalues(kv); - if (ifacefile) - fclose(ifacefile); -} - -void usage(void) -{ -#ifdef ovpndebug - printf("Wrapper for OpenVPN %s-debug\n", WRAPPERVERSION); -#else - printf("Wrapper for OpenVPN %s\n", WRAPPERVERSION); -#endif - printf("openvpnctrl