From a3fa1b1285609820a944c04497c21db5f5dff679 Mon Sep 17 00:00:00 2001 From: Stephen Watt Date: Thu, 21 Sep 2017 13:40:21 -0400 Subject: [PATCH] Slightly kludgy workaround for gtk-3.20 dependence in gtk-3.18 builds. Added SGFW_CONF environment variable for overriding default SGFW configuration path. Added SGFW_SOCKS_CONFIG environment variable for overriding default SGFW SOCKS json config file path. Updated readme with information on building outside SGOS. --- README-DEV.txt | 12 ++++++++++++ fw-settings/builder.go | 14 ++++++++++++++ sgfw/config.go | 8 +++++++- sgfw/prompt.go | 6 +++--- sgfw/sgfw.go | 10 ++++++++-- sources/etc/sgfw/sgfw.conf | 5 +++++ 6 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 sources/etc/sgfw/sgfw.conf diff --git a/README-DEV.txt b/README-DEV.txt index a68758e..63a0c7c 100644 --- a/README-DEV.txt +++ b/README-DEV.txt @@ -1,3 +1,15 @@ +*** Please also refer to the notes found in fw-prompt/README.txt: you will need to copy both files in sources/etc/dbus-1/system.d/ into /etc/dbus-1/system.d/ + +Build complications: +You may need to run the following first, esp. on Ubuntu 16.04: +go install -tags gtk_3_18 github.com/gotk3/gotk3/gtk + +and build with the following: +go build -v -tags gtk_3_18 -gcflags "-N -l" fw-prompt + +Otherwise standard go build and go install procedures should suffice. + + Before running fw-daemon, make sure to export: GODEBUG=cgocheck=0 Also, here's a default fw-daemon-socks.json config file: diff --git a/fw-settings/builder.go b/fw-settings/builder.go index c66bca2..b8647c6 100644 --- a/fw-settings/builder.go +++ b/fw-settings/builder.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "regexp" "reflect" "github.com/gotk3/gotk3/glib" @@ -35,6 +36,19 @@ func builderForDefinition(uiName string) *gtk.Builder { template := getDefinitionWithFileFallback(uiName) + maj := gtk.GetMajorVersion() + min := gtk.GetMinorVersion() + + if ((maj == 3) && (min < 20)) { + fmt.Fprintf(os.Stderr, + "Attempting runtime work-around for older versions of libgtk-3...\n"); + dep_re := regexp.MustCompile(`<\s?property\s+name\s?=\s?"icon_size"\s?>.+<\s?/property\s?>`) + template = dep_re.ReplaceAllString(template, ``) + + dep_re2 := regexp.MustCompile(`version\s?=\s?"3.20"`) + template = dep_re2.ReplaceAllString(template, `version="3.18"`) + } + builder, err := gtk.BuilderNew() if err != nil { //We cant recover from this diff --git a/sgfw/config.go b/sgfw/config.go index bacd7cc..eaf24a1 100644 --- a/sgfw/config.go +++ b/sgfw/config.go @@ -27,7 +27,13 @@ type FirewallConfigs struct { var FirewallConfig FirewallConfigs func _readConfig(file string) []byte { - f, err := os.Open(configDefaultPath) + envFile := os.Getenv("SGFW_CONF") + + if envFile != "" { + file = envFile + } + + f, err := os.Open(file) if err != nil { log.Warning(err.Error()) return []byte{} diff --git a/sgfw/prompt.go b/sgfw/prompt.go index 18a0a09..71e7752 100644 --- a/sgfw/prompt.go +++ b/sgfw/prompt.go @@ -53,11 +53,11 @@ func (p *prompter) prompt(policy *Policy) { func (p *prompter) promptLoop() { p.lock.Lock() for { - fmt.Println("promptLoop() outer") +// fmt.Println("XXX: promptLoop() outer") for p.processNextPacket() { - fmt.Println("promptLoop() inner") +// fmt.Println("XXX: promptLoop() inner") } - fmt.Println("promptLoop() wait") +// fmt.Println("promptLoop() wait") p.cond.Wait() } } diff --git a/sgfw/sgfw.go b/sgfw/sgfw.go index af8faf9..8aa49ac 100644 --- a/sgfw/sgfw.go +++ b/sgfw/sgfw.go @@ -241,7 +241,13 @@ func Main() { wg := sync.WaitGroup{} - config, err := loadSocksConfiguration(defaultSocksCfgPath) + scfile := os.Getenv("SGFW_SOCKS_CONFIG") + + if scfile == "" { + scfile = defaultSocksCfgPath + } + + config, err := loadSocksConfiguration(scfile) if err != nil && !os.IsNotExist(err) { panic(err) } @@ -250,7 +256,7 @@ func Main() { chain := NewSocksChain(socksConfig, &wg, fw) chain.start() } else { - log.Notice("Did not find SOCKS5 configuration file at", defaultSocksCfgPath, "; ignoring subsystem...") + log.Notice("Did not find SOCKS5 configuration file at", scfile, "; ignoring subsystem...") } dbusp, err = newDbusObjectPrompt() diff --git a/sources/etc/sgfw/sgfw.conf b/sources/etc/sgfw/sgfw.conf new file mode 100644 index 0000000..5dbc668 --- /dev/null +++ b/sources/etc/sgfw/sgfw.conf @@ -0,0 +1,5 @@ +log_level="NOTICE" +log_redact=false +prompt_expanded=true +prompt_expert=true +default_action="SESSION"