Protect all selinux calls with try/except

This commit is contained in:
Stephen Fromm 2012-08-07 22:57:44 -07:00
parent 454de792f4
commit 3fb3eae7b6

View file

@ -124,16 +124,34 @@ class Facts(object):
self.facts['selinux']['status'] = 'disabled' self.facts['selinux']['status'] = 'disabled'
else: else:
self.facts['selinux']['status'] = 'enabled' self.facts['selinux']['status'] = 'enabled'
self.facts['selinux']['policyvers'] = selinux.security_policyvers() try:
(rc, configmode) = selinux.selinux_getenforcemode() self.facts['selinux']['policyvers'] = selinux.security_policyvers()
if rc == 0 and Facts.SELINUX_MODE_DICT.has_key(configmode): except:
self.facts['selinux']['config_mode'] = Facts.SELINUX_MODE_DICT[configmode] self.facts['selinux']['policyvers'] = 'unknown'
mode = selinux.security_getenforce() try:
if Facts.SELINUX_MODE_DICT.has_key(mode): (rc, configmode) = selinux.selinux_getenforcemode()
self.facts['selinux']['mode'] = Facts.SELINUX_MODE_DICT[mode] if rc == 0 and Facts.SELINUX_MODE_DICT.has_key(configmode):
(rc, policytype) = selinux.selinux_getpolicytype() self.facts['selinux']['config_mode'] = Facts.SELINUX_MODE_DICT[configmode]
if rc == 0: else:
self.facts['selinux']['type'] = policytype self.facts['selinux']['config_mode'] = 'unknown'
except OSError, e:
self.facts['selinux']['config_mode'] = 'unknown'
try:
mode = selinux.security_getenforce()
if Facts.SELINUX_MODE_DICT.has_key(mode):
self.facts['selinux']['mode'] = Facts.SELINUX_MODE_DICT[mode]
else:
self.facts['selinux']['mode'] = 'unknown'
except OSError, e:
self.facts['selinux']['mode'] = 'unknown'
try:
(rc, policytype) = selinux.selinux_getpolicytype()
if rc == 0:
self.facts['selinux']['type'] = policytype
else:
self.facts['selinux']['type'] = 'unknown'
except OSError, e:
self.facts['selinux']['type'] = 'unknown'
class Hardware(Facts): class Hardware(Facts):
""" """