MCPcopy Create free account
hub / github.com/PowerShell/DSC / enumerate_rules

Method enumerate_rules

resources/windows_firewall/src/firewall.rs:73–102  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

71 }
72
73 fn enumerate_rules(&self) -> Result<Vec<INetFwRule>, FirewallError> {
74 let enumerator = unsafe { self.rules._NewEnum() }
75 .map_err(|error| t!("firewall.ruleEnumerationFailed", error = error.to_string()).to_string())?;
76 let enum_variant: IEnumVARIANT = enumerator
77 .cast()
78 .map_err(|error| t!("firewall.ruleEnumerationFailed", error = error.to_string()).to_string())?;
79
80 let mut results = Vec::new();
81 loop {
82 let mut fetched = 0u32;
83 let mut safe_variant = SafeVariant::new();
84 let hr = unsafe { enum_variant.Next(std::slice::from_mut(safe_variant.as_mut()), &mut fetched) };
85 if hr == S_FALSE || fetched == 0 {
86 break;
87 }
88 hr.ok()
89 .map_err(|error| t!("firewall.ruleEnumerationFailed", error = error.to_string()).to_string())?;
90
91 let dispatch = IDispatch::try_from(safe_variant.as_ref())
92 .map_err(|error: windows::core::Error| t!("firewall.ruleEnumerationFailed", error = error.to_string()).to_string())?;
93 let rule: INetFwRule = dispatch
94 .cast()
95 .map_err(|error| t!("firewall.ruleEnumerationFailed", error = error.to_string()).to_string())?;
96 results.push(rule);
97
98 // SafeVariant will automatically call VariantClear when it goes out of scope
99 }
100
101 Ok(results)
102 }
103
104 fn find_by_selector(&self, selector: &FirewallRule) -> Result<Option<INetFwRule>, FirewallError> {
105 // HRESULT 0x80070002 is HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), returned when the

Callers 1

export_rulesFunction · 0.80

Calls 3

as_mutMethod · 0.80
newFunction · 0.50
as_refMethod · 0.45

Tested by

no test coverage detected