Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add openconnect executable to config #37

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions configs/oc-client.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"XMLProfile": "/var/lib/oc-daemon/profile.xml",
"VPNServer": "My VPN Server Name",
"User": "$USER",
"OpenConnect": "openconnect",
"Protocol": "anyconnect",
"UserAgent": "AnyConnect",
"Quiet": true,
Expand Down
1 change: 1 addition & 0 deletions configs/oc-daemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"ListenTCP": true
},
"OpenConnect": {
"OpenConnect": "openconnect",
"XMLProfile": "/var/lib/oc-daemon/profile.xml",
"VPNCScript": "/usr/bin/oc-daemon-vpncscript",
"VPNDevice": "oc-daemon-tun0",
Expand Down
1 change: 1 addition & 0 deletions internal/daemon/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func TestConfigLoad(t *testing.T) {
"ListenTCP": true
},
"OpenConnect": {
"OpenConnect": "openconnect",
"XMLProfile": "/var/lib/oc-daemon/profile.xml",
"VPNCScript": "/usr/bin/oc-daemon-vpncscript",
"VPNDevice": "oc-daemon-tun0",
Expand Down
8 changes: 8 additions & 0 deletions internal/ocrunner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package ocrunner
import "strconv"

var (
// OpenConnect is the default openconnect executable
OpenConnect = "openconnect"

// XMLProfile is the default AnyConnect Profile
XMLProfile = "/var/lib/oc-daemon/profile.xml"

Expand Down Expand Up @@ -36,6 +39,8 @@ var (

// Config is the configuration for an openconnect connection runner
type Config struct {
OpenConnect string

XMLProfile string
VPNCScript string
VPNDevice string
Expand All @@ -53,6 +58,7 @@ type Config struct {
// Valid returns whether the openconnect configuration is valid
func (c *Config) Valid() bool {
if c == nil ||
c.OpenConnect == "" ||
c.XMLProfile == "" ||
c.VPNCScript == "" ||
c.VPNDevice == "" ||
Expand All @@ -76,6 +82,8 @@ func (c *Config) Valid() bool {
// NewConfig returns a new configuration for an openconnect connection runner
func NewConfig() *Config {
return &Config{
OpenConnect: OpenConnect,

XMLProfile: XMLProfile,
VPNCScript: VPNCScript,
VPNDevice: VPNDevice,
Expand Down
5 changes: 5 additions & 0 deletions internal/ocrunner/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ func TestConfigValid(t *testing.T) {
nil,
{},
{
OpenConnect: "openconnect",
XMLProfile: "/test/profile",
VPNCScript: "/test/vpncscript",
VPNDevice: "test-device",
PIDFile: "/test/pid",
PIDPermissions: "invalid",
},
{
OpenConnect: "openconnect",
XMLProfile: "/test/profile",
VPNCScript: "/test/vpncscript",
VPNDevice: "test-device",
Expand All @@ -38,6 +40,7 @@ func TestConfigValid(t *testing.T) {
for _, valid := range []*Config{
NewConfig(),
{
OpenConnect: "openconnect",
XMLProfile: "/test/profile",
VPNCScript: "/test/vpncscript",
VPNDevice: "test-device",
Expand All @@ -57,6 +60,8 @@ func TestConfigValid(t *testing.T) {
// TestNewConfig tests NewConfig
func TestNewConfig(t *testing.T) {
want := &Config{
OpenConnect: OpenConnect,

XMLProfile: XMLProfile,
VPNCScript: VPNCScript,
VPNDevice: VPNDevice,
Expand Down
4 changes: 2 additions & 2 deletions internal/ocrunner/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (c *Connect) handleConnect(e *ConnectEvent) {
parameters = append(parameters, device)
}
parameters = append(parameters, c.config.ExtraArgs...)
c.command = exec.Command("openconnect", parameters...)
c.command = exec.Command(c.config.OpenConnect, parameters...)

// run command, pass login info to stdin
b := bytes.NewBufferString(e.login.Cookie)
Expand Down Expand Up @@ -316,7 +316,7 @@ func CleanupConnect(config *Config) {
return
}

if !strings.HasPrefix(string(cmdLine), "openconnect") {
if !strings.HasPrefix(string(cmdLine), config.OpenConnect) {
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ var authenticate = func(d *DBusClient) error {
parameters = append(parameters, config.ExtraArgs...)
parameters = append(parameters, config.VPNServer)

command := exec.Command("openconnect", parameters...)
command := exec.Command(config.OpenConnect, parameters...)

// run command: allow user input, show stderr, buffer stdout
var b bytes.Buffer
Expand Down
32 changes: 19 additions & 13 deletions pkg/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ var (
// of the system configuration is stored
SystemConfigDirPath = "/var/lib"

// OpenConnect is the openconnect executable
OpenConnect = "openconnect"

// Protocol is the protocol used by openconnect
Protocol = "anyconnect"

Expand Down Expand Up @@ -51,12 +54,13 @@ type Config struct {
User string
Password string `json:"-"`

Protocol string
UserAgent string
Quiet bool
NoProxy bool
ExtraEnv []string
ExtraArgs []string
OpenConnect string
Protocol string
UserAgent string
Quiet bool
NoProxy bool
ExtraEnv []string
ExtraArgs []string
}

// Copy returns a copy of Config
Expand Down Expand Up @@ -87,6 +91,7 @@ func (c *Config) Valid() bool {
c.ClientKey == "" ||
c.XMLProfile == "" ||
c.VPNServer == "" ||
c.OpenConnect == "" ||
c.Protocol == "" ||
c.UserAgent == "" {
// invalid
Expand Down Expand Up @@ -136,13 +141,14 @@ func (c *Config) Save(file string) error {
// NewConfig returns a new Config
func NewConfig() *Config {
return &Config{
XMLProfile: xmlprofile.SystemProfile,
Protocol: Protocol,
UserAgent: UserAgent,
Quiet: Quiet,
NoProxy: NoProxy,
ExtraEnv: ExtraEnv,
ExtraArgs: ExtraArgs,
XMLProfile: xmlprofile.SystemProfile,
OpenConnect: OpenConnect,
Protocol: Protocol,
UserAgent: UserAgent,
Quiet: Quiet,
NoProxy: NoProxy,
ExtraEnv: ExtraEnv,
ExtraArgs: ExtraArgs,
}
}

Expand Down
13 changes: 7 additions & 6 deletions pkg/client/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ func TestLoadConfig(t *testing.T) {
VPNServer: "server.example.com",
User: "user1",

Protocol: "test",
UserAgent: "agent",
Quiet: true,
NoProxy: true,
ExtraEnv: []string{"oc_daemon_var_is_not=used"},
ExtraArgs: []string{"--arg-does-not=exist"},
OpenConnect: "openconnect",
Protocol: "test",
UserAgent: "agent",
Quiet: true,
NoProxy: true,
ExtraEnv: []string{"oc_daemon_var_is_not=used"},
ExtraArgs: []string{"--arg-does-not=exist"},
}

// create temporary file
Expand Down