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-04-19 23:43:02 +02:00
|
|
|
RuleBase
|
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{
|
|
|
|
RuleBase: newBase(rule),
|
|
|
|
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-19 19:44:55 +02:00
|
|
|
RuleBase: newBaseFromLog(log),
|
2024-04-15 00:58:34 +02:00
|
|
|
Qualifier: newQualifierFromLog(log),
|
2023-09-25 01:06:07 +02:00
|
|
|
Create: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-23 11:57:46 +02:00
|
|
|
b := &r.RuleBase
|
|
|
|
return b.merge(o.RuleBase)
|
2024-06-22 21:59:43 +02:00
|
|
|
}
|
|
|
|
|
2024-04-23 22:26:09 +02:00
|
|
|
func (r *Userns) String() string {
|
2024-05-05 00:41:47 +02:00
|
|
|
return renderTemplate(r.Kind(), r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Userns) Constraint() constraint {
|
|
|
|
return blockKind
|
|
|
|
}
|
|
|
|
|
2024-05-28 19:15:22 +02:00
|
|
|
func (r *Userns) Kind() Kind {
|
|
|
|
return USERNS
|
2024-04-23 22:26:09 +02:00
|
|
|
}
|