-
Notifications
You must be signed in to change notification settings - Fork 0
/
nfs4_ace.go
227 lines (205 loc) · 5.85 KB
/
nfs4_ace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package nfs4acl
import (
"bytes"
"fmt"
)
//Static Functions
func AceGetWhoType(who string) uint {
switch who {
case NFS4_ACL_WHO_OWNER_STRING:
return NFS4_ACL_WHO_OWNER
case NFS4_ACL_WHO_GROUP_STRING:
return NFS4_ACL_WHO_GROUP
case NFS4_ACL_WHO_EVERYONE_STRING:
return NFS4_ACL_WHO_EVERYONE
} //implicit default/else
return NFS4_ACL_WHO_NAMED
}
func AceWhoStringAtomLength(whoLength int) int {
//since the Who string isn't necessarily uint32 sized
//we need to find out how many uint32's, rounding up, it used
//so we can properly increment the pointer
// get the size of our Who string, rounded down to the nears atom
whoIncrement := int(whoLength/ATOM_SIZE) * ATOM_SIZE //increment ptr
//if these match, then our Who string was uint32 sized
if whoIncrement < whoLength {
//otherwise, pad it out to the next increment
whoIncrement += ATOM_SIZE
}
return whoIncrement
}
//Struct Declaration
type NFS4ACE struct {
AceType uint32
WhoType uint
Who string
Flags uint32
AccessMask uint32
}
//NFS4ACE struct constructor
func NewNFS4ACE(aceType, flag, mask uint32, who string) *NFS4ACE {
return &NFS4ACE{
AceType: aceType,
Who: who,
WhoType: AceGetWhoType(who),
Flags: flag,
AccessMask: mask,
}
}
//Ace methods
//Prints the Ace
func (ace *NFS4ACE) PrintACE(verbose, isDir bool) error {
//Create print buffer
var buffer bytes.Buffer
//Prepare Ace Type
if verbose {
switch ace.AceType {
case NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE:
buffer.WriteString("ALLOW")
case NFS4_ACE_ACCESS_DENIED_ACE_TYPE:
buffer.WriteString("DENY")
case NFS4_ACE_SYSTEM_AUDIT_ACE_TYPE:
buffer.WriteString("AUDIT")
case NFS4_ACE_SYSTEM_ALARM_ACE_TYPE:
buffer.WriteString("ALARM")
}
} else {
switch ace.AceType {
case NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE:
buffer.WriteRune(TYPE_ALLOW)
case NFS4_ACE_ACCESS_DENIED_ACE_TYPE:
buffer.WriteRune(TYPE_DENY)
case NFS4_ACE_SYSTEM_AUDIT_ACE_TYPE:
buffer.WriteRune(TYPE_AUDIT)
case NFS4_ACE_SYSTEM_ALARM_ACE_TYPE:
buffer.WriteRune(TYPE_ALARM)
}
}
buffer.WriteRune(':')
//Prepare Ace Flags
if ace.Flags&NFS4_ACE_FILE_INHERIT_ACE != 0 {
buffer.WriteRune(FLAG_FILE_INHERIT)
}
if ace.Flags&NFS4_ACE_DIRECTORY_INHERIT_ACE != 0 {
buffer.WriteRune(FLAG_DIR_INHERIT)
}
if ace.Flags&NFS4_ACE_NO_PROPAGATE_INHERIT_ACE != 0 {
buffer.WriteRune(FLAG_NO_PROPAGATE_INHERIT)
}
if ace.Flags&NFS4_ACE_INHERIT_ONLY_ACE != 0 {
buffer.WriteRune(FLAG_INHERIT_ONLY)
}
if ace.Flags&NFS4_ACE_SUCCESSFUL_ACCESS_ACE_FLAG != 0 {
buffer.WriteRune(FLAG_SUCCESSFUL_ACCESS)
}
if ace.Flags&NFS4_ACE_FAILED_ACCESS_ACE_FLAG != 0 {
buffer.WriteRune(FLAG_FAILED_ACCESS)
}
if ace.Flags&NFS4_ACE_IDENTIFIER_GROUP != 0 {
buffer.WriteRune(FLAG_GROUP)
}
if ace.Flags&NFS4_ACE_OWNER != 0 {
buffer.WriteRune(FLAG_OWNER_AT)
}
if ace.Flags&NFS4_ACE_GROUP != 0 {
buffer.WriteRune(FLAG_GROUP_AT)
}
if ace.Flags&NFS4_ACE_EVERYONE != 0 {
buffer.WriteRune(FLAG_EVERYONE_AT)
}
buffer.WriteRune(':')
//Prepare Ace WHO
buffer.WriteString(ace.Who)
buffer.WriteRune(':')
//Prepare Ace Mask
if isDir {
if ace.AccessMask&NFS4_ACE_LIST_DIRECTORY != 0 {
buffer.WriteRune(PERM_LIST_DIR)
}
if ace.AccessMask&NFS4_ACE_ADD_FILE != 0 {
buffer.WriteRune(PERM_CREATE_FILE)
}
if ace.AccessMask&NFS4_ACE_ADD_SUBDIRECTORY != 0 {
buffer.WriteRune(PERM_CREATE_SUBDIR)
}
if ace.AccessMask&NFS4_ACE_DELETE_CHILD != 0 {
buffer.WriteRune(PERM_DELETE_CHILD)
}
} else {
if ace.AccessMask&NFS4_ACE_READ_DATA != 0 {
buffer.WriteRune(PERM_READ_DATA)
}
if ace.AccessMask&NFS4_ACE_WRITE_DATA != 0 {
buffer.WriteRune(PERM_WRITE_DATA)
}
if ace.AccessMask&NFS4_ACE_APPEND_DATA != 0 {
buffer.WriteRune(PERM_APPEND_DATA)
}
}
if ace.AccessMask&NFS4_ACE_DELETE != 0 {
buffer.WriteRune(PERM_DELETE)
}
if ace.AccessMask&NFS4_ACE_EXECUTE != 0 {
buffer.WriteRune(PERM_EXECUTE)
}
if ace.AccessMask&NFS4_ACE_READ_ATTRIBUTES != 0 {
buffer.WriteRune(PERM_READ_ATTR)
}
if ace.AccessMask&NFS4_ACE_WRITE_ATTRIBUTES != 0 {
buffer.WriteRune(PERM_WRITE_ATTR)
}
if ace.AccessMask&NFS4_ACE_READ_NAMED_ATTRS != 0 {
buffer.WriteRune(PERM_READ_NAMED_ATTR)
}
if ace.AccessMask&NFS4_ACE_WRITE_NAMED_ATTRS != 0 {
buffer.WriteRune(PERM_WRITE_NAMED_ATTR)
}
if ace.AccessMask&NFS4_ACE_READ_ACL != 0 {
buffer.WriteRune(PERM_READ_ACL)
}
if ace.AccessMask&NFS4_ACE_WRITE_ACL != 0 {
buffer.WriteRune(PERM_WRITE_ACL)
}
if ace.AccessMask&NFS4_ACE_WRITE_OWNER != 0 {
buffer.WriteRune(PERM_WRITE_OWNER)
}
if ace.AccessMask&NFS4_ACE_SYNCHRONIZE != 0 {
buffer.WriteRune(PERM_SYNCHRONIZE)
}
fmt.Println(buffer.String())
return nil
}
//Bitwise ORs the access mask. This will set any bits in the specified access mask
//but will not modify any existing set bits
// value = 00110101
// mask | 00000011
// result 00110111
func (ace *NFS4ACE) applyAccessMask(accessMask uint32) {
ace.AccessMask = ace.AccessMask | accessMask
}
//Bitwise AND NOT the access mask (bit clear). This will unset any bits in the specified access mask
//but will not modify any others
// value = 00110101 mask = 00000011
// NOT MASK & 11111100
// result 00110100
func (ace *NFS4ACE) removeAccessMask(accessMask uint32) {
ace.AccessMask = ace.AccessMask &^ accessMask
}
//Sets the accessmask to the specified mask. Total overwrite
func (ace *NFS4ACE) setAccessMask(accessMask uint32) {
ace.AccessMask = accessMask
}
//Bitwise ORs the flags. This will set any bits in the specified flags
//but will not modify any existing set bits
func (ace *NFS4ACE) applyFlags(flags uint32) {
ace.Flags = ace.Flags | flags
}
//Bitwise AND NOT the flags (bit clear). This will unset any bits in the specified flags
//but will not modify any others
func (ace *NFS4ACE) removeFlags(flags uint32) {
ace.Flags = ace.Flags &^ flags
}
//Sets the flags to the specified mask. Total overwrite
func (ace *NFS4ACE) setFlags(flags uint32) {
ace.Flags = flags
}