Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion openvpn/tunnel/setup_tun_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
package tunnel

import (
gerrors "errors"
"io/ioutil"
"os"
"os/exec"
"runtime"
"strconv"
"strings"

Expand Down Expand Up @@ -52,7 +54,20 @@ type tunDevice struct {

// Setup sets the tunel up
func (service *LinuxTunDeviceManager) Setup(configuration *config.GenericConfig) error {
configuration.SetScriptParam("iproute", config.SimplePath("nonpriv-ip"))

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")
}

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()
Expand Down