2024-12-16 18:27:19 +09:00
|
|
|
// Package acl implements simple ACL manipulation via libacl.
|
|
|
|
package acl
|
|
|
|
|
2025-02-17 20:33:18 +09:00
|
|
|
/*
|
|
|
|
#cgo linux pkg-config: --static libacl
|
|
|
|
|
2025-02-17 20:37:10 +09:00
|
|
|
#include "acl-update.h"
|
2025-02-17 20:33:18 +09:00
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
2025-02-17 20:37:10 +09:00
|
|
|
type Perm C.acl_perm_t
|
2025-02-17 20:33:18 +09:00
|
|
|
|
|
|
|
const (
|
2025-02-17 20:37:10 +09:00
|
|
|
Read Perm = C.ACL_READ
|
|
|
|
Write Perm = C.ACL_WRITE
|
|
|
|
Execute Perm = C.ACL_EXECUTE
|
2025-02-17 20:33:18 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
// Update replaces ACL_USER entry with qualifier uid.
|
|
|
|
func Update(name string, uid int, perms ...Perm) error {
|
2025-02-17 20:37:10 +09:00
|
|
|
var p *Perm
|
2025-02-17 20:33:18 +09:00
|
|
|
if len(perms) > 0 {
|
2025-02-17 20:37:10 +09:00
|
|
|
p = &perms[0]
|
2024-12-16 18:27:19 +09:00
|
|
|
}
|
2025-02-17 20:33:18 +09:00
|
|
|
|
2025-02-17 20:37:10 +09:00
|
|
|
r, err := C.f_acl_update_file_by_uid(
|
|
|
|
C.CString(name),
|
|
|
|
C.uid_t(uid),
|
|
|
|
(*C.acl_perm_t)(p),
|
|
|
|
C.size_t(len(perms)),
|
|
|
|
)
|
|
|
|
if r == 0 {
|
|
|
|
return nil
|
2025-02-17 20:33:18 +09:00
|
|
|
}
|
2025-02-17 20:37:10 +09:00
|
|
|
return err
|
2024-12-16 18:27:19 +09:00
|
|
|
}
|