Converts a bitmask of firewall profile flags to a list of profile name strings. `NET_FW_PROFILE2_ALL` is `0x7FFFFFFF` (a sentinel meaning all profiles), while the combination of the three individual profile bits is `0x7`. Both are normalized to `["All"]`.
(mask: i32)
| 177 | /// `NET_FW_PROFILE2_ALL` is `0x7FFFFFFF` (a sentinel meaning all profiles), while the |
| 178 | /// combination of the three individual profile bits is `0x7`. Both are normalized to `["All"]`. |
| 179 | fn profiles_from_mask(mask: i32) -> Vec<String> { |
| 180 | let all_bits = NET_FW_PROFILE2_DOMAIN.0 | NET_FW_PROFILE2_PRIVATE.0 | NET_FW_PROFILE2_PUBLIC.0; |
| 181 | if mask == NET_FW_PROFILE2_ALL.0 || mask == all_bits { |
| 182 | return vec!["All".to_string()]; |
| 183 | } |
| 184 | |
| 185 | let mut profiles = Vec::new(); |
| 186 | if mask & NET_FW_PROFILE2_DOMAIN.0 != 0 { |
| 187 | profiles.push("Domain".to_string()); |
| 188 | } |
| 189 | if mask & NET_FW_PROFILE2_PRIVATE.0 != 0 { |
| 190 | profiles.push("Private".to_string()); |
| 191 | } |
| 192 | if mask & NET_FW_PROFILE2_PUBLIC.0 != 0 { |
| 193 | profiles.push("Public".to_string()); |
| 194 | } |
| 195 | profiles |
| 196 | } |
| 197 | |
| 198 | fn profiles_to_mask(values: &[String]) -> Result<i32, FirewallError> { |
| 199 | if values.is_empty() { |