rusthound_ce/objects/
schema.rs1use std::collections::HashMap;
2use ldap3::SearchEntry;
3use log::{debug, trace};
4
5use crate::enums::decode_guid_le;
6
7pub struct Schema;
8
9impl Schema {
10 pub fn new() -> Self {
12 Schema
13 }
14
15 pub fn parse(
17 &self,
18 result: SearchEntry,
19 schema_guid_map: &mut HashMap<String, String>,
20 ) -> Result<(), Box<dyn std::error::Error>> {
21
22 let result_dn: String = result.dn.to_uppercase();
23 let result_attrs: HashMap<String, Vec<String>> = result.attrs;
24 let result_bin: HashMap<String, Vec<Vec<u8>>> = result.bin_attrs;
25
26 debug!("Parse schema: {result_dn}");
28
29 for (key, value) in &result_attrs {
31 trace!(" {key:?}:{value:?}");
32 }
33 for (key, value) in &result_bin {
35 trace!(" {key:?}:{value:?}");
36 }
37
38 if let (Some(names), Some(guids)) = (
40 result_attrs.get("name"),
41 result_bin.get("schemaIDGUID"),
42 ) {
43 if let (Some(name), Some(guid_bytes)) = (names.first(), guids.first()) {
44 let guid = decode_guid_le(guid_bytes);
45 trace!("Parse Schema object .to_lowercase(): {}:{}", name.to_lowercase(), guid.to_lowercase());
46 schema_guid_map.insert(name.to_lowercase(), guid.to_lowercase());
47 }
48 }
49
50 Ok(())
51 }
52}