|
|
6ec638 |
diff --git a/org_fedora_oscap/rule_handling.py b/org_fedora_oscap/rule_handling.py
|
|
|
6ec638 |
index f712ac4..738465f 100644
|
|
|
6ec638 |
--- a/org_fedora_oscap/rule_handling.py
|
|
|
6ec638 |
+++ b/org_fedora_oscap/rule_handling.py
|
|
|
6ec638 |
@@ -26,7 +26,13 @@
|
|
|
6ec638 |
import optparse
|
|
|
6ec638 |
import shlex
|
|
|
6ec638 |
import logging
|
|
|
6ec638 |
+
|
|
|
6ec638 |
from pyanaconda.pwpolicy import F22_PwPolicyData
|
|
|
6ec638 |
+from pyanaconda.core.constants import (
|
|
|
6ec638 |
+ FIREWALL_ENABLED, FIREWALL_DISABLED, FIREWALL_USE_SYSTEM_DEFAULTS)
|
|
|
6ec638 |
+from pyanaconda.modules.common.constants.objects import FIREWALL, BOOTLOADER
|
|
|
6ec638 |
+from pyanaconda.modules.common.constants.services import NETWORK, STORAGE, USERS
|
|
|
6ec638 |
+
|
|
|
6ec638 |
from org_fedora_oscap import common
|
|
|
6ec638 |
from org_fedora_oscap.common import OSCAPaddonError, RuleMessage
|
|
|
6ec638 |
|
|
|
6ec638 |
@@ -496,7 +502,10 @@ def eval_rules(self, ksdata, storage, report_only=False):
|
|
|
6ec638 |
return []
|
|
|
6ec638 |
|
|
|
6ec638 |
ret = []
|
|
|
6ec638 |
- if not ksdata.rootpw.password:
|
|
|
6ec638 |
+
|
|
|
6ec638 |
+ users_proxy = USERS.get_proxy()
|
|
|
6ec638 |
+
|
|
|
6ec638 |
+ if not users_proxy.IsRootPasswordSet:
|
|
|
6ec638 |
# root password was not set
|
|
|
6ec638 |
|
|
|
6ec638 |
msg = _("make sure to create password with minimal length of %d "
|
|
|
6ec638 |
@@ -505,12 +514,12 @@ def eval_rules(self, ksdata, storage, report_only=False):
|
|
|
6ec638 |
common.MESSAGE_TYPE_WARNING, msg)]
|
|
|
6ec638 |
else:
|
|
|
6ec638 |
# root password set
|
|
|
6ec638 |
- if ksdata.rootpw.isCrypted:
|
|
|
6ec638 |
+ if users_proxy.IsRootPasswordCrypted:
|
|
|
6ec638 |
msg = _("cannot check root password length (password is crypted)")
|
|
|
6ec638 |
log.warning("cannot check root password length (password is crypted)")
|
|
|
6ec638 |
return [RuleMessage(self.__class__,
|
|
|
6ec638 |
common.MESSAGE_TYPE_WARNING, msg)]
|
|
|
6ec638 |
- elif len(ksdata.rootpw.password) < self._minlen:
|
|
|
6ec638 |
+ elif len(users_proxy.RootPassword) < self._minlen:
|
|
|
6ec638 |
# too short
|
|
|
6ec638 |
msg = _("root password is too short, a longer one with at "
|
|
|
6ec638 |
"least %d characters is required") % self._minlen
|
|
|
6ec638 |
@@ -705,10 +714,13 @@ def __str__(self):
|
|
|
6ec638 |
def eval_rules(self, ksdata, storage, report_only=False):
|
|
|
6ec638 |
""":see: RuleHandler.eval_rules"""
|
|
|
6ec638 |
|
|
|
6ec638 |
- if self._require_password and not storage.bootloader.password:
|
|
|
6ec638 |
- # Anaconda doesn't provide a way to set bootloader password, so
|
|
|
6ec638 |
- # users cannot do much about that --> we shouldn't stop the
|
|
|
6ec638 |
- # installation, should we?
|
|
|
6ec638 |
+ bootloader_proxy = STORAGE.get_proxy(BOOTLOADER)
|
|
|
6ec638 |
+
|
|
|
6ec638 |
+ if self._require_password and not bootloader_proxy.password_is_set:
|
|
|
6ec638 |
+ # TODO: Anaconda provides a way to set bootloader password:
|
|
|
6ec638 |
+ # bootloader_proxy.set_password(...)
|
|
|
6ec638 |
+ # We don't support setting the bootloader password yet,
|
|
|
6ec638 |
+ # but we shouldn't stop the installation, just because of that.
|
|
|
6ec638 |
return [RuleMessage(self.__class__, common.MESSAGE_TYPE_WARNING,
|
|
|
6ec638 |
"boot loader password not set up")]
|
|
|
6ec638 |
else:
|
|
|
6ec638 |
@@ -802,8 +814,13 @@ def __init__(self):
|
|
|
6ec638 |
self._added_trusts = set()
|
|
|
6ec638 |
self._removed_svcs = set()
|
|
|
6ec638 |
|
|
|
6ec638 |
+ self._new_services_to_add = set()
|
|
|
6ec638 |
+ self._new_ports_to_add = set()
|
|
|
6ec638 |
+ self._new_trusts_to_add = set()
|
|
|
6ec638 |
+ self._new_services_to_remove = set()
|
|
|
6ec638 |
+
|
|
|
6ec638 |
self._firewall_enabled = None
|
|
|
6ec638 |
- self._firewall_default_enabled = None
|
|
|
6ec638 |
+ self._firewall_default_state = None
|
|
|
6ec638 |
|
|
|
6ec638 |
def add_services(self, services):
|
|
|
6ec638 |
"""
|
|
|
6ec638 |
@@ -895,25 +912,26 @@ def __str__(self):
|
|
|
6ec638 |
def eval_rules(self, ksdata, storage, report_only=False):
|
|
|
6ec638 |
""":see: RuleHandler.eval_rules"""
|
|
|
6ec638 |
|
|
|
6ec638 |
+ firewall_proxy = NETWORK.get_proxy(FIREWALL)
|
|
|
6ec638 |
messages = []
|
|
|
6ec638 |
|
|
|
6ec638 |
- if self._firewall_default_enabled is None:
|
|
|
6ec638 |
+ if self._firewall_default_state is None:
|
|
|
6ec638 |
# firewall default startup setting
|
|
|
6ec638 |
- self._firewall_default_enabled = ksdata.firewall.enabled
|
|
|
6ec638 |
+ self._firewall_default_state = firewall_proxy.FirewallMode
|
|
|
6ec638 |
|
|
|
6ec638 |
if self._firewall_enabled is False:
|
|
|
6ec638 |
msg = _("Firewall will be disabled on startup")
|
|
|
6ec638 |
messages.append(RuleMessage(self.__class__,
|
|
|
6ec638 |
common.MESSAGE_TYPE_INFO, msg))
|
|
|
6ec638 |
if not report_only:
|
|
|
6ec638 |
- ksdata.firewall.enabled = self._firewall_enabled
|
|
|
6ec638 |
+ firewall_proxy.SetFirewallMode(FIREWALL_DISABLED)
|
|
|
6ec638 |
|
|
|
6ec638 |
elif self._firewall_enabled is True:
|
|
|
6ec638 |
msg = _("Firewall will be enabled on startup")
|
|
|
6ec638 |
messages.append(RuleMessage(self.__class__,
|
|
|
6ec638 |
common.MESSAGE_TYPE_INFO, msg))
|
|
|
6ec638 |
if not report_only:
|
|
|
6ec638 |
- ksdata.firewall.enabled = self._firewall_enabled
|
|
|
6ec638 |
+ firewall_proxy.SetFirewallMode(FIREWALL_ENABLED)
|
|
|
6ec638 |
|
|
|
6ec638 |
# add messages for the already added services
|
|
|
6ec638 |
for svc in self._added_svcs:
|
|
|
6ec638 |
@@ -937,49 +955,58 @@ def eval_rules(self, ksdata, storage, report_only=False):
|
|
|
6ec638 |
common.MESSAGE_TYPE_INFO, msg))
|
|
|
6ec638 |
|
|
|
6ec638 |
# services, that should be added
|
|
|
6ec638 |
- services_to_add = (svc for svc in self._add_svcs
|
|
|
6ec638 |
- if svc not in ksdata.firewall.services)
|
|
|
6ec638 |
+ self._new_services_to_add = {
|
|
|
6ec638 |
+ svc for svc in self._add_svcs
|
|
|
6ec638 |
+ if svc not in firewall_proxy.EnabledServices}
|
|
|
6ec638 |
|
|
|
6ec638 |
# ports, that should be added
|
|
|
6ec638 |
- ports_to_add = (ports for ports in self._add_ports
|
|
|
6ec638 |
- if ports not in ksdata.firewall.ports)
|
|
|
6ec638 |
+ self._new_ports_to_add = {
|
|
|
6ec638 |
+ ports for ports in self._add_ports
|
|
|
6ec638 |
+ if ports not in firewall_proxy.EnabledPorts}
|
|
|
6ec638 |
|
|
|
6ec638 |
# trusts, that should be added
|
|
|
6ec638 |
- trusts_to_add = (trust for trust in self._add_trusts
|
|
|
6ec638 |
- if trust not in ksdata.firewall.trusts)
|
|
|
6ec638 |
+ self._new_trusts_to_add = {
|
|
|
6ec638 |
+ trust for trust in self._add_trusts
|
|
|
6ec638 |
+ if trust not in firewall_proxy.Trusts}
|
|
|
6ec638 |
|
|
|
6ec638 |
- for svc in services_to_add:
|
|
|
6ec638 |
+ for svc in self._new_services_to_add:
|
|
|
6ec638 |
# add the service unless already added
|
|
|
6ec638 |
if not report_only:
|
|
|
6ec638 |
self._added_svcs.add(svc)
|
|
|
6ec638 |
- ksdata.firewall.services.append(svc)
|
|
|
6ec638 |
|
|
|
6ec638 |
msg = _("service '%s' has been added to the list of services to be "
|
|
|
6ec638 |
"added to the firewall" % svc)
|
|
|
6ec638 |
messages.append(RuleMessage(self.__class__,
|
|
|
6ec638 |
common.MESSAGE_TYPE_INFO, msg))
|
|
|
6ec638 |
+ if not report_only:
|
|
|
6ec638 |
+ all_services = list(self._add_svcs.union(set(firewall_proxy.EnabledServices)))
|
|
|
6ec638 |
+ firewall_proxy.SetEnabledServices(all_services)
|
|
|
6ec638 |
|
|
|
6ec638 |
- for port in ports_to_add:
|
|
|
6ec638 |
+ for port in self._new_ports_to_add:
|
|
|
6ec638 |
# add the port unless already added
|
|
|
6ec638 |
if not report_only:
|
|
|
6ec638 |
self._added_ports.add(port)
|
|
|
6ec638 |
- ksdata.firewall.ports.append(port)
|
|
|
6ec638 |
|
|
|
6ec638 |
msg = _("port '%s' has been added to the list of ports to be "
|
|
|
6ec638 |
"added to the firewall" % port)
|
|
|
6ec638 |
messages.append(RuleMessage(self.__class__,
|
|
|
6ec638 |
common.MESSAGE_TYPE_INFO, msg))
|
|
|
6ec638 |
+ if not report_only:
|
|
|
6ec638 |
+ all_ports = list(self._add_ports.union(set(firewall_proxy.EnabledPorts)))
|
|
|
6ec638 |
+ firewall_proxy.SetEnabledPorts(all_ports)
|
|
|
6ec638 |
|
|
|
6ec638 |
- for trust in trusts_to_add:
|
|
|
6ec638 |
+ for trust in self._new_trusts_to_add:
|
|
|
6ec638 |
# add the trust unless already added
|
|
|
6ec638 |
if not report_only:
|
|
|
6ec638 |
self._added_trusts.add(trust)
|
|
|
6ec638 |
- ksdata.firewall.trusts.append(trust)
|
|
|
6ec638 |
|
|
|
6ec638 |
msg = _("trust '%s' has been added to the list of trusts to be "
|
|
|
6ec638 |
"added to the firewall" % trust)
|
|
|
6ec638 |
messages.append(RuleMessage(self.__class__,
|
|
|
6ec638 |
common.MESSAGE_TYPE_INFO, msg))
|
|
|
6ec638 |
+ if not report_only:
|
|
|
6ec638 |
+ all_trusts = list(self._add_trusts.union(set(firewall_proxy.Trusts)))
|
|
|
6ec638 |
+ firewall_proxy.SetTrusts(all_trusts)
|
|
|
6ec638 |
|
|
|
6ec638 |
# now do the same for the services that should be excluded
|
|
|
6ec638 |
|
|
|
6ec638 |
@@ -990,52 +1017,56 @@ def eval_rules(self, ksdata, storage, report_only=False):
|
|
|
6ec638 |
messages.append(RuleMessage(self.__class__,
|
|
|
6ec638 |
common.MESSAGE_TYPE_INFO, msg))
|
|
|
6ec638 |
|
|
|
6ec638 |
- # services, that should be added
|
|
|
6ec638 |
- services_to_remove = (svc for svc in self._remove_svcs
|
|
|
6ec638 |
- if svc not in ksdata.firewall.remove_services)
|
|
|
6ec638 |
+ # services, that should be excluded
|
|
|
6ec638 |
+ self._new_services_to_remove = {
|
|
|
6ec638 |
+ svc for svc in self._remove_svcs
|
|
|
6ec638 |
+ if svc not in firewall_proxy.DisabledServices}
|
|
|
6ec638 |
|
|
|
6ec638 |
- for svc in services_to_remove:
|
|
|
6ec638 |
+ for svc in self._new_services_to_remove:
|
|
|
6ec638 |
# exclude the service unless already excluded
|
|
|
6ec638 |
if not report_only:
|
|
|
6ec638 |
self._removed_svcs.add(svc)
|
|
|
6ec638 |
- ksdata.firewall.remove_services.append(svc)
|
|
|
6ec638 |
|
|
|
6ec638 |
msg = _("service '%s' has been added to the list of services to be "
|
|
|
6ec638 |
"removed from the firewall" % svc)
|
|
|
6ec638 |
messages.append(RuleMessage(self.__class__,
|
|
|
6ec638 |
common.MESSAGE_TYPE_INFO, msg))
|
|
|
6ec638 |
+ if not report_only:
|
|
|
6ec638 |
+ all_services = list(self._remove_svcs.union(set(firewall_proxy.DisabledServices)))
|
|
|
6ec638 |
+ firewall_proxy.SetDisabledServices(all_services)
|
|
|
6ec638 |
|
|
|
6ec638 |
return messages
|
|
|
6ec638 |
|
|
|
6ec638 |
def revert_changes(self, ksdata, storage):
|
|
|
6ec638 |
""":see: RuleHander.revert_changes"""
|
|
|
6ec638 |
+ firewall_proxy = NETWORK.get_proxy(FIREWALL)
|
|
|
6ec638 |
|
|
|
6ec638 |
if self._firewall_enabled is not None:
|
|
|
6ec638 |
- ksdata.firewall.enabled = self._firewall_default_enabled
|
|
|
6ec638 |
+ firewall_proxy.SetFirewallMode(self._firewall_default_state)
|
|
|
6ec638 |
|
|
|
6ec638 |
# remove all services this handler added
|
|
|
6ec638 |
- for svc in self._added_svcs:
|
|
|
6ec638 |
- if svc in ksdata.firewall.services:
|
|
|
6ec638 |
- ksdata.firewall.services.remove(svc)
|
|
|
6ec638 |
+ all_services = firewall_proxy.EnabledServices
|
|
|
6ec638 |
+ orig_services = set(all_services).difference(self._new_services_to_add)
|
|
|
6ec638 |
+ firewall_proxy.SetEnabledServices(list(orig_services))
|
|
|
6ec638 |
|
|
|
6ec638 |
# remove all ports this handler added
|
|
|
6ec638 |
- for port in self._added_ports:
|
|
|
6ec638 |
- if port in ksdata.firewall.ports:
|
|
|
6ec638 |
- ksdata.firewall.ports.remove(port)
|
|
|
6ec638 |
+ all_ports = firewall_proxy.EnabledPorts
|
|
|
6ec638 |
+ orig_ports = set(all_ports).difference(self._new_ports_to_add)
|
|
|
6ec638 |
+ firewall_proxy.SetEnabledPorts(list(orig_ports))
|
|
|
6ec638 |
|
|
|
6ec638 |
# remove all trusts this handler added
|
|
|
6ec638 |
- for trust in self._added_trusts:
|
|
|
6ec638 |
- if trust in ksdata.firewall.trusts:
|
|
|
6ec638 |
- ksdata.firewall.trusts.remove(trust)
|
|
|
6ec638 |
+ all_trusts = firewall_proxy.Trusts
|
|
|
6ec638 |
+ orig_trusts = set(all_trusts).difference(self._new_trusts_to_add)
|
|
|
6ec638 |
+ firewall_proxy.SetTrusts(list(orig_trusts))
|
|
|
6ec638 |
|
|
|
6ec638 |
# remove all services this handler excluded
|
|
|
6ec638 |
- for svc in self._removed_svcs:
|
|
|
6ec638 |
- if svc in ksdata.firewall.remove_services:
|
|
|
6ec638 |
- ksdata.firewall.remove_services.remove(svc)
|
|
|
6ec638 |
+ all_services = firewall_proxy.DisabledServices
|
|
|
6ec638 |
+ orig_services = set(all_services).difference(self._new_services_to_remove)
|
|
|
6ec638 |
+ firewall_proxy.SetDisabledServices(list(orig_services))
|
|
|
6ec638 |
|
|
|
6ec638 |
self._added_svcs = set()
|
|
|
6ec638 |
self._added_ports = set()
|
|
|
6ec638 |
self._added_trusts = set()
|
|
|
6ec638 |
self._removed_svcs = set()
|
|
|
6ec638 |
self._firewall_enabled = None
|
|
|
6ec638 |
- self._firewall_default_enabled = None
|
|
|
6ec638 |
+ self._firewall_default_state = None
|