aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-10-25 16:23:22 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-10-25 16:23:22 +0900
commit2a348c7f912a17dbb0d29624cb3bef2add9d7492 (patch)
treefd13835b3f70ccac14af4a6f47c1342d5ee0b6f7 /internal
parenteb767e7642ccd581c9b29303f5e7e3b2adc87c09 (diff)
system: include more info in ACL Stringer
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal')
-rw-r--r--internal/system/acl.go24
-rw-r--r--internal/system/acl_test.go19
2 files changed, 16 insertions, 27 deletions
diff --git a/internal/system/acl.go b/internal/system/acl.go
index efc48842..f927f187 100644
--- a/internal/system/acl.go
+++ b/internal/system/acl.go
@@ -28,7 +28,7 @@ func (sys *I) UpdatePermType(et Enablement, path string, perms ...acl.Perm) *I {
type ACL struct {
et Enablement
path string
- perms []acl.Perm
+ perms acl.Perms
}
func (a *ACL) Type() Enablement {
@@ -36,20 +36,18 @@ func (a *ACL) Type() Enablement {
}
func (a *ACL) apply(sys *I) error {
- fmsg.VPrintf("applying ACL %s uid: %d type: %s path: %q",
- a, sys.uid, TypeString(a.et), a.path)
+ fmsg.VPrintln("applying ACL", a)
return fmsg.WrapErrorSuffix(acl.UpdatePerm(a.path, sys.uid, a.perms...),
fmt.Sprintf("cannot apply ACL entry to %q:", a.path))
}
func (a *ACL) revert(sys *I, ec *Criteria) error {
if ec.hasType(a) {
- fmsg.VPrintf("stripping ACL %s uid: %d type: %s path: %q",
- a, sys.uid, TypeString(a.et), a.path)
+ fmsg.VPrintln("stripping ACL", a)
return fmsg.WrapErrorSuffix(acl.UpdatePerm(a.path, sys.uid),
fmt.Sprintf("cannot strip ACL entry from %q:", a.path))
} else {
- fmsg.VPrintln("skipping ACL", a, "uid:", sys.uid, "tag:", TypeString(a.et), "path:", a.path)
+ fmsg.VPrintln("skipping ACL", a)
return nil
}
}
@@ -67,16 +65,6 @@ func (a *ACL) Path() string {
}
func (a *ACL) String() string {
- var s = []byte("---")
- for _, p := range a.perms {
- switch p {
- case acl.Read:
- s[0] = 'r'
- case acl.Write:
- s[1] = 'w'
- case acl.Execute:
- s[2] = 'x'
- }
- }
- return string(s)
+ return fmt.Sprintf("%s type: %s path: %q",
+ a.perms, TypeString(a.et), a.path)
}
diff --git a/internal/system/acl_test.go b/internal/system/acl_test.go
index fe456c70..ed449ef3 100644
--- a/internal/system/acl_test.go
+++ b/internal/system/acl_test.go
@@ -49,21 +49,22 @@ func TestUpdatePermType(t *testing.T) {
func TestACL_String(t *testing.T) {
testCases := []struct {
want string
+ et Enablement
perms []acl.Perm
}{
- {"---", []acl.Perm{}},
- {"r--", []acl.Perm{acl.Read}},
- {"-w-", []acl.Perm{acl.Write}},
- {"--x", []acl.Perm{acl.Execute}},
- {"rw-", []acl.Perm{acl.Read, acl.Write}},
- {"r-x", []acl.Perm{acl.Read, acl.Execute}},
- {"rwx", []acl.Perm{acl.Read, acl.Write, acl.Execute}},
- {"rwx", []acl.Perm{acl.Read, acl.Write, acl.Write, acl.Execute}},
+ {`--- type: Process path: "/nonexistent"`, Process, []acl.Perm{}},
+ {`r-- type: User path: "/nonexistent"`, User, []acl.Perm{acl.Read}},
+ {`-w- type: Wayland path: "/nonexistent"`, EWayland, []acl.Perm{acl.Write}},
+ {`--x type: X11 path: "/nonexistent"`, EX11, []acl.Perm{acl.Execute}},
+ {`rw- type: D-Bus path: "/nonexistent"`, EDBus, []acl.Perm{acl.Read, acl.Write}},
+ {`r-x type: PulseAudio path: "/nonexistent"`, EPulse, []acl.Perm{acl.Read, acl.Execute}},
+ {`rwx type: User path: "/nonexistent"`, User, []acl.Perm{acl.Read, acl.Write, acl.Execute}},
+ {`rwx type: Process path: "/nonexistent"`, Process, []acl.Perm{acl.Read, acl.Write, acl.Write, acl.Execute}},
}
for _, tc := range testCases {
t.Run(tc.want, func(t *testing.T) {
- a := &ACL{perms: tc.perms}
+ a := &ACL{et: tc.et, perms: tc.perms, path: "/nonexistent"}
if got := a.String(); got != tc.want {
t.Errorf("String() = %v, want %v",
got, tc.want)