Skip to main content

rusthound_ce/objects/
schema.rs

1use 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    /// New Schema
11    pub fn new() -> Self {
12        Schema
13    }
14
15    /// Function to parse value for Schema object.
16    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 for current object
27        debug!("Parse schema: {result_dn}");
28
29        // Trace all result attributes
30        for (key, value) in &result_attrs {
31            trace!("  {key:?}:{value:?}");
32        }
33        // Trace all bin result attributes
34        for (key, value) in &result_bin {
35            trace!("  {key:?}:{value:?}");
36        }
37
38        // Only get name:schemaIDGUID
39        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}