Clean up linter errors
This commit is contained in:
@@ -29,7 +29,7 @@ func makeDefaultFallbackProfile() *Profile {
|
||||
Related: status.SecurityLevelDynamic,
|
||||
},
|
||||
ServiceEndpoints: []*EndpointPermission{
|
||||
&EndpointPermission{
|
||||
{
|
||||
Type: EptAny,
|
||||
Protocol: 0,
|
||||
StartPort: 0,
|
||||
|
||||
@@ -15,8 +15,8 @@ type Endpoints []*EndpointPermission
|
||||
|
||||
// EndpointPermission holds a decision about an endpoint.
|
||||
type EndpointPermission struct {
|
||||
Type EPType
|
||||
Value string
|
||||
Type EPType
|
||||
|
||||
Protocol uint8
|
||||
StartPort uint16
|
||||
@@ -55,10 +55,7 @@ const (
|
||||
|
||||
// IsSet returns whether the Endpoints object is "set".
|
||||
func (e Endpoints) IsSet() bool {
|
||||
if len(e) > 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return len(e) > 0
|
||||
}
|
||||
|
||||
// CheckDomain checks the if the given endpoint matches a EndpointPermission in the list.
|
||||
@@ -246,7 +243,7 @@ func (ep EndpointPermission) MatchesIP(domain string, ip net.IP, protocol uint8,
|
||||
}
|
||||
|
||||
func (e Endpoints) String() string {
|
||||
var s []string
|
||||
s := make([]string, 0, len(e))
|
||||
for _, entry := range e {
|
||||
s = append(s, entry.String())
|
||||
}
|
||||
|
||||
@@ -155,15 +155,14 @@ func TestEndpointMatching(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEPString(t *testing.T) {
|
||||
var endpoints Endpoints
|
||||
endpoints = []*EndpointPermission{
|
||||
&EndpointPermission{
|
||||
var endpoints Endpoints = []*EndpointPermission{
|
||||
{
|
||||
Type: EptDomain,
|
||||
Value: "example.com",
|
||||
Protocol: 6,
|
||||
Permit: true,
|
||||
},
|
||||
&EndpointPermission{
|
||||
{
|
||||
Type: EptIPv4,
|
||||
Value: "1.1.1.1",
|
||||
Protocol: 17, // TCP
|
||||
@@ -171,7 +170,7 @@ func TestEPString(t *testing.T) {
|
||||
EndPort: 53,
|
||||
Permit: false,
|
||||
},
|
||||
&EndpointPermission{
|
||||
{
|
||||
Type: EptDomain,
|
||||
Value: "example.org",
|
||||
Permit: false,
|
||||
@@ -181,8 +180,7 @@ func TestEPString(t *testing.T) {
|
||||
t.Errorf("unexpected result: %s", endpoints.String())
|
||||
}
|
||||
|
||||
var noEndpoints Endpoints
|
||||
noEndpoints = []*EndpointPermission{}
|
||||
var noEndpoints Endpoints = []*EndpointPermission{}
|
||||
if noEndpoints.String() != "[]" {
|
||||
t.Errorf("unexpected result: %s", noEndpoints.String())
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func GetFingerprintWeight(fpType string) (weight int) {
|
||||
}
|
||||
|
||||
// AddFingerprint adds the given fingerprint to the profile.
|
||||
func (p *Profile) AddFingerprint(fp *Fingerprint) {
|
||||
func (profile *Profile) AddFingerprint(fp *Fingerprint) {
|
||||
if fp.OS == "" {
|
||||
fp.OS = osIdentifier
|
||||
}
|
||||
@@ -44,5 +44,5 @@ func (p *Profile) AddFingerprint(fp *Fingerprint) {
|
||||
fp.LastUsed = time.Now().Unix()
|
||||
}
|
||||
|
||||
p.Fingerprints = append(p.Fingerprints, fp)
|
||||
profile.Fingerprints = append(profile.Fingerprints, fp)
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@ func New() *Profile {
|
||||
}
|
||||
|
||||
// MakeProfileKey creates the correct key for a profile with the given namespace and ID.
|
||||
func MakeProfileKey(namespace, ID string) string {
|
||||
return fmt.Sprintf("core:profiles/%s/%s", namespace, ID)
|
||||
func MakeProfileKey(namespace, id string) string {
|
||||
return fmt.Sprintf("core:profiles/%s/%s", namespace, id)
|
||||
}
|
||||
|
||||
// Save saves the profile to the database
|
||||
@@ -98,17 +98,17 @@ func (profile *Profile) DetailedString() string {
|
||||
}
|
||||
|
||||
// GetUserProfile loads a profile from the database.
|
||||
func GetUserProfile(ID string) (*Profile, error) {
|
||||
return getProfile(UserNamespace, ID)
|
||||
func GetUserProfile(id string) (*Profile, error) {
|
||||
return getProfile(UserNamespace, id)
|
||||
}
|
||||
|
||||
// GetStampProfile loads a profile from the database.
|
||||
func GetStampProfile(ID string) (*Profile, error) {
|
||||
return getProfile(StampNamespace, ID)
|
||||
func GetStampProfile(id string) (*Profile, error) {
|
||||
return getProfile(StampNamespace, id)
|
||||
}
|
||||
|
||||
func getProfile(namespace, ID string) (*Profile, error) {
|
||||
r, err := profileDB.Get(MakeProfileKey(namespace, ID))
|
||||
func getProfile(namespace, id string) (*Profile, error) {
|
||||
r, err := profileDB.Get(MakeProfileKey(namespace, id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -8,10 +8,6 @@ import (
|
||||
"github.com/safing/portmaster/status"
|
||||
)
|
||||
|
||||
var (
|
||||
emptyFlags = Flags{}
|
||||
)
|
||||
|
||||
// Set handles Profile chaining.
|
||||
type Set struct {
|
||||
sync.Mutex
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//nolint:unparam
|
||||
package profile
|
||||
|
||||
import (
|
||||
@@ -30,25 +31,25 @@ func init() {
|
||||
Independent: status.SecurityLevelFortress,
|
||||
},
|
||||
Endpoints: []*EndpointPermission{
|
||||
&EndpointPermission{
|
||||
{
|
||||
Type: EptDomain,
|
||||
Value: "good.bad.example.com.",
|
||||
Permit: true,
|
||||
Created: time.Now().Unix(),
|
||||
},
|
||||
&EndpointPermission{
|
||||
{
|
||||
Type: EptDomain,
|
||||
Value: "*bad.example.com.",
|
||||
Permit: false,
|
||||
Created: time.Now().Unix(),
|
||||
},
|
||||
&EndpointPermission{
|
||||
{
|
||||
Type: EptDomain,
|
||||
Value: "example.com.",
|
||||
Permit: true,
|
||||
Created: time.Now().Unix(),
|
||||
},
|
||||
&EndpointPermission{
|
||||
{
|
||||
Type: EptAny,
|
||||
Permit: true,
|
||||
Protocol: 6,
|
||||
@@ -67,13 +68,13 @@ func init() {
|
||||
// Internet: status.SecurityLevelsAll,
|
||||
// },
|
||||
Endpoints: []*EndpointPermission{
|
||||
&EndpointPermission{
|
||||
{
|
||||
Type: EptDomain,
|
||||
Value: "*bad2.example.com.",
|
||||
Permit: false,
|
||||
Created: time.Now().Unix(),
|
||||
},
|
||||
&EndpointPermission{
|
||||
{
|
||||
Type: EptAny,
|
||||
Permit: true,
|
||||
Protocol: 6,
|
||||
@@ -83,7 +84,7 @@ func init() {
|
||||
},
|
||||
},
|
||||
ServiceEndpoints: []*EndpointPermission{
|
||||
&EndpointPermission{
|
||||
{
|
||||
Type: EptAny,
|
||||
Permit: true,
|
||||
Protocol: 17,
|
||||
@@ -91,7 +92,7 @@ func init() {
|
||||
EndPort: 12347,
|
||||
Created: time.Now().Unix(),
|
||||
},
|
||||
&EndpointPermission{ // default deny
|
||||
{ // default deny
|
||||
Type: EptAny,
|
||||
Permit: false,
|
||||
Created: time.Now().Unix(),
|
||||
@@ -173,6 +174,6 @@ func TestProfileSet(t *testing.T) {
|
||||
}
|
||||
|
||||
func getLineNumberOfCaller(levels int) int {
|
||||
_, _, line, _ := runtime.Caller(levels + 1)
|
||||
_, _, line, _ := runtime.Caller(levels + 1) //nolint:dogsled
|
||||
return line
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func initSpecialProfiles() (err error) {
|
||||
return err
|
||||
}
|
||||
globalProfile = makeDefaultGlobalProfile()
|
||||
globalProfile.Save(SpecialNamespace)
|
||||
_ = globalProfile.Save(SpecialNamespace)
|
||||
}
|
||||
|
||||
fallbackProfile, err = getSpecialProfile("fallback")
|
||||
@@ -34,15 +34,15 @@ func initSpecialProfiles() (err error) {
|
||||
}
|
||||
fallbackProfile = makeDefaultFallbackProfile()
|
||||
ensureServiceEndpointsDenyAll(fallbackProfile)
|
||||
fallbackProfile.Save(SpecialNamespace)
|
||||
_ = fallbackProfile.Save(SpecialNamespace)
|
||||
}
|
||||
ensureServiceEndpointsDenyAll(fallbackProfile)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getSpecialProfile(ID string) (*Profile, error) {
|
||||
return getProfile(SpecialNamespace, ID)
|
||||
func getSpecialProfile(id string) (*Profile, error) {
|
||||
return getProfile(SpecialNamespace, id)
|
||||
}
|
||||
|
||||
func ensureServiceEndpointsDenyAll(p *Profile) (changed bool) {
|
||||
@@ -52,7 +52,7 @@ func ensureServiceEndpointsDenyAll(p *Profile) (changed bool) {
|
||||
ep.Protocol == 0 &&
|
||||
ep.StartPort == 0 &&
|
||||
ep.EndPort == 0 &&
|
||||
ep.Permit == false {
|
||||
!ep.Permit {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ func updateListener(sub *database.Subscription) {
|
||||
profile.Unlock()
|
||||
|
||||
if profileChanged {
|
||||
profile.Save(SpecialNamespace)
|
||||
_ = profile.Save(SpecialNamespace)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user