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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
use crate::prelude::*;
use std::collections::BTreeSet;
use crate::filter::{Filter, FilterValid};
use kanidm_proto::v1::Filter as ProtoFilter;
#[derive(Debug, Clone)]
pub struct AccessControlSearch {
pub acp: AccessControlProfile,
pub attrs: BTreeSet<AttrString>,
}
impl AccessControlSearch {
pub fn try_from(
qs: &mut QueryServerWriteTransaction,
value: &Entry<EntrySealed, EntryCommitted>,
) -> Result<Self, OperationError> {
if !value.attribute_equality("class", &PVCLASS_ACS) {
admin_error!("class access_control_search not present.");
return Err(OperationError::InvalidAcpState(
"Missing access_control_search".to_string(),
));
}
let attrs = value
.get_ava_iter_iutf8("acp_search_attr")
.ok_or_else(|| {
admin_error!("Missing acp_search_attr");
OperationError::InvalidAcpState("Missing acp_search_attr".to_string())
})?
.map(AttrString::from)
.collect();
let acp = AccessControlProfile::try_from(qs, value)?;
Ok(AccessControlSearch { acp, attrs })
}
#[cfg(test)]
pub(super) unsafe fn from_raw(
name: &str,
uuid: Uuid,
receiver: Uuid,
targetscope: Filter<FilterValid>,
attrs: &str,
) -> Self {
AccessControlSearch {
acp: AccessControlProfile {
name: name.to_string(),
uuid,
receiver: Some(receiver),
targetscope,
},
attrs: attrs
.split_whitespace()
.map(|s| AttrString::from(s))
.collect(),
}
}
}
#[derive(Debug, Clone)]
pub struct AccessControlDelete {
pub acp: AccessControlProfile,
}
impl AccessControlDelete {
pub fn try_from(
qs: &mut QueryServerWriteTransaction,
value: &Entry<EntrySealed, EntryCommitted>,
) -> Result<Self, OperationError> {
if !value.attribute_equality("class", &PVCLASS_ACD) {
admin_error!("class access_control_delete not present.");
return Err(OperationError::InvalidAcpState(
"Missing access_control_delete".to_string(),
));
}
Ok(AccessControlDelete {
acp: AccessControlProfile::try_from(qs, value)?,
})
}
#[cfg(test)]
pub(super) unsafe fn from_raw(
name: &str,
uuid: Uuid,
receiver: Uuid,
targetscope: Filter<FilterValid>,
) -> Self {
AccessControlDelete {
acp: AccessControlProfile {
name: name.to_string(),
uuid,
receiver: Some(receiver),
targetscope,
},
}
}
}
#[derive(Debug, Clone)]
pub struct AccessControlCreate {
pub acp: AccessControlProfile,
pub classes: Vec<AttrString>,
pub attrs: Vec<AttrString>,
}
impl AccessControlCreate {
pub fn try_from(
qs: &mut QueryServerWriteTransaction,
value: &Entry<EntrySealed, EntryCommitted>,
) -> Result<Self, OperationError> {
if !value.attribute_equality("class", &PVCLASS_ACC) {
admin_error!("class access_control_create not present.");
return Err(OperationError::InvalidAcpState(
"Missing access_control_create".to_string(),
));
}
let attrs = value
.get_ava_iter_iutf8("acp_create_attr")
.map(|i| i.map(AttrString::from).collect())
.unwrap_or_else(Vec::new);
let classes = value
.get_ava_iter_iutf8("acp_create_class")
.map(|i| i.map(AttrString::from).collect())
.unwrap_or_else(Vec::new);
Ok(AccessControlCreate {
acp: AccessControlProfile::try_from(qs, value)?,
classes,
attrs,
})
}
#[cfg(test)]
pub(super) unsafe fn from_raw(
name: &str,
uuid: Uuid,
receiver: Uuid,
targetscope: Filter<FilterValid>,
classes: &str,
attrs: &str,
) -> Self {
AccessControlCreate {
acp: AccessControlProfile {
name: name.to_string(),
uuid,
receiver: Some(receiver),
targetscope,
},
classes: classes.split_whitespace().map(AttrString::from).collect(),
attrs: attrs.split_whitespace().map(AttrString::from).collect(),
}
}
}
#[derive(Debug, Clone)]
pub struct AccessControlModify {
pub acp: AccessControlProfile,
pub classes: Vec<AttrString>,
pub presattrs: Vec<AttrString>,
pub remattrs: Vec<AttrString>,
}
impl AccessControlModify {
pub fn try_from(
qs: &mut QueryServerWriteTransaction,
value: &Entry<EntrySealed, EntryCommitted>,
) -> Result<Self, OperationError> {
if !value.attribute_equality("class", &PVCLASS_ACM) {
admin_error!("class access_control_modify not present.");
return Err(OperationError::InvalidAcpState(
"Missing access_control_modify".to_string(),
));
}
let presattrs = value
.get_ava_iter_iutf8("acp_modify_presentattr")
.map(|i| i.map(AttrString::from).collect())
.unwrap_or_else(Vec::new);
let remattrs = value
.get_ava_iter_iutf8("acp_modify_removedattr")
.map(|i| i.map(AttrString::from).collect())
.unwrap_or_else(Vec::new);
let classes = value
.get_ava_iter_iutf8("acp_modify_class")
.map(|i| i.map(AttrString::from).collect())
.unwrap_or_else(Vec::new);
Ok(AccessControlModify {
acp: AccessControlProfile::try_from(qs, value)?,
classes,
presattrs,
remattrs,
})
}
#[cfg(test)]
pub(super) unsafe fn from_raw(
name: &str,
uuid: Uuid,
receiver: Uuid,
targetscope: Filter<FilterValid>,
presattrs: &str,
remattrs: &str,
classes: &str,
) -> Self {
AccessControlModify {
acp: AccessControlProfile {
name: name.to_string(),
uuid,
receiver: Some(receiver),
targetscope,
},
classes: classes
.split_whitespace()
.map(|s| AttrString::from(s))
.collect(),
presattrs: presattrs
.split_whitespace()
.map(|s| AttrString::from(s))
.collect(),
remattrs: remattrs
.split_whitespace()
.map(|s| AttrString::from(s))
.collect(),
}
}
}
#[derive(Debug, Clone)]
pub struct AccessControlProfile {
pub name: String,
#[allow(dead_code)]
uuid: Uuid,
pub receiver: Option<Uuid>,
pub targetscope: Filter<FilterValid>,
}
impl AccessControlProfile {
pub(super) fn try_from(
qs: &mut QueryServerWriteTransaction,
value: &Entry<EntrySealed, EntryCommitted>,
) -> Result<Self, OperationError> {
if !value.attribute_equality("class", &PVCLASS_ACP) {
admin_error!("class access_control_profile not present.");
return Err(OperationError::InvalidAcpState(
"Missing access_control_profile".to_string(),
));
}
let name = value
.get_ava_single_iname("name")
.ok_or_else(|| {
admin_error!("Missing name");
OperationError::InvalidAcpState("Missing name".to_string())
})?
.to_string();
let uuid = value.get_uuid();
let receiver = value.get_ava_single_refer("acp_receiver_group");
let targetscope_f: ProtoFilter = value
.get_ava_single_protofilter("acp_targetscope")
.cloned()
.ok_or_else(|| {
admin_error!("Missing acp_targetscope");
OperationError::InvalidAcpState("Missing acp_targetscope".to_string())
})?;
let ident = Identity::from_internal();
let targetscope_i = Filter::from_rw(&ident, &targetscope_f, qs).map_err(|e| {
admin_error!("Targetscope validation failed {:?}", e);
e
})?;
let targetscope = targetscope_i.validate(qs.get_schema()).map_err(|e| {
admin_error!("acp_targetscope Schema Violation {:?}", e);
OperationError::SchemaViolation(e)
})?;
Ok(AccessControlProfile {
name,
uuid,
receiver,
targetscope,
})
}
}