windows_eventlog_native/
security.rs1use chrono::{DateTime, Utc};
2
3use crate::error::Result;
4use crate::event::Event;
5use crate::query::{EventLog, QueryDirection};
6
7pub fn security_audit_by_id(ids: &[u32], since: DateTime<Utc>) -> Result<Vec<Event>> {
17 let xpath = build_event_id_xpath(ids, since);
18 let iter = EventLog::query("Security", &xpath, QueryDirection::Reverse)?;
19
20 let mut out = Vec::new();
21 for evt in iter {
22 out.push(evt?);
23 }
24 Ok(out)
25}
26
27pub(crate) fn build_event_id_xpath(ids: &[u32], since: DateTime<Utc>) -> String {
32 let ts = since.format("%Y-%m-%dT%H:%M:%S%.3fZ");
34
35 if ids.is_empty() {
36 return format!("*[System[TimeCreated[@SystemTime>='{ts}']]]");
37 }
38
39 let mut clause = String::from("(");
40 for (i, id) in ids.iter().enumerate() {
41 if i > 0 {
42 clause.push_str(" or ");
43 }
44 clause.push_str(&format!("EventID={id}"));
45 }
46 clause.push(')');
47
48 format!("*[System[{clause} and TimeCreated[@SystemTime>='{ts}']]]")
49}