Merge branch 'develop' into feature/new-kext

This commit is contained in:
Vladimir Stoilov
2024-04-29 17:08:04 +03:00
12 changed files with 144 additions and 54 deletions

View File

@@ -111,12 +111,17 @@ func resetAllConnectionVerdicts() {
func resetConnectionVerdict(ctx context.Context, conn *network.Connection) (verdictChanged bool) {
tracer := log.Tracer(ctx)
// Remove any active prompt as we settings are being re-evaluated.
// Remove any active prompt as the settings are being re-evaluated.
conn.RemovePrompt()
conn.Lock()
defer conn.Unlock()
// Do not re-evaluate connection that have already ended.
if conn.Ended > 0 {
return false
}
// Update feature flags.
if err := conn.UpdateFeatures(); err != nil && !errors.Is(err, access.ErrNotLoggedIn) {
tracer.Warningf("filter: failed to update connection feature flags: %s", err)

View File

@@ -100,7 +100,12 @@ func handleGetProfileIcon(ar *api.Request) (data []byte, err error) {
// Get profile icon.
data, err = binmeta.GetProfileIcon(name)
if err != nil {
switch {
case err == nil:
// Continue
case errors.Is(err, binmeta.ErrIconIgnored):
return nil, api.ErrorWithStatus(err, http.StatusNotFound)
default:
return nil, err
}

View File

@@ -19,6 +19,9 @@ import (
// Must not be changed once set.
var ProfileIconStoragePath = ""
// ErrIconIgnored is returned when the icon should be ignored.
var ErrIconIgnored = errors.New("icon is ignored")
// GetProfileIcon returns the profile icon with the given ID and extension.
func GetProfileIcon(name string) (data []byte, err error) {
// Check if enabled.
@@ -26,6 +29,11 @@ func GetProfileIcon(name string) (data []byte, err error) {
return nil, errors.New("api icon storage not configured")
}
// Check if icon should be ignored.
if IgnoreIcon(name) {
return nil, ErrIconIgnored
}
// Build storage path.
iconPath := filepath.Clean(
filepath.Join(ProfileIconStoragePath, name),
@@ -59,6 +67,11 @@ func UpdateProfileIcon(data []byte, ext string) (filename string, err error) {
}
sum := hex.EncodeToString(h.Sum(nil))
// Check if icon should be ignored.
if IgnoreIcon(sum) {
return "", ErrIconIgnored
}
// Check ext.
ext = strings.ToLower(ext)
switch ext {

View File

@@ -0,0 +1,30 @@
package binmeta
import (
"strings"
)
var ignoreIcons = map[string]struct{}{
// Windows Default Icons.
"a27898ddfa4e0481b62c69faa196919a738fcade": {},
"5a3eea8bcd08b9336ce9c5083f26185164268ee9": {},
"573393d6ad238d255b20dc1c1b303c95debe6965": {},
"d459b2cb23c27cc31ccab5025533048d5d8301bf": {},
"d35a0d91ebfda81df5286f68ec5ddb1d6ad6b850": {},
"cc33187385498384f1b648e23be5ef1a2e9f5f71": {},
}
// IgnoreIcon returns whether an icon should be ignored or not.
func IgnoreIcon(name string) bool {
// Make lower case.
name = strings.ToLower(name)
// Remove extension.
extIndex := strings.Index(name, ".")
if extIndex > 0 {
name = name[:extIndex]
}
// Check if ID is in list.
_, found := ignoreIcons[name]
return found
}

View File

@@ -515,7 +515,13 @@ func (profile *Profile) updateMetadataFromSystem(ctx context.Context, md Matchin
// Get binary icon and name.
newIcon, newName, err := binmeta.GetIconAndName(ctx, profile.PresentationPath, home)
if err != nil {
switch {
case err == nil:
// Continue
case errors.Is(err, binmeta.ErrIconIgnored):
newIcon = nil
// Continue
default:
log.Warningf("profile: failed to get binary icon/name for %s: %s", profile.PresentationPath, err)
}