]> git.proxmox.com Git - pxar.git/blob - src/format/acl.rs
import
[pxar.git] / src / format / acl.rs
1 //! ACL related data
2
3 use std::cmp::Ordering;
4
5 use endian_trait::Endian;
6
7 bitflags::bitflags! {
8 /// ACL permission bits.
9 #[derive(Endian)]
10 pub struct Permissions: u64 {
11 const PXAR_ACL_PERMISSION_READ = 4;
12 const PXAR_ACL_PERMISSION_WRITE = 2;
13 const PXAR_ACL_PERMISSION_EXECUTE = 1;
14 }
15 }
16
17 #[derive(Clone, Debug, Endian, Eq)]
18 #[repr(C)]
19 pub struct User {
20 pub uid: u64,
21 pub permissions: Permissions,
22 //pub name: Vec<u64>, not impl for now
23 }
24
25 // TODO if also name is impl, sort by uid, then by name and last by permissions
26 impl Ord for User {
27 fn cmp(&self, other: &User) -> Ordering {
28 match self.uid.cmp(&other.uid) {
29 // uids are equal, entries ordered by permissions
30 Ordering::Equal => self.permissions.cmp(&other.permissions),
31 // uids are different, entries ordered by uid
32 uid_order => uid_order,
33 }
34 }
35 }
36
37 impl PartialOrd for User {
38 fn partial_cmp(&self, other: &User) -> Option<Ordering> {
39 Some(self.cmp(other))
40 }
41 }
42
43 impl PartialEq for User {
44 fn eq(&self, other: &User) -> bool {
45 self.uid == other.uid && self.permissions == other.permissions
46 }
47 }
48
49 #[derive(Clone, Debug, Endian, Eq)]
50 #[repr(C)]
51 pub struct Group {
52 pub gid: u64,
53 pub permissions: Permissions,
54 //pub name: Vec<u64>, not impl for now
55 }
56
57 // TODO if also name is impl, sort by gid, then by name and last by permissions
58 impl Ord for Group {
59 fn cmp(&self, other: &Group) -> Ordering {
60 match self.gid.cmp(&other.gid) {
61 // gids are equal, entries are ordered by permissions
62 Ordering::Equal => self.permissions.cmp(&other.permissions),
63 // gids are different, entries ordered by gid
64 gid_ordering => gid_ordering,
65 }
66 }
67 }
68
69 impl PartialOrd for Group {
70 fn partial_cmp(&self, other: &Group) -> Option<Ordering> {
71 Some(self.cmp(other))
72 }
73 }
74
75 impl PartialEq for Group {
76 fn eq(&self, other: &Group) -> bool {
77 self.gid == other.gid && self.permissions == other.permissions
78 }
79 }
80
81 #[derive(Clone, Debug, Endian)]
82 #[repr(C)]
83 pub struct GroupObject {
84 pub permissions: Permissions,
85 }
86
87 #[derive(Clone, Debug, Endian)]
88 #[repr(C)]
89 pub struct Default {
90 pub user_obj_permissions: Permissions,
91 pub group_obj_permissions: Permissions,
92 pub other_permissions: Permissions,
93 pub mask_permissions: Permissions,
94 }