Blame SOURCES/firewalld-0.3.9-RHBZ#1059800.patch

36ae71
diff -up firewalld-0.3.9/doc/man/man1/firewall-offline-cmd.1.RHBZ#1059800 firewalld-0.3.9/doc/man/man1/firewall-offline-cmd.1
36ae71
--- firewalld-0.3.9/doc/man/man1/firewall-offline-cmd.1.RHBZ#1059800	2014-01-13 17:07:04.000000000 +0100
36ae71
+++ firewalld-0.3.9/doc/man/man1/firewall-offline-cmd.1	2014-02-26 09:30:43.439191822 +0100
36ae71
@@ -66,7 +66,7 @@ is not given\&.
36ae71
 .RS 4
36ae71
 Disable the firewall by disabling the firewalld service\&.
36ae71
 .RE
36ae71
-.SS "General Options"
36ae71
+.SS "Lokkit Compatibility Options"
36ae71
 .PP
36ae71
 \fB\-\-addmodule\fR=\fImodule\fR
36ae71
 .RS 4
36ae71
@@ -168,6 +168,813 @@ The
36ae71
 is the one of the icmp types firewalld supports\&. To get a listing of supported icmp types:
36ae71
 \fBfirewall\-cmd \-\-get\-icmptypes\fR
36ae71
 .RE
36ae71
+.SS "Zone Options"
36ae71
+.PP
36ae71
+\fB\-\-get\-default\-zone\fR
36ae71
+.RS 4
36ae71
+Print default zone for connections and interfaces\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-set\-default\-zone\fR=\fIzone\fR
36ae71
+.RS 4
36ae71
+Set default zone for connections and interfaces where no zone has been selected\&. Setting the default zone changes the zone for the connections or interfaces, that are using the default zone\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-get\-zones\fR
36ae71
+.RS 4
36ae71
+Print predefined zones as a space separated list\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-get\-services\fR
36ae71
+.RS 4
36ae71
+Print predefined services as a space separated list\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-get\-icmptypes\fR
36ae71
+.RS 4
36ae71
+Print predefined icmptypes as a space separated list\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-get\-zone\-of\-interface\fR=\fIinterface\fR
36ae71
+.RS 4
36ae71
+Print the name of the zone the
36ae71
+\fIinterface\fR
36ae71
+is bound to or
36ae71
+\fIno zone\fR\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-get\-zone\-of\-source\fR=\fIsource\fR[/\fImask\fR]
36ae71
+.RS 4
36ae71
+Print the name of the zone the
36ae71
+\fIsource\fR[/\fImask\fR]
36ae71
+is bound to or
36ae71
+\fIno zone\fR\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-list\-all\-zones\fR
36ae71
+.RS 4
36ae71
+List everything added for or enabled in all zones\&. The output format is:
36ae71
+.sp
36ae71
+.if n \{\
36ae71
+.RS 4
36ae71
+.\}
36ae71
+.nf
36ae71
+\fIzone1\fR
36ae71
+  interfaces: \fIinterface1\fR \&.\&.
36ae71
+  sources: \fIsource1\fR \&.\&.
36ae71
+  services: \fIservice1\fR \&.\&.
36ae71
+  ports: \fIport1\fR \&.\&.
36ae71
+  forward\-ports:
36ae71
+        \fIforward\-port1\fR
36ae71
+        \&.\&.
36ae71
+  icmp\-blocks: \fIicmp\-type1\fR \&.\&.
36ae71
+  rich rules:
36ae71
+        \fIrich\-rule1\fR
36ae71
+        \&.\&.
36ae71
+\&.\&.
36ae71
+              
36ae71
+.fi
36ae71
+.if n \{\
36ae71
+.RE
36ae71
+.\}
36ae71
+.sp
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-new\-zone\fR=\fIzone\fR
36ae71
+.RS 4
36ae71
+Add a new permanent zone\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-delete\-zone\fR=\fIzone\fR
36ae71
+.RS 4
36ae71
+Delete an existing permanent zone\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-zone\fR=\fIzone\fR \fB\-\-get\-target\fR
36ae71
+.RS 4
36ae71
+Get the target of a permanent zone\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-zone\fR=\fIzone\fR \fB\-\-set\-target\fR=\fIzone\fR
36ae71
+.RS 4
36ae71
+Set the target of a permanent zone\&.
36ae71
+.RE
36ae71
+.SS "Options to Adapt and Query Zones"
36ae71
+.PP
36ae71
+Options in this section affect only one particular zone\&. If used with
36ae71
+\fB\-\-zone\fR=\fIzone\fR
36ae71
+option, they affect the zone
36ae71
+\fIzone\fR\&. If the option is omitted, they affect default zone (see
36ae71
+\fB\-\-get\-default\-zone\fR)\&.
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-list\-all\fR
36ae71
+.RS 4
36ae71
+List everything added for or enabled in
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-list\-services\fR
36ae71
+.RS 4
36ae71
+List services added for
36ae71
+\fIzone\fR
36ae71
+as a space separated list\&. If zone is omitted, default zone will be used\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-add\-service\fR=\fIservice\fR
36ae71
+.RS 4
36ae71
+Add a service for
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. This option can be specified multiple times\&.
36ae71
+.sp
36ae71
+The service is one of the firewalld provided services\&. To get a list of the supported services, use
36ae71
+\fBfirewall\-cmd \-\-get\-services\fR\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-remove\-service\-from\-zone\fR=\fIservice\fR
36ae71
+.RS 4
36ae71
+Remove a service from
36ae71
+\fIzone\fR\&. This option can be specified multiple times\&. If zone is omitted, default zone will be used\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-query\-service\fR=\fIservice\fR
36ae71
+.RS 4
36ae71
+Return whether
36ae71
+\fIservice\fR
36ae71
+has been added for
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-list\-ports\fR
36ae71
+.RS 4
36ae71
+List ports added for
36ae71
+\fIzone\fR
36ae71
+as a space separated list\&. A port is of the form
36ae71
+\fIportid\fR[\-\fIportid\fR]/\fIprotocol\fR, it can be either a port and protocol pair or a port range with a protocol\&. If zone is omitted, default zone will be used\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-add\-port\fR=\fIportid\fR[\-\fIportid\fR]/\fIprotocol\fR
36ae71
+.RS 4
36ae71
+Add the port for
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. This option can be specified multiple times\&.
36ae71
+.sp
36ae71
+The port can either be a single port number or a port range
36ae71
+\fIportid\fR\-\fIportid\fR\&. The protocol can either be
36ae71
+\fItcp\fR
36ae71
+or
36ae71
+\fIudp\fR\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-remove\-port\fR=\fIportid\fR[\-\fIportid\fR]/\fIprotocol\fR
36ae71
+.RS 4
36ae71
+Remove the port from
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. This option can be specified multiple times\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-query\-port\fR=\fIportid\fR[\-\fIportid\fR]/\fIprotocol\fR
36ae71
+.RS 4
36ae71
+Return whether the port has been added for
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-list\-icmp\-blocks\fR
36ae71
+.RS 4
36ae71
+List Internet Control Message Protocol (ICMP) type blocks added for
36ae71
+\fIzone\fR
36ae71
+as a space separated list\&. If zone is omitted, default zone will be used\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-add\-icmp\-block\fR=\fIicmptype\fR
36ae71
+.RS 4
36ae71
+Add an ICMP block for
36ae71
+\fIicmptype\fR
36ae71
+for
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. This option can be specified multiple times\&.
36ae71
+.sp
36ae71
+The
36ae71
+\fIicmptype\fR
36ae71
+is the one of the icmp types firewalld supports\&. To get a listing of supported icmp types:
36ae71
+\fBfirewall\-cmd \-\-get\-icmptypes\fR
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-remove\-icmp\-block\fR=\fIicmptype\fR
36ae71
+.RS 4
36ae71
+Remove the ICMP block for
36ae71
+\fIicmptype\fR
36ae71
+from
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. This option can be specified multiple times\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-query\-icmp\-block\fR=\fIicmptype\fR
36ae71
+.RS 4
36ae71
+Return whether an ICMP block for
36ae71
+\fIicmptype\fR
36ae71
+has been added for
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-list\-forward\-ports\fR
36ae71
+.RS 4
36ae71
+List
36ae71
+\fIIPv4\fR
36ae71
+forward ports added for
36ae71
+\fIzone\fR
36ae71
+as a space separated list\&. If zone is omitted, default zone will be used\&.
36ae71
+.sp
36ae71
+For
36ae71
+\fIIPv6\fR
36ae71
+forward ports, please use the rich language\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-add\-forward\-port\fR=port=\fIportid\fR[\-\fIportid\fR]:proto=\fIprotocol\fR[:toport=\fIportid\fR[\-\fIportid\fR]][:toaddr=\fIaddress\fR[/\fImask\fR]]
36ae71
+.RS 4
36ae71
+Add the
36ae71
+\fIIPv4\fR
36ae71
+forward port for
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. This option can be specified multiple times\&.
36ae71
+.sp
36ae71
+The port can either be a single port number
36ae71
+\fIportid\fR
36ae71
+or a port range
36ae71
+\fIportid\fR\-\fIportid\fR\&. The protocol can either be
36ae71
+\fItcp\fR
36ae71
+or
36ae71
+\fIudp\fR\&. The destination address is a simple IP address\&.
36ae71
+.sp
36ae71
+For
36ae71
+\fIIPv6\fR
36ae71
+forward ports, please use the rich language\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-remove\-forward\-port\fR=port=\fIportid\fR[\-\fIportid\fR]:proto=\fIprotocol\fR[:toport=\fIportid\fR[\-\fIportid\fR]][:toaddr=\fIaddress\fR[/\fImask\fR]]
36ae71
+.RS 4
36ae71
+Remove the
36ae71
+\fIIPv4\fR
36ae71
+forward port from
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. This option can be specified multiple times\&.
36ae71
+.sp
36ae71
+For
36ae71
+\fIIPv6\fR
36ae71
+forward ports, please use the rich language\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-query\-forward\-port\fR=port=\fIportid\fR[\-\fIportid\fR]:proto=\fIprotocol\fR[:toport=\fIportid\fR[\-\fIportid\fR]][:toaddr=\fIaddress\fR[/\fImask\fR]]
36ae71
+.RS 4
36ae71
+Return whether the
36ae71
+\fIIPv4\fR
36ae71
+forward port has been added for
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.sp
36ae71
+For
36ae71
+\fIIPv6\fR
36ae71
+forward ports, please use the rich language\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-add\-masquerade\fR
36ae71
+.RS 4
36ae71
+Enable
36ae71
+\fIIPv4\fR
36ae71
+masquerade for
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. Masquerading is useful if the machine is a router and machines connected over an interface in another zone should be able to use the first connection\&.
36ae71
+.sp
36ae71
+For
36ae71
+\fIIPv6\fR
36ae71
+masquerading, please use the rich language\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-remove\-masquerade\fR
36ae71
+.RS 4
36ae71
+Disable
36ae71
+\fIIPv4\fR
36ae71
+masquerade for
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&.
36ae71
+.sp
36ae71
+For
36ae71
+\fIIPv6\fR
36ae71
+masquerading, please use the rich language\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-query\-masquerade\fR
36ae71
+.RS 4
36ae71
+Return whether
36ae71
+\fIIPv4\fR
36ae71
+masquerading has been enabled for
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.sp
36ae71
+For
36ae71
+\fIIPv6\fR
36ae71
+masquerading, please use the rich language\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-list\-rich\-rules\fR
36ae71
+.RS 4
36ae71
+List rich language rules added for
36ae71
+\fIzone\fR
36ae71
+as a newline separated list\&. If zone is omitted, default zone will be used\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-add\-rich\-rule\fR=\*(Aq\fIrule\fR\*(Aq
36ae71
+.RS 4
36ae71
+Add rich language rule \*(Aq\fIrule\fR\*(Aq for
36ae71
+\fIzone\fR\&. This option can be specified multiple times\&. If zone is omitted, default zone will be used\&.
36ae71
+.sp
36ae71
+For the rich language rule syntax, please have a look at
36ae71
+\fBfirewalld.richlanguage\fR(5)\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-remove\-rich\-rule\fR=\*(Aq\fIrule\fR\*(Aq
36ae71
+.RS 4
36ae71
+Remove rich language rule \*(Aq\fIrule\fR\*(Aq from
36ae71
+\fIzone\fR\&. This option can be specified multiple times\&. If zone is omitted, default zone will be used\&.
36ae71
+.sp
36ae71
+For the rich language rule syntax, please have a look at
36ae71
+\fBfirewalld.richlanguage\fR(5)\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-query\-rich\-rule\fR=\*(Aq\fIrule\fR\*(Aq
36ae71
+.RS 4
36ae71
+Return whether a rich language rule \*(Aq\fIrule\fR\*(Aq has been added for
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.sp
36ae71
+For the rich language rule syntax, please have a look at
36ae71
+\fBfirewalld.richlanguage\fR(5)\&.
36ae71
+.RE
36ae71
+.SS "Options to Handle Bindings of Interfaces"
36ae71
+.PP
36ae71
+Binding an interface to a zone means that this zone settings are used to restrict traffic via the interface\&.
36ae71
+.PP
36ae71
+Options in this section affect only one particular zone\&. If used with
36ae71
+\fB\-\-zone\fR=\fIzone\fR
36ae71
+option, they affect the zone
36ae71
+\fIzone\fR\&. If the option is omitted, they affect default zone (see
36ae71
+\fB\-\-get\-default\-zone\fR)\&.
36ae71
+.PP
36ae71
+For a list of predefined zones use
36ae71
+\fBfirewall\-cmd \-\-get\-zones\fR\&.
36ae71
+.PP
36ae71
+An interface name is a string up to 16 characters long, that may not contain
36ae71
+\fB\*(Aq \*(Aq\fR,
36ae71
+\fB\*(Aq/\*(Aq\fR,
36ae71
+\fB\*(Aq!\*(Aq\fR
36ae71
+and
36ae71
+\fB\*(Aq*\*(Aq\fR\&.
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-list\-interfaces\fR
36ae71
+.RS 4
36ae71
+List interfaces that are bound to zone
36ae71
+\fIzone\fR
36ae71
+as a space separated list\&. If zone is omitted, default zone will be used\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-add\-interface\fR=\fIinterface\fR
36ae71
+.RS 4
36ae71
+Bind interface
36ae71
+\fIinterface\fR
36ae71
+to zone
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-change\-interface\fR=\fIinterface\fR
36ae71
+.RS 4
36ae71
+Change zone the interface
36ae71
+\fIinterface\fR
36ae71
+is bound to to zone
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. If old and new zone are the same, the call will be ignored without an error\&. If the interface has not been bound to a zone before, it will behave like
36ae71
+\fB\-\-add\-interface\fR\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-query\-interface\fR=\fIinterface\fR
36ae71
+.RS 4
36ae71
+Query whether interface
36ae71
+\fIinterface\fR
36ae71
+is bound to zone
36ae71
+\fIzone\fR\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-remove\-interface\fR=\fIinterface\fR
36ae71
+.RS 4
36ae71
+Remove binding of interface
36ae71
+\fIinterface\fR
36ae71
+from zone
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&.
36ae71
+.RE
36ae71
+.SS "Options to Handle Bindings of Sources"
36ae71
+.PP
36ae71
+Binding a source to a zone means that this zone settings will be used to restrict traffic from this source\&.
36ae71
+.PP
36ae71
+A source address or address range is either an IP address or a network IP address with a mask for IPv4 or IPv6\&. For IPv4, the mask can be a network mask or a plain number\&. For IPv6 the mask is a plain number\&. The use of host names is not supported\&.
36ae71
+.PP
36ae71
+Options in this section affect only one particular zone\&. If used with
36ae71
+\fB\-\-zone\fR=\fIzone\fR
36ae71
+option, they affect the zone
36ae71
+\fIzone\fR\&. If the option is omitted, they affect default zone (see
36ae71
+\fB\-\-get\-default\-zone\fR)\&.
36ae71
+.PP
36ae71
+For a list of predefined zones use
36ae71
+\fBfirewall\-cmd \-\-get\-zones\fR\&.
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-list\-sources\fR
36ae71
+.RS 4
36ae71
+List sources that are bound to zone
36ae71
+\fIzone\fR
36ae71
+as a space separated list\&. If zone is omitted, default zone will be used\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-add\-source\fR=\fIsource\fR[/\fImask\fR]
36ae71
+.RS 4
36ae71
+Bind source
36ae71
+\fIsource\fR[/\fImask\fR]
36ae71
+to zone
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-change\-source\fR=\fIsource\fR[/\fImask\fR]
36ae71
+.RS 4
36ae71
+Change zone the source
36ae71
+\fIsource\fR[/\fImask\fR]
36ae71
+is bound to to zone
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&. If old and new zone are the same, the call will be ignored without an error\&. If the source has not been bound to a zone before, it will behave like
36ae71
+\fB\-\-add\-source\fR\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-query\-source\fR=\fIsource\fR[/\fImask\fR]
36ae71
+.RS 4
36ae71
+Query whether the source
36ae71
+\fIsource\fR[/\fImask\fR]
36ae71
+is bound to the zone
36ae71
+\fIzone\fR\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+[\fB\-\-zone\fR=\fIzone\fR] \fB\-\-remove\-source\fR=\fIsource\fR[/\fImask\fR]
36ae71
+.RS 4
36ae71
+Remove binding of source
36ae71
+\fIsource\fR[/\fImask\fR]
36ae71
+from zone
36ae71
+\fIzone\fR\&. If zone is omitted, default zone will be used\&.
36ae71
+.RE
36ae71
+.SS "Service Options"
36ae71
+.PP
36ae71
+\fB\-\-new\-service\fR=\fIservice\fR
36ae71
+.RS 4
36ae71
+Add a new permanent service\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-delete\-service\fR=\fIservice\fR
36ae71
+.RS 4
36ae71
+Delete an existing permanent service\&.
36ae71
+.RE
36ae71
+.SS "Internet Control Message Protocol (ICMP) type Options"
36ae71
+.PP
36ae71
+\fB\-\-new\-icmptype\fR=\fIicmptype\fR
36ae71
+.RS 4
36ae71
+Add a new permanent icmptype\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-delete\-icmptype\fR=\fIicmptype\fR
36ae71
+.RS 4
36ae71
+Delete an existing permanent icmptype\&.
36ae71
+.RE
36ae71
+.SS "Direct Options"
36ae71
+.PP
36ae71
+The direct options give a more direct access to the firewall\&. These options require user to know basic iptables concepts, i\&.e\&.
36ae71
+\fItable\fR
36ae71
+(filter/mangle/nat/\&.\&.\&.),
36ae71
+\fIchain\fR
36ae71
+(INPUT/OUTPUT/FORWARD/\&.\&.\&.),
36ae71
+\fIcommands\fR
36ae71
+(\-A/\-D/\-I/\&.\&.\&.),
36ae71
+\fIparameters\fR
36ae71
+(\-p/\-s/\-d/\-j/\&.\&.\&.) and
36ae71
+\fItargets\fR
36ae71
+(ACCEPT/DROP/REJECT/\&.\&.\&.)\&.
36ae71
+.PP
36ae71
+Direct options should be used only as a last resort when it\*(Aqs not possible to use for example
36ae71
+\fB\-\-add\-service\fR=\fIservice\fR
36ae71
+or
36ae71
+\fB\-\-add\-rich\-rule\fR=\*(Aq\fIrule\fR\*(Aq\&.
36ae71
+.PP
36ae71
+The first argument of each option has to be
36ae71
+\fIipv4\fR
36ae71
+or
36ae71
+\fIipv6\fR
36ae71
+or
36ae71
+\fIeb\fR\&. With
36ae71
+\fIipv4\fR
36ae71
+it will be for IPv4 (\fBiptables\fR(8)), with
36ae71
+\fIipv6\fR
36ae71
+for IPv6 (\fBip6tables\fR(8)) and with
36ae71
+\fIeb\fR
36ae71
+for ethernet bridges (\fBebtables\fR(8))\&.
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-get\-all\-chains\fR
36ae71
+.RS 4
36ae71
+Get all chains added to all tables\&.
36ae71
+.sp
36ae71
+This option concerns only chains previously added with
36ae71
+\fB\-\-direct \-\-add\-chain\fR\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-get\-chains\fR { \fIipv4\fR | \fIipv6\fR | \fIeb\fR } \fItable\fR
36ae71
+.RS 4
36ae71
+Get all chains added to table
36ae71
+\fItable\fR
36ae71
+as a space separated list\&.
36ae71
+.sp
36ae71
+This option concerns only chains previously added with
36ae71
+\fB\-\-direct \-\-add\-chain\fR\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-add\-chain\fR { \fIipv4\fR | \fIipv6\fR | \fIeb\fR } \fItable\fR \fIchain\fR
36ae71
+.RS 4
36ae71
+Add a new chain with name
36ae71
+\fIchain\fR
36ae71
+to table
36ae71
+\fItable\fR\&.
36ae71
+.sp
36ae71
+There already exist basic chains to use with direct options, for example
36ae71
+\fIINPUT_direct\fR
36ae71
+chain (see
36ae71
+\fIiptables\-save | grep direct\fR
36ae71
+output for all of them)\&. These chains are jumped into before chains for zones, i\&.e\&. every rule put into
36ae71
+\fIINPUT_direct\fR
36ae71
+will be checked before rules in zones\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-remove\-chain\fR { \fIipv4\fR | \fIipv6\fR | \fIeb\fR } \fItable\fR \fIchain\fR
36ae71
+.RS 4
36ae71
+Remove the chain with name
36ae71
+\fIchain\fR
36ae71
+from table
36ae71
+\fItable\fR\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-query\-chain\fR { \fIipv4\fR | \fIipv6\fR | \fIeb\fR } \fItable\fR \fIchain\fR
36ae71
+.RS 4
36ae71
+Return whether a chain with name
36ae71
+\fIchain\fR
36ae71
+exists in table
36ae71
+\fItable\fR\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.sp
36ae71
+This option concerns only chains previously added with
36ae71
+\fB\-\-direct \-\-add\-chain\fR\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-get\-all\-rules\fR
36ae71
+.RS 4
36ae71
+Get all rules added to all chains in all tables as a newline separated list of the priority and arguments\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-get\-rules\fR { \fIipv4\fR | \fIipv6\fR | \fIeb\fR } \fItable\fR \fIchain\fR
36ae71
+.RS 4
36ae71
+Get all rules added to chain
36ae71
+\fIchain\fR
36ae71
+in table
36ae71
+\fItable\fR
36ae71
+as a newline separated list of the priority and arguments\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-add\-rule\fR { \fIipv4\fR | \fIipv6\fR | \fIeb\fR } \fItable\fR \fIchain\fR \fIpriority\fR \fIargs\fR
36ae71
+.RS 4
36ae71
+Add a rule with the arguments
36ae71
+\fIargs\fR
36ae71
+to chain
36ae71
+\fIchain\fR
36ae71
+in table
36ae71
+\fItable\fR
36ae71
+with priority
36ae71
+\fIpriority\fR\&.
36ae71
+.sp
36ae71
+The
36ae71
+\fIpriority\fR
36ae71
+is used to order rules\&. Priority 0 means add rule on top of the chain, with a higher priority the rule will be added further down\&. Rules with the same priority are on the same level and the order of these rules is not fixed and may change\&. If you want to make sure that a rule will be added after another one, use a low priority for the first and a higher for the following\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-remove\-rule\fR { \fIipv4\fR | \fIipv6\fR | \fIeb\fR } \fItable\fR \fIchain\fR \fIpriority\fR \fIargs\fR
36ae71
+.RS 4
36ae71
+Remove a rule with
36ae71
+\fIpriority\fR
36ae71
+and the arguments
36ae71
+\fIargs\fR
36ae71
+from chain
36ae71
+\fIchain\fR
36ae71
+in table
36ae71
+\fItable\fR\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-remove\-rules\fR { \fIipv4\fR | \fIipv6\fR | \fIeb\fR } \fItable\fR \fIchain\fR
36ae71
+.RS 4
36ae71
+Remove all rules in the chain with name
36ae71
+\fIchain\fR
36ae71
+exists in table
36ae71
+\fItable\fR\&.
36ae71
+.sp
36ae71
+This option concerns only rules previously added with
36ae71
+\fB\-\-direct \-\-add\-rule\fR
36ae71
+in this chain\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-query\-rule\fR { \fIipv4\fR | \fIipv6\fR | \fIeb\fR } \fItable\fR \fIchain\fR \fIpriority\fR \fIargs\fR
36ae71
+.RS 4
36ae71
+Return whether a rule with
36ae71
+\fIpriority\fR
36ae71
+and the arguments
36ae71
+\fIargs\fR
36ae71
+exists in chain
36ae71
+\fIchain\fR
36ae71
+in table
36ae71
+\fItable\fR\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-get\-all\-passthroughs\fR
36ae71
+.RS 4
36ae71
+Get all permanent passthrough as a newline separated list of the ipv value and arguments\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-get\-passthroughs\fR { \fIipv4\fR | \fIipv6\fR | \fIeb\fR }
36ae71
+.RS 4
36ae71
+Get all permanent passthrough rules for the ipv value as a newline separated list of the priority and arguments\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-add\-passthrough\fR { \fIipv4\fR | \fIipv6\fR | \fIeb\fR } \fIargs\fR
36ae71
+.RS 4
36ae71
+Add a permanent passthrough rule with the arguments
36ae71
+\fIargs\fR
36ae71
+for the ipv value\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-remove\-passthrough\fR { \fIipv4\fR | \fIipv6\fR | \fIeb\fR } \fIargs\fR
36ae71
+.RS 4
36ae71
+Remove a permanent passthrough rule with the arguments
36ae71
+\fIargs\fR
36ae71
+for the ipv value\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-direct\fR \fB\-\-query\-passthrough\fR { \fIipv4\fR | \fIipv6\fR | \fIeb\fR } \fIargs\fR
36ae71
+.RS 4
36ae71
+Return whether a permanent passthrough rule with the arguments
36ae71
+\fIargs\fR
36ae71
+exists for the ipv value\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.RE
36ae71
+.SS "Lockdown Options"
36ae71
+.PP
36ae71
+Local applications or services are able to change the firewall configuration if they are running as root (example: libvirt) or are authenticated using PolicyKit\&. With this feature administrators can lock the firewall configuration so that only applications on lockdown whitelist are able to request firewall changes\&.
36ae71
+.PP
36ae71
+The lockdown access check limits D\-Bus methods that are changing firewall rules\&. Query, list and get methods are not limited\&.
36ae71
+.PP
36ae71
+The lockdown feature is a very light version of user and application policies for firewalld and is turned off by default\&.
36ae71
+.PP
36ae71
+\fB\-\-lockdown\-on\fR
36ae71
+.RS 4
36ae71
+Enable lockdown\&. Be careful \- if firewall\-cmd is not on lockdown whitelist when you enable lockdown you won\*(Aqt be able to disable it again with firewall\-cmd, you would need to edit firewalld\&.conf\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-lockdown\-off\fR
36ae71
+.RS 4
36ae71
+Disable lockdown\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-query\-lockdown\fR
36ae71
+.RS 4
36ae71
+Query whether lockdown is enabled\&. Returns 0 if lockdown is enabled, 1 otherwise\&.
36ae71
+.RE
36ae71
+.SS "Lockdown Whitelist Options"
36ae71
+.PP
36ae71
+The lockdown whitelist can contain
36ae71
+\fIcommands\fR,
36ae71
+\fIcontexts\fR,
36ae71
+\fIusers\fR
36ae71
+and
36ae71
+\fIuser ids\fR\&.
36ae71
+.PP
36ae71
+If a command entry on the whitelist ends with an asterisk \*(Aq*\*(Aq, then all command lines starting with the command will match\&. If the \*(Aq*\*(Aq is not there the absolute command inclusive arguments must match\&.
36ae71
+.PP
36ae71
+Commands for user root and others is not always the same\&. Example: As root
36ae71
+\fB/bin/firewall\-cmd\fR
36ae71
+is used, as a normal user
36ae71
+\fB/usr/bin/firewall\-cmd\fR
36ae71
+is be used on Fedora\&.
36ae71
+.PP
36ae71
+The context is the security (SELinux) context of a running application or service\&. To get the context of a running application use
36ae71
+\fBps \-e \-\-context\fR\&.
36ae71
+.PP
36ae71
+\fBWarning:\fR
36ae71
+If the context is unconfined, then this will open access for more than the desired application\&.
36ae71
+.PP
36ae71
+The lockdown whitelist entries are checked in the following order:
36ae71
+.RS 4
36ae71
+1\&. \fIcontext\fR
36ae71
+.RE
36ae71
+.RS 4
36ae71
+2\&. \fIuid\fR
36ae71
+.RE
36ae71
+.RS 4
36ae71
+3\&. \fIuser\fR
36ae71
+.RE
36ae71
+.RS 4
36ae71
+4\&. \fIcommand\fR
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-list\-lockdown\-whitelist\-commands\fR
36ae71
+.RS 4
36ae71
+List all command lines that are on the whitelist\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-add\-lockdown\-whitelist\-command\fR=\fIcommand\fR
36ae71
+.RS 4
36ae71
+Add the
36ae71
+\fIcommand\fR
36ae71
+to the whitelist\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-remove\-lockdown\-whitelist\-command\fR=\fIcommand\fR
36ae71
+.RS 4
36ae71
+Remove the
36ae71
+\fIcommand\fR
36ae71
+from the whitelist\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-query\-lockdown\-whitelist\-command\fR=\fIcommand\fR
36ae71
+.RS 4
36ae71
+Query whether the
36ae71
+\fIcommand\fR
36ae71
+is on the whitelist\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-list\-lockdown\-whitelist\-contexts\fR
36ae71
+.RS 4
36ae71
+List all contexts that are on the whitelist\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-add\-lockdown\-whitelist\-context\fR=\fIcontext\fR
36ae71
+.RS 4
36ae71
+Add the context
36ae71
+\fIcontext\fR
36ae71
+to the whitelist\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-remove\-lockdown\-whitelist\-context\fR=\fIcontext\fR
36ae71
+.RS 4
36ae71
+Remove the
36ae71
+\fIcontext\fR
36ae71
+from the whitelist\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-query\-lockdown\-whitelist\-context\fR=\fIcontext\fR
36ae71
+.RS 4
36ae71
+Query whether the
36ae71
+\fIcontext\fR
36ae71
+is on the whitelist\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-list\-lockdown\-whitelist\-uids\fR
36ae71
+.RS 4
36ae71
+List all user ids that are on the whitelist\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-add\-lockdown\-whitelist\-uid\fR=\fIuid\fR
36ae71
+.RS 4
36ae71
+Add the user id
36ae71
+\fIuid\fR
36ae71
+to the whitelist\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-remove\-lockdown\-whitelist\-uid\fR=\fIuid\fR
36ae71
+.RS 4
36ae71
+Remove the user id
36ae71
+\fIuid\fR
36ae71
+from the whitelist\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-query\-lockdown\-whitelist\-uid\fR=\fIuid\fR
36ae71
+.RS 4
36ae71
+Query whether the user id
36ae71
+\fIuid\fR
36ae71
+is on the whitelist\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-list\-lockdown\-whitelist\-users\fR
36ae71
+.RS 4
36ae71
+List all user names that are on the whitelist\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-add\-lockdown\-whitelist\-user\fR=\fIuser\fR
36ae71
+.RS 4
36ae71
+Add the user name
36ae71
+\fIuser\fR
36ae71
+to the whitelist\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-remove\-lockdown\-whitelist\-user\fR=\fIuser\fR
36ae71
+.RS 4
36ae71
+Remove the user name
36ae71
+\fIuser\fR
36ae71
+from the whitelist\&.
36ae71
+.RE
36ae71
+.PP
36ae71
+\fB\-\-query\-lockdown\-whitelist\-user\fR=\fIuser\fR
36ae71
+.RS 4
36ae71
+Query whether the user name
36ae71
+\fIuser\fR
36ae71
+is on the whitelist\&. Returns 0 if true, 1 otherwise\&.
36ae71
+.RE
36ae71
 .SH "SEE ALSO"
36ae71
 \fBfirewall-applet\fR(1), \fBfirewalld\fR(1), \fBfirewall-cmd\fR(1), \fBfirewall-config\fR(1), \fBfirewalld.conf\fR(5), \fBfirewalld.direct\fR(5), \fBfirewalld.icmptype\fR(5), \fBfirewalld.lockdown-whitelist\fR(5), \fBfirewall-offline-cmd\fR(1), \fBfirewalld.richlanguage\fR(5), \fBfirewalld.service\fR(5), \fBfirewalld.zone\fR(5), \fBfirewalld.zones\fR(5)
36ae71
 .SH "NOTES"
36ae71
diff -up firewalld-0.3.9/src/firewall/core/fw_test.py.RHBZ#1059800 firewalld-0.3.9/src/firewall/core/fw_test.py
36ae71
--- firewalld-0.3.9/src/firewall/core/fw_test.py.RHBZ#1059800	2014-02-26 09:30:43.439191822 +0100
36ae71
+++ firewalld-0.3.9/src/firewall/core/fw_test.py	2014-02-26 09:30:43.439191822 +0100
36ae71
@@ -0,0 +1,420 @@
36ae71
+# -*- coding: utf-8 -*-
36ae71
+#
36ae71
+# Copyright (C) 2010-2012 Red Hat, Inc.
36ae71
+#
36ae71
+# Authors:
36ae71
+# Thomas Woerner <twoerner@redhat.com>
36ae71
+#
36ae71
+# This program is free software; you can redistribute it and/or modify
36ae71
+# it under the terms of the GNU General Public License as published by
36ae71
+# the Free Software Foundation; either version 2 of the License, or
36ae71
+# (at your option) any later version.
36ae71
+#
36ae71
+# This program is distributed in the hope that it will be useful,
36ae71
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
36ae71
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36ae71
+# GNU General Public License for more details.
36ae71
+#
36ae71
+# You should have received a copy of the GNU General Public License
36ae71
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
36ae71
+#
36ae71
+
36ae71
+import os.path
36ae71
+import copy
36ae71
+from firewall.config import *
36ae71
+from firewall import functions
36ae71
+from firewall.core.fw_icmptype import FirewallIcmpType
36ae71
+from firewall.core.fw_service import FirewallService
36ae71
+from firewall.core.fw_zone import FirewallZone
36ae71
+from firewall.core.fw_direct import FirewallDirect
36ae71
+from firewall.core.fw_config import FirewallConfig
36ae71
+from firewall.core.fw_policies import FirewallPolicies
36ae71
+from firewall.core.logger import log
36ae71
+from firewall.core.io.firewalld_conf import firewalld_conf
36ae71
+from firewall.core.io.direct import Direct
36ae71
+from firewall.core.io.service import service_reader
36ae71
+from firewall.core.io.icmptype import icmptype_reader
36ae71
+from firewall.core.io.zone import zone_reader, Zone
36ae71
+from firewall.errors import *
36ae71
+
36ae71
+############################################################################
36ae71
+#
36ae71
+# class Firewall
36ae71
+#
36ae71
+############################################################################
36ae71
+
36ae71
+class Firewall_test:
36ae71
+    def __init__(self):
36ae71
+        self._firewalld_conf = firewalld_conf(FIREWALLD_CONF)
36ae71
+
36ae71
+        self.ip4tables_enabled = False
36ae71
+        self.ip6tables_enabled = False
36ae71
+        self.ebtables_enabled = False
36ae71
+
36ae71
+        self.icmptype = FirewallIcmpType(self)
36ae71
+        self.service = FirewallService(self)
36ae71
+        self.zone = FirewallZone(self)
36ae71
+        self.direct = FirewallDirect(self)
36ae71
+        self.config = FirewallConfig(self)
36ae71
+        self.policies = FirewallPolicies()
36ae71
+
36ae71
+        self.__init_vars()
36ae71
+
36ae71
+    def __repr__(self):
36ae71
+        return '%s(%r, %r, %r, %r, %r, %r, %r, %r, %r, %r, %r)' % \
36ae71
+            (self.__class__, self.ip4tables_enabled, self.ip6tables_enabled,
36ae71
+             self.ebtables_enabled, self._state, self._panic,
36ae71
+             self._default_zone, self._module_refcount, self._marks,
36ae71
+             self._min_mark, self.cleanup_on_exit, self.ipv6_rpfilter_enabled)
36ae71
+
36ae71
+    def __init_vars(self):
36ae71
+        self._state = "INIT"
36ae71
+        self._panic = False
36ae71
+        self._default_zone = ""
36ae71
+        self._module_refcount = { }
36ae71
+        self._marks = [ ]
36ae71
+        self._min_mark = FALLBACK_MINIMAL_MARK # will be overloaded by firewalld.conf
36ae71
+        self.cleanup_on_exit = True
36ae71
+        self.ipv6_rpfilter_enabled = True
36ae71
+
36ae71
+    def start(self):
36ae71
+        # initialize firewall
36ae71
+        default_zone = FALLBACK_ZONE
36ae71
+
36ae71
+        # load firewalld config
36ae71
+        log.debug1("Loading firewalld config file '%s'", FIREWALLD_CONF)
36ae71
+        try:
36ae71
+            self._firewalld_conf.read()
36ae71
+        except Exception as msg:
36ae71
+            log.error("Failed to open firewalld config file '%s': %s",
36ae71
+                      FIREWALLD_CONF, msg)
36ae71
+        else:
36ae71
+            if self._firewalld_conf.get("DefaultZone"):
36ae71
+                default_zone = self._firewalld_conf.get("DefaultZone")
36ae71
+            if self._firewalld_conf.get("MinimalMark"):
36ae71
+                mark = self._firewalld_conf.get("MinimalMark")
36ae71
+                if mark != None:
36ae71
+                    try:
36ae71
+                        self._min_mark = int(mark)
36ae71
+                    except Exception as msg:
36ae71
+                        log.error("MinimalMark %s is not valid, using default "
36ae71
+                                  "value %d", mark, self._min_mark)
36ae71
+            if self._firewalld_conf.get("CleanupOnExit"):
36ae71
+                value = self._firewalld_conf.get("CleanupOnExit")
36ae71
+                if value != None and value.lower() in [ "no", "false" ]:
36ae71
+                    self.cleanup_on_exit = False
36ae71
+
36ae71
+            if self._firewalld_conf.get("Lockdown"):
36ae71
+                value = self._firewalld_conf.get("Lockdown")
36ae71
+                if value != None and value.lower() in [ "yes", "true" ]:
36ae71
+                    log.debug1("Lockdown is enabled")
36ae71
+                    try:
36ae71
+                        self.policies.enable_lockdown()
36ae71
+                    except FirewallError:
36ae71
+                        # already enabled, this is probably reload
36ae71
+                        pass
36ae71
+
36ae71
+            if self._firewalld_conf.get("IPv6_rpfilter"):
36ae71
+                value = self._firewalld_conf.get("IPv6_rpfilter")
36ae71
+                if value != None:
36ae71
+                    if value.lower() in [ "no", "false" ]:
36ae71
+                        self.ipv6_rpfilter_enabled = False
36ae71
+                    if value.lower() in [ "yes", "true" ]:
36ae71
+                        self.ipv6_rpfilter_enabled = True
36ae71
+            if self.ipv6_rpfilter_enabled:
36ae71
+                log.debug1("IPv6 rpfilter is enabled")
36ae71
+            else:
36ae71
+                log.debug1("IPV6 rpfilter is disabled")
36ae71
+
36ae71
+        self.config.set_firewalld_conf(copy.deepcopy(self._firewalld_conf))
36ae71
+
36ae71
+        # load lockdown whitelist
36ae71
+        log.debug1("Loading lockdown whitelist")
36ae71
+        try:
36ae71
+            self.policies.lockdown_whitelist.read()
36ae71
+        except Exception as msg:
36ae71
+            log.error("Failed to load lockdown whitelist '%s': %s",
36ae71
+                      self.policies.lockdown_whitelist.filename, msg)
36ae71
+
36ae71
+        # copy policies to config interface
36ae71
+        self.config.set_policies(copy.deepcopy(self.policies))
36ae71
+
36ae71
+        # load icmptype files
36ae71
+        self._loader(FIREWALLD_ICMPTYPES, "icmptype")
36ae71
+        self._loader(ETC_FIREWALLD_ICMPTYPES, "icmptype")
36ae71
+
36ae71
+        if len(self.icmptype.get_icmptypes()) == 0:
36ae71
+            log.error("No icmptypes found.")
36ae71
+
36ae71
+        # load service files
36ae71
+        self._loader(FIREWALLD_SERVICES, "service")
36ae71
+        self._loader(ETC_FIREWALLD_SERVICES, "service")
36ae71
+
36ae71
+        if len(self.service.get_services()) == 0:
36ae71
+            log.error("No services found.")
36ae71
+
36ae71
+        # load zone files
36ae71
+        self._loader(FIREWALLD_ZONES, "zone")
36ae71
+        self._loader(ETC_FIREWALLD_ZONES, "zone")
36ae71
+
36ae71
+        if len(self.zone.get_zones()) == 0:
36ae71
+            log.fatal("No zones found.")
36ae71
+            sys.exit(1)
36ae71
+
36ae71
+        # check minimum required zones
36ae71
+        error = False
36ae71
+        for z in [ "block", "drop", "trusted" ]:
36ae71
+            if not z in self.zone.get_zones():
36ae71
+                log.fatal("Zone '%s' is not available.", z)
36ae71
+                error = True
36ae71
+        if error:
36ae71
+            sys.exit(1)
36ae71
+
36ae71
+        # load direct rules
36ae71
+        obj = Direct(FIREWALLD_DIRECT)
36ae71
+        if os.path.exists(FIREWALLD_DIRECT):
36ae71
+            log.debug1("Loading direct rules file '%s'" % FIREWALLD_DIRECT)
36ae71
+            try:
36ae71
+                obj.read()
36ae71
+            except Exception as msg:
36ae71
+                log.debug1("Failed to load direct rules file '%s': %s",
36ae71
+                           FIREWALLD_DIRECT, msg)
36ae71
+        self.config.set_direct(copy.deepcopy(obj))
36ae71
+
36ae71
+        # check if default_zone is a valid zone
36ae71
+        if default_zone not in self.zone.get_zones():
36ae71
+            if "public" in self.zone.get_zones():
36ae71
+                zone = "public"
36ae71
+            elif "external" in self.zone.get_zones():
36ae71
+                zone = "external"
36ae71
+            else:
36ae71
+                zone = "block" # block is a base zone, therefore it has to exist
36ae71
+
36ae71
+            log.error("Default zone '%s' is not valid. Using '%s'.",
36ae71
+                      default_zone, zone)
36ae71
+            default_zone = zone
36ae71
+        else:
36ae71
+            log.debug1("Using default zone '%s'", default_zone)
36ae71
+
36ae71
+        self._default_zone = self.check_zone(default_zone)
36ae71
+
36ae71
+        self._state = "RUNNING"
36ae71
+
36ae71
+    def _loader(self, path, reader_type, combine=False):
36ae71
+        # combine: several zone files are getting combined into one obj
36ae71
+        if not os.path.isdir(path):
36ae71
+            return
36ae71
+
36ae71
+        if combine == True:
36ae71
+            if path.startswith(ETC_FIREWALLD) and reader_type == "zone":
36ae71
+                combined_zone = Zone()
36ae71
+                combined_zone.name = os.path.basename(path)
36ae71
+                combined_zone.check_name(combined_zone.name)
36ae71
+                combined_zone.path = path
36ae71
+                combined_zone.default = False
36ae71
+            else:
36ae71
+                combine = False
36ae71
+
36ae71
+        for filename in sorted(os.listdir(path)):
36ae71
+            if not filename.endswith(".xml"):
36ae71
+                if path.startswith(ETC_FIREWALLD) and \
36ae71
+                        reader_type == "zone" and \
36ae71
+                        os.path.isdir("%s/%s" % (path, filename)):
36ae71
+                    self._loader("%s/%s" % (path, filename), reader_type,
36ae71
+                                 combine=True)
36ae71
+                continue
36ae71
+
36ae71
+            name = "%s/%s" % (path, filename)
36ae71
+            log.debug1("Loading %s file '%s'", reader_type, name)
36ae71
+            try:
36ae71
+                if reader_type == "icmptype":
36ae71
+                    obj = icmptype_reader(filename, path)
36ae71
+                    if obj.name in self.icmptype.get_icmptypes():
36ae71
+                        orig_obj = self.icmptype.get_icmptype(obj.name)
36ae71
+                        log.debug1("  Overloads %s '%s' ('%s/%s')", reader_type,
36ae71
+                                   orig_obj.name, orig_obj.path,
36ae71
+                                   orig_obj.filename)
36ae71
+                        self.icmptype.remove_icmptype(orig_obj.name)
36ae71
+                    self.icmptype.add_icmptype(obj)
36ae71
+                    # add a deep copy to the configuration interface
36ae71
+                    self.config.add_icmptype(copy.deepcopy(obj))
36ae71
+                elif reader_type == "service":
36ae71
+                    obj = service_reader(filename, path)
36ae71
+                    if obj.name in self.service.get_services():
36ae71
+                        orig_obj = self.service.get_service(obj.name)
36ae71
+                        log.debug1("  Overloads %s '%s' ('%s/%s')", reader_type,
36ae71
+                                   orig_obj.name, orig_obj.path,
36ae71
+                                   orig_obj.filename)
36ae71
+                        self.service.remove_service(orig_obj.name)
36ae71
+                    self.service.add_service(obj)
36ae71
+                    # add a deep copy to the configuration interface
36ae71
+                    self.config.add_service(copy.deepcopy(obj))
36ae71
+                elif reader_type == "zone":
36ae71
+                    obj = zone_reader(filename, path)
36ae71
+                    if combine:
36ae71
+                        # Change name for permanent configuration
36ae71
+                        obj.name = "%s/%s" % (
36ae71
+                            os.path.basename(path),
36ae71
+                            os.path.basename(filename)[0:-4])
36ae71
+                        obj.check_name(obj.name)
36ae71
+                    # Copy object before combine
36ae71
+                    config_obj = copy.deepcopy(obj)
36ae71
+                    if obj.name in self.zone.get_zones():
36ae71
+                        orig_obj = self.zone.get_zone(obj.name)
36ae71
+                        self.zone.remove_zone(orig_obj.name)
36ae71
+                        if orig_obj.combined:
36ae71
+                            log.debug1("  Combining %s '%s' ('%s/%s')",
36ae71
+                                        reader_type, obj.name,
36ae71
+                                        path, filename)
36ae71
+                            obj.combine(orig_obj)
36ae71
+                        else:
36ae71
+                            log.debug1("  Overloads %s '%s' ('%s/%s')",
36ae71
+                                       reader_type,
36ae71
+                                       orig_obj.name, orig_obj.path,
36ae71
+                                       orig_obj.filename)
36ae71
+                    self.config.add_zone(config_obj)
36ae71
+                    if combine:
36ae71
+                        log.debug1("  Combining %s '%s' ('%s/%s')",
36ae71
+                                   reader_type, combined_zone.name,
36ae71
+                                   path, filename)
36ae71
+                        combined_zone.combine(obj)
36ae71
+                    else:
36ae71
+                        self.zone.add_zone(obj)
36ae71
+                else:
36ae71
+                    log.fatal("Unknown reader type %s", reader_type)
36ae71
+            except FirewallError as msg:
36ae71
+                log.error("Failed to load %s file '%s': %s", reader_type,
36ae71
+                          name, msg)
36ae71
+            except Exception as msg:
36ae71
+                log.error("Failed to load %s file '%s':", reader_type, name)
36ae71
+                log.exception()
36ae71
+
36ae71
+        if combine == True and combined_zone.combined == True:
36ae71
+            if combined_zone.name in self.zone.get_zones():
36ae71
+                orig_obj = self.zone.get_zone(combined_zone.name)
36ae71
+                log.debug1("  Overloading and deactivating %s '%s' ('%s/%s')",
36ae71
+                           reader_type, orig_obj.name, orig_obj.path,
36ae71
+                           orig_obj.filename)
36ae71
+                try:
36ae71
+                    self.zone.remove_zone(combined_zone.name)
36ae71
+                except:
36ae71
+                    pass
36ae71
+                self.config.forget_zone(combined_zone.name)
36ae71
+            self.zone.add_zone(combined_zone)
36ae71
+
36ae71
+    def cleanup(self):
36ae71
+        self.icmptype.cleanup()
36ae71
+        self.service.cleanup()
36ae71
+        self.zone.cleanup()
36ae71
+        self.config.cleanup()
36ae71
+        self.direct.cleanup()
36ae71
+        self.policies.cleanup()
36ae71
+        self._firewalld_conf.cleanup()
36ae71
+        self.__init_vars()
36ae71
+
36ae71
+    def stop(self):
36ae71
+        self.cleanup()
36ae71
+
36ae71
+    # check functions
36ae71
+
36ae71
+    def check_panic(self):
36ae71
+        return
36ae71
+
36ae71
+    def check_zone(self, zone):
36ae71
+        _zone = zone
36ae71
+        if not _zone or _zone == "":
36ae71
+            _zone = self.get_default_zone()
36ae71
+        if _zone not in self.zone.get_zones():
36ae71
+            raise FirewallError(INVALID_ZONE, _zone)
36ae71
+        return _zone
36ae71
+
36ae71
+    def check_interface(self, interface):
36ae71
+        if not functions.checkInterface(interface):
36ae71
+            raise FirewallError(INVALID_INTERFACE, interface)
36ae71
+
36ae71
+    def check_service(self, service):
36ae71
+        self.service.check_service(service)
36ae71
+
36ae71
+    def check_port(self, port):
36ae71
+        range = functions.getPortRange(port)
36ae71
+
36ae71
+        if range == -2 or range == -1 or range == None or \
36ae71
+                (len(range) == 2 and range[0] >= range[1]):
36ae71
+            if range == -2:
36ae71
+                log.debug2("'%s': port > 65535" % port)
36ae71
+            elif range == -1:
36ae71
+                log.debug2("'%s': port is invalid" % port)
36ae71
+            elif range == None:
36ae71
+                log.debug2("'%s': port is ambiguous" % port)
36ae71
+            elif len(range) == 2 and range[0] >= range[1]:
36ae71
+                log.debug2("'%s': range start >= end" % port)
36ae71
+            raise FirewallError(INVALID_PORT, port)
36ae71
+
36ae71
+    def check_protocol(self, protocol):
36ae71
+        if not protocol:
36ae71
+            raise FirewallError(MISSING_PROTOCOL)
36ae71
+        if not protocol in [ "tcp", "udp" ]:
36ae71
+            raise FirewallError(INVALID_PROTOCOL, protocol)
36ae71
+
36ae71
+    def check_ip(self, ip):
36ae71
+        if not functions.checkIP(ip):
36ae71
+            raise FirewallError(INVALID_ADDR, ip)
36ae71
+
36ae71
+    def check_address(self, ipv, source):
36ae71
+        if ipv == "ipv4":
36ae71
+            if not functions.checkIPnMask(source):
36ae71
+                raise FirewallError(INVALID_ADDR, source)
36ae71
+        elif ipv == "ipv6":
36ae71
+            if not functions.checkIP6nMask(source):
36ae71
+                raise FirewallError(INVALID_ADDR, source)
36ae71
+        else:
36ae71
+            raise FirewallError(INVALID_IPV)
36ae71
+
36ae71
+    def check_icmptype(self, icmp):
36ae71
+        self.icmptype.check_icmptype(icmp)
36ae71
+
36ae71
+    # RELOAD
36ae71
+
36ae71
+    def reload(self, stop=False):
36ae71
+        return
36ae71
+
36ae71
+    # STATE
36ae71
+
36ae71
+    def get_state(self):
36ae71
+        return self._state
36ae71
+
36ae71
+    # PANIC MODE
36ae71
+
36ae71
+    def enable_panic_mode(self):
36ae71
+        return
36ae71
+
36ae71
+    def disable_panic_mode(self):
36ae71
+        return
36ae71
+
36ae71
+    def query_panic_mode(self):
36ae71
+        return (self._panic == True)
36ae71
+
36ae71
+    # DEFAULT ZONE
36ae71
+
36ae71
+    def get_default_zone(self):
36ae71
+        return self._default_zone
36ae71
+
36ae71
+    def set_default_zone(self, zone):
36ae71
+        _zone = self.check_zone(zone)
36ae71
+        if _zone != self._default_zone:
36ae71
+            _old_dz = self._default_zone
36ae71
+            self._default_zone = _zone
36ae71
+            self._firewalld_conf.set("DefaultZone", _zone)
36ae71
+            self._firewalld_conf.write()
36ae71
+        else:
36ae71
+            raise FirewallError(ZONE_ALREADY_SET, _zone)
36ae71
+
36ae71
+    # lockdown
36ae71
+
36ae71
+    def enable_lockdown(self):
36ae71
+        self._firewalld_conf.set("Lockdown", "yes")
36ae71
+        self._firewalld_conf.write()
36ae71
+        
36ae71
+    def disable_lockdown(self):
36ae71
+        self._firewalld_conf.set("Lockdown", "no")
36ae71
+        self._firewalld_conf.write()
36ae71
diff -up firewalld-0.3.9/src/firewall/core/io/direct.py.RHBZ#1059800 firewalld-0.3.9/src/firewall/core/io/direct.py
36ae71
--- firewalld-0.3.9/src/firewall/core/io/direct.py.RHBZ#1059800	2014-02-26 09:30:43.357192830 +0100
36ae71
+++ firewalld-0.3.9/src/firewall/core/io/direct.py	2014-02-26 09:30:43.440191809 +0100
36ae71
@@ -199,28 +199,28 @@ class Direct(IO_Object):
36ae71
                             (chain, table, ipv)
36ae71
                         + "already in list, ignoring")
36ae71
 
36ae71
-#    def remove_chain(self, ipv, table, chain):
36ae71
-#        key = (ipv, table)
36ae71
-#        if key in self.chains and chain in self.chains[key]:
36ae71
-#            self.chains[key].remove(chain)
36ae71
-#            if len(self.chains[key]) == 0:
36ae71
-#                del self.chains[key]
36ae71
-#        else:
36ae71
-#            raise ValueError( \
36ae71
-#                "Chain '%s' with table '%s' with ipv '%s' not in list" % \
36ae71
-#                (chain, table, ipv))
36ae71
-
36ae71
-#    def query_chain(self, ipv, table, chain):
36ae71
-#        key = (ipv, table)
36ae71
-#        return (key in self.chains and chain in self.chains[key])
36ae71
-
36ae71
-#    def get_chains(self, ipv, table):
36ae71
-#        key = (ipv, table)
36ae71
-#        if key in self.chains:
36ae71
-#            return self.chains[key]
36ae71
-#        else:
36ae71
-#            raise ValueError("No chains for table '%s' with ipv '%s'" % \
36ae71
-#                             (table, ipv))
36ae71
+    def remove_chain(self, ipv, table, chain):
36ae71
+        key = (ipv, table)
36ae71
+        if key in self.chains and chain in self.chains[key]:
36ae71
+            self.chains[key].remove(chain)
36ae71
+            if len(self.chains[key]) == 0:
36ae71
+                del self.chains[key]
36ae71
+        else:
36ae71
+            raise ValueError( \
36ae71
+                "Chain '%s' with table '%s' with ipv '%s' not in list" % \
36ae71
+                (chain, table, ipv))
36ae71
+
36ae71
+    def query_chain(self, ipv, table, chain):
36ae71
+        key = (ipv, table)
36ae71
+        return (key in self.chains and chain in self.chains[key])
36ae71
+
36ae71
+    def get_chains(self, ipv, table):
36ae71
+        key = (ipv, table)
36ae71
+        if key in self.chains:
36ae71
+            return self.chains[key]
36ae71
+        else:
36ae71
+            raise ValueError("No chains for table '%s' with ipv '%s'" % \
36ae71
+                             (table, ipv))
36ae71
 
36ae71
     def get_all_chains(self):
36ae71
         return self.chains
36ae71
@@ -240,30 +240,38 @@ class Direct(IO_Object):
36ae71
                         + "with ipv '%s' and priority %d " % (ipv, priority)
36ae71
                         + "already in list, ignoring")
36ae71
 
36ae71
-#    def remove_rule(self, ipv, table, chain, priority, args):
36ae71
-#        key = (ipv, table, chain)
36ae71
-#        value = (priority, tuple(args))
36ae71
-#        if key in self.rules and value in self.rules[key]:
36ae71
-#            del self.rules[key][value]
36ae71
-#            if len(self.rules[key]) == 0:
36ae71
-#                del self.rules[key]
36ae71
-#        else:
36ae71
-#            raise ValueError("Rule '%s' for table '%s' and chain '%s' " % \
36ae71
-#                ("',".join(args), table, chain) + \
36ae71
-#                "with ipv '%s' and priority %d not in list" % (ipv, priority))
36ae71
-
36ae71
-#    def query_rule(self, ipv, table, chain, priority, args):
36ae71
-#        key = (ipv, table, chain)
36ae71
-#        value = (priority, tuple(args))
36ae71
-#        return (key in self.rules and value in self.rules[key])
36ae71
-
36ae71
-#    def get_rules(self, ipv, table, chain):
36ae71
-#        key = (ipv, table, chain)
36ae71
-#        if key in self.rules:
36ae71
-#            return self.rules[key]
36ae71
-#        else:
36ae71
-#            raise ValueError("No rules for table '%s' and chain '%s' " %\
36ae71
-#                             (table, chain) + "with ipv '%s'" % (ipv))
36ae71
+    def remove_rule(self, ipv, table, chain, priority, args):
36ae71
+        key = (ipv, table, chain)
36ae71
+        value = (priority, tuple(args))
36ae71
+        if key in self.rules and value in self.rules[key]:
36ae71
+            del self.rules[key][value]
36ae71
+            if len(self.rules[key]) == 0:
36ae71
+                del self.rules[key]
36ae71
+        else:
36ae71
+            raise ValueError("Rule '%s' for table '%s' and chain '%s' " % \
36ae71
+                ("',".join(args), table, chain) + \
36ae71
+                "with ipv '%s' and priority %d not in list" % (ipv, priority))
36ae71
+
36ae71
+    def remove_rules(self, ipv, table, chain):
36ae71
+        key = (ipv, table, chain)
36ae71
+        if key in self.rules:
36ae71
+            for value in self.rules[key].keys():
36ae71
+                del self.rules[key][value]
36ae71
+            if len(self.rules[key]) == 0:
36ae71
+                del self.rules[key]
36ae71
+
36ae71
+    def query_rule(self, ipv, table, chain, priority, args):
36ae71
+        key = (ipv, table, chain)
36ae71
+        value = (priority, tuple(args))
36ae71
+        return (key in self.rules and value in self.rules[key])
36ae71
+
36ae71
+    def get_rules(self, ipv, table, chain):
36ae71
+        key = (ipv, table, chain)
36ae71
+        if key in self.rules:
36ae71
+            return self.rules[key]
36ae71
+        else:
36ae71
+            raise ValueError("No rules for table '%s' and chain '%s' " %\
36ae71
+                             (table, chain) + "with ipv '%s'" % (ipv))
36ae71
 
36ae71
     def get_all_rules(self):
36ae71
         return self.rules
36ae71
@@ -279,25 +287,25 @@ class Direct(IO_Object):
36ae71
             log.warning("Passthrough '%s' for ipv '%s'" % \
36ae71
                             ("',".join(args), ipv)
36ae71
                         + "already in list, ignoring")
36ae71
-#
36ae71
-#    def remove_passthrough(self, ipv, args):
36ae71
-#        if ipv in self.passthroughs and args in self.passthroughs[ipv]:
36ae71
-#            self.passthroughs[ipv].remove(args)
36ae71
-#            if len(self.passthroughs[ipv]) == 0:
36ae71
-#                del self.passthroughs[ipv]
36ae71
-#        else:
36ae71
-#            raise ValueError, "Passthrough '%s' for ipv '%s'" % \
36ae71
-#                ("',".join(args), ipv) + "not in list"
36ae71
-#
36ae71
-#    def query_passthrough(self, ipv, args):
36ae71
-#        return (ipv in self.passthroughs and args in self.passthroughs[ipv])
36ae71
-#
36ae71
-#    def get_passthroughs(self, ipv):
36ae71
-#        if ipv in self.passthroughs:
36ae71
-#            return self.passthroughs[ipv]
36ae71
-#        else:
36ae71
-#            raise ValueError, "No passthroughs for ipv '%s'" % (ipv)
36ae71
-#
36ae71
+
36ae71
+    def remove_passthrough(self, ipv, args):
36ae71
+        if ipv in self.passthroughs and args in self.passthroughs[ipv]:
36ae71
+            self.passthroughs[ipv].remove(args)
36ae71
+            if len(self.passthroughs[ipv]) == 0:
36ae71
+                del self.passthroughs[ipv]
36ae71
+        else:
36ae71
+            raise ValueError, "Passthrough '%s' for ipv '%s'" % \
36ae71
+                ("',".join(args), ipv) + "not in list"
36ae71
+
36ae71
+    def query_passthrough(self, ipv, args):
36ae71
+        return (ipv in self.passthroughs and args in self.passthroughs[ipv])
36ae71
+
36ae71
+    def get_passthroughs(self, ipv):
36ae71
+        if ipv in self.passthroughs:
36ae71
+            return self.passthroughs[ipv]
36ae71
+        else:
36ae71
+            raise ValueError, "No passthroughs for ipv '%s'" % (ipv)
36ae71
+
36ae71
     def get_all_passthroughs(self):
36ae71
         return self.passthroughs
36ae71
 
36ae71
diff -up firewalld-0.3.9/src/firewall/core/ipXtables.py.RHBZ#1059800 firewalld-0.3.9/src/firewall/core/ipXtables.py
36ae71
--- firewalld-0.3.9/src/firewall/core/ipXtables.py.RHBZ#1059800	2013-12-03 14:59:48.000000000 +0100
36ae71
+++ firewalld-0.3.9/src/firewall/core/ipXtables.py	2014-02-26 09:30:43.440191809 +0100
36ae71
@@ -153,7 +153,7 @@ class ip4tables:
36ae71
                 self.__run(["-t", table, "-L"])
36ae71
                 ret.append(table)
36ae71
             except ValueError:
36ae71
-                log.error("%s table '%s' does not exist (or not enough permission to check)." % (self.ipv, table))
36ae71
+                log.debug1("%s table '%s' does not exist (or not enough permission to check)." % (self.ipv, table))
36ae71
 
36ae71
         return ret
36ae71
 
36ae71
diff -up firewalld-0.3.9/src/firewall/core/ebtables.py.RHBZ#1059800 firewalld-0.3.9/src/firewall/core/ebtables.py
36ae71
--- firewalld-0.3.9/src/firewall/core/ebtables.py.RHBZ#1059800	2014-02-26 09:31:12.702831560 +0100
36ae71
+++ firewalld-0.3.9/src/firewall/core/ebtables.py	2014-02-26 09:31:24.722683430 +0100
36ae71
@@ -66,7 +66,7 @@ class ebtables:
36ae71
                 self.__run(["-t", table, "-L"])
36ae71
                 ret.append(table)
36ae71
             except ValueError:
36ae71
-                log.warning("ebtables table '%s' does not exist." % table)
36ae71
+                log.debug1("ebtables table '%s' does not exist." % table)
36ae71
 
36ae71
         return ret
36ae71
 
36ae71
diff -up firewalld-0.3.9/src/firewall-offline-cmd.RHBZ#1059800 firewalld-0.3.9/src/firewall-offline-cmd
36ae71
--- firewalld-0.3.9/src/firewall-offline-cmd.RHBZ#1059800	2013-12-03 14:59:48.000000000 +0100
36ae71
+++ firewalld-0.3.9/src/firewall-offline-cmd	2014-02-26 09:30:43.442191785 +0100
36ae71
@@ -1,10 +1,11 @@
36ae71
 #!/usr/bin/python
36ae71
 # -*- coding: utf-8 -*-
36ae71
 #
36ae71
-# Copyright (C) 2009-2012 Red Hat, Inc.
36ae71
+# Copyright (C) 2009-2014 Red Hat, Inc.
36ae71
 #
36ae71
 # Authors:
36ae71
 # Thomas Woerner <twoerner@redhat.com>
36ae71
+# Jiri Popelka <jpopelka@redhat.com>
36ae71
 #
36ae71
 # This program is free software; you can redistribute it and/or modify
36ae71
 # it under the terms of the GNU General Public License as published by
36ae71
@@ -20,307 +21,346 @@
36ae71
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
36ae71
 #
36ae71
 
36ae71
-from __future__ import print_function
36ae71
+from gi.repository import GObject
36ae71
 import sys
36ae71
-import os, os.path
36ae71
-from copy import copy
36ae71
+sys.modules['gobject'] = GObject
36ae71
 
36ae71
-from firewall.config import *
36ae71
-from firewall.core.io.firewalld_conf import firewalld_conf
36ae71
-from firewall.core.io.zone import Zone, zone_reader, zone_writer
36ae71
-from optparse import Option, OptionError, OptionParser, Values, \
36ae71
-    SUPPRESS_HELP, BadOptionError, OptionGroup
36ae71
-from firewall.functions import getPortID, getPortRange, getServiceName, \
36ae71
-    checkIP, checkInterface
36ae71
+import argparse
36ae71
+import dbus
36ae71
+import os
36ae71
+
36ae71
+#from firewall.config import *
36ae71
+from firewall.core.fw_test import Firewall_test
36ae71
+from firewall.client import *
36ae71
+from firewall.errors import *
36ae71
+from firewall.functions import joinArgs
36ae71
 
36ae71
 # check for root user
36ae71
 if os.getuid() != 0:
36ae71
     print(_("You need to be root to run %s.") % sys.argv[0])
36ae71
     sys.exit(-1)
36ae71
 
36ae71
-def usage():
36ae71
-    print("Usage: %s -h | --help" % sys.argv[0])
36ae71
+def __usage():
36ae71
+    print ("""
36ae71
+Usage: firewall-offline-cmd [OPTIONS...]
36ae71
+
36ae71
+If no options are given, configuration from '/etc/sysconfig/system-config-firewall' will be migrated.
36ae71
+
36ae71
+General Options
36ae71
+  -h, --help           Prints a short help text and exists
36ae71
+  -V, --version        Print the version string of firewalld
36ae71
+
36ae71
+Lokkit Compatibility Options
36ae71
+  --enabled             Enable firewall (default)
36ae71
+  --disabled            Disable firewall
36ae71
+  --addmodule=<module>  Ignored option, was used to enable an iptables module
36ae71
+  --removemodule=<module>
36ae71
+                        Ignored option, was used to disable an iptables module
36ae71
+  -s <service>, --service=<service>
36ae71
+                        Enable a service in the default zone (example: ssh)
36ae71
+  --remove-service=<service>
36ae71
+                        Disable a service in the default zone (example: ssh)
36ae71
+  -p <port>[-<port>]:<protocol>, --port=<port>[-<port>]:<protocol>
36ae71
+                        Enable a port in the default zone (example: ssh:tcp)
36ae71
+  -t <interface>, --trust=<interface>
36ae71
+                        Bind an interface to the trusted zone
36ae71
+  -m <interface>, --masq=<interface>
36ae71
+                        Enables masquerading in the default zone, interface
36ae71
+                        argument is ignored. This is IPv4 only.
36ae71
+  --custom-rules=[<type>:][:]<filename>
36ae71
+                        Ignored option. Was used to add custom rules to the
36ae71
+                        firewall (Example:
36ae71
+                        ipv4:filter:/etc/sysconfig/ipv4_filter_addon)
36ae71
+  --forward-port=if=<interface>:port=<port>:proto=<protocol>[:toport=<destination port>][:toaddr=<destination address>]
36ae71
+                        Forward the port with protocol for the interface to
36ae71
+                        either another local destination port (no destination
36ae71
+                        address given) or to an other destination address with
36ae71
+                        an optional destination port. This will be added to
36ae71
+                        the default zone. This is IPv4 only.
36ae71
+  --block-icmp=<icmp type>
36ae71
+                        Block this ICMP type in the default zone. The default
36ae71
+                        is to accept all ICMP types.
36ae71
+
36ae71
+Zone Options
36ae71
+  --get-default-zone   Print default zone for connections and interfaces
36ae71
+  --set-default-zone=<zone>
36ae71
+                       Set default zone
36ae71
+  --get-zones          Print predefined zones
36ae71
+  --get-services       Print predefined services
36ae71
+  --get-icmptypes      Print predefined icmptypes
36ae71
+  --get-zone-of-interface=<interface>
36ae71
+                       Print name of the zone the interface is bound to
36ae71
+  --get-zone-of-source=<source>[/<mask>]
36ae71
+                       Print name of the zone the source[/mask] is bound to
36ae71
+  --list-all-zones     List everything added for or enabled in all zones
36ae71
+  --new-zone=<zone>    Add a new zone
36ae71
+  --delete-zone=<zone> Delete an existing zone
36ae71
+  --zone=<zone>        Use this zone to set or query options, else default zone
36ae71
+                       Usable for options maked with [Z]
36ae71
+  --get-target         Get the zone target
36ae71
+  --set-target=<target>
36ae71
+                       Set the zone target
36ae71
+
36ae71
+IcmpType Options
36ae71
+  --new-icmptype=<icmptype>
36ae71
+                       Add a new icmptype
36ae71
+  --delete-icmptype=<icmptype>
36ae71
+                       Delete and existing icmptype
36ae71
+
36ae71
+Service Options
36ae71
+  --new-service=<service>
36ae71
+                       Add a new service
36ae71
+  --delete-service=<service>
36ae71
+                       Delete and existing service
36ae71
+
36ae71
+Options to Adapt and Query Zones
36ae71
+  --list-all           List everything added for or enabled in a zone [Z]
36ae71
+  --list-services      List services added for a zone [Z]
36ae71
+  --add-service=<service>
36ae71
+                       Add a service for a zone [Z]
36ae71
+  --remove-service-from-zone=<service>
36ae71
+                       Remove a service from a zone [Z]
36ae71
+  --query-service=<service>
36ae71
+                       Return whether service has been added for a zone [Z]
36ae71
+  --list-ports         List ports added for a zone [Z]
36ae71
+  --add-port=<portid>[-<portid>]/<protocol>
36ae71
+                       Add the port for a zone [Z]
36ae71
+  --remove-port=<portid>[-<portid>]/<protocol>
36ae71
+                       Remove the port from a zone [Z]
36ae71
+  --query-port=<portid>[-<portid>]/<protocol>
36ae71
+                       Return whether the port has been added for zone [Z]
36ae71
+  --list-icmp-blocks   List Internet ICMP type blocks added for a zone [Z]
36ae71
+  --add-icmp-block=<icmptype>
36ae71
+                       Add an ICMP block for a zone [Z]
36ae71
+  --remove-icmp-block=<icmptype>
36ae71
+                       Remove the ICMP block from a zone [Z]
36ae71
+  --query-icmp-block=<icmptype>
36ae71
+                       Return whether an ICMP block has been added for a zone
36ae71
+                       [Z]
36ae71
+  --list-forward-ports List IPv4 forward ports added for a zone [Z]
36ae71
+  --add-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
36ae71
+                       Add the IPv4 forward port for a zone [Z]
36ae71
+  --remove-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
36ae71
+                       Remove the IPv4 forward port from a zone [Z]
36ae71
+
36ae71
+
36ae71
+  --query-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
36ae71
+                       Return whether the IPv4 forward port has been added for
36ae71
+                       a zone [Z]
36ae71
+  --add-masquerade     Enable IPv4 masquerade for a zone [Z]
36ae71
+  --remove-masquerade  Disable IPv4 masquerade for a zone [Z]
36ae71
+  --query-masquerade   Return whether IPv4 masquerading has been enabled for a
36ae71
+                       zone [Z]
36ae71
+  --list-rich-rules    List rich language rules added for a zone [Z]
36ae71
+  --add-rich-rule=<rule>
36ae71
+                       Add rich language rule 'rule' for a zone [Z]
36ae71
+  --remove-rich-rule=<rule>
36ae71
+                       Remove rich language rule 'rule' from a zone [Z]
36ae71
+  --query-rich-rule=<rule>
36ae71
+                       Return whether a rich language rule 'rule' has been
36ae71
+                       added for a zone [Z]
36ae71
+
36ae71
+Options to Handle Bindings of Interfaces
36ae71
+  --list-interfaces    List interfaces that are bound to a zone [Z]
36ae71
+  --add-interface=<interface>
36ae71
+                       Bind the <interface> to a zone [Z]
36ae71
+  --change-interface=<interface>
36ae71
+                       Change zone the <interface> is bound to [Z]
36ae71
+  --query-interface=<interface>
36ae71
+                       Query whether <interface> is bound to a zone [Z]
36ae71
+  --remove-interface=<interface>
36ae71
+                       Remove binding of <interface> from a zone [Z]
36ae71
+
36ae71
+Options to Handle Bindings of Sources
36ae71
+  --list-sources       List sources that are bound to a zone [Z]
36ae71
+  --add-source=<source>[/<mask>]
36ae71
+                       Bind <source>[/<mask>] to a zone [Z]
36ae71
+  --change-source=<source>[/<mask>]
36ae71
+                       Change zone the <source>[/<mask>] is bound to [Z]
36ae71
+  --query-source=<source>[/<mask>]
36ae71
+                       Query whether <source>[/<mask>] is bound to a zone
36ae71
+                       [Z]
36ae71
+  --remove-source=<source>[/<mask>]
36ae71
+                       Remove binding of <source>[/<mask>] from a zone [Z]
36ae71
+
36ae71
+Direct Options
36ae71
+  --direct             First option for all direct options
36ae71
+  --get-all-chains
36ae71
+                       Get all chains
36ae71
+  --get-chains {ipv4|ipv6|eb} 
36ae71
+                       Get all chains added to the table
36ae71
+  --add-chain {ipv4|ipv6|eb}  <chain>
36ae71
+                       Add a new chain to the table
36ae71
+  --remove-chain {ipv4|ipv6|eb}  <chain>
36ae71
+                       Remove the chain from the table
36ae71
+  --query-chain {ipv4|ipv6|eb}  <chain>
36ae71
+                       Return whether the chain has been added to the table
36ae71
+  --get-all-rules
36ae71
+                       Get all rules
36ae71
+  --get-rules {ipv4|ipv6|eb}  <chain>
36ae71
+                       Get all rules added to chain in table
36ae71
+  --add-rule {ipv4|ipv6|eb}  <chain> <priority> <arg>...
36ae71
+                       Add rule to chain in table
36ae71
+  --remove-rule {ipv4|ipv6|eb}  <chain> <priority> <arg>...
36ae71
+                       Remove rule with priority from chain in table
36ae71
+  --remove-rules {ipv4|ipv6|eb}  <chain>
36ae71
+                       Remove rules from chain in table
36ae71
+  --query-rule {ipv4|ipv6|eb}  <chain> <priority> <arg>...
36ae71
+                       Return whether a rule with priority has been added to
36ae71
+                       chain in table
36ae71
+  --get-all-passthroughs
36ae71
+                       Get all passthrough rules
36ae71
+  --get-passthroughs {ipv4|ipv6|eb} <arg>...
36ae71
+                       Get passthrough rules
36ae71
+  --add-passthrough {ipv4|ipv6|eb} <arg>...
36ae71
+                       Add a new passthrough rule
36ae71
+  --remove-passthrough {ipv4|ipv6|eb} <arg>...
36ae71
+                       Remove a passthrough rule
36ae71
+  --query-passthrough {ipv4|ipv6|eb} <arg>...
36ae71
+                       Return whether the passthrough rule has been added
36ae71
+                      
36ae71
+
36ae71
+Lockdown Options
36ae71
+  --lockdown-on        Enable lockdown.
36ae71
+  --lockdown-off       Disable lockdown.
36ae71
+  --query-lockdown     Query whether lockdown is enabled
36ae71
+
36ae71
+Lockdown Whitelist Options
36ae71
+  --list-lockdown-whitelist-commands
36ae71
+                       List all command lines that are on the whitelist
36ae71
+  --add-lockdown-whitelist-command=<command>
36ae71
+                       Add the command to the whitelist
36ae71
+  --remove-lockdown-whitelist-command=<command>
36ae71
+                       Remove the command from the whitelist
36ae71
+  --query-lockdown-whitelist-command=<command>
36ae71
+                       Query whether the command is on the whitelist
36ae71
+  --list-lockdown-whitelist-contexts
36ae71
+                       List all contexts that are on the whitelist
36ae71
+  --add-lockdown-whitelist-context=<context>
36ae71
+                       Add the context context to the whitelist
36ae71
+  --remove-lockdown-whitelist-context=<context>
36ae71
+                       Remove the context from the whitelist
36ae71
+  --query-lockdown-whitelist-context=<context>
36ae71
+                       Query whether the context is on the whitelist
36ae71
+  --list-lockdown-whitelist-uids
36ae71
+                       List all user ids that are on the whitelist
36ae71
+  --add-lockdown-whitelist-uid=<uid>
36ae71
+                       Add the user id uid to the whitelist
36ae71
+  --remove-lockdown-whitelist-uid=<uid>
36ae71
+                       Remove the user id uid from the whitelist
36ae71
+  --query-lockdown-whitelist-uid=<uid>
36ae71
+                       Query whether the user id uid is on the whitelist
36ae71
+  --list-lockdown-whitelist-users
36ae71
+                       List all user names that are on the whitelist
36ae71
+  --add-lockdown-whitelist-user=<user>
36ae71
+                       Add the user name user to the whitelist
36ae71
+  --remove-lockdown-whitelist-user=<user>
36ae71
+                       Remove the user name user from the whitelist
36ae71
+  --query-lockdown-whitelist-user=<user>
36ae71
+                       Query whether the user name user is on the whitelist
36ae71
 
36ae71
-def error(text):
36ae71
-    print("%s %s" % (_("Error:"), text))
36ae71
+""")
36ae71
 
36ae71
-def warning(text):
36ae71
-    print("%s %s" % (_("Warning:"), text))
36ae71
-
36ae71
-def __fail(msg=None):
36ae71
+def __print(msg=None):
36ae71
     if msg:
36ae71
-        error(msg)
36ae71
-    sys.exit(2)
36ae71
-
36ae71
-# system-config-firewall: fw_parser
36ae71
+        print(msg)
36ae71
 
36ae71
-def _check_port(option, opt, value):
36ae71
-    failure = False
36ae71
-    try:
36ae71
-        (ports, protocol) = value.split(":")
36ae71
-    except:
36ae71
-        failure = True
36ae71
+def __print_and_exit(msg=None, exit_code=0):
36ae71
+    FAIL = '\033[91m'
36ae71
+    OK =   '\033[92m'
36ae71
+    END =  '\033[00m'
36ae71
+    if exit_code != 0:
36ae71
+        __print(msg)
36ae71
+        #__print(FAIL + msg + END)
36ae71
     else:
36ae71
-        range = getPortRange(ports.strip())
36ae71
-        if range < 0:
36ae71
-            failure = True
36ae71
-        elif range == None:
36ae71
-            raise OptionError(_("port range %s is not unique.") % value, opt)
36ae71
-        elif len(range) == 2 and range[0] >= range[1]:
36ae71
-            raise OptionError(_("%s is not a valid range (start port >= end "
36ae71
-                                "port).") % value, opt)
36ae71
-    if not failure:
36ae71
-        protocol = protocol.strip()
36ae71
-        if protocol not in [ "tcp", "udp" ]:
36ae71
-            raise OptionError(_("%s is not a valid protocol.") % protocol, opt)
36ae71
-    if failure:
36ae71
-        raise OptionError(_("invalid port definition %s.") % value, opt)
36ae71
-    return (ports.strip(), protocol)
36ae71
-
36ae71
-def _check_forward_port(option, opt, value):
36ae71
-    result = { }
36ae71
-    error = None
36ae71
-    splits = value.split(":", 1)
36ae71
-    while len(splits) > 0:
36ae71
-        key_val = splits[0].split("=")
36ae71
-        if len(key_val) != 2:
36ae71
-            error = _("Invalid argument %s") % splits[0]
36ae71
-            break
36ae71
-        (key, val) = key_val
36ae71
-        if (key == "if" and checkInterface(val)) or \
36ae71
-                (key == "proto" and val in [ "tcp", "udp" ]) or \
36ae71
-                (key == "toaddr" and checkIP(val)):
36ae71
-            result[key] = val
36ae71
-        elif (key == "port" or key == "toport") and getPortRange(val) > 0:
36ae71
-            result[key] = val
36ae71
-        else:
36ae71
-            error = _("Invalid argument %s") % splits[0]
36ae71
-            break
36ae71
-        if len(splits) > 1:
36ae71
-            if splits[1].count("=") == 1:
36ae71
-                # last element
36ae71
-                splits = [ splits[1] ]
36ae71
-            else:
36ae71
-                splits = splits[1].split(":", 1)
36ae71
-        else:
36ae71
-            # finish
36ae71
-            splits.pop()
36ae71
-
36ae71
-    if error:
36ae71
-        dict = { "option": opt, "value": value, "error": error }
36ae71
-        raise OptionError(_("option %(option)s: invalid forward_port "
36ae71
-                                 "'%(value)s': %(error)s.") % dict, opt)
36ae71
-
36ae71
-    error = False
36ae71
-    for key in [ "if", "port", "proto" ]:
36ae71
-        if key not in result.keys():
36ae71
-            error = True
36ae71
-    if not "toport" in result.keys() and not "toaddr" in result.keys():
36ae71
-        error = True
36ae71
-    if error:
36ae71
-        dict = { "option": opt, "value": value }
36ae71
-        raise OptionError(_("option %(option)s: invalid forward_port "
36ae71
-                                 "'%(value)s'.") % dict, opt)
36ae71
-
36ae71
-    return result
36ae71
-
36ae71
-def _check_interface(option, opt, value):
36ae71
-    if not checkInterface(value):
36ae71
-        raise OptionError(_("invalid interface '%s'.") % value, opt)
36ae71
-    return value
36ae71
+        __print(msg)
36ae71
+        #__print(OK + msg + END)
36ae71
+    sys.exit(exit_code)
36ae71
 
36ae71
-def _append_unique(option, opt, value, parser, *args, **kwargs):
36ae71
-    vals = getattr(parser.values, option.dest)
36ae71
-    if vals and value in vals:
36ae71
-        return
36ae71
-    parser.values.ensure_value(option.dest, []).append(value)
36ae71
-
36ae71
-class _Option(Option):
36ae71
-    TYPES = Option.TYPES + ("port", "rulesfile", "service", "forward_port",
36ae71
-                            "icmp_type", "interface")
36ae71
-    TYPE_CHECKER = copy(Option.TYPE_CHECKER)
36ae71
-    TYPE_CHECKER["port"] = _check_port
36ae71
-    TYPE_CHECKER["forward_port"] = _check_forward_port
36ae71
-    TYPE_CHECKER["interface"] = _check_interface
36ae71
-
36ae71
-def _addStandardOptions(parser):
36ae71
-    parser.add_option("--enabled",
36ae71
-                      action="store_true", dest="enabled", default=True,
36ae71
-                      help=_("Enable firewall (default)"))
36ae71
-    parser.add_option("--disabled",
36ae71
-                      action="store_false", dest="enabled",
36ae71
-                      help=_("Disable firewall"))
36ae71
-#    parser.add_option("--update",
36ae71
-#                      action="store_false", dest="update",
36ae71
-#                      help=_("Ignored option, was used to update the firewall"))
36ae71
-    parser.add_option("--addmodule",
36ae71
-                      action="callback", dest="add_module", type="string",
36ae71
-                      metavar=_("<module>"),  callback=_append_unique,
36ae71
-                      help=_("Ignored option, was used to enable an iptables module"))
36ae71
-    parser.add_option("--removemodule",
36ae71
-                      action="callback", dest="remove_module", type="string",
36ae71
-                      metavar=_("<module>"), callback=_append_unique,
36ae71
-                      help=_("Ignored option, was used to disable an iptables module"))
36ae71
-    parser.add_option("-s", "--service",
36ae71
-                      action="callback", dest="services", type="service",
36ae71
-                      default=[ ],
36ae71
-                      metavar=_("<service>"), callback=_append_unique,
36ae71
-                      help=_("Enable a service in the default zone (example: ssh)"))
36ae71
-    parser.add_option("--remove-service",
36ae71
-                      action="callback", dest="remove_services", type="service",
36ae71
-                      default=[ ],
36ae71
-                      metavar=_("<service>"), callback=_append_unique,
36ae71
-                      help=_("Disable a service in the default zone (example: ssh)"))
36ae71
-    parser.add_option("-p", "--port",
36ae71
-                      action="callback", dest="ports", type="port",
36ae71
-                      metavar=_("<port>[-<port>]:<protocol>"),
36ae71
-                      callback=_append_unique,
36ae71
-                      help=_("Enable a port in the default zone "
36ae71
-                             "(example: ssh:tcp)"))
36ae71
-    parser.add_option("-t", "--trust",
36ae71
-                      action="callback", dest="trust", type="interface",
36ae71
-                      metavar=_("<interface>"), callback=_append_unique,
36ae71
-                      help=_("Bind an interface to the trusted zone"))
36ae71
-    parser.add_option("-m", "--masq",
36ae71
-                      action="callback", dest="masq", type="interface",
36ae71
-                      metavar=_("<interface>"), callback=_append_unique,
36ae71
-                      help=_("Enables masquerading in the default zone, interface argument is ignored. This is IPv4 only."))
36ae71
-    parser.add_option("--custom-rules",
36ae71
-                      action="callback", dest="custom_rules", type="rulesfile",
36ae71
-                      metavar=_("[<type>:][:]<filename>"),
36ae71
-                      callback=_append_unique,
36ae71
-                      help=_("Ignored option. Was used to add custom rules to the firewall (Example: ipv4:filter:/etc/sysconfig/ipv4_filter_addon)"))
36ae71
-    parser.add_option("--forward-port",
36ae71
-                      action="callback", dest="forward_port",
36ae71
-                      type="forward_port",
36ae71
-                      metavar=_("if=<interface>:port=<port>:proto=<protocol>"
36ae71
-                                "[:toport=<destination port>]"
36ae71
-                                "[:toaddr=<destination address>]"),
36ae71
-                      callback=_append_unique,
36ae71
-                      help=_("Forward the port with protocol for the interface to either another local destination port (no destination address given) or to an other destination address with an optional destination port. This will be added to the default zone. This is IPv4 only."))
36ae71
-    parser.add_option("--block-icmp",
36ae71
-                      action="callback", dest="block_icmp", type="icmp_type",
36ae71
-                      default=[ ],
36ae71
-                      callback=_append_unique,
36ae71
-                      metavar=_("<icmp type>"),
36ae71
-                      help=_("Block this ICMP type in the default zone. The default is to accept all ICMP types."))
36ae71
+def __fail(msg=None):
36ae71
+    __print_and_exit(msg, 2)
36ae71
 
36ae71
-def _parse_args(parser, args, options=None):
36ae71
+def __parse_port(value):
36ae71
     try:
36ae71
-        (_options, _args) = parser.parse_args(args, options)
36ae71
-    except Exception as error:
36ae71
-        parser.error(error)
36ae71
-        return None
36ae71
+        (port, proto) = value.split("/")
36ae71
+    except Exception as e:
36ae71
+        __fail("bad port (most likely missing protocol), correct syntax is portid[-portid]/protocol")
36ae71
+    return (port, proto)
36ae71
 
36ae71
-    if len(_args) != 0:
36ae71
-        for arg in _args:
36ae71
-            parser.error(_("no such option: %s") % arg)
36ae71
-    if parser._fw_exit:
36ae71
-        sys.exit(2)
36ae71
-    if not hasattr(_options, "filename"):
36ae71
-        _options.filename = None
36ae71
-    if not hasattr(_options, "converted"):
36ae71
-        _options.converted = False
36ae71
-    return _options
36ae71
-
36ae71
-class _OptionParser(OptionParser):
36ae71
-    # overload print_help: rhpl._ returns UTF-8
36ae71
-    def print_help(self, file=None):
36ae71
-        if file is None:
36ae71
-            file = sys.stdout
36ae71
-
36ae71
-        file.write(_("This tool tries to convert system-config-firewall/lokkit options as much as possible to firewalld, but there are limitations for example with custom rules, modules and masquerading.") + "\n\n")
36ae71
-        str = self.format_help()
36ae71
-        if isinstance(str, unicode):
36ae71
-            encoding = self._get_encoding(file)
36ae71
-            str = str.encode(encoding, "replace")
36ae71
-        file.write(str)
36ae71
-        file.write("\n" + _("If no options are given, the configuration from '%s' be migrated.") % (CONFIG) + "\n")
36ae71
-        self.exit()
36ae71
-    def print_usage(self, file=None):
36ae71
-        pass
36ae71
-    def exit(self, status=0, msg=None):
36ae71
-        if msg:
36ae71
-            print(msg, file=sys.stderr)
36ae71
-        sys.exit(status)
36ae71
-    def error(self, msg):
36ae71
-        if self._fw_source:
36ae71
-            text = "%s: %s" % (self._fw_source, msg)
36ae71
-        else:
36ae71
-            text = str(msg)
36ae71
-        self.exit(2, msg=text)
36ae71
-    def _match_long_opt(self, opt):
36ae71
-        if opt in self._long_opt:
36ae71
-            return opt
36ae71
-        raise BadOptionError(opt)
36ae71
-    def _process_long_opt(self, rargs, values):
36ae71
-        # allow to ignore errors in the ui
36ae71
-        try:
36ae71
-            self.__process_long_opt(rargs, values)
36ae71
-        except Exception as msg:
36ae71
-            self.error(msg)
36ae71
-    def _process_short_opts(self, rargs, values):
36ae71
-        # allow to ignore errors in the ui
36ae71
+def __parse_port_lokkit(value):
36ae71
+    try:
36ae71
+        (port, proto) = value.split(":")
36ae71
+    except Exception as e:
36ae71
+        __fail("bad port (most likely missing protocol), correct syntax is portid[-portid]:protocol")
36ae71
+    return (port, proto)
36ae71
+
36ae71
+def __parse_forward_port(value):
36ae71
+    port = None
36ae71
+    protocol = None
36ae71
+    toport = None
36ae71
+    toaddr = None
36ae71
+    args = value.split(":")
36ae71
+    for arg in args:
36ae71
         try:
36ae71
-            OptionParser._process_short_opts(self, rargs, values)
36ae71
-        except Exception as msg:
36ae71
-            self.error(msg)
36ae71
-    def __process_long_opt(self, rargs, values):
36ae71
-        arg = rargs.pop(0)
36ae71
-
36ae71
-        # Value explicitly attached to arg?  Pretend it's the next
36ae71
-        # argument.
36ae71
-        if "=" in arg:
36ae71
-            (opt, next_arg) = arg.split("=", 1)
36ae71
-            had_explicit_value = True
36ae71
-        else:
36ae71
-            opt = arg
36ae71
-            had_explicit_value = False
36ae71
-
36ae71
-        opt = self._match_long_opt(opt)
36ae71
-        option = self._long_opt[opt]
36ae71
-        if option.takes_value():
36ae71
-            nargs = option.nargs
36ae71
-            if len(rargs)+int(had_explicit_value) < nargs:
36ae71
-                if nargs == 1:
36ae71
-                    self.error(_("%s option requires an argument") % opt)
36ae71
-                else:
36ae71
-                    dict = { "option": opt, "count": nargs }
36ae71
-                    self.error(_("%(option)s option requires %(count)s "
36ae71
-                                 "arguments") % dict)
36ae71
-            elif nargs == 1 and had_explicit_value:
36ae71
-                value = next_arg
36ae71
-            elif nargs == 1:
36ae71
-                value = rargs.pop(0)
36ae71
-            elif had_explicit_value:
36ae71
-                value = tuple([ next_arg ] + rargs[0:nargs-1])
36ae71
-                del rargs[0:nargs-1]
36ae71
-            else:
36ae71
-                value = tuple(rargs[0:nargs])
36ae71
-                del rargs[0:nargs]
36ae71
-
36ae71
-        elif had_explicit_value:
36ae71
-            self.error(_("%s option does not take a value") % opt)
36ae71
-
36ae71
-        else:
36ae71
-            value = None
36ae71
+            (opt,val) = arg.split("=")
36ae71
+            if opt == "port":
36ae71
+                port = val
36ae71
+            elif opt == "proto":
36ae71
+                protocol = val
36ae71
+            elif opt == "toport":
36ae71
+                toport = val
36ae71
+            elif opt == "toaddr":
36ae71
+                toaddr = val
36ae71
+        except:
36ae71
+            __fail("invalid forward port arg '%s'" % (arg))
36ae71
+    if not port:
36ae71
+        __fail("missing port")
36ae71
+    if not protocol:
36ae71
+        __fail("missing protocol")
36ae71
+    if not (toport or toaddr):
36ae71
+        __fail("missing destination")
36ae71
+    return (port, protocol, toport, toaddr)
36ae71
+
36ae71
+def _check_ipv(value):
36ae71
+    if value != "ipv4" and value != "ipv6" and value != "eb":
36ae71
+        __fail("invalid argument: %s (choose from 'ipv4', 'ipv6', 'eb')" % value)
36ae71
+    return value
36ae71
 
36ae71
-        option.process(opt, value, values, self)
36ae71
-
36ae71
-def _gen_parser(source=None):
36ae71
-    parser = _OptionParser(option_class=_Option)
36ae71
-    parser._fw_source = source
36ae71
-    parser._fw_exit = False
36ae71
-    return parser
36ae71
-
36ae71
-def parseSysconfigArgs(args, options=None, source=None):
36ae71
-    parser = _gen_parser(source)
36ae71
-    _addStandardOptions(parser)
36ae71
-    return _parse_args(parser, args, options)
36ae71
+def __print_all(zone, interfaces, sources, services, ports, masquerade, forward_ports, icmp_blocks, rules):
36ae71
+    attributes = []
36ae71
+    if zone == fw.get_default_zone():
36ae71
+        attributes.append("default")
36ae71
+    if attributes:
36ae71
+        zone = zone + " (%s)" % ", ".join(attributes)
36ae71
+    __print(zone)
36ae71
+    __print("  interfaces: " + " ".join(interfaces))
36ae71
+    __print("  sources: " + " ".join(sources))
36ae71
+    __print("  services: " + " ".join(services))
36ae71
+    __print("  ports: " + " ".join(["%s/%s" % (port[0], port[1]) for port in ports]))
36ae71
+    __print("  masquerade: %s" % ("yes" if masquerade else "no"))
36ae71
+    __print("  forward-ports: " + "\n\t".join(["port=%s:proto=%s:toport=%s:toaddr=%s" % (port, protocol, toport, toaddr) for (port, protocol, toport, toaddr) in forward_ports]))
36ae71
+    __print("  icmp-blocks: " + " ".join(icmp_blocks))
36ae71
+    __print("  rich rules: \n\t" + "\n\t".join(rules))
36ae71
+
36ae71
+def __list_all_permanent(fw_settings, zone):
36ae71
+    interfaces = fw_settings.getInterfaces()
36ae71
+    sources = fw_settings.getSources()
36ae71
+    services = fw_settings.getServices()
36ae71
+    ports = fw_settings.getPorts()
36ae71
+    masquerade = fw_settings.getMasquerade()
36ae71
+    forward_ports = fw_settings.getForwardPorts()
36ae71
+    icmp_blocks = fw_settings.getIcmpBlocks()
36ae71
+    rules = fw_settings.getRichRules()
36ae71
+    __print_all(zone, interfaces, sources, services, ports, masquerade, forward_ports, icmp_blocks, rules)
36ae71
+
36ae71
+def __print_query_result(value):
36ae71
+    if value:
36ae71
+        __print_and_exit("yes")
36ae71
+    else:
36ae71
+        __print_and_exit("no", 1)
36ae71
 
36ae71
 # system-config-firewall: fw_sysconfig
36ae71
 CONFIG = '/etc/sysconfig/system-config-firewall'
36ae71
-
36ae71
 def read_sysconfig_args():
36ae71
     filename = None
36ae71
     if os.path.exists(CONFIG) and os.path.isfile(CONFIG):
36ae71
@@ -338,163 +378,738 @@ def read_sysconfig_args():
36ae71
             continue
36ae71
         argv.append(line)
36ae71
     f.close()
36ae71
-    return (argv, filename)
36ae71
+    return argv
36ae71
 
36ae71
-def parse_sysconfig_args(args, merge_config=None, filename=None):
36ae71
-    config = parseSysconfigArgs(args, options=merge_config, source=filename)
36ae71
-    if not config:
36ae71
-        return None
36ae71
-    config.filename = filename
36ae71
-    return config
36ae71
+##############################################################################
36ae71
 
36ae71
-def read_sysconfig_config(merge_config=None):
36ae71
-    args = read_sysconfig_args() # returns: (args, filename) or None
36ae71
-    if not args:
36ae71
-        return merge_config
36ae71
-    return parse_sysconfig_args(args[0], merge_config, args[1])
36ae71
+parser = argparse.ArgumentParser(usage="see firewall-offline-cmd man page",
36ae71
+                                 add_help=False)
36ae71
 
36ae71
-if len(sys.argv) > 1:
36ae71
-    # Parse the cmdline args and setup the initial firewall state
36ae71
-    conf = parse_sysconfig_args(None)
36ae71
-    if not conf:
36ae71
-        error(_("Problem parsing arguments."))
36ae71
-        sys.exit(1)
36ae71
-else:
36ae71
-    # open system-config-firewall config
36ae71
-    conf = read_sysconfig_config()
36ae71
-    if not conf:
36ae71
-        error(_("Opening of '%s' failed, exiting." % CONFIG))
36ae71
-        sys.exit(1)
36ae71
+parser_group_lokkit = parser.add_argument_group()
36ae71
+parser_group_lokkit.add_argument("--enabled", action="store_true")
36ae71
+parser_group_lokkit.add_argument("--disabled", action="store_true")
36ae71
+parser_group_lokkit.add_argument("--addmodule", metavar="<module>", action='append')
36ae71
+parser_group_lokkit.add_argument("--removemodule", metavar="<module>", action='append')
36ae71
+parser_group_lokkit.add_argument("--service", "-s", metavar="<service>", action='append')
36ae71
+parser_group_lokkit.add_argument("--remove-service", metavar="<service>", action='append')
36ae71
+parser_group_lokkit.add_argument("--port", "-p", metavar="<port>", action='append')
36ae71
+parser_group_lokkit.add_argument("--trust", "-t", metavar="<iface>", action='append')
36ae71
+parser_group_lokkit.add_argument("--masq", "-m", metavar="<iface>", action='append')
36ae71
+parser_group_lokkit.add_argument("--custom-rules", metavar="<filename>", action='append')
36ae71
+parser_group_lokkit.add_argument("--forward-port", metavar="<port>", action='append')
36ae71
+parser_group_lokkit.add_argument("--block-icmp", metavar="<icmptype>", action='append')
36ae71
+
36ae71
+parser_group_standalone = parser.add_mutually_exclusive_group()
36ae71
+parser_group_standalone.add_argument("-h", "--help",
36ae71
+                                     action="store_true")
36ae71
+parser_group_standalone.add_argument("-V", "--version", action="store_true")
36ae71
+parser_group_standalone.add_argument("--lockdown-on", action="store_true")
36ae71
+parser_group_standalone.add_argument("--lockdown-off", action="store_true")
36ae71
+parser_group_standalone.add_argument("--query-lockdown", action="store_true")
36ae71
+
36ae71
+parser_group_standalone.add_argument("--get-default-zone", action="store_true")
36ae71
+parser_group_standalone.add_argument("--set-default-zone", metavar="<zone>")
36ae71
+parser_group_standalone.add_argument("--get-zones", action="store_true")
36ae71
+parser_group_standalone.add_argument("--get-services", action="store_true")
36ae71
+parser_group_standalone.add_argument("--get-icmptypes", action="store_true")
36ae71
+parser_group_standalone.add_argument("--get-zone-of-interface", metavar="<iface>")
36ae71
+parser_group_standalone.add_argument("--get-zone-of-source", metavar="<source>")
36ae71
+parser_group_standalone.add_argument("--list-all-zones", action="store_true")
36ae71
+
36ae71
+parser_group_config = parser.add_mutually_exclusive_group()
36ae71
+parser_group_config.add_argument("--new-icmptype", metavar="<icmptype>")
36ae71
+parser_group_config.add_argument("--delete-icmptype", metavar="<icmptype>")
36ae71
+parser_group_config.add_argument("--new-service", metavar="<service>")
36ae71
+parser_group_config.add_argument("--delete-service", metavar="<service>")
36ae71
+parser_group_config.add_argument("--new-zone", metavar="<zone>")
36ae71
+parser_group_config.add_argument("--delete-zone", metavar="<zone>")
36ae71
+
36ae71
+parser_group_lockdown_whitelist = parser.add_mutually_exclusive_group()
36ae71
+parser_group_lockdown_whitelist.add_argument("--list-lockdown-whitelist-commands", action="store_true")
36ae71
+parser_group_lockdown_whitelist.add_argument("--add-lockdown-whitelist-command", metavar="<command>")
36ae71
+parser_group_lockdown_whitelist.add_argument("--remove-lockdown-whitelist-command", metavar="<command>")
36ae71
+parser_group_lockdown_whitelist.add_argument("--query-lockdown-whitelist-command", metavar="<command>")
36ae71
+
36ae71
+parser_group_lockdown_whitelist.add_argument("--list-lockdown-whitelist-contexts", action="store_true")
36ae71
+parser_group_lockdown_whitelist.add_argument("--add-lockdown-whitelist-context", metavar="<context>")
36ae71
+parser_group_lockdown_whitelist.add_argument("--remove-lockdown-whitelist-context", metavar="<context>")
36ae71
+parser_group_lockdown_whitelist.add_argument("--query-lockdown-whitelist-context", metavar="<context>")
36ae71
+
36ae71
+parser_group_lockdown_whitelist.add_argument("--list-lockdown-whitelist-uids", action="store_true")
36ae71
+parser_group_lockdown_whitelist.add_argument("--add-lockdown-whitelist-uid", metavar="<uid>", type=int)
36ae71
+parser_group_lockdown_whitelist.add_argument("--remove-lockdown-whitelist-uid", metavar="<uid>", type=int)
36ae71
+parser_group_lockdown_whitelist.add_argument("--query-lockdown-whitelist-uid", metavar="<uid>", type=int)
36ae71
+
36ae71
+parser_group_lockdown_whitelist.add_argument("--list-lockdown-whitelist-users", action="store_true")
36ae71
+parser_group_lockdown_whitelist.add_argument("--add-lockdown-whitelist-user", metavar="<user>")
36ae71
+parser_group_lockdown_whitelist.add_argument("--remove-lockdown-whitelist-user", metavar="<user>")
36ae71
+parser_group_lockdown_whitelist.add_argument("--query-lockdown-whitelist-user", metavar="<user>")
36ae71
+
36ae71
+parser.add_argument("--zone", default="", metavar="<zone>")
36ae71
+
36ae71
+parser_group_zone = parser.add_mutually_exclusive_group()
36ae71
+parser_group_zone.add_argument("--add-interface", metavar="<iface>")
36ae71
+parser_group_zone.add_argument("--remove-interface", metavar="<iface>")
36ae71
+parser_group_zone.add_argument("--query-interface", metavar="<iface>")
36ae71
+parser_group_zone.add_argument("--change-interface", "--change-zone", metavar="<iface>")
36ae71
+parser_group_zone.add_argument("--list-interfaces", action="store_true")
36ae71
+parser_group_zone.add_argument("--add-source", metavar="<source>")
36ae71
+parser_group_zone.add_argument("--remove-source", metavar="<source>")
36ae71
+parser_group_zone.add_argument("--query-source", metavar="<source>")
36ae71
+parser_group_zone.add_argument("--change-source", metavar="<source>")
36ae71
+parser_group_zone.add_argument("--list-sources", action="store_true")
36ae71
+parser_group_zone.add_argument("--add-rich-rule", metavar="<rule>", action='append')
36ae71
+parser_group_zone.add_argument("--remove-rich-rule", metavar="<rule>", action='append')
36ae71
+parser_group_zone.add_argument("--query-rich-rule", metavar="<rule>")
36ae71
+parser_group_zone.add_argument("--add-service", metavar="<service>", action='append')
36ae71
+parser_group_zone.add_argument("--remove-service-from-zone", metavar="<zone>", action='append')
36ae71
+parser_group_zone.add_argument("--query-service", metavar="<zone>")
36ae71
+parser_group_zone.add_argument("--add-port", metavar="<port>", action='append')
36ae71
+parser_group_zone.add_argument("--remove-port", metavar="<port>", action='append')
36ae71
+parser_group_zone.add_argument("--query-port", metavar="<port>")
36ae71
+parser_group_zone.add_argument("--add-masquerade", action="store_true")
36ae71
+parser_group_zone.add_argument("--remove-masquerade", action="store_true")
36ae71
+parser_group_zone.add_argument("--query-masquerade", action="store_true")
36ae71
+parser_group_zone.add_argument("--add-icmp-block", metavar="<icmptype>", action='append')
36ae71
+parser_group_zone.add_argument("--remove-icmp-block", metavar="<icmptype>", action='append')
36ae71
+parser_group_zone.add_argument("--query-icmp-block", metavar="<icmptype>")
36ae71
+parser_group_zone.add_argument("--add-forward-port", metavar="<port>", action='append')
36ae71
+parser_group_zone.add_argument("--remove-forward-port", metavar="<port>", action='append')
36ae71
+parser_group_zone.add_argument("--query-forward-port", metavar="<port>")
36ae71
+parser_group_zone.add_argument("--list-rich-rules", action="store_true")
36ae71
+parser_group_zone.add_argument("--list-services", action="store_true")
36ae71
+parser_group_zone.add_argument("--list-ports", action="store_true")
36ae71
+parser_group_zone.add_argument("--list-icmp-blocks", action="store_true")
36ae71
+parser_group_zone.add_argument("--list-forward-ports", action="store_true")
36ae71
+parser_group_zone.add_argument("--list-all", action="store_true")
36ae71
+parser_group_zone.add_argument("--get-target", action="store_true")
36ae71
+parser_group_zone.add_argument("--set-target", metavar="<target>")
36ae71
+
36ae71
+parser.add_argument("--direct", action="store_true")
36ae71
+
36ae71
+parser_direct = parser.add_mutually_exclusive_group()
36ae71
+parser_direct.add_argument("--add-passthrough", nargs=argparse.REMAINDER,
36ae71
+                    metavar=("{ ipv4 | ipv6 | eb }", "<args>"))
36ae71
+parser_direct.add_argument("--remove-passthrough", nargs=argparse.REMAINDER,
36ae71
+                    metavar=("{ ipv4 | ipv6 | eb }", "<args>"))
36ae71
+parser_direct.add_argument("--query-passthrough", nargs=argparse.REMAINDER,
36ae71
+                    metavar=("{ ipv4 | ipv6 | eb }", "<args>"))
36ae71
+parser_direct.add_argument("--get-passthroughs", nargs=1,
36ae71
+                    metavar=("{ ipv4 | ipv6 | eb }", "<args>"))
36ae71
+parser_direct.add_argument("--get-all-passthroughs", action="store_true")
36ae71
+parser_direct.add_argument("--add-chain", nargs=3,
36ae71
+                    metavar=("{ ipv4 | ipv6 | eb }", "", "<chain>"))
36ae71
+parser_direct.add_argument("--remove-chain", nargs=3,
36ae71
+                        metavar=("{ ipv4 | ipv6 | eb }", "", "<chain>"))
36ae71
+parser_direct.add_argument("--query-chain", nargs=3,
36ae71
+                        metavar=("{ ipv4 | ipv6 | eb }", "", "<chain>"))
36ae71
+parser_direct.add_argument("--get-all-chains", action="store_true")
36ae71
+parser_direct.add_argument("--get-chains", nargs=2,
36ae71
+                        metavar=("{ ipv4 | ipv6 | eb }", ""))
36ae71
+parser_direct.add_argument("--add-rule", nargs=argparse.REMAINDER,
36ae71
+                        metavar=("{ ipv4 | ipv6 | eb }", " <chain> <priority> <args>"))
36ae71
+parser_direct.add_argument("--remove-rule", nargs=argparse.REMAINDER,
36ae71
+                        metavar=("{ ipv4 | ipv6 | eb }", " <chain> <priority> <args>"))
36ae71
+parser_direct.add_argument("--remove-rules", nargs=3,
36ae71
+                        metavar=("{ ipv4 | ipv6 | eb }", " <chain> <args>"))
36ae71
+parser_direct.add_argument("--query-rule", nargs=argparse.REMAINDER,
36ae71
+                        metavar=("{ ipv4 | ipv6 | eb }", " <chain> <priority> <args>"))
36ae71
+parser_direct.add_argument("--get-rules", nargs=3,
36ae71
+                        metavar=("{ ipv4 | ipv6 | eb }", "", "<chain>"))
36ae71
+parser_direct.add_argument("--get-all-rules", action="store_true")
36ae71
 
36ae71
+##############################################################################
36ae71
 
36ae71
-if conf.enabled == False:
36ae71
-    os.system("systemctl disable firewalld.service")
36ae71
+if len(sys.argv) > 1:
36ae71
+    a = parser.parse_args()
36ae71
 else:
36ae71
-    os.system("systemctl enable firewalld.service")
36ae71
-
36ae71
-
36ae71
-# open firewalld config file to get default zone
36ae71
+    # migrate configuration from /etc/sysconfig/system-config-firewall
36ae71
+    args = read_sysconfig_args()
36ae71
+    if args:
36ae71
+        a = parser.parse_args(args)
36ae71
+    else:
36ae71
+        __fail("Opening of '%s' failed, exiting." % CONFIG)
36ae71
 
36ae71
-default_zone = "public" # default zone in case of missing config file
36ae71
-trusted_zone = "trusted"
36ae71
+options_lokkit = a.enabled or a.disabled or a.addmodule or a.removemodule or \
36ae71
+                 a.trust or a.masq or a.custom_rules or \
36ae71
+                 a.service or a.remove_service or a.port or \
36ae71
+                 a.trust or a.masq or a.forward_port or a.block_icmp
36ae71
+
36ae71
+options_standalone = a.help or a.version or \
36ae71
+    a.lockdown_on or a.lockdown_off or a.query_lockdown or \
36ae71
+    a.get_default_zone or a.set_default_zone
36ae71
+
36ae71
+options_lockdown_whitelist = \
36ae71
+    a.list_lockdown_whitelist_commands or a.add_lockdown_whitelist_command or \
36ae71
+    a.remove_lockdown_whitelist_command or \
36ae71
+    a.query_lockdown_whitelist_command or \
36ae71
+    a.list_lockdown_whitelist_contexts or a.add_lockdown_whitelist_context or \
36ae71
+    a.remove_lockdown_whitelist_context or \
36ae71
+    a.query_lockdown_whitelist_context or \
36ae71
+    a.list_lockdown_whitelist_uids or a.add_lockdown_whitelist_uid != None or \
36ae71
+    a.remove_lockdown_whitelist_uid != None or \
36ae71
+    a.query_lockdown_whitelist_uid != None or \
36ae71
+    a.list_lockdown_whitelist_users or a.add_lockdown_whitelist_user or \
36ae71
+    a.remove_lockdown_whitelist_user or \
36ae71
+    a.query_lockdown_whitelist_user
36ae71
+
36ae71
+options_config = a.get_zones or a.get_services or a.get_icmptypes or \
36ae71
+                 options_lockdown_whitelist or a.list_all_zones or \
36ae71
+                 a.get_zone_of_interface or a.get_zone_of_source
36ae71
+
36ae71
+options_zone_action_action = \
36ae71
+    a.add_service or a.remove_service_from_zone or a.query_service or \
36ae71
+    a.add_port or a.remove_port or a.query_port or \
36ae71
+    a.add_icmp_block or a.remove_icmp_block or a.query_icmp_block or \
36ae71
+    a.add_forward_port or a.remove_forward_port or a.query_forward_port
36ae71
+
36ae71
+options_zone_interfaces_sources = \
36ae71
+    a.list_interfaces or a.change_interface or \
36ae71
+    a.add_interface or a.remove_interface or a.query_interface or \
36ae71
+    a.list_sources or a.change_source or \
36ae71
+    a.add_source or a.remove_source or a.query_source
36ae71
+
36ae71
+options_zone_adapt_query = \
36ae71
+    a.add_rich_rule or a.remove_rich_rule or a.query_rich_rule or \
36ae71
+    a.add_masquerade or a.remove_masquerade or a.query_masquerade or \
36ae71
+    a.list_services or a.list_ports or a.list_icmp_blocks or \
36ae71
+    a.list_forward_ports or a.list_rich_rules or a.list_all or \
36ae71
+    a.get_target or a.set_target
36ae71
+
36ae71
+options_zone_ops = options_zone_interfaces_sources or \
36ae71
+               options_zone_action_action or options_zone_adapt_query
36ae71
+
36ae71
+options_zone = a.zone or options_zone_ops
36ae71
+
36ae71
+options_permanent = options_config or options_zone or \
36ae71
+                    a.new_icmptype or a.delete_icmptype or \
36ae71
+                    a.new_service or a.delete_service or \
36ae71
+                    a.new_zone or a.delete_zone
36ae71
+
36ae71
+options_direct = \
36ae71
+           a.add_chain or a.remove_chain or a.query_chain or \
36ae71
+           a.get_chains or a.get_all_chains or \
36ae71
+           a.add_rule or a.remove_rule or a.remove_rules or a.query_rule or \
36ae71
+           a.get_rules or a.get_all_rules or \
36ae71
+           a.add_passthrough or a.remove_passthrough or a.query_passthrough or \
36ae71
+           a.get_passthroughs or a.get_all_passthroughs
36ae71
+
36ae71
+# these are supposed to only write out some output
36ae71
+options_list_get = a.help or a.version or a.list_all or a.list_all_zones or \
36ae71
+ a.list_lockdown_whitelist_commands or a.list_lockdown_whitelist_contexts or \
36ae71
+ a.list_lockdown_whitelist_uids or a.list_lockdown_whitelist_users or \
36ae71
+ a.list_services or a.list_ports or a.list_icmp_blocks or a.list_forward_ports \
36ae71
+ or a.list_rich_rules or a.list_interfaces or a.list_sources or \
36ae71
+ a.get_default_zone or a.get_zone_of_interface or \
36ae71
+ a.get_zone_of_source or a.get_zones or a.get_services or a.get_icmptypes or \
36ae71
+ a.get_target or a.set_target
36ae71
+
36ae71
+###############################################################################
36ae71
+
36ae71
+# Check various impossible combinations of options
36ae71
+
36ae71
+if not (options_lokkit or options_standalone or \
36ae71
+        options_permanent or options_direct):
36ae71
+    __fail(parser.format_usage() + "No option specified.")
36ae71
+
36ae71
+if options_lokkit and (options_standalone or \
36ae71
+                       options_permanent or options_direct):
36ae71
+    __fail(parser.format_usage() +
36ae71
+           "Can't use lokkit options with other options.")
36ae71
+
36ae71
+if options_standalone and (options_permanent or \
36ae71
+                           options_direct):
36ae71
+    __fail(parser.format_usage() +
36ae71
+           "Can't use stand-alone options with other options.")
36ae71
+
36ae71
+if options_direct and options_zone:
36ae71
+    __fail(parser.format_usage() +
36ae71
+           "Can't use 'direct' options with other options.")
36ae71
+
36ae71
+if (a.direct and not options_direct) or (options_direct and not a.direct):
36ae71
+    __fail(parser.format_usage() +
36ae71
+           "Wrong usage of 'direct' options.")
36ae71
+
36ae71
+if options_config and options_zone:
36ae71
+    __fail(parser.format_usage() +
36ae71
+           "Wrong usage of --get-zones | --get-services | --get-icmptypes.")
36ae71
+
36ae71
+if a.help:
36ae71
+    __usage()
36ae71
+    sys.exit(0)
36ae71
+
36ae71
+zone = a.zone
36ae71
+fw = Firewall_test()
36ae71
+fw.start()
36ae71
 
36ae71
-_firewalld_conf = firewalld_conf(FIREWALLD_CONF)
36ae71
 try:
36ae71
-    _firewalld_conf.read()
36ae71
-except Exception as msg:
36ae71
-    # ignore read error, use default zone
36ae71
-    pass
36ae71
-else:
36ae71
-    default_zone = _firewalld_conf.get("DefaultZone")
36ae71
+    if a.version:
36ae71
+        __print_and_exit(VERSION)
36ae71
 
36ae71
-obj = None
36ae71
-for path in [ ETC_FIREWALLD_ZONES, FIREWALLD_ZONES ]:
36ae71
-    filename = "%s.xml" % default_zone
36ae71
-    if os.path.exists("%s/%s" %(path, filename)):
36ae71
-        print(_("Opening default zone '%s'" % default_zone))
36ae71
-        obj = zone_reader(filename, path)
36ae71
-        break
36ae71
-
36ae71
-if not obj:
36ae71
-    error(_("Unable to open default zone '%s', exiting.") % default_zone)
36ae71
-    # create new zone?
36ae71
-    sys.exit(1)
36ae71
-
36ae71
-trusted_obj = None
36ae71
-if default_zone != trusted_zone:
36ae71
-    for path in [ ETC_FIREWALLD_ZONES, FIREWALLD_ZONES ]:
36ae71
-        filename = "%s.xml" % trusted_zone
36ae71
-        if os.path.exists("%s/%s" %(path, filename)):
36ae71
-            trusted_obj = zone_reader(filename, path)
36ae71
-            break
36ae71
-    if conf.trust and not trusted_obj:
36ae71
-        error(_("Unable to open zone '%s', exiting.") % trusted_zone)
36ae71
-        sys.exit(1)
36ae71
-else:
36ae71
-    trusted_obj = obj
36ae71
+    # Lokkit Compatibility Options
36ae71
+    if options_lokkit:
36ae71
+        trusted_zone = "trusted"
36ae71
+        default_zone = fw.get_default_zone()
36ae71
+        fw_zone = fw.config.get_zone(default_zone)
36ae71
+        fw_settings = FirewallClientZoneSettings(
36ae71
+            list(fw.config.get_zone_config(fw_zone)))
36ae71
+
36ae71
+        if a.enabled:
36ae71
+            # Enable firewall (default)
36ae71
+            os.system("systemctl enable firewalld.service")
36ae71
+        if a.disabled:
36ae71
+            # Disable firewall
36ae71
+            os.system("systemctl disable firewalld.service")
36ae71
+        if a.addmodule:
36ae71
+            for m in a.addmodule:
36ae71
+                __print("Ignoring addmodule '%s'" % m)
36ae71
+        if a.removemodule:
36ae71
+            for m in a.removemodule:
36ae71
+                __print("Ignoring removemodule '%s'" % m)
36ae71
+        if a.custom_rules:
36ae71
+            for c in a.custom_rules:
36ae71
+                __print("Ignoring custom-rule '%s'" % c)
36ae71
+        if a.service:
36ae71
+            for s in a.service:
36ae71
+                __print("Adding service '%s' to default zone." % s)
36ae71
+                fw_settings.addService(s)
36ae71
+        if a.remove_service:
36ae71
+            for s in a.remove_service:
36ae71
+                __print("Removing service '%s' from default zone." % s)
36ae71
+                fw_settings.removeService(s)
36ae71
+        if a.port:
36ae71
+            for port_proto in a.port:
36ae71
+                (port, proto) = __parse_port_lokkit(port_proto)
36ae71
+                __print("Adding port '%s/%s' to default zone." % (port, proto))
36ae71
+                fw_settings.addPort(port, proto)
36ae71
+        if a.trust:
36ae71
+            if default_zone != trusted_zone:
36ae71
+                fw_trusted = fw.config.get_zone("trusted")
36ae71
+                fw_trusted_settings = FirewallClientZoneSettings(
36ae71
+                                 list(fw.config.get_zone_config(fw_trusted)))
36ae71
+                # Bind an interface to the trusted zone
36ae71
+                for i in a.trust:
36ae71
+                    __print("Interface '%s' will be bound to zone '%s'." % \
36ae71
+                            (i, trusted_zone))
36ae71
+                    fw_trusted_settings.addInterface(i)
36ae71
+                fw.config.set_zone_config(fw_trusted, fw_trusted_settings.settings)
36ae71
+            else:
36ae71
+                for i in a.trust:
36ae71
+                    __print("Interface '%s' will be bound to zone '%s'." % \
36ae71
+                            (i, trusted_zone))
36ae71
+                    fw_settings.addInterface(i)
36ae71
+        if a.masq:
36ae71
+            # Enables masquerading in the default zone, interface argument is ignored
36ae71
+            __print("Enabling masquerade for the default zone.")
36ae71
+            fw_settings.setMasquerade(True)
36ae71
+        if a.forward_port:
36ae71
+            for fp in a.forward_port:
36ae71
+                (port, protocol, toport, toaddr) = __parse_forward_port(fp)
36ae71
+                __print("Adding forward port %s:%s:%s:%s to default zone." % \
36ae71
+                      (port, protocol, toport, toaddr))
36ae71
+                fw_settings.addForwardPort(port, protocol, toport, toaddr)
36ae71
+        if a.block_icmp:
36ae71
+            for ib in a.block_icmp:
36ae71
+                __print("Adding icmpblock '%s' to default zone." % ib)
36ae71
+                fw_settings.addIcmpBlock(ib)
36ae71
+
36ae71
+        fw.config.set_zone_config(fw_zone, fw_settings.settings)
36ae71
+
36ae71
+    # options from firewall-cmd
36ae71
+    elif a.get_default_zone:
36ae71
+        __print_and_exit(fw.get_default_zone())
36ae71
+    elif a.set_default_zone:
36ae71
+        fw.set_default_zone(a.set_default_zone)
36ae71
+
36ae71
+    # lockdown
36ae71
+    elif a.lockdown_on:
36ae71
+        fw.enable_lockdown()
36ae71
+    elif a.lockdown_off:
36ae71
+        fw.disable_lockdown()
36ae71
+    elif a.query_lockdown:
36ae71
+        __print_query_result(fw.policies.query_lockdown())
36ae71
+
36ae71
+    # zones
36ae71
+    elif a.get_zones:
36ae71
+        zones = fw.config.get_zones()
36ae71
+        __print_and_exit(" ".join(zones))
36ae71
+    elif a.get_services:
36ae71
+        services = fw.config.get_services()
36ae71
+        __print_and_exit(" ".join(services))
36ae71
+    elif a.get_icmptypes:
36ae71
+        icmptypes = fw.config.get_icmptypes()
36ae71
+        __print_and_exit(" ".join(icmptypes))
36ae71
+
36ae71
+    elif a.new_zone:
36ae71
+        fw.config.new_zone(a.new_zone, FirewallClientZoneSettings().settings)
36ae71
+
36ae71
+    elif a.delete_zone:
36ae71
+        obj = fw.config.get_zone(a.delete_zone)
36ae71
+        fw.config.remove_zone(obj)
36ae71
+
36ae71
+    elif a.new_service:
36ae71
+        fw.config.new_service(a.new_service,
36ae71
+                              FirewallClientServiceSettings().settings)
36ae71
+
36ae71
+    elif a.delete_service:
36ae71
+        obj = fw.config.get_service(a.delete_service)
36ae71
+        fw.config.remove_service(obj)
36ae71
+
36ae71
+    elif a.new_icmptype:
36ae71
+        fw.config.new_icmptype(a.new_icmptype,
36ae71
+                               FirewallClientIcmpTypeSettings().settings)
36ae71
+
36ae71
+    elif a.delete_icmptype:
36ae71
+        obj = fw.config.get_icmptype(a.delete_icmptype)
36ae71
+        fw.config.remove_icmptype(obj)
36ae71
+
36ae71
+    # lockdown whitelist
36ae71
+
36ae71
+    elif options_lockdown_whitelist:
36ae71
+        whitelist = fw.config.get_policies().lockdown_whitelist
36ae71
+
36ae71
+        # commands
36ae71
+        if a.list_lockdown_whitelist_commands:
36ae71
+            l = whitelist.get_commands()
36ae71
+            __print_and_exit("\n".join(l))
36ae71
+        elif a.add_lockdown_whitelist_command:
36ae71
+            whitelist.add_command(a.add_lockdown_whitelist_command)
36ae71
+        elif a.remove_lockdown_whitelist_command:
36ae71
+            whitelist.remove_command(a.remove_lockdown_whitelist_command)
36ae71
+        elif a.query_lockdown_whitelist_command:
36ae71
+            __print_query_result(a.query_lockdown_whitelist_command in 
36ae71
+                                 whitelist.get_commands())
36ae71
+
36ae71
+        # contexts
36ae71
+        elif a.list_lockdown_whitelist_contexts:
36ae71
+            l = whitelist.get_contexts()
36ae71
+            __print_and_exit("\n".join(l))
36ae71
+        elif a.add_lockdown_whitelist_context:
36ae71
+            whitelist.add_context(a.add_lockdown_whitelist_context)
36ae71
+        elif a.remove_lockdown_whitelist_context:
36ae71
+            whitelist.remove_context(a.remove_lockdown_whitelist_context)
36ae71
+        elif a.query_lockdown_whitelist_context:
36ae71
+            __print_query_result(a.query_lockdown_whitelist_context in 
36ae71
+                                 whitelist.get_contexts())
36ae71
+
36ae71
+        # uids
36ae71
+        elif a.list_lockdown_whitelist_uids:
36ae71
+            l = whitelist.get_uids()
36ae71
+            __print_and_exit(" ".join(map(str, l)))
36ae71
+        elif a.add_lockdown_whitelist_uid != None:
36ae71
+            whitelist.add_uid(a.add_lockdown_whitelist_uid)
36ae71
+        elif a.remove_lockdown_whitelist_uid != None:
36ae71
+            whitelist.remove_uid(a.remove_lockdown_whitelist_uid)
36ae71
+        elif a.query_lockdown_whitelist_uid != None:
36ae71
+            __print_query_result(a.query_lockdown_whitelist_uid in
36ae71
+                                 whitelist.get_uids())
36ae71
+
36ae71
+        # users
36ae71
+        elif a.list_lockdown_whitelist_users:
36ae71
+            l = whitelist.get_users()
36ae71
+            __print_and_exit("\n".join(l))
36ae71
+        elif a.add_lockdown_whitelist_user:
36ae71
+            whitelist.add_user(a.add_lockdown_whitelist_user)
36ae71
+        elif a.remove_lockdown_whitelist_user:
36ae71
+            whitelist.remove_user(a.remove_lockdown_whitelist_user)
36ae71
+        elif a.query_lockdown_whitelist_user:
36ae71
+            __print_query_result(a.query_lockdown_whitelist_user in
36ae71
+                                 whitelist.get_users())
36ae71
+
36ae71
+        # apply whitelist changes
36ae71
+        whitelist.write()
36ae71
+
36ae71
+    elif options_direct:
36ae71
+        settings = fw.config.get_direct()
36ae71
+
36ae71
+        if a.add_passthrough:
36ae71
+            if len (a.add_passthrough) < 2:
36ae71
+                __fail("usage: --direct --add-passthrough { ipv4 | ipv6 | eb } <args>")
36ae71
+            __print(settings.add_passthrough(_check_ipv(a.add_passthrough[0]),
36ae71
+                                             a.add_passthrough[1:]))
36ae71
+
36ae71
+        elif a.remove_passthrough:
36ae71
+            if len (a.remove_passthrough) < 2:
36ae71
+                __fail("usage: --direct --remove-passthrough { ipv4 | ipv6 | eb } <args>")
36ae71
+            settings.remove_passthrough(_check_ipv(a.remove_passthrough[0]),
36ae71
+                                        a.remove_passthrough[1:])
36ae71
+        elif a.query_passthrough:
36ae71
+            if len (a.query_passthrough) < 2:
36ae71
+                __fail("usage: --direct --query-passthrough { ipv4 | ipv6 | eb } <args>")
36ae71
+            __print_query_result(
36ae71
+                settings.query_passthrough(_check_ipv(a.query_passthrough[0]),
36ae71
+                                           a.query_passthrough[1:]))
36ae71
+            sys.exit(0)
36ae71
+        elif a.get_passthroughs:
36ae71
+            rules = settings.get_passthroughs(_check_ipv(a.get_passthroughs[0]))
36ae71
+            for rule in rules:
36ae71
+                __print(joinArgs(rule))
36ae71
+            sys.exit(0)
36ae71
+        elif a.get_all_passthroughs:
36ae71
+            pt = settings.get_all_passthroughs()
36ae71
+            for ipv in pt:
36ae71
+                for rule in pt[ipv]:
36ae71
+                    __print("%s %s" % (ipv, joinArgs(rule)))
36ae71
+            sys.exit(0)
36ae71
+
36ae71
+        elif a.add_chain:
36ae71
+            settings.add_chain(_check_ipv(a.add_chain[0]),
36ae71
+                               a.add_chain[1], a.add_chain[2])
36ae71
+        elif a.remove_chain:
36ae71
+            settings.remove_chain(_check_ipv(a.remove_chain[0]),
36ae71
+                                  a.remove_chain[1], a.remove_chain[2])
36ae71
+        elif a.query_chain:
36ae71
+            __print_query_result(
36ae71
+                settings.query_chain(_check_ipv(a.query_chain[0]),
36ae71
+                                     a.query_chain[1], a.query_chain[2]))
36ae71
+            sys.exit(0)
36ae71
+        elif a.get_chains:
36ae71
+            __print_and_exit(
36ae71
+                    " ".join(settings.get_chains(_check_ipv(a.get_chains[0]),
36ae71
+                                                 a.get_chains[1])))
36ae71
+            sys.exit(0)
36ae71
+        elif a.get_all_chains:
36ae71
+            chains = settings.get_all_chains()
36ae71
+            for (ipv, table) in chains:
36ae71
+                for chain in chains[(ipv,table)]:
36ae71
+                    __print("%s %s %s" % (ipv, table, chain))
36ae71
+            sys.exit(0)
36ae71
+
36ae71
+        elif a.add_rule:
36ae71
+            if len (a.add_rule) < 5:
36ae71
+                __fail("usage: --direct --add-rule { ipv4 | ipv6 | eb }  <chain> <priority> <args>")
36ae71
+            try:
36ae71
+                priority = int(a.add_rule[3])
36ae71
+            except ValueError:
36ae71
+                __fail("wrong priority\nusage: --direct --add-rule { ipv4 | ipv6 | eb }  <chain> <priority> <args>")
36ae71
+            settings.add_rule(_check_ipv(a.add_rule[0]), a.add_rule[1],
36ae71
+                              a.add_rule[2], priority, a.add_rule[4:])
36ae71
+        elif a.remove_rule:
36ae71
+            if len (a.remove_rule) < 5:
36ae71
+                __fail("usage: --direct --remove-rule { ipv4 | ipv6 | eb }  <chain> <priority> <args>")
36ae71
+            try:
36ae71
+                priority = int(a.remove_rule[3])
36ae71
+            except ValueError:
36ae71
+                __fail("usage: --direct --remove-rule { ipv4 | ipv6 | eb }  <chain> <priority> <args>")
36ae71
+            settings.remove_rule(_check_ipv(a.remove_rule[0]), a.remove_rule[1],
36ae71
+                                a.remove_rule[2], priority, a.remove_rule[4:])
36ae71
+        elif a.remove_rules:
36ae71
+            if len (a.remove_rules) < 3:
36ae71
+                __fail("usage: --direct --remove-rules { ipv4 | ipv6 | eb }  <chain>")
36ae71
+            settings.remove_rules(_check_ipv(a.remove_rules[0]),
36ae71
+                                  a.remove_rules[1], a.remove_rules[2])
36ae71
+        elif a.query_rule:
36ae71
+            if len (a.query_rule) < 5:
36ae71
+                __fail("usage: --direct --query-rule { ipv4 | ipv6 | eb }  <chain> <priority> <args>")
36ae71
+            try:
36ae71
+                priority = int(a.query_rule[3])
36ae71
+            except ValueError:
36ae71
+                __fail("usage: --direct --query-rule { ipv4 | ipv6 | eb }  <chain> <priority> <args>")
36ae71
+            __print_query_result(
36ae71
+                    settings.query_rule(_check_ipv(a.query_rule[0]),
36ae71
+                                        a.query_rule[1], a.query_rule[2],
36ae71
+                                        priority, a.query_rule[4:]))
36ae71
+            sys.exit(0)
36ae71
+        elif a.get_rules:
36ae71
+            rules = settings.get_rules(_check_ipv(a.get_rules[0]),
36ae71
+                                       a.get_rules[1], a.get_rules[2])
36ae71
+            for (priority, rule) in rules:
36ae71
+                __print("%d %s" % (priority, joinArgs(rule)))
36ae71
+            sys.exit(0)
36ae71
+        elif a.get_all_rules:
36ae71
+            rules = settings.get_all_rules()
36ae71
+            for (ipv, table, chain) in rules:
36ae71
+                for (priority, rule) in rules[(ipv, table, chain)]:
36ae71
+                    __print("%s %s %s %d %s" % (ipv, table, chain, priority,
36ae71
+                                                joinArgs(rule)))
36ae71
+            sys.exit(0)
36ae71
 
36ae71
-changed = False
36ae71
-changed_trusted = False
36ae71
+        settings.write()
36ae71
 
36ae71
-# fields that can not get converted into a zone, need NM work
36ae71
+    else:
36ae71
+        if zone == "":
36ae71
+            zone = fw.get_default_zone()
36ae71
+        fw_zone = fw.config.get_zone(zone)
36ae71
+        fw_settings = FirewallClientZoneSettings(
36ae71
+            list(fw.config.get_zone_config(fw_zone))) # convert to list, for setMasquerade
36ae71
+
36ae71
+        # interface
36ae71
+        if a.list_interfaces:
36ae71
+            l = fw_settings.getInterfaces()
36ae71
+            __print_and_exit(" ".join(l))
36ae71
+        elif a.get_zone_of_interface:
36ae71
+            ret = []
36ae71
+            for zone in fw.config.get_zones():
36ae71
+                obj = fw.config.get_zone(zone)
36ae71
+                if a.get_zone_of_interface in obj.interfaces:
36ae71
+                    ret.append(obj.name)
36ae71
+            if len(ret) > 1:
36ae71
+                # Even it shouldn't happen, it's actually possible that
36ae71
+                # the same interface is in several zone XML files
36ae71
+                __print_and_exit(" ".join(ret) + "  (ERROR: interface '%s' is in %s zone XML files, can be only in one)" % (a.get_zone_of_interface, len(ret)))
36ae71
+            if len(ret) == 1:
36ae71
+                __print_and_exit(ret[0])
36ae71
+            else:
36ae71
+                __print_and_exit("no zone", 2)
36ae71
+        elif a.change_interface:
36ae71
+            ret = []
36ae71
+            for old_zone in fw.config.get_zones():
36ae71
+                old_zone_obj = fw.config.get_zone(old_zone)
36ae71
+                if a.change_interface in old_zone_obj.interfaces:
36ae71
+                    if old_zone_obj.name != zone:
36ae71
+                        old_zone_settings = FirewallClientZoneSettings(
36ae71
+                            fw.config.get_zone_config(old_zone_obj))
36ae71
+
36ae71
+                        old_zone_settings.removeInterface(a.change_interface) # remove from old
36ae71
+                        fw.config.set_zone_config(old_zone_obj, old_zone_settings.settings)
36ae71
+            fw_settings.addInterface(a.change_interface)              # add to new
36ae71
+        elif a.add_interface:
36ae71
+            fw_settings.addInterface(a.add_interface)
36ae71
+        elif a.remove_interface:
36ae71
+            fw_settings.removeInterface(a.remove_interface)
36ae71
+        elif a.query_interface:
36ae71
+            __print_query_result(fw_settings.queryInterface(a.query_interface))
36ae71
+
36ae71
+        # source
36ae71
+        if a.list_sources:
36ae71
+            sources = fw_settings.getSources()
36ae71
+            __print_and_exit(" ".join(sources))
36ae71
+        elif a.get_zone_of_source:
36ae71
+            ret = []
36ae71
+            for zone in fw.config.get_zones():
36ae71
+                obj = fw.config.get_zone(zone)
36ae71
+                if a.get_zone_of_source in obj.sources:
36ae71
+                    ret.append(obj.name)
36ae71
+            if len(ret) > 1:
36ae71
+                # Even it shouldn't happen, it's actually possible that
36ae71
+                # the same source is in several zone XML files
36ae71
+                __print_and_exit(" ".join(ret) + "  (ERROR: source '%s' is in %s zone XML files, can be only in one)" % (a.get_zone_of_source, len(ret)))
36ae71
+            if len(ret) == 1:
36ae71
+                __print_and_exit(ret[0])
36ae71
+            else:
36ae71
+                __print_and_exit("no zone", 2)
36ae71
+        elif a.change_source:
36ae71
+            ret = []
36ae71
+            for old_zone in fw.config.get_zones():
36ae71
+                old_zone_obj = fw.config.get_zone(old_zone)
36ae71
+                if a.change_source in old_zone_obj.sources:
36ae71
+                    if old_zone_obj.name != zone:
36ae71
+                        old_zone_settings = FirewallClientZoneSettings(
36ae71
+                            fw.config.get_zone_config(old_zone_obj))
36ae71
+
36ae71
+                        old_zone_settings.removeSource(a.change_source) # remove from old
36ae71
+                        fw.config.set_zone_config(old_zone_obj, old_zone_settings.settings)
36ae71
+            fw_settings.addSource(a.change_source)              # add to new
36ae71
+        elif a.add_source:
36ae71
+            fw_settings.addSource(a.add_source)
36ae71
+        elif a.remove_source:
36ae71
+            fw_settings.removeSource(a.remove_source)
36ae71
+        elif a.query_source:
36ae71
+            __print_query_result(fw_settings.querySource(a.query_source))
36ae71
+
36ae71
+        # rich rules
36ae71
+        if a.list_rich_rules:
36ae71
+            l = fw_settings.getRichRules()
36ae71
+            __print_and_exit("\n".join(l))
36ae71
+        elif a.add_rich_rule:
36ae71
+            for s in a.add_rich_rule:
36ae71
+                fw_settings.addRichRule(s)
36ae71
+        elif a.remove_rich_rule:
36ae71
+            for s in a.remove_rich_rule:
36ae71
+                fw_settings.removeRichRule(s)
36ae71
+        elif a.query_rich_rule:
36ae71
+            __print_query_result(fw_settings.queryRichRule(a.query_rich_rule))
36ae71
+
36ae71
+        # service
36ae71
+        if a.list_services:
36ae71
+            l = fw_settings.getServices()
36ae71
+            __print_and_exit(" ".join(l))
36ae71
+        elif a.add_service:
36ae71
+            for s in a.add_service:
36ae71
+                fw_settings.addService(s)
36ae71
+        elif a.remove_service_from_zone:
36ae71
+            for s in a.remove_service_from_zone:
36ae71
+                fw_settings.removeService(s)
36ae71
+        elif a.query_service:
36ae71
+            __print_query_result(fw_settings.queryService(a.query_service))
36ae71
+
36ae71
+        # port
36ae71
+        elif a.list_ports:
36ae71
+            l = fw_settings.getPorts()
36ae71
+            __print_and_exit(" ".join(["%s/%s" % (port[0], port[1]) for port in l]))
36ae71
+        elif a.add_port:
36ae71
+            for port_proto in a.add_port:
36ae71
+                (port, proto) = __parse_port(port_proto)
36ae71
+                fw_settings.addPort(port, proto)
36ae71
+        elif a.remove_port:
36ae71
+            for port_proto in a.remove_port:
36ae71
+                (port, proto) = __parse_port(port_proto)
36ae71
+                fw_settings.removePort(port, proto)
36ae71
+        elif a.query_port:
36ae71
+            (port, proto) = __parse_port(a.query_port)
36ae71
+            __print_query_result(fw_settings.queryPort(port, proto))
36ae71
+
36ae71
+        # masquerade
36ae71
+        elif a.add_masquerade:
36ae71
+            fw_settings.setMasquerade(True)
36ae71
+        elif a.remove_masquerade:
36ae71
+            fw_settings.setMasquerade(False)
36ae71
+        elif a.query_masquerade:
36ae71
+            __print_query_result(fw_settings.getMasquerade())
36ae71
+
36ae71
+        # forward port
36ae71
+        elif a.list_forward_ports:
36ae71
+            l = fw_settings.getForwardPorts()
36ae71
+            __print_and_exit("\n".join(["port=%s:proto=%s:toport=%s:toaddr=%s" % (port, protocol, toport, toaddr) for (port, protocol, toport, toaddr) in l]))
36ae71
+        elif a.add_forward_port:
36ae71
+            for fp in a.add_forward_port:
36ae71
+                (port, protocol, toport, toaddr) = __parse_forward_port(fp)
36ae71
+                fw_settings.addForwardPort(port, protocol, toport, toaddr)
36ae71
+        elif a.remove_forward_port:
36ae71
+            for fp in a.remove_forward_port:
36ae71
+                (port, protocol, toport, toaddr) = __parse_forward_port(fp)
36ae71
+                fw_settings.removeForwardPort(port, protocol, toport, toaddr)
36ae71
+        elif a.query_forward_port:
36ae71
+            (port, protocol, toport, toaddr) = __parse_forward_port(a.query_forward_port)
36ae71
+            __print_query_result(fw_settings.queryForwardPort(port, protocol, toport, toaddr))
36ae71
+
36ae71
+        # block icmp
36ae71
+        elif a.list_icmp_blocks:
36ae71
+            l = fw_settings.getIcmpBlocks()
36ae71
+            __print_and_exit(" ".join(l))
36ae71
+        elif a.add_icmp_block:
36ae71
+            for ib in a.add_icmp_block:
36ae71
+                fw_settings.addIcmpBlock(ib)
36ae71
+        elif a.remove_icmp_block:
36ae71
+            for ib in a.remove_icmp_block:
36ae71
+                fw_settings.removeIcmpBlock(ib)
36ae71
+        elif a.query_icmp_block:
36ae71
+            __print_query_result(fw_settings.queryIcmpBlock(a.query_icmp_block))
36ae71
+
36ae71
+        # zone target
36ae71
+        elif a.get_target:
36ae71
+            __print_and_exit(fw_settings.getTarget())
36ae71
+        elif a.set_target:
36ae71
+            fw_settings.setTarget(a.set_target)
36ae71
+
36ae71
+        # list all zone settings
36ae71
+        elif a.list_all:
36ae71
+            __list_all_permanent(fw_settings, zone if zone else fw.get_default_zone())
36ae71
+            sys.exit(0)
36ae71
+
36ae71
+        # list everything
36ae71
+        elif a.list_all_zones:
36ae71
+            zones = fw.config.get_zones()
36ae71
+            for zone in zones:
36ae71
+                fw_zone = fw.config.get_zone(zone)
36ae71
+                fw_settings = FirewallClientZoneSettings(list(fw.config.get_zone_config(fw_zone)))
36ae71
+                __list_all_permanent(fw_settings, zone)
36ae71
+                __print("")
36ae71
+            sys.exit(0)
36ae71
 
36ae71
-if conf.trust:
36ae71
-    if trusted_obj:
36ae71
-        for dev in conf.trust:
36ae71
-            warning(_("The device '%s' will be bound to the %s zone.") % \
36ae71
-                          (dev, trusted_zone))
36ae71
-            trusted_obj.interfaces.append(dev)
36ae71
-            changed_trusted = True
36ae71
-
36ae71
-# no custom rules
36ae71
-if conf.custom_rules and len(conf.custom_rules) > 0:
36ae71
-    for custom in conf.custom_rules:
36ae71
-        warning(_("Ignoring custom-rule file '%s'") % ":".join(custom))
36ae71
-
36ae71
-# no modules
36ae71
-if conf.add_module and len(conf.add_module) > 0:
36ae71
-    for module in conf.add_module:
36ae71
-        warning(_("Ignoring addmodule '%s'") % module)
36ae71
-if conf.remove_module and len(conf.remove_module) > 0:
36ae71
-    for module in conf.remove_module:
36ae71
-        warning(_("Ignoring removemodule '%s'") % module)
36ae71
-
36ae71
-if conf.masq:
36ae71
-    for dev in conf.masq:
36ae71
-        if obj.masquerade != True:
36ae71
-            warning(_("Device '%s' was masqueraded, enabling masquerade for the default zone.") % dev)
36ae71
-            obj.masquerade = True
36ae71
-            changed = True
36ae71
-
36ae71
-if conf.ports and len(conf.ports) > 0:
36ae71
-    for item in conf.ports:
36ae71
-        if item not in obj.ports:
36ae71
-            print(_("Adding port '%s/%s' to default zone.") % \
36ae71
-                      (item[0], item[1]))
36ae71
-            obj.ports.append(item)
36ae71
-            changed = True
36ae71
-
36ae71
-if conf.remove_services:
36ae71
-    for service in conf.remove_services:
36ae71
-        if service in obj.services:
36ae71
-            print(_("Removing service '%s' from default zone.") % service)
36ae71
-            obj.services.remove(service)
36ae71
-            changed = True
36ae71
-
36ae71
-if conf.services:
36ae71
-    for service in conf.services:
36ae71
-        if service not in obj.services:
36ae71
-            print(_("Adding service '%s' to default zone.") % service)
36ae71
-            obj.services.append(service)
36ae71
-            changed = True
36ae71
-
36ae71
-if conf.block_icmp:
36ae71
-    for icmp in conf.block_icmp:
36ae71
-        if icmp not in obj.icmp_blocks:
36ae71
-            print(_("Adding icmpblock '%s' to default zone.") % icmp)
36ae71
-            obj.icmp_blocks.append(icmp)
36ae71
-            changed = True
36ae71
-
36ae71
-if conf.forward_port:
36ae71
-    for fwd in conf.forward_port:
36ae71
-        # ignore interface, should belong to default zone
36ae71
-        entry = (fwd.get("port", ""), fwd.get("proto", ""),
36ae71
-                 fwd.get("toport", ""), fwd.get("toaddr", ""))
36ae71
-        if entry not in obj.forward_ports:
36ae71
-            print(_("Adding forward port %s:%s:%s:%s to default zone.") % \
36ae71
-                      (entry[0], entry[1], entry[2], entry[3]))
36ae71
-            obj.forward_ports.append(entry)
36ae71
-            changed = True
36ae71
+        fw.config.set_zone_config(fw_zone, fw_settings.settings)
36ae71
 
36ae71
-if changed:
36ae71
-    zone_writer(obj, ETC_FIREWALLD_ZONES)
36ae71
+except Exception as msg:
36ae71
+    __fail("%s" % msg)
36ae71
 else:
36ae71
-    print(_("No changes to default zone needed."))
36ae71
-
36ae71
-if changed_trusted:
36ae71
-    zone_writer(trusted_obj, ETC_FIREWALLD_ZONES)
36ae71
-    print(_("Changed trusted zone configuration."))
36ae71
-    print("\n")
36ae71
-    warning(_("If one of the trusted interfaces is used for a connection with NetworkManager or if there is an ifcfg file for this interface, the zone will be changed to the zone defined in the configuration as soon as it gets activated. To change the zone of a connection use <command>nm-connection-editor</command> and set the zone to trusted, for an ifcfg file, use an editor and add \"ZONE=trusted\". If the zone is not defined in the ifcfg file, the firewalld default zone will be used."))
36ae71
-
36ae71
-sys.exit(0)
36ae71
+    __print_and_exit("success")
36ae71
diff -up firewalld-0.3.9/src/Makefile.in.RHBZ#1059800 firewalld-0.3.9/src/Makefile.in
36ae71
--- firewalld-0.3.9/src/Makefile.in.RHBZ#1059800	2014-01-13 17:06:59.000000000 +0100
36ae71
+++ firewalld-0.3.9/src/Makefile.in	2014-02-26 09:30:43.442191785 +0100
36ae71
@@ -358,6 +358,7 @@ nobase_dist_python_DATA = \
36ae71
 	firewall/core/fw_icmptype.py \
36ae71
 	firewall/core/fw_policies.py \
36ae71
 	firewall/core/fw.py \
36ae71
+	firewall/core/fw_test.py \
36ae71
 	firewall/core/fw_service.py \
36ae71
 	firewall/core/fw_zone.py \
36ae71
 	firewall/core/__init__.py \