LoadDefaultProfile ensures the default profile to be loaded with the given name. Returns nil error if the profile is already loaded.
(name string)
| 52 | // LoadDefaultProfile ensures the default profile to be loaded with the given name. |
| 53 | // Returns nil error if the profile is already loaded. |
| 54 | func LoadDefaultProfile(name string) error { |
| 55 | yes, err := isLoaded(name) |
| 56 | if err != nil { |
| 57 | return err |
| 58 | } |
| 59 | if yes { |
| 60 | return nil |
| 61 | } |
| 62 | p, err := loadData(name) |
| 63 | if err != nil { |
| 64 | return err |
| 65 | } |
| 66 | f, err := os.CreateTemp(os.Getenv("XDG_RUNTIME_DIR"), p.Name) |
| 67 | if err != nil { |
| 68 | return err |
| 69 | } |
| 70 | defer f.Close() |
| 71 | path := f.Name() |
| 72 | defer os.Remove(path) |
| 73 | |
| 74 | if err := generate(p, f); err != nil { |
| 75 | return err |
| 76 | } |
| 77 | if err := load(path); err != nil { |
| 78 | return fmt.Errorf("load apparmor profile %s: %w", path, err) |
| 79 | } |
| 80 | return nil |
| 81 | } |
| 82 | |
| 83 | // DumpDefaultProfile dumps the default profile with the given name. |
| 84 | func DumpDefaultProfile(name string) (string, error) { |