build(directive): support both liust & map.

This commit is contained in:
Alexandre Pujol 2024-03-23 17:41:10 +00:00
parent f81ceb9185
commit 88fcdd8c8e
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
10 changed files with 126 additions and 86 deletions

View file

@ -8,6 +8,7 @@ import (
"strings"
"github.com/roddhjav/apparmor.d/pkg/aa"
"golang.org/x/exp/slices"
)
type Exec struct {
@ -26,16 +27,14 @@ func init() {
func (d Exec) Apply(opt *Option, profile string) string {
transition := "Px"
transitions := []string{"P", "U", "p", "u", "PU", "pu"}
for _, t := range transitions {
if _, present := opt.Args[t]; present {
transition = t + "x"
delete(opt.Args, t)
break
}
t := opt.ArgList[0]
if slices.Contains(transitions, t) {
transition = t + "x"
delete(opt.ArgMap, t)
}
p := &aa.AppArmorProfile{}
for name := range opt.Args {
for name := range opt.ArgMap {
content, err := rootApparmord.Join(name).ReadFile()
if err != nil {
panic(err)