From 5c851a848a6eeb86472e8a1cca814dd0cb1b0483 Mon Sep 17 00:00:00 2001 From: adnan shaheen Date: Mon, 5 Feb 2018 14:01:55 +1000 Subject: WIXFEAT:4009 - Add support for outbound firewall rule --- src/wixext/FirewallCompiler.cs | 7 +++++++ src/wixext/FirewallConstants.cs | 2 ++ src/wixext/FirewallDecompiler.cs | 13 +++++++++++++ src/wixext/FirewallTableDefinitions.cs | 1 + src/wixext/Tuples/WixFirewallExceptionTuple.cs | 8 ++++++++ src/wixext/firewall.xsd | 10 +++++++++- 6 files changed, 40 insertions(+), 1 deletion(-) (limited to 'src/wixext') diff --git a/src/wixext/FirewallCompiler.cs b/src/wixext/FirewallCompiler.cs index 1fa80f48..900af7aa 100644 --- a/src/wixext/FirewallCompiler.cs +++ b/src/wixext/FirewallCompiler.cs @@ -81,6 +81,7 @@ namespace WixToolset.Firewall string scope = null; string remoteAddresses = null; string description = null; + int? direction = null; foreach (var attrib in element.Attributes()) { @@ -177,6 +178,11 @@ namespace WixToolset.Firewall case "Description": description = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); break; + case "Outbound": + direction = this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib) == YesNoType.Yes + ? FirewallConstants.NET_FW_RULE_DIR_OUT + : FirewallConstants.NET_FW_RULE_DIR_IN; + break; default: this.ParseHelper.UnexpectedAttribute(element, attrib); break; @@ -260,6 +266,7 @@ namespace WixToolset.Firewall Profile = profile ?? FirewallConstants.NET_FW_PROFILE2_ALL, ComponentRef = componentId, Description = description, + Direction = direction ?? FirewallConstants.NET_FW_RULE_DIR_IN, }); if (!String.IsNullOrEmpty(port)) diff --git a/src/wixext/FirewallConstants.cs b/src/wixext/FirewallConstants.cs index 16caa5b4..7bb12ba4 100644 --- a/src/wixext/FirewallConstants.cs +++ b/src/wixext/FirewallConstants.cs @@ -9,6 +9,8 @@ namespace WixToolset.Firewall static class FirewallConstants { // from icftypes.h + public const int NET_FW_RULE_DIR_IN = 1; + public const int NET_FW_RULE_DIR_OUT = 2; public const int NET_FW_IP_PROTOCOL_TCP = 6; public const int NET_FW_IP_PROTOCOL_UDP = 17; diff --git a/src/wixext/FirewallDecompiler.cs b/src/wixext/FirewallDecompiler.cs index b060f8e2..c9478de1 100644 --- a/src/wixext/FirewallDecompiler.cs +++ b/src/wixext/FirewallDecompiler.cs @@ -146,6 +146,19 @@ namespace WixToolset.Firewall fire.Description = (string)row[9]; } + if (!row.IsColumnEmpty(10)) + { + switch (Convert.ToInt32(row[10])) + { + case FirewallConstants.NET_FW_RULE_DIR_IN: + fire.Direction = Firewall.FirewallException.DirectionType.@in; + break; + case FirewallConstants.NET_FW_RULE_DIR_OUT: + fire.Direction = Firewall.FirewallException.DirectionType.@out; + break; + } + } + Wix.Component component = (Wix.Component)this.Core.GetIndexedElement("Component", (string)row[8]); if (null != component) { diff --git a/src/wixext/FirewallTableDefinitions.cs b/src/wixext/FirewallTableDefinitions.cs index 4bae1ef0..068fe696 100644 --- a/src/wixext/FirewallTableDefinitions.cs +++ b/src/wixext/FirewallTableDefinitions.cs @@ -21,6 +21,7 @@ namespace WixToolset.Firewall new ColumnDefinition("Profile", ColumnType.Number, 4, primaryKey: false, nullable: false, ColumnCategory.Integer, minValue: 1, maxValue: 2147483647, description: "Profile (1=domain; 2=private; 4=public; 2147483647=all)."), new ColumnDefinition("Component_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, keyTable: "Component", keyColumn: 1, description: "Foreign key into the Component table referencing component that controls the firewall configuration.", modularizeType: ColumnModularizeType.Column), new ColumnDefinition("Description", ColumnType.String, 255, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "Description displayed in Windows Firewall manager for this firewall rule."), + new ColumnDefinition("Direction", ColumnType.Number, 1, primaryKey: false, nullable: true, ColumnCategory.Integer, minValue: 1, maxValue: 2, description: "Direction (1=in; 2=out)"), }, tupleIdIsPrimaryKey: true ); diff --git a/src/wixext/Tuples/WixFirewallExceptionTuple.cs b/src/wixext/Tuples/WixFirewallExceptionTuple.cs index d08b9e45..d34b8207 100644 --- a/src/wixext/Tuples/WixFirewallExceptionTuple.cs +++ b/src/wixext/Tuples/WixFirewallExceptionTuple.cs @@ -20,6 +20,7 @@ namespace WixToolset.Firewall new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.Profile), IntermediateFieldType.Number), new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.ComponentRef), IntermediateFieldType.String), new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.Description), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.Direction), IntermediateFieldType.Number), }, typeof(WixFirewallExceptionTuple)); } @@ -40,6 +41,7 @@ namespace WixToolset.Firewall.Tuples Profile, ComponentRef, Description, + Direction, } public class WixFirewallExceptionTuple : IntermediateTuple @@ -107,5 +109,11 @@ namespace WixToolset.Firewall.Tuples get => this.Fields[(int)WixFirewallExceptionTupleFields.Description].AsString(); set => this.Set((int)WixFirewallExceptionTupleFields.Description, value); } + + public int Direction + { + get => this.Fields[(int)WixFirewallExceptionTupleFields.Direction].AsNumber(); + set => this.Set((int)WixFirewallExceptionTupleFields.Direction, value); + } } } \ No newline at end of file diff --git a/src/wixext/firewall.xsd b/src/wixext/firewall.xsd index d64aafef..fec7e37a 100644 --- a/src/wixext/firewall.xsd +++ b/src/wixext/firewall.xsd @@ -141,7 +141,7 @@ - If "yes," failures to register this firewall exception will be silently + If "yes", failures to register this firewall exception will be silently ignored. If "no" (the default), failures will cause rollback. @@ -170,6 +170,14 @@ + + + + + If "yes", registers an outbound firewall rule. + + + -- cgit v1.2.3-55-g6feb