main
cs 83 lines 2.45 KB
Raw
1 // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3 namespace WixTestTools.Firewall
4 {
5 using NetFwTypeLib;
6
7 /// <summary>
8 /// A lot of firewall rules don't follow the Microsoft recommendation of using unique names.<br/>
9 /// This class helps to disambiguate the rules based on Name, Direction, Profile, Protocol, ApplicationName, LocalUserOwner and RemoteAddresses.
10 /// </summary>
11 public class UniqueCheck
12 {
13 public UniqueCheck()
14 {
15 }
16
17 public UniqueCheck(RuleDetails details)
18 {
19 this.Name = details.Name;
20 this.Direction = details.Direction;
21 this.Profile = details.Profiles;
22 this.Protocol = details.Protocol;
23 this.ApplicationName = details.ApplicationName;
24 this.LocalUserOwner = details.LocalUserOwner;
25 this.RemoteAddresses = details.RemoteAddresses;
26 }
27
28
29 public string Name { get; set; }
30
31 public NET_FW_RULE_DIRECTION_? Direction { get; set; }
32
33 public int? Profile { get; set; }
34
35 public int? Protocol { get; set; }
36
37 public string ApplicationName { get; set; }
38
39 public string LocalUserOwner { get; set; }
40
41 public string RemoteAddresses { get; set; }
42
43 public bool FirewallRuleIsUnique(INetFwRule3 rule)
44 {
45 if (this.Name != null && rule.Name != this.Name)
46 {
47 return false;
48 }
49
50 if (this.Direction.HasValue && rule.Direction != this.Direction.Value)
51 {
52 return false;
53 }
54
55 if (this.Profile.HasValue && rule.Profiles != this.Profile.Value)
56 {
57 return false;
58 }
59
60 if (this.Protocol.HasValue && rule.Protocol != this.Protocol.Value)
61 {
62 return false;
63 }
64
65 if (this.ApplicationName != null && rule.ApplicationName != this.ApplicationName)
66 {
67 return false;
68 }
69
70 if (this.LocalUserOwner != null && rule.LocalUserOwner != this.LocalUserOwner)
71 {
72 return false;
73 }
74
75 if (this.RemoteAddresses != null && rule.RemoteAddresses != this.RemoteAddresses)
76 {
77 return false;
78 }
79
80 return true;
81 }
82 }
83 }