From 084c194da332577d892c866ae41f323c3dd46207 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 22 Jul 2020 11:13:57 +0200 Subject: [PATCH 1/3] Enable building on unsupported systems --- ...nment_darwin.go => environment_default.go} | 2 + network/state/system_default.go | 43 +++++++++++++++++++ process/process_default.go | 28 ++++++++++++ process/process_linux.go | 2 +- 4 files changed, 74 insertions(+), 1 deletion(-) rename netenv/{environment_darwin.go => environment_default.go} (96%) create mode 100644 network/state/system_default.go create mode 100644 process/process_default.go diff --git a/netenv/environment_darwin.go b/netenv/environment_default.go similarity index 96% rename from netenv/environment_darwin.go rename to netenv/environment_default.go index b9f7c0da..f4312c2f 100644 --- a/netenv/environment_darwin.go +++ b/netenv/environment_default.go @@ -1,3 +1,5 @@ +//+build !windows,!linux + package netenv import "net" diff --git a/network/state/system_default.go b/network/state/system_default.go new file mode 100644 index 00000000..64cff2fb --- /dev/null +++ b/network/state/system_default.go @@ -0,0 +1,43 @@ +// +build !windows,!linux + +package state + +import ( + "time" + + "github.com/safing/portbase/config" + "github.com/safing/portmaster/network/socket" +) + +func init() { + // This increases performance on unsupported system. + // It's not critical at all and does not break anything if it fails. + go func() { + // Wait for one minute before we set the default value, as we + // currently cannot easily integrate into the startup procedure. + time.Sleep(1 * time.Minute) + + // We cannot use process.CfgOptionEnableProcessDetectionKey, because of an import loop. + config.SetDefaultConfigOption("core/enableProcessDetection", false) + }() +} + +func getTCP4Table() (connections []*socket.ConnectionInfo, listeners []*socket.BindInfo, err error) { + return nil, nil, nil +} + +func getTCP6Table() (connections []*socket.ConnectionInfo, listeners []*socket.BindInfo, err error) { + return nil, nil, nil +} + +func getUDP4Table() (binds []*socket.BindInfo, err error) { + return nil, nil +} + +func getUDP6Table() (binds []*socket.BindInfo, err error) { + return nil, nil +} + +func checkPID(socketInfo socket.Info, connInbound bool) (pid int, inbound bool, err error) { + return socketInfo.GetPID(), connInbound, nil +} diff --git a/process/process_default.go b/process/process_default.go new file mode 100644 index 00000000..48f32cd0 --- /dev/null +++ b/process/process_default.go @@ -0,0 +1,28 @@ +//+build !windows,!linux + +package process + +// IsUser returns whether the process is run by a normal user. +func (p *Process) IsUser() bool { + return true +} + +// IsAdmin returns whether the process is run by an admin user. +func (p *Process) IsAdmin() bool { + return false +} + +// IsSystem returns whether the process is run by the operating system. +func (p *Process) IsSystem() bool { + return false +} + +// IsKernel returns whether the process is the Kernel. +func (p *Process) IsKernel() bool { + return p.Pid == 0 +} + +// specialOSInit does special OS specific Process initialization. +func (p *Process) specialOSInit() { + +} diff --git a/process/process_linux.go b/process/process_linux.go index 44a21098..a4702588 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -7,7 +7,7 @@ func (p *Process) IsUser() bool { // IsAdmin returns whether the process is run by an admin user. func (p *Process) IsAdmin() bool { - return p.UserID >= 0 + return p.UserID >= 0 && p.UserID < 1000 } // IsSystem returns whether the process is run by the operating system. From f9a74b71c72aa8aa60380f25092d9ed02d48a060 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 22 Jul 2020 11:14:18 +0200 Subject: [PATCH 2/3] Add darwin to core and control build scripts --- pack_core | 2 ++ pmctl/pack | 2 ++ 2 files changed, 4 insertions(+) diff --git a/pack_core b/pack_core index edd368f4..de86b2f8 100755 --- a/pack_core +++ b/pack_core @@ -70,11 +70,13 @@ function build { function check_all { GOOS=linux GOARCH=amd64 check GOOS=windows GOARCH=amd64 check + GOOS=darwin GOARCH=amd64 check } function build_all { GOOS=linux GOARCH=amd64 build GOOS=windows GOARCH=amd64 build + GOOS=darwin GOARCH=amd64 build } case $1 in diff --git a/pmctl/pack b/pmctl/pack index 6e050ec4..1e83e602 100755 --- a/pmctl/pack +++ b/pmctl/pack @@ -70,11 +70,13 @@ function build { function check_all { GOOS=linux GOARCH=amd64 check GOOS=windows GOARCH=amd64 check + GOOS=darwin GOARCH=amd64 check } function build_all { GOOS=linux GOARCH=amd64 build GOOS=windows GOARCH=amd64 build + GOOS=darwin GOARCH=amd64 build } case $1 in From 430031d4acb2f27c60fc4f3ad9dc9e7220f9ec1d Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 22 Jul 2020 11:46:59 +0200 Subject: [PATCH 3/3] Remove unused user scope checks --- process/process_default.go | 15 --------------- process/process_linux.go | 15 --------------- process/process_windows.go | 17 ----------------- 3 files changed, 47 deletions(-) diff --git a/process/process_default.go b/process/process_default.go index 48f32cd0..5266462b 100644 --- a/process/process_default.go +++ b/process/process_default.go @@ -2,21 +2,6 @@ package process -// IsUser returns whether the process is run by a normal user. -func (p *Process) IsUser() bool { - return true -} - -// IsAdmin returns whether the process is run by an admin user. -func (p *Process) IsAdmin() bool { - return false -} - -// IsSystem returns whether the process is run by the operating system. -func (p *Process) IsSystem() bool { - return false -} - // IsKernel returns whether the process is the Kernel. func (p *Process) IsKernel() bool { return p.Pid == 0 diff --git a/process/process_linux.go b/process/process_linux.go index a4702588..90dcfecc 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -1,20 +1,5 @@ package process -// IsUser returns whether the process is run by a normal user. -func (p *Process) IsUser() bool { - return p.UserID >= 1000 -} - -// IsAdmin returns whether the process is run by an admin user. -func (p *Process) IsAdmin() bool { - return p.UserID >= 0 && p.UserID < 1000 -} - -// IsSystem returns whether the process is run by the operating system. -func (p *Process) IsSystem() bool { - return p.UserID == 0 -} - // IsKernel returns whether the process is the Kernel. func (p *Process) IsKernel() bool { return p.Pid == 0 diff --git a/process/process_windows.go b/process/process_windows.go index 31bbdc73..2a59c3d1 100644 --- a/process/process_windows.go +++ b/process/process_windows.go @@ -2,28 +2,11 @@ package process import ( "fmt" - "strings" "github.com/safing/portbase/log" "github.com/safing/portbase/utils/osdetail" ) -// IsUser returns whether the process is run by a normal user. -func (p *Process) IsUser() bool { - return p.Pid != 4 && // Kernel - !strings.HasPrefix(p.UserName, "NT") // NT-Authority (localized!) -} - -// IsAdmin returns whether the process is run by an admin user. -func (p *Process) IsAdmin() bool { - return strings.HasPrefix(p.UserName, "NT") // NT-Authority (localized!) -} - -// IsSystem returns whether the process is run by the operating system. -func (p *Process) IsSystem() bool { - return p.Pid == 4 -} - // IsKernel returns whether the process is the Kernel. func (p *Process) IsKernel() bool { return p.Pid == 4