本文整理汇总了Python中src.stonix_resources.CommandHelper.CommandHelper.getReturnCode方法的典型用法代码示例。如果您正苦于以下问题:Python CommandHelper.getReturnCode方法的具体用法?Python CommandHelper.getReturnCode怎么用?Python CommandHelper.getReturnCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类src.stonix_resources.CommandHelper.CommandHelper
的用法示例。
在下文中一共展示了CommandHelper.getReturnCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: zzzTestDisableAFPFileSharing
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getReturnCode [as 别名]
class zzzTestDisableAFPFileSharing(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = DisableAFPFileSharing(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.cmdhelper = CommandHelper(self.logdispatch)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
'''
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: Breen Malmberg
'''
success = True
try:
cmd = '/bin/launchctl enable system/com.apple.AppleFileServer'
self.cmdhelper.executeCommand(cmd)
retcode = self.cmdhelper.getReturnCode()
if retcode != 0:
errstr = self.cmdhelper.getErrorString()
self.logdispatch.log(LogPriority.DEBUG, errstr)
success = False
except Exception:
raise
return success
def checkReportForRule(self, pCompliance, pRuleSuccess):
'''
check on whether report was correct
@param self: essential if you override this definition
@param pCompliance: the self.iscompliant value of rule
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " + \
str(pCompliance) + ".")
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
return success
def checkFixForRule(self, pRuleSuccess):
'''
check on whether fix was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
return success
def checkUndoForRule(self, pRuleSuccess):
'''
check on whether undo was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
return success
示例2: zzzTestRuleDisableInactiveAccounts
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getReturnCode [as 别名]
class zzzTestRuleDisableInactiveAccounts(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = DisableInactiveAccounts(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
def tearDown(self):
pass
def runTest(self):
self.setConditionsForRule()
self.simpleRuleTest()
def setConditionsForRule(self):
'''
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: Breen Malmberg
'''
success = True
return success
def test_dscl_path(self):
'''
test for valid location of dscl command path
@author: Breen Malmberg
'''
found = False
if os.path.exists('/usr/bin/dscl'):
found = True
self.assertTrue(found, True)
def test_get_users(self):
'''
test the command to get the list of users
@author: Breen Malmberg
'''
self.ch.executeCommand('/usr/bin/dscl . -ls /Users')
rc = self.ch.getReturnCode()
# rc should always be 0 after this command is run (means it ran successfully)
# however 0 is interpreted as false by python, so.. assertFalse
self.assertFalse(rc, "The return code for getting the list of users should always be 0 (success)")
def test_pwpolicy_path(self):
'''
test for valid location of pwpolicy command path
@author: Breen Malmberg
'''
found = False
if os.path.exists('/usr/bin/pwpolicy'):
found = True
self.assertTrue(found, True)
def test_initobjs(self):
'''
test whether the private method initobjs works
@author: Breen Malmberg
'''
self.rule.initobjs()
self.assertTrue(self.rule.cmdhelper, "CommandHelper object should always initialize after initobjs() is run")
def checkReportForRule(self, pCompliance, pRuleSuccess):
'''
check on whether report was correct
@param self: essential if you override this definition
@param pCompliance: the self.iscompliant value of rule
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: Breen Malmberg
'''
self.logdispatch.log(LogPriority.DEBUG, "pCompliance = " + \
str(pCompliance) + ".")
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
return success
def checkFixForRule(self, pRuleSuccess):
'''
check on whether fix was correct
@param self: essential if you override this definition
@param pRuleSuccess: did report run successfully
@return: boolean - If successful True; If failure False
@author: Breen Malmberg
'''
self.logdispatch.log(LogPriority.DEBUG, "pRuleSuccess = " + \
str(pRuleSuccess) + ".")
success = True
return success
#.........这里部分代码省略.........
示例3: zzzTestRuleDisableRemoveableStorage
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getReturnCode [as 别名]
class zzzTestRuleDisableRemoveableStorage(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = DisableRemoveableStorage(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
self.rule.storageci.updatecurrvalue(True)
self.logger = self.logdispatch
self.ignoreresults = True
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
'''
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
success = True
if self.environ.getostype() == "Mac OS X":
success = self.setConditionsForMac()
else:
success = self.setConditionsForLinux()
return success
def setConditionsForMac(self):
'''
Method to configure mac non compliant for unit test
@author: dwalker
@return: boolean
'''
success = True
daemonpath = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]))) + "/src/stonix_resources/disablestorage"
plistpath = "/Library/LaunchDaemons/gov.lanl.stonix.disablestorage.plist"
self.rule.daemonpath = daemonpath
if re.search("^10.11", self.environ.getosver()):
usb = "IOUSBMassStorageDriver"
else:
usb = "IOUSBMassStorageClass"
kernelmods = [usb,
"IOFireWireFamily",
"AppleThunderboltUTDM",
"AppleSDXC"]
check = "/usr/sbin/kextstat"
load = "/sbin/kextload"
'''Remove plist file for launch job if exists'''
if os.path.exists(plistpath):
os.remove(plistpath)
'''Remove daemon file if exists'''
if os.path.exists(daemonpath):
os.remove(daemonpath)
for kmod in kernelmods:
cmd = check + "| grep " + kmod
self.ch.executeCommand(cmd)
if self.ch.getReturnCode() != 0:
'''kernel mod is not loaded, load to make non-compliant'''
cmd = load + " /System/Library/Extensions/" + kmod + ".kext"
if not self.ch.executeCommand(cmd):
debug = "Unable to load kernel module " + kmod + " for unit test\n"
self.logdispatch.log(LogPriority.DEBUG, debug)
success = False
return success
def setConditionsForLinux(self):
'''
Method to configure mac non compliant for unit test
@author: dwalker
@return: boolean
'''
success = True
self.ph = Pkghelper(self.logger, self.environ)
# check compliance of grub file(s) if files exist
if re.search("Red Hat", self.environ.getostype()) and \
re.search("^6", self.environ.getosver()):
self.grubperms = [0, 0, 0o600]
elif self.ph.manager is "apt-get":
self.grubperms = [0, 0, 0o400]
else:
self.grubperms = [0, 0, 0o644]
grubfiles = ["/boot/grub2/grub.cfg",
"/boot/grub/grub.cfg"
"/boot/grub/grub.conf"]
for grub in grubfiles:
if os.path.exists(grub):
if self.grubperms:
if checkPerms(grub, self.grubperms, self.logger):
if not setPerms(grub, [0, 0, 0o777], self.logger):
success = False
contents = readFile(grub, self.logger)
if contents:
for line in contents:
#.........这里部分代码省略.........
示例4: zzzTestRuleNoCoreDumps
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getReturnCode [as 别名]
class zzzTestRuleNoCoreDumps(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = NoCoreDumps(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.logger = self.logdispatch
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.checkUndo = True
self.ch = CommandHelper(self.logger)
def tearDown(self):
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
"""
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: Ekkehard J. Koch
"""
success = True
if self.environ.getosfamily() == "linux":
if not self.setLinuxConditions():
success = False
elif self.environ.getostype() == "mac":
if not self.setMacConditions():
success = False
return success
def setMacConditions(self):
success = True
self.ch.executeCommand("/usr/bin/launchctl limit core")
retcode = self.ch.getReturnCode()
if retcode != 0:
self.detailedresults += "\nFailed to run launchctl command to get current value of core dumps configuration"
errmsg = self.ch.getErrorString()
self.logger.log(LogPriority.DEBUG, errmsg)
else:
output = self.ch.getOutputString()
if output:
if not re.search("1", output):
self.ch.executeCommand("/usr/bin/launchctl limit core 1 1")
def setLinuxConditions(self):
success = True
path1 = "/etc/security/limits.conf"
if os.path.exists(path1):
lookfor1 = "(^\*)\s+hard\s+core\s+0?"
contents = readFile(path1, self.logger)
if contents:
tempstring = ""
for line in contents:
if not re.search(lookfor1, line.strip()):
tempstring += line
if not writeFile(path1, tempstring, self.logger):
debug = "unable to write incorrect contents to " + path1 + "\n"
self.logger.log(LogPriority.DEBUG, debug)
success = False
if checkPerms(path1, [0, 0, 0o644], self.logger):
if not setPerms(path1, [0, 0, 0o777], self.logger):
debug = "Unable to set incorrect permissions on " + path1 + "\n"
self.logger.log(LogPriority.DEBUG, debug)
success = False
else:
debug = "successfully set incorrect permissions on " + path1 + "\n"
self.logger.log(LogPriority.DEBUG, debug)
self.ch.executeCommand("/sbin/sysctl fs.suid_dumpable")
retcode = self.ch.getReturnCode()
if retcode != 0:
self.detailedresults += "Failed to get value of core dumps configuration with sysctl command\n"
errmsg = self.ch.getErrorString()
self.logger.log(LogPriority.DEBUG, errmsg)
success = False
else:
output = self.ch.getOutputString()
if output.strip() != "fs.suid_dumpable = 1":
if not self.ch.executeCommand("/sbin/sysctl -w fs.suid_dumpable=1"):
debug = "Unable to set incorrect value for fs.suid_dumpable"
self.logger.log(LogPriority.DEBUG, debug)
success = False
elif not self.ch.executeCommand("/sbin/sysctl -p"):
debug = "Unable to set incorrect value for fs.suid_dumpable"
self.logger.log(LogPriority.DEBUG, debug)
success = False
return success
def checkReportForRule(self, pCompliance, pRuleSuccess):
"""
check on whether report was correct
@param self: essential if you override this definition
@param pCompliance: the self.iscompliant value of rule
#.........这里部分代码省略.........
示例5: zzzTestRuleEnableKernelAuditing
# 需要导入模块: from src.stonix_resources.CommandHelper import CommandHelper [as 别名]
# 或者: from src.stonix_resources.CommandHelper.CommandHelper import getReturnCode [as 别名]
class zzzTestRuleEnableKernelAuditing(RuleTest):
def setUp(self):
RuleTest.setUp(self)
self.rule = EnableKernelAuditing(self.config,
self.environ,
self.logdispatch,
self.statechglogger)
self.rulename = self.rule.rulename
self.rulenumber = self.rule.rulenumber
self.ch = CommandHelper(self.logdispatch)
def tearDown(self):
# restore backups of original files, made before testing
# if self.environ.getosfamily() == 'darwin':
# auditcontrolbak = '/etc/security/audit_control.stonixbak'
# audituserbak = '/etc/security/audit_user.stonixbak'
# if os.path.exists(auditcontrolbak):
# os.rename(auditcontrolbak, '/etc/security/audit_control')
# if os.path.exists(audituserbak):
# os.rename(audituserbak, '/etc/security/audit_user')
# else:
# auditdbaks =['/etc/audit/auditd.conf.stonixbak', '/etc/auditd.conf.stonixbak']
# auditrulesbaks = ['/etc/audit/audit.rules.stonixbak', '/etc/audit/rules.d/audit.rules.stonixbak']
# for bak in auditdbaks:
# if os.path.exists(bak):
# os.rename(bak, bak[:-10])
# for bak in auditrulesbaks:
# if os.path.exists(bak):
# os.rename(bak, bak[:-10])
pass
def runTest(self):
self.simpleRuleTest()
def setConditionsForRule(self):
'''
Configure system for the unit test
@param self: essential if you override this definition
@return: boolean - If successful True; If failure False
@author: ekkehard j. koch
'''
success = True
#
# # make backups of any original files, before testing
# if self.environ.getosfamily() == 'darwin':
# if os.path.exists('/etc/security/audit_control'):
# os.rename('/etc/security/audit_control', '/etc/security/audit_control.stonixbak')
# if os.path.exists('/etc/security/audit_user'):
# os.rename('/etc/security/audit_user', '/etc/security/audit_user.stonixbak')
# else:
# auditdpaths = ['/etc/audit/auditd.conf', '/etc/auditd.conf']
# for path in auditdpaths:
# if os.path.exists(path):
# os.rename(path, path + '.stonixbak')
# if os.path.exists('/etc/audisp/audispd.conf'):
# os.rename('/etc/audisp/audispd.conf', '/etc/audisp/audispd.conf.stonixbak')
# auditruleslocs = ['/etc/audit/audit.rules', '/etc/audit/rules.d/audit.rules']
# for loc in auditruleslocs:
# if os.path.exists(loc):
# os.rename(loc, loc + '.stonixbak')
return success
def test_freqci_in_range(self):
'''
test if the frequency ci value is within range
@author: Breen Malmberg
'''
allowable_freq_range = range(1,100)
self.assertTrue(self.rule.freqci.getcurrvalue() in allowable_freq_range)
def test_flushtype_valid(self):
'''
test if the flush type ci value is a valid flush type
@author: Breen Malmberg
'''
allowable_flush_types = ['data', 'incremental', 'sync']
self.assertTrue(self.rule.flushtypeci.getcurrvalue() in allowable_flush_types)
def test_get_system_arch(self):
'''
test the command to get the system arch
@author: Breen Malmberg
'''
found = False
self.ch.executeCommand('/usr/bin/uname -m')
self.assertEqual(0, self.ch.getReturnCode())
outputlines = self.ch.getOutput()
self.assertFalse(outputlines == '')
for line in outputlines:
if re.search('^x86\_64', line):
found = True
for line in outputlines:
#.........这里部分代码省略.........