mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2024-11-14 23:43:56 +01:00
build: use new internal structure.
This commit is contained in:
parent
c8512bc2c6
commit
0f1f9ce49b
@ -33,7 +33,7 @@ func init() {
|
||||
case "ubuntu":
|
||||
if cfg.Release["VERSION_CODENAME"] == "noble" {
|
||||
builder.Register("abi3")
|
||||
cfg.Overwrite = true
|
||||
cfg.Overwrite.Enabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,27 +32,17 @@ func init() {
|
||||
|
||||
func (p SetFlags) Apply() ([]string, error) {
|
||||
res := []string{}
|
||||
for _, name := range []string{"main.flags", cfg.Distribution + ".flags"} {
|
||||
path := cfg.FlagDir.Join(name)
|
||||
if !path.Exist() {
|
||||
continue
|
||||
}
|
||||
lines, _ := path.ReadFileAsLines()
|
||||
for _, line := range lines {
|
||||
if strings.HasPrefix(line, "#") || line == "" {
|
||||
continue
|
||||
}
|
||||
manifest := strings.Split(line, " ")
|
||||
profile := manifest[0]
|
||||
for _, name := range []string{"main", cfg.Distribution} {
|
||||
for profile, flags := range cfg.Flags.Read(name) {
|
||||
file := cfg.RootApparmord.Join(profile)
|
||||
if !file.Exist() {
|
||||
res = append(res, fmt.Sprintf("Profile %s not found, ignoring", profile))
|
||||
continue
|
||||
}
|
||||
|
||||
// If flags is set, overwrite profile flag
|
||||
if len(manifest) > 1 {
|
||||
flags := " flags=(" + manifest[1] + ") {"
|
||||
// Overwrite profile flags
|
||||
if len(flags) > 0 {
|
||||
flagsStr := " flags=(" + strings.Join(flags, ",") + ") {"
|
||||
content, err := file.ReadFile()
|
||||
if err != nil {
|
||||
return res, err
|
||||
@ -60,13 +50,13 @@ func (p SetFlags) Apply() ([]string, error) {
|
||||
|
||||
// Remove all flags definition, then set manifest' flags
|
||||
out := regFlags.ReplaceAllLiteralString(string(content), "")
|
||||
out = regProfileHeader.ReplaceAllLiteralString(out, flags)
|
||||
out = regProfileHeader.ReplaceAllLiteralString(out, flagsStr)
|
||||
if err := file.WriteFile([]byte(out)); err != nil {
|
||||
return res, err
|
||||
}
|
||||
}
|
||||
}
|
||||
res = append(res, path.String())
|
||||
res = append(res, cfg.FlagDir.Join(name+".flags").String())
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
@ -5,8 +5,6 @@
|
||||
package prepare
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/arduino/go-paths-helper"
|
||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
||||
)
|
||||
@ -26,19 +24,11 @@ func init() {
|
||||
|
||||
func (p Ignore) Apply() ([]string, error) {
|
||||
res := []string{}
|
||||
for _, name := range []string{"main.ignore", cfg.Distribution + ".ignore"} {
|
||||
path := cfg.DistDir.Join("ignore", name)
|
||||
if !path.Exist() {
|
||||
continue
|
||||
}
|
||||
lines, _ := path.ReadFileAsLines()
|
||||
for _, line := range lines {
|
||||
if strings.HasPrefix(line, "#") || line == "" {
|
||||
continue
|
||||
}
|
||||
profile := cfg.Root.Join(line)
|
||||
for _, name := range []string{"main", cfg.Distribution} {
|
||||
for _, ignore := range cfg.Ignore.Read(name) {
|
||||
profile := cfg.Root.Join(ignore)
|
||||
if profile.NotExist() {
|
||||
files, err := cfg.RootApparmord.ReadDirRecursiveFiltered(nil, paths.FilterNames(line))
|
||||
files, err := cfg.RootApparmord.ReadDirRecursiveFiltered(nil, paths.FilterNames(ignore))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@ -53,7 +43,7 @@ func (p Ignore) Apply() ([]string, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
res = append(res, path.String())
|
||||
res = append(res, cfg.IgnoreDir.Join(name+".ignore").String())
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
@ -94,4 +94,3 @@ func CopyTo(src *paths.Path, dst *paths.Path) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user