2023-09-25 01:06:07 +02:00
|
|
|
// apparmor.d - Full set of apparmor profiles
|
2024-02-07 00:16:21 +01:00
|
|
|
// Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
|
2023-09-25 01:06:07 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
package aa
|
|
|
|
|
2024-06-19 19:34:58 +02:00
|
|
|
import "fmt"
|
|
|
|
|
2024-05-28 19:15:22 +02:00
|
|
|
const USERNS Kind = "userns"
|
2024-04-23 22:26:09 +02:00
|
|
|
|
2023-09-25 01:06:07 +02:00
|
|
|
type Userns struct {
|
2024-06-25 20:50:27 +02:00
|
|
|
Base
|
2023-09-25 01:06:07 +02:00
|
|
|
Qualifier
|
|
|
|
Create bool
|
|
|
|
}
|
|
|
|
|
2024-06-20 00:22:49 +02:00
|
|
|
func newUserns(q Qualifier, rule rule) (Rule, error) {
|
|
|
|
var create bool
|
|
|
|
switch len(rule) {
|
|
|
|
case 0:
|
|
|
|
create = true
|
|
|
|
case 1:
|
|
|
|
if rule.Get(0) != "create" {
|
|
|
|
return nil, fmt.Errorf("invalid userns format: %s", rule)
|
|
|
|
}
|
|
|
|
create = true
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("invalid userns format: %s", rule)
|
|
|
|
}
|
|
|
|
return &Userns{
|
2024-06-25 20:50:27 +02:00
|
|
|
Base: newBase(rule),
|
2024-06-20 00:22:49 +02:00
|
|
|
Qualifier: q,
|
|
|
|
Create: create,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2024-04-19 23:43:02 +02:00
|
|
|
func newUsernsFromLog(log map[string]string) Rule {
|
2023-09-25 01:06:07 +02:00
|
|
|
return &Userns{
|
2024-06-25 20:50:27 +02:00
|
|
|
Base: newBaseFromLog(log),
|
2024-04-15 00:58:34 +02:00
|
|
|
Qualifier: newQualifierFromLog(log),
|
2023-09-25 01:06:07 +02:00
|
|
|
Create: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-25 20:56:36 +02:00
|
|
|
func (r *Userns) Kind() Kind {
|
|
|
|
return USERNS
|
|
|
|
}
|
|
|
|
|
2024-06-27 19:45:32 +02:00
|
|
|
func (r *Userns) Constraint() Constraint {
|
|
|
|
return BlockRule
|
2024-06-25 20:56:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Userns) String() string {
|
|
|
|
return renderTemplate(r.Kind(), r)
|
|
|
|
}
|
|
|
|
|
2024-05-25 23:36:39 +02:00
|
|
|
func (r *Userns) Validate() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-06-19 19:34:58 +02:00
|
|
|
func (r *Userns) Compare(other Rule) int {
|
2023-09-25 01:09:11 +02:00
|
|
|
o, _ := other.(*Userns)
|
2024-06-19 19:34:58 +02:00
|
|
|
if res := compare(r.Create, o.Create); res != 0 {
|
|
|
|
return res
|
2023-09-25 01:09:11 +02:00
|
|
|
}
|
2024-06-19 19:34:58 +02:00
|
|
|
return r.Qualifier.Compare(o.Qualifier)
|
2023-09-25 01:09:11 +02:00
|
|
|
}
|
2024-04-23 22:26:09 +02:00
|
|
|
|
2024-06-22 21:59:43 +02:00
|
|
|
func (r *Userns) Merge(other Rule) bool {
|
|
|
|
o, _ := other.(*Userns)
|
2024-06-25 20:50:27 +02:00
|
|
|
b := &r.Base
|
2024-06-29 23:27:39 +02:00
|
|
|
return b.merge(o.Base) // Always merge userns rules
|
2024-06-22 21:59:43 +02:00
|
|
|
}
|
2024-06-29 23:27:39 +02:00
|
|
|
|
|
|
|
func (r *Userns) Lengths() []int {
|
|
|
|
return []int{} // No len for userns
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Userns) setPaddings(max []int) {} // No paddings for userns
|