From 9a9a262708d6e5e6fc6dfca713a2eac237a52249 Mon Sep 17 00:00:00 2001 From: odkidehliro Date: Sat, 27 Apr 2024 17:49:00 +0330 Subject: [PATCH 1/4] chore: add necessary file check and errors --- openvpn/tunnel/setup_tun_linux.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/openvpn/tunnel/setup_tun_linux.go b/openvpn/tunnel/setup_tun_linux.go index 671d1c6..2af9f72 100644 --- a/openvpn/tunnel/setup_tun_linux.go +++ b/openvpn/tunnel/setup_tun_linux.go @@ -20,6 +20,7 @@ package tunnel import ( + gerrors "errors" "io/ioutil" "os" "os/exec" @@ -52,7 +53,17 @@ type tunDevice struct { // Setup sets the tunel up func (service *LinuxTunDeviceManager) Setup(configuration *config.GenericConfig) error { + + if _, err := os.Stat(configuration.GetFullScriptPath(config.SimplePath("nonpriv-ip"))); gerrors.Is(err, os.ErrNotExist) { + return errors.Wrap(err, "required nonpriv-ip script was not found") + } + configuration.SetScriptParam("iproute", config.SimplePath("nonpriv-ip")) + + if _, err := os.Stat(configuration.GetFullScriptPath(config.SimplePath("prepare-env.sh"))); gerrors.Is(err, os.ErrNotExist) { + return errors.Wrap(err, "required prepare-env.sh script was not found") + } + service.scriptSetup = configuration.GetFullScriptPath(config.SimplePath("prepare-env.sh")) err := service.createDeviceNode() From 2e6c2ee11e86f0592fbd95ddfd6fbf9e9376ecfb Mon Sep 17 00:00:00 2001 From: odkidehliro Date: Sat, 27 Apr 2024 17:49:55 +0330 Subject: [PATCH 2/4] chore: only pass iproute switch when not running as root --- openvpn/tunnel/setup_tun_linux.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/openvpn/tunnel/setup_tun_linux.go b/openvpn/tunnel/setup_tun_linux.go index 2af9f72..5db5e0a 100644 --- a/openvpn/tunnel/setup_tun_linux.go +++ b/openvpn/tunnel/setup_tun_linux.go @@ -54,11 +54,14 @@ type tunDevice struct { // Setup sets the tunel up func (service *LinuxTunDeviceManager) Setup(configuration *config.GenericConfig) error { - if _, err := os.Stat(configuration.GetFullScriptPath(config.SimplePath("nonpriv-ip"))); gerrors.Is(err, os.ErrNotExist) { - return errors.Wrap(err, "required nonpriv-ip script was not found") - } + if os.Geteuid() != 0 { // 0 == root + // only need to pass this option when running as non-root user + if _, err := os.Stat(configuration.GetFullScriptPath(config.SimplePath("nonpriv-ip"))); gerrors.Is(err, os.ErrNotExist) { + return errors.Wrap(err, "required nonpriv-ip script was not found") + } - configuration.SetScriptParam("iproute", config.SimplePath("nonpriv-ip")) + configuration.SetScriptParam("iproute", config.SimplePath("nonpriv-ip")) + } if _, err := os.Stat(configuration.GetFullScriptPath(config.SimplePath("prepare-env.sh"))); gerrors.Is(err, os.ErrNotExist) { return errors.Wrap(err, "required prepare-env.sh script was not found") From b0f80425cc1c1ed388deec70a7d1fd6d37096d47 Mon Sep 17 00:00:00 2001 From: odkidehliro Date: Tue, 30 Apr 2024 05:48:54 +0330 Subject: [PATCH 3/4] fix: the condition for passing iproute --- openvpn/tunnel/setup_tun_linux.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openvpn/tunnel/setup_tun_linux.go b/openvpn/tunnel/setup_tun_linux.go index 5db5e0a..2462115 100644 --- a/openvpn/tunnel/setup_tun_linux.go +++ b/openvpn/tunnel/setup_tun_linux.go @@ -24,6 +24,7 @@ import ( "io/ioutil" "os" "os/exec" + "runtime" "strconv" "strings" @@ -54,7 +55,7 @@ type tunDevice struct { // Setup sets the tunel up func (service *LinuxTunDeviceManager) Setup(configuration *config.GenericConfig) error { - if os.Geteuid() != 0 { // 0 == root + if (runtime.GOOS == "linux" && os.Geteuid() != 0) || runtime.GOOS != "linux" { // 0 == root // only need to pass this option when running as non-root user if _, err := os.Stat(configuration.GetFullScriptPath(config.SimplePath("nonpriv-ip"))); gerrors.Is(err, os.ErrNotExist) { return errors.Wrap(err, "required nonpriv-ip script was not found") From 0c26f833a8fb949c522e16f7e8f6a6c93ace4177 Mon Sep 17 00:00:00 2001 From: odkidehliro Date: Sun, 12 May 2024 04:34:22 +0330 Subject: [PATCH 4/4] fix: update the condition for passing iproute --- openvpn/tunnel/setup_tun_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openvpn/tunnel/setup_tun_linux.go b/openvpn/tunnel/setup_tun_linux.go index 2462115..f74e0a1 100644 --- a/openvpn/tunnel/setup_tun_linux.go +++ b/openvpn/tunnel/setup_tun_linux.go @@ -55,7 +55,7 @@ type tunDevice struct { // Setup sets the tunel up func (service *LinuxTunDeviceManager) Setup(configuration *config.GenericConfig) error { - if (runtime.GOOS == "linux" && os.Geteuid() != 0) || runtime.GOOS != "linux" { // 0 == root + if !(runtime.GOOS == "linux" && os.Geteuid() == 0) { // only need to pass this option when running as non-root user if _, err := os.Stat(configuration.GetFullScriptPath(config.SimplePath("nonpriv-ip"))); gerrors.Is(err, os.ErrNotExist) { return errors.Wrap(err, "required nonpriv-ip script was not found")