diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-10-13 21:11:23 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-10-13 21:44:54 +0900 |
| commit | 40e4c9031652731622315e778a9bcace6cea6cb3 (patch) | |
| tree | d349d24c5ddff712d3979254a7eb74f3ca3de88f /internal/acl/acl.go | |
| parent | 9e95987536f895ef1a989fcd9e69ab84a1b94a17 (diff) | |
internal/acl: use O_PATH descriptor
This avoids TOCTOU during hakurei_update_acl.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/acl/acl.go')
| -rw-r--r-- | internal/acl/acl.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/internal/acl/acl.go b/internal/acl/acl.go index 7718ba3c..8b862ba2 100644 --- a/internal/acl/acl.go +++ b/internal/acl/acl.go @@ -7,7 +7,12 @@ package acl #include "libacl-helper.h" */ import "C" -import "os" + +import ( + "os" + + "hakurei.app/container" +) // Perm represents acl_perm_t. type Perm C.acl_perm_t @@ -83,11 +88,21 @@ func (e Error) Error() string { // Update replaces ACL_USER entry with qualifier uid. func Update(name string, uid int, perms Perm) error { + f, _err := os.OpenFile(name, container.O_PATH, 0) + if _err != nil { + return _err + } + r, err := C.hakurei_update_acl( - C.CString(name), + C.int(f.Fd()), C.uid_t(uid), C.acl_perm_t(perms), ) + + if _err = f.Close(); _err != nil { + return _err + } + if r == C.HAKUREI_ACL_OK { return nil } |
