aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/acl/acl.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/acl/acl.go')
-rw-r--r--internal/acl/acl.go84
1 files changed, 73 insertions, 11 deletions
diff --git a/internal/acl/acl.go b/internal/acl/acl.go
index 366ad533..7718ba3c 100644
--- a/internal/acl/acl.go
+++ b/internal/acl/acl.go
@@ -7,27 +7,89 @@ package acl
#include "libacl-helper.h"
*/
import "C"
+import "os"
+// Perm represents acl_perm_t.
type Perm C.acl_perm_t
const (
- Read Perm = C.ACL_READ
- Write Perm = C.ACL_WRITE
+ // Read represents ACL_READ.
+ Read Perm = C.ACL_READ
+ // Write represents ACL_WRITE.
+ Write Perm = C.ACL_WRITE
+ // Execute represents ACL_EXECUTE.
Execute Perm = C.ACL_EXECUTE
)
-// Update replaces ACL_USER entry with qualifier uid.
-func Update(name string, uid int, perms ...Perm) error {
- var p *Perm
- if len(perms) > 0 {
- p = &perms[0]
+// Status is the outcome of an ACL update operation.
+type Status = C.enum_hakurei_acl_status
+
+// An Error describes an error encountered during [Update].
+type Error struct {
+ // Pathname of the file to update ACL for.
+ Path string
+ // Function that returned the error.
+ Op Status
+ // Underlying errno.
+ Err error
+}
+
+// Unwrap returns an [os.PathError] describing e.
+func (e Error) Unwrap() error {
+ v := os.PathError{Path: e.Path, Err: e.Err}
+ switch e.Op {
+ case C.HAKUREI_ACL_OK:
+ return os.ErrInvalid
+
+ case C.HAKUREI_ACL_GET_FILE:
+ v.Op = "acl_get_file"
+ case C.HAKUREI_ACL_GET_TAG_TYPE:
+ v.Op = "acl_get_tag_type"
+ case C.HAKUREI_ACL_GET_QUALIFIER:
+ v.Op = "acl_get_qualifier"
+ case C.HAKUREI_ACL_DELETE_ENTRY:
+ v.Op = "acl_delete_entry"
+ case C.HAKUREI_ACL_CREATE_ENTRY:
+ v.Op = "acl_create_entry"
+ case C.HAKUREI_ACL_GET_PERMSET:
+ v.Op = "acl_get_permset"
+ case C.HAKUREI_ACL_ADD_PERM:
+ v.Op = "acl_add_perm"
+ case C.HAKUREI_ACL_SET_TAG_TYPE:
+ v.Op = "acl_set_tag_type"
+ case C.HAKUREI_ACL_SET_QUALIFIER:
+ v.Op = "acl_set_qualifier"
+ case C.HAKUREI_ACL_CALC_MASK:
+ v.Op = "acl_calc_mask"
+ case C.HAKUREI_ACL_VALID:
+ v.Op = "acl_valid"
+ case C.HAKUREI_ACL_SET_FILE:
+ v.Op = "acl_set_file"
+ case C.HAKUREI_ACL_GET_PERM:
+ v.Op = "acl_get_perm"
+ case C.HAKUREI_ACL_DUP:
+ v.Op = "acl_dup"
+
+ default: // unreachable
+ v.Op = "setfacl"
}
+ return &v
+}
+
+// Error returns the message of the resulting [os.PathError].
+func (e Error) Error() string {
+ return e.Unwrap().Error()
+}
- r, err := C.hakurei_acl_update_file_by_uid(
+// Update replaces ACL_USER entry with qualifier uid.
+func Update(name string, uid int, perms Perm) error {
+ r, err := C.hakurei_update_acl(
C.CString(name),
C.uid_t(uid),
- (*C.acl_perm_t)(p),
- C.size_t(len(perms)),
+ C.acl_perm_t(perms),
)
- return newAclPathError(name, int(r), err)
+ if r == C.HAKUREI_ACL_OK {
+ return nil
+ }
+ return &Error{name, r, err}
}