예제 #1
0
 def chpasswd(self, username, password, crypt_id=6, salt_len=10):
     passwd_hash = self.gen_password_hash(password, crypt_id, salt_len)
     cmd = ['usermod', '-p', passwd_hash, username]
     ret, output = ext_utils.run_command_get_output(cmd, log_cmd=False)
     if ret != 0:
         return "Failed to set password for {0}: {1}".format(
             username, output)
    def test_code_injection(self):
        # failure cases
        exit_code, string_output = ext_utils.run_command_get_output(
            "echo hello; echo world")
        self.assertNotEqual(0, exit_code, "exit code != 0")
        exit_code, string_output = ext_utils.run_command_get_output(
            ["echo hello; echo world"])
        self.assertNotEqual(0, exit_code, "exit code != 0")

        # success case
        exit_code, string_output = ext_utils.run_command_get_output(
            ["echo", "hello", ";", "echo", "world"])
        self.assertEqual(0, exit_code, "exit code == 0")
        self.assertEqual("hello ; echo world\n", string_output,
                         "unexpected output")
        exit_code, string_output = ext_utils.run_command_get_output(
            ["echo", "hello", "world"])
        self.assertEqual(0, exit_code, "exit code == 0")
예제 #3
0
def _fsck_repair(hutil, disk_name):
    # first unmount disks and loop devices lazy + forced
    try:
        cmd_result = ext_utils.run(['umount', '-f', '/' + disk_name])
        if cmd_result != 0:
            # Fail fast
            hutil.log("Failed to unmount disk: %s" % disk_name)
            # run repair
            retcode = ext_utils.run(['fsck', '-AR', '-y'])
            hutil.log("Ran fsck with return code: %d" % retcode)
            if retcode == 0:
                retcode, output = ext_utils.run_command_get_output(["mount"])
                hutil.log(output)
                return output
        else:
            raise Exception("Failed to mount disks")
    except Exception as e:
        hutil.error("{0}, {1}".format(str(e), traceback.format_exc()))
        hutil.do_exit(1, 'Repair', 'error', '0', 'Repair failed.')
예제 #4
0
def _insert_rule_if_not_exists(rule_string):
    rule_string_for_cmp = " ".join(rule_string)
    cmd_result = ext_utils.run_command_get_output(['iptables-save'])
    if cmd_result[0] == 0 and (rule_string_for_cmp not in cmd_result[1]):
        ext_utils.run_command_get_output(['iptables', '-I'] + rule_string)
예제 #5
0
def _del_rule_if_exists(rule_string):
    rule_string_for_cmp = " ".join(rule_string)
    cmd_result = ext_utils.run_command_get_output(['iptables-save'])
    while cmd_result[0] == 0 and (rule_string_for_cmp in cmd_result[1]):
        ext_utils.run(['iptables', '-D'] + rule_string)
        cmd_result = ext_utils.run_command_get_output(['iptables-save'])