From e3ab56486ba1ddf04856852fb922c98f112aab9d Mon Sep 17 00:00:00 2001 From: Stephen Watt Date: Thu, 21 Sep 2017 14:31:31 -0400 Subject: [PATCH] Upgraded standalone fw-prompt for DBus compatibility with new fw-daemon. Averted potential panic issue in SOCKS5 listener. Fixed strange whole-window scrolling behavior in fw-prompt. Removed verbose debug output in fw-prompt. --- fw-prompt/dbus.go | 6 +++--- fw-prompt/fw-prompt.go | 23 ++++++++++++++++------- sgfw/prompt.go | 10 +++++----- sgfw/socks_server_chain.go | 6 ++++++ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/fw-prompt/dbus.go b/fw-prompt/dbus.go index b4bfc38..3344a62 100644 --- a/fw-prompt/dbus.go +++ b/fw-prompt/dbus.go @@ -63,9 +63,9 @@ func newDbusServer() (*dbusServer, error) { } func (ds *dbusServer) RequestPrompt(application, icon, path, address string, port int32, ip, origin, proto string, uid, gid int32, username, groupname string, pid int32, sandbox string, - optstring string, expanded, expert bool, action int32) (int32, string, *dbus.Error) { - log.Printf("request prompt: app = %s, icon = %s, path = %s, address = %s, action = %v\n", application, icon, path, address, action) - decision := addRequest(nil, path, proto, int(pid), ip, address, int(port), int(uid), int(gid), origin, optstring, sandbox) + is_socks bool, optstring string, expanded, expert bool, action int32) (int32, string, *dbus.Error) { + log.Printf("request prompt: app = %s, icon = %s, path = %s, address = %s, is_socks = %v, action = %v\n", application, icon, path, address, is_socks, action) + decision := addRequest(nil, path, proto, int(pid), ip, address, int(port), int(uid), int(gid), origin, is_socks, optstring, sandbox) log.Print("Waiting on decision...") decision.Cond.L.Lock() for !decision.Ready { diff --git a/fw-prompt/fw-prompt.go b/fw-prompt/fw-prompt.go index c8c5e8a..5b03297 100644 --- a/fw-prompt/fw-prompt.go +++ b/fw-prompt/fw-prompt.go @@ -101,7 +101,7 @@ func promptInfo(msg string) { } scrollbox.Add(tv) - scrollbox.SetSizeRequest(600, 100) + scrollbox.SetSizeRequest(500, 100) box, err := dialog.GetContentArea() @@ -315,13 +315,21 @@ func createListStore(general bool) *gtk.ListStore { return listStore } -func addRequest(listStore *gtk.ListStore, path, proto string, pid int, ipaddr, hostname string, port, uid, gid int, origin, optstring string, sandbox string) *decisionWaiter { +func addRequest(listStore *gtk.ListStore, path, proto string, pid int, ipaddr, hostname string, port, uid, gid int, origin string, is_socks bool, optstring string, sandbox string) *decisionWaiter { if listStore == nil { listStore = globalLS } iter := listStore.Append() + if (is_socks) { + if ((optstring != "") && (strings.Index(optstring, "SOCKS") == -1)) { + optstring = "SOCKS5 / " + optstring + } else if (optstring == "") { + optstring = "SOCKS5" + } + } + colVals := make([]interface{}, 11) colVals[0] = 1 colVals[1] = path @@ -744,8 +752,6 @@ func main() { log.Fatal("Unable to create scrolled window:", err) } - scrollbox.Add(box) - tv, err := gtk.TreeViewNew() if err != nil { @@ -839,7 +845,9 @@ func main() { box.PackStart(bb, false, false, 5) box.PackStart(editbox, false, false, 5) - box.PackStart(tv, false, true, 5) + scrollbox.Add(tv) +// box.PackStart(tv, false, true, 5) + box.PackStart(scrollbox, false, true, 5) tv.AppendColumn(createColumn("#", 0)) tv.AppendColumn(createColumn("Path", 1)) @@ -975,8 +983,9 @@ func main() { }) scrollbox.SetSizeRequest(600, 400) - Notebook.AppendPage(scrollbox, nbLabel) - // setup_settings() +// Notebook.AppendPage(scrollbox, nbLabel) + Notebook.AppendPage(box, nbLabel) +// setup_settings() mainWin.Add(Notebook) if userPrefs.Winheight > 0 && userPrefs.Winwidth > 0 { diff --git a/sgfw/prompt.go b/sgfw/prompt.go index 71e7752..f461a20 100644 --- a/sgfw/prompt.go +++ b/sgfw/prompt.go @@ -79,7 +79,7 @@ func (p *prompter) processNextPacket() bool { empty := true for { pc, empty = p.nextConnection() - fmt.Println("processNextPacket() loop; empty = ", empty, " / pc = ", pc) +// fmt.Println("XXX: processNextPacket() loop; empty = ", empty, " / pc = ", pc) if pc == nil && empty { return false } else if pc == nil { @@ -90,7 +90,7 @@ func (p *prompter) processNextPacket() bool { } p.lock.Unlock() defer p.lock.Lock() - fmt.Println("Waiting for prompt lock go...") +// fmt.Println("XXX: Waiting for prompt lock go...") for { promptLock.Lock() if outstandingPrompts >= MAX_PROMPTS { @@ -106,9 +106,9 @@ func (p *prompter) processNextPacket() bool { break } - fmt.Println("Passed prompt lock!") +// fmt.Println("XXX: Passed prompt lock!") outstandingPrompts++ - fmt.Println("Incremented outstanding to ", outstandingPrompts) +// fmt.Println("XXX: Incremented outstanding to ", outstandingPrompts) promptLock.Unlock() // if !pc.getPrompting() { pc.setPrompting(true) @@ -120,7 +120,7 @@ func (p *prompter) processNextPacket() bool { func processReturn(pc pendingConnection) { promptLock.Lock() outstandingPrompts-- - fmt.Println("Return decremented outstanding to ", outstandingPrompts) +// fmt.Println("XXX: Return decremented outstanding to ", outstandingPrompts) promptLock.Unlock() pc.setPrompting(false) } diff --git a/sgfw/socks_server_chain.go b/sgfw/socks_server_chain.go index 7c652c0..6836d58 100644 --- a/sgfw/socks_server_chain.go +++ b/sgfw/socks_server_chain.go @@ -101,6 +101,12 @@ func (sc *pendingSocksConnection) src() net.IP { } func (sc *pendingSocksConnection) deliverVerdict(v int) { + defer func() { + if r := recover(); r != nil { + log.Warning("SOCKS5 server recovered from panic while delivering firewall verdict:", r) + } + }() + sc.verdict <- v close(sc.verdict) }