aa-log: cosmetic.

This commit is contained in:
Alexandre Pujol 2021-11-21 21:57:11 +00:00
parent 0294ef3270
commit 7f7a2e5eda
No known key found for this signature in database
GPG Key ID: C5469996F0DF68EC
2 changed files with 13 additions and 9 deletions

View File

@ -33,8 +33,7 @@ type AppArmorLogs []AppArmorLog
func removeDuplicateLog(logs []string) []string { func removeDuplicateLog(logs []string) []string {
list := []string{} list := []string{}
keys := make(map[string]interface{}) keys := map[string]interface{}{"": true}
keys[""] = true
for _, log := range logs { for _, log := range logs {
if _, v := keys[log]; !v { if _, v := keys[log]; !v {
keys[log] = true keys[log] = true
@ -96,11 +95,13 @@ func (aaLogs AppArmorLogs) String() string {
"DENIED": BoldRed + "DENIED " + Reset, "DENIED": BoldRed + "DENIED " + Reset,
"ALLOWED": BoldGreen + "ALLOWED" + Reset, "ALLOWED": BoldGreen + "ALLOWED" + Reset,
} }
// Order of impression
keys := []string{ keys := []string{
"profile", "operation", "name", "info", "comm", "laddr", "profile", "operation", "name", "info", "comm", "laddr",
"lport", "faddr", "fport", "family", "sock_type", "protocol", "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{ colors := map[string]string{
"profile": FgBlue, "profile": FgBlue,
"operation": FgYellow, "operation": FgYellow,
@ -109,8 +110,8 @@ func (aaLogs AppArmorLogs) String() string {
"denied_mask": "denied_mask=" + BoldRed, "denied_mask": "denied_mask=" + BoldRed,
} }
for _, log := range aaLogs { for _, log := range aaLogs {
seen := map[string]bool{"apparmor": true}
res += state[log["apparmor"]] res += state[log["apparmor"]]
delete(log, "apparmor")
for _, key := range keys { for _, key := range keys {
if log[key] != "" { if log[key] != "" {
@ -119,12 +120,14 @@ func (aaLogs AppArmorLogs) String() string {
} else { } else {
res += " " + key + "=" + log[key] res += " " + key + "=" + log[key]
} }
delete(log, key) seen[key] = true
} }
} }
for key, value := range log { for key, value := range log {
res += " " + key + "=" + value if !seen[key] {
res += " " + key + "=" + value
}
} }
res += "\n" res += "\n"
} }
@ -139,12 +142,13 @@ func main() {
file, err := os.Open(LogFile) file, err := os.Open(LogFile)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err)
return os.Exit(1)
} }
defer func() { defer func() {
if err := file.Close(); err != nil { if err := file.Close(); err != nil {
fmt.Println("Error closing file:", err) fmt.Println("Error closing file:", err)
os.Exit(1)
} }
}() }()

View File

@ -1,3 +1,3 @@
module gitlab.com/roddhjav/apparmor.d module github.com/roddhjav/apparmor.d
go 1.17 go 1.17