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
use clap::{Subcommand, ValueEnum};
use strum::Display;
use crate::cli::SdDisplayOption;
use super::{EntryFormat, MemberOfAttribute, OutputFormat};
#[derive(clap::ValueEnum, Clone, Copy, Display, Eq, PartialEq)]
pub enum EntrySearchField {
/// search for an entry with a specific ID.
///
/// Requires <id> to be an i32.
EntryId,
/// search for SID instead for NTDS.DIT entry id.
/// <ENTRY_ID> will be interpreted as RID, wich is the last part of the SID;
/// e.g. 500 will return the Administrator account
///
/// Requires <id> to be an u32.
Sid,
/// search for an entry with a specific object GUID
///
/// Requires <id> to be an GUID.
Guid,
}
#[derive(Subcommand)]
pub enum Commands {
/// Display user accounts
User {
/// Output format
#[clap(value_enum, short('F'), long("format"), default_value_t = OutputFormat::Csv)]
format: OutputFormat,
/// show all non-empty values. This option is ignored when CSV-Output is selected
#[clap(short('A'), long("show-all"))]
show_all: bool,
/// include the distinguished name (DN) in the output.
///
/// Note that this
/// property is not an attribute of the AD entry iself; instead it is
/// constructed from the relative DN (RDN) of the entry and
/// all of its parents. That's why this property is normally not shown.
#[clap(short('D'), long("include-dn"))]
include_dn: bool,
/// include the security descriptor in the output
#[clap(short('S'), long("security-descriptor"), default_value_t=SdDisplayOption::Hide)]
sd_display_option: SdDisplayOption,
/// specify which attribute shall be used to display group memberships
#[clap(long("member-of"), default_value_t=MemberOfAttribute::Rdn)]
member_of_attribute: MemberOfAttribute,
},
/// Display groups
Group {
/// Output format
#[clap(value_enum, short('F'), long("format"), default_value_t = OutputFormat::Csv)]
format: OutputFormat,
/// show all non-empty values. This option is ignored when CSV-Output is selected
#[clap(short('A'), long("show-all"))]
show_all: bool,
/// include the distinguished name (DN) in the output.
///
/// Note that this
/// property is not an attribute of the AD entry iself; instead it is
/// constructed from the relative DN (RDN) of the entry and
/// all of its parents. That's why this property is normally not shown.
#[clap(short('D'), long("include-dn"))]
include_dn: bool,
/// include the security descriptor in the output
#[clap(short('S'), long("security-descriptor"), default_value_t=SdDisplayOption::Hide)]
sd_display_option: SdDisplayOption,
/// specify which attribute shall be used to display group memberships
#[clap(long("member-of"), default_value_t=MemberOfAttribute::Rdn)]
member_of_attribute: MemberOfAttribute,
},
/// display computer accounts
Computer {
/// Output format
#[clap(value_enum, short('F'), long("format"), default_value_t = OutputFormat::Csv)]
format: OutputFormat,
/// show all non-empty values. This option is ignored when CSV-Output is selected
#[clap(short('A'), long("show-all"))]
show_all: bool,
/// include the distinguished name (DN) in the output.
///
/// Note that this
/// property is not an attribute of the AD entry iself; instead it is
/// constructed from the relative DN (RDN) of the entry and
/// all of its parents. That's why this property is normally not shown.
#[clap(short('D'), long("include-dn"))]
include_dn: bool,
/// include the security descriptor in the output
#[clap(short('S'), long("security-descriptor"), default_value_t = SdDisplayOption::Hide)]
sd_display_option: SdDisplayOption,
/// specify which attribute shall be used to display group memberships
#[clap(long("member-of"), default_value_t=MemberOfAttribute::Rdn)]
member_of_attribute: MemberOfAttribute,
},
/// create a timeline (in flow-record format)
Timeline {
/// show objects of any type (this might be a lot)
#[clap(long("all-objects"))]
all_objects: bool,
/// include also deleted objects (which don't have an AttObjectCategory attribute)
#[clap(long("include-deleted"))]
include_deleted: bool,
/// output format
#[clap(short('F'), long("format"), default_value_t=TimelineFormat::Record)]
format: TimelineFormat,
},
/// list all defined types
Types {
/// Output format
#[clap(value_enum, short('F'), long("format"), default_value_t = OutputFormat::Csv)]
format: OutputFormat,
},
/// display the directory information tree
Tree {
/// maximum recursion depth
#[clap(long("max-depth"), default_value_t = 4)]
max_depth: u8,
},
/// display one single entry from the directory information tree
Entry {
#[clap(short('f'), long("field"), default_value_t = EntrySearchField::Sid)]
search_field: EntrySearchField,
/// id of the entry to show
id: String,
#[clap(short('F'), long("format"), default_value_t = EntryFormat::Simple)]
entry_format: EntryFormat,
},
/// search for entries whose values match to some regular expression
Search {
/// regular expression to match against
regex: String,
/// case-insensitive search (ignore case)
#[clap(short('i'), long("ignore-case"))]
ignore_case: bool,
},
}
impl Commands {
pub fn display_all_attributes(&self) -> bool {
match self {
Commands::User {
format: OutputFormat::Json,
show_all,
include_dn: _,
sd_display_option: _,
member_of_attribute: _,
}
| Commands::User {
format: OutputFormat::JsonLines,
show_all,
include_dn: _,
sd_display_option: _,
member_of_attribute: _,
}
| Commands::Computer {
format: OutputFormat::Json,
show_all,
include_dn: _,
sd_display_option: _,
member_of_attribute: _,
}
| Commands::Computer {
format: OutputFormat::JsonLines,
show_all,
include_dn: _,
sd_display_option: _,
member_of_attribute: _,
} => *show_all,
_ => false,
}
}
pub fn include_dn(&self) -> bool {
match self {
Commands::User {
format: _,
show_all: _,
include_dn,
sd_display_option: _,
member_of_attribute: _,
}
| Commands::Group {
format: _,
show_all: _,
include_dn,
sd_display_option: _,
member_of_attribute: _,
} => *include_dn,
Commands::Computer {
format: _,
show_all: _,
include_dn,
sd_display_option: _,
member_of_attribute: _,
} => *include_dn,
_ => false,
}
}
pub fn show_security_descriptor(&self) -> SdDisplayOption {
match self {
Commands::User {
format: _,
show_all: _,
include_dn: _,
sd_display_option,
member_of_attribute: _,
}
| Commands::Group {
format: _,
show_all: _,
include_dn: _,
sd_display_option,
member_of_attribute: _,
}
| Commands::Computer {
format: _,
show_all: _,
include_dn: _,
sd_display_option,
member_of_attribute: _,
} => *sd_display_option,
_ => SdDisplayOption::Hide,
}
}
pub fn member_of_attribute(&self) -> MemberOfAttribute {
match self {
Commands::User {
format: _,
show_all: _,
include_dn: _,
sd_display_option: _,
member_of_attribute,
} => *member_of_attribute,
Commands::Group {
format: _,
show_all: _,
include_dn: _,
sd_display_option: _,
member_of_attribute,
} => *member_of_attribute,
Commands::Computer {
format: _,
show_all: _,
include_dn: _,
sd_display_option: _,
member_of_attribute,
} => *member_of_attribute,
_ => MemberOfAttribute::Rdn,
}
}
pub fn flat_serialization(&self) -> bool {
matches!(
&self,
Commands::User {
format: OutputFormat::Csv,
..
} | Commands::Computer {
format: OutputFormat::Csv,
..
} | Commands::Group {
format: OutputFormat::Csv,
..
} | Commands::Timeline { .. }
)
}
pub fn format(&self) -> OutputFormat {
match self {
Commands::User { format, .. } => *format,
Commands::Group { format, .. } => *format,
Commands::Computer { format, .. } => *format,
Commands::Types { format } => *format,
_ => OutputFormat::default(),
}
}
}
#[derive(ValueEnum, Clone, Display)]
pub enum TimelineFormat {
/// bodyfile format
#[strum(serialize = "bodyfile")]
Bodyfile,
/// flow record format (<https://docs.rs/flow-record>)
#[strum(serialize = "record")]
Record,
}