mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2024-11-14 23:43:56 +01:00
build: ensure @{exec_path} is present in profile att.
This commit is contained in:
parent
8ef9a18242
commit
9b2470462f
@ -5,6 +5,7 @@
|
|||||||
package builder
|
package builder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -12,8 +13,10 @@ import (
|
|||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const tokATTACHMENT = "@{exec_path}"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
regAttachments = regexp.MustCompile(`(profile .* @{exec_path})`)
|
regAttachments = regexp.MustCompile(`(profile .* ` + tokATTACHMENT + `)`)
|
||||||
)
|
)
|
||||||
|
|
||||||
type Userspace struct {
|
type Userspace struct {
|
||||||
@ -41,13 +44,18 @@ func (b Userspace) Apply(opt *Option, profile string) (string, error) {
|
|||||||
if _, err := f.Parse(profile); err != nil {
|
if _, err := f.Parse(profile); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
if len(f.GetDefaultProfile().Attachments) > 0 &&
|
||||||
|
f.GetDefaultProfile().Attachments[0] != tokATTACHMENT {
|
||||||
|
return "", fmt.Errorf("missing '%s' attachment", tokATTACHMENT)
|
||||||
|
}
|
||||||
if err := f.Resolve(); err != nil {
|
if err := f.Resolve(); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
att := f.GetDefaultProfile().GetAttachments()
|
|
||||||
matches := regAttachments.FindAllString(profile, -1)
|
matches := regAttachments.FindAllString(profile, -1)
|
||||||
if len(matches) > 0 {
|
if len(matches) > 0 {
|
||||||
strheader := strings.Replace(matches[0], "@{exec_path}", att, -1)
|
att := f.GetDefaultProfile().GetAttachments()
|
||||||
|
strheader := strings.Replace(matches[0], tokATTACHMENT, att, -1)
|
||||||
return regAttachments.ReplaceAllLiteralString(profile, strheader), nil
|
return regAttachments.ReplaceAllLiteralString(profile, strheader), nil
|
||||||
}
|
}
|
||||||
return profile, nil
|
return profile, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user