2024-03-26 00:34:14 +01:00
|
|
|
// apparmor.d - Full set of apparmor profiles
|
|
|
|
// Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
package prepare
|
|
|
|
|
|
|
|
import (
|
2024-04-28 01:36:16 +02:00
|
|
|
"github.com/roddhjav/apparmor.d/pkg/paths"
|
2024-03-26 00:34:14 +01:00
|
|
|
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Ignore struct {
|
|
|
|
cfg.Base
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RegisterTask(&Ignore{
|
|
|
|
Base: cfg.Base{
|
|
|
|
Keyword: "ignore",
|
|
|
|
Msg: "Ignore profiles and files from:",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p Ignore) Apply() ([]string, error) {
|
|
|
|
res := []string{}
|
2024-03-26 19:07:48 +01:00
|
|
|
for _, name := range []string{"main", cfg.Distribution} {
|
|
|
|
for _, ignore := range cfg.Ignore.Read(name) {
|
|
|
|
profile := cfg.Root.Join(ignore)
|
2024-03-26 00:34:14 +01:00
|
|
|
if profile.NotExist() {
|
2024-03-26 19:07:48 +01:00
|
|
|
files, err := cfg.RootApparmord.ReadDirRecursiveFiltered(nil, paths.FilterNames(ignore))
|
2024-03-26 00:34:14 +01:00
|
|
|
if err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
for _, path := range files {
|
|
|
|
if err := path.RemoveAll(); err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := profile.RemoveAll(); err != nil {
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-03-26 19:07:48 +01:00
|
|
|
res = append(res, cfg.IgnoreDir.Join(name+".ignore").String())
|
2024-03-26 00:34:14 +01:00
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|