예제 #1
0
if __name__ == "__main__":
    # check usage
    if len(sys.argv) != 3:
        print usage
        exit()
    input_file = sys.argv[1]
    output_file = sys.argv[2]
    policy = SELinuxPolicy()
    policy.from_file_name(input_file) #load data from file

    # expand rules into 4-tuples for SELinux.h checkAccess() check
    xml_root = Element('SELinux_AVC_Rules')
    count = 1
    for a in policy.allow_rules:
        expanded_xml = SELinux_CTS.expand_avc_rule_to_xml(policy, a, str(count), 'allow')
        if len(expanded_xml):
            xml_root.append(expanded_xml)
            count += 1
    count = 1
    for n in policy.neverallow_rules:
        expanded_xml = SELinux_CTS.expand_avc_rule_to_xml(policy, n, str(count), 'neverallow')
        if len(expanded_xml):
            xml_root.append(expanded_xml)
            count += 1

    #print out the xml file
    s = tostring(xml_root)
    s_parsed = minidom.parseString(s)
    output = s_parsed.toprettyxml(indent="    ")
    with open(output_file, 'w') as out_file:
예제 #2
0
if __name__ == "__main__":
    # check usage
    if len(sys.argv) != 3:
        print usage
        exit()
    input_file = sys.argv[1]
    output_file = sys.argv[2]
    policy = SELinuxPolicy()
    policy.from_file_name(input_file)  #load data from file

    # expand rules into 4-tuples for SELinux.h checkAccess() check
    xml_root = Element('SELinux_AVC_Rules')
    count = 1
    for a in policy.allow_rules:
        expanded_xml = SELinux_CTS.expand_avc_rule_to_xml(
            policy, a, str(count), 'allow')
        if len(expanded_xml):
            xml_root.append(expanded_xml)
            count += 1
    count = 1
    for n in policy.neverallow_rules:
        expanded_xml = SELinux_CTS.expand_avc_rule_to_xml(
            policy, n, str(count), 'neverallow')
        if len(expanded_xml):
            xml_root.append(expanded_xml)
            count += 1

    #print out the xml file
    s = tostring(xml_root)
    s_parsed = minidom.parseString(s)
    output = s_parsed.toprettyxml(indent="    ")