From 7f7a2e5eda4481ebb5ddc87cd769d986a00fd88c Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Sun, 21 Nov 2021 21:57:11 +0000 Subject: [PATCH] aa-log: cosmetic. --- src/cmd/aa-log/main.go | 20 ++++++++++++-------- src/go.mod | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/cmd/aa-log/main.go b/src/cmd/aa-log/main.go index 18079e01..cfe97bf4 100644 --- a/src/cmd/aa-log/main.go +++ b/src/cmd/aa-log/main.go @@ -33,8 +33,7 @@ type AppArmorLogs []AppArmorLog func removeDuplicateLog(logs []string) []string { list := []string{} - keys := make(map[string]interface{}) - keys[""] = true + keys := map[string]interface{}{"": true} for _, log := range logs { if _, v := keys[log]; !v { keys[log] = true @@ -96,11 +95,13 @@ func (aaLogs AppArmorLogs) String() string { "DENIED": BoldRed + "DENIED " + Reset, "ALLOWED": BoldGreen + "ALLOWED" + Reset, } + // Order of impression keys := []string{ "profile", "operation", "name", "info", "comm", "laddr", "lport", "faddr", "fport", "family", "sock_type", "protocol", - "requested_mask", "denied_mask", // "fsuid", "ouid", "FSUID", "OUID", + "requested_mask", "denied_mask", "signal", "peer", // "fsuid", "ouid", "FSUID", "OUID", } + // Optional colors template to use colors := map[string]string{ "profile": FgBlue, "operation": FgYellow, @@ -109,8 +110,8 @@ func (aaLogs AppArmorLogs) String() string { "denied_mask": "denied_mask=" + BoldRed, } for _, log := range aaLogs { + seen := map[string]bool{"apparmor": true} res += state[log["apparmor"]] - delete(log, "apparmor") for _, key := range keys { if log[key] != "" { @@ -119,12 +120,14 @@ func (aaLogs AppArmorLogs) String() string { } else { res += " " + key + "=" + log[key] } - delete(log, key) + seen[key] = true } } for key, value := range log { - res += " " + key + "=" + value + if !seen[key] { + res += " " + key + "=" + value + } } res += "\n" } @@ -139,12 +142,13 @@ func main() { file, err := os.Open(LogFile) if err != nil { - fmt.Println(err.Error()) - return + fmt.Println(err) + os.Exit(1) } defer func() { if err := file.Close(); err != nil { fmt.Println("Error closing file:", err) + os.Exit(1) } }() diff --git a/src/go.mod b/src/go.mod index 993e156a..718c8195 100644 --- a/src/go.mod +++ b/src/go.mod @@ -1,3 +1,3 @@ -module gitlab.com/roddhjav/apparmor.d +module github.com/roddhjav/apparmor.d go 1.17