mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2024-11-14 23:43:56 +01:00
build: update directive and prepare tasks to new structure.
This commit is contained in:
parent
17cee26dc0
commit
b614bdda36
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/builder"
|
"github.com/roddhjav/apparmor.d/pkg/prebuild/builder"
|
||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/directive"
|
"github.com/roddhjav/apparmor.d/pkg/prebuild/directive"
|
||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/prepare"
|
"github.com/roddhjav/apparmor.d/pkg/prebuild/prepare"
|
||||||
|
"github.com/roddhjav/apparmor.d/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -8,10 +8,12 @@ package directive
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/roddhjav/apparmor.d/pkg/aa"
|
"github.com/roddhjav/apparmor.d/pkg/aa"
|
||||||
|
"github.com/roddhjav/apparmor.d/pkg/paths"
|
||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild"
|
"github.com/roddhjav/apparmor.d/pkg/prebuild"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,7 +45,14 @@ func (d Exec) Apply(opt *Option, profileRaw string) (string, error) {
|
|||||||
|
|
||||||
rules := aa.Rules{}
|
rules := aa.Rules{}
|
||||||
for name := range opt.ArgMap {
|
for name := range opt.ArgMap {
|
||||||
profiletoTransition := prebuild.RootApparmord.Join(name).MustReadFileAsString()
|
match, err := filepath.Glob(prebuild.Root.String() + "/*/" + name)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if len(match) != 1 {
|
||||||
|
return "", fmt.Errorf("No profile found for %s", name)
|
||||||
|
}
|
||||||
|
profiletoTransition := paths.New(match[0]).MustReadFileAsString()
|
||||||
dstProfile := aa.DefaultTunables()
|
dstProfile := aa.DefaultTunables()
|
||||||
if _, err := dstProfile.Parse(profiletoTransition); err != nil {
|
if _, err := dstProfile.Parse(profiletoTransition); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -6,10 +6,12 @@ package directive
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/roddhjav/apparmor.d/pkg/paths"
|
||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild"
|
"github.com/roddhjav/apparmor.d/pkg/prebuild"
|
||||||
"github.com/roddhjav/apparmor.d/pkg/util"
|
"github.com/roddhjav/apparmor.d/pkg/util"
|
||||||
)
|
)
|
||||||
@ -55,7 +57,14 @@ func (s Stack) Apply(opt *Option, profile string) (string, error) {
|
|||||||
|
|
||||||
res := ""
|
res := ""
|
||||||
for name := range opt.ArgMap {
|
for name := range opt.ArgMap {
|
||||||
stackedProfile := prebuild.RootApparmord.Join(name).MustReadFileAsString()
|
match, err := filepath.Glob(prebuild.Root.String() + "/*/" + name)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if len(match) != 1 {
|
||||||
|
return "", fmt.Errorf("No profile found for %s", name)
|
||||||
|
}
|
||||||
|
stackedProfile := paths.New(match[0]).MustReadFileAsString()
|
||||||
m := regRules.FindStringSubmatch(stackedProfile)
|
m := regRules.FindStringSubmatch(stackedProfile)
|
||||||
if len(m) < 2 {
|
if len(m) < 2 {
|
||||||
return "", fmt.Errorf("No profile found in %s", name)
|
return "", fmt.Errorf("No profile found in %s", name)
|
||||||
|
@ -66,7 +66,7 @@ func getRootBuild() *paths.Path {
|
|||||||
func getPackages() []string {
|
func getPackages() []string {
|
||||||
files, err := PkgDir.ReadDirRecursiveFiltered(nil, paths.FilterOutDirectories())
|
files, err := PkgDir.ReadDirRecursiveFiltered(nil, paths.FilterOutDirectories())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return []string{}
|
||||||
}
|
}
|
||||||
packages := make([]string, 0, len(files))
|
packages := make([]string, 0, len(files))
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
package prepare
|
package prepare
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/roddhjav/apparmor.d/pkg/paths"
|
"github.com/roddhjav/apparmor.d/pkg/paths"
|
||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild"
|
"github.com/roddhjav/apparmor.d/pkg/prebuild"
|
||||||
)
|
)
|
||||||
@ -26,21 +29,39 @@ func (p Ignore) Apply() ([]string, error) {
|
|||||||
res := []string{}
|
res := []string{}
|
||||||
for _, name := range []string{"main", prebuild.Distribution} {
|
for _, name := range []string{"main", prebuild.Distribution} {
|
||||||
for _, ignore := range prebuild.Ignore.Read(name) {
|
for _, ignore := range prebuild.Ignore.Read(name) {
|
||||||
profile := prebuild.Root.Join(ignore)
|
// Ignore file from share/
|
||||||
if profile.NotExist() {
|
path := prebuild.Root.Join(ignore)
|
||||||
files, err := prebuild.RootApparmord.ReadDirRecursiveFiltered(nil, paths.FilterNames(ignore))
|
if path.Exist() {
|
||||||
|
if err := path.RemoveAll(); err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ignore file from apparmor.d/
|
||||||
|
profile := strings.TrimPrefix(ignore, prebuild.Src+"/")
|
||||||
|
if strings.HasPrefix(ignore, prebuild.Src) {
|
||||||
|
path = prebuild.RootApparmord.Join(profile)
|
||||||
|
}
|
||||||
|
if path.Exist() {
|
||||||
|
if err := path.RemoveAll(); err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
files, err := prebuild.RootApparmord.ReadDirRecursiveFiltered(nil, paths.FilterNames(profile))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
if len(files) == 0 {
|
||||||
|
return res, fmt.Errorf("%s.ignore: no files found for '%s'", name, profile)
|
||||||
|
}
|
||||||
for _, path := range files {
|
for _, path := range files {
|
||||||
if err := path.RemoveAll(); err != nil {
|
if err := path.RemoveAll(); err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if err := profile.RemoveAll(); err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res = append(res, prebuild.IgnoreDir.Join(name+".ignore").String())
|
res = append(res, prebuild.IgnoreDir.Join(name+".ignore").String())
|
||||||
|
@ -48,7 +48,7 @@ func (p Merge) Apply() ([]string, error) {
|
|||||||
|
|
||||||
files, err = filepath.Glob(prebuild.RootApparmord.Join(dirRemoved).String())
|
files, err = filepath.Glob(prebuild.RootApparmord.Join(dirRemoved).String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{}, err
|
return res, err
|
||||||
}
|
}
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if err := paths.New(file).RemoveAll(); err != nil {
|
if err := paths.New(file).RemoveAll(); err != nil {
|
||||||
|
@ -50,7 +50,6 @@ func (p Overwrite) Apply() ([]string, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := origin.Rename(dest); err != nil {
|
if err := origin.Rename(dest); err != nil {
|
||||||
|
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
originRel, err := origin.RelFrom(dest)
|
originRel, err := origin.RelFrom(dest)
|
||||||
|
@ -33,14 +33,15 @@ func (p Synchronise) Apply() ([]string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if p.Path == "" {
|
if p.Path == "" {
|
||||||
for _, name := range []string{"apparmor.d", "share"} {
|
if err := paths.CopyTo(paths.New("share"), prebuild.Root.Join("share")); err != nil {
|
||||||
if err := paths.CopyTo(paths.New(name), prebuild.Root.Join(name)); err != nil {
|
return res, err
|
||||||
return res, err
|
}
|
||||||
}
|
if err := paths.CopyTo(prebuild.SrcApparmord, prebuild.RootApparmord); err != nil {
|
||||||
|
return res, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
file := paths.New(p.Path)
|
file := paths.New(p.Path)
|
||||||
destination, err := file.RelFrom(paths.New("apparmor.d"))
|
destination, err := file.RelFrom(prebuild.SrcApparmord)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user