File: template.py

package info (click to toggle)
scap-security-guide 0.1.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 110,644 kB
  • sloc: xml: 241,883; sh: 73,777; python: 32,527; makefile: 27
file content (18 lines) | stat: -rw-r--r-- 853 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def preprocess(data, lang):
    if lang == "oval" and data["attribute"] == 'permissions':
        # create STATEMODE used in the OVAL template by processing the octal permission and
        # creating the equivalent permission fields of "unix:file_state" element.
        mode = data["value"]
        fields = [
            'oexec', 'owrite', 'oread', 'gexec', 'gwrite', 'gread',
            'uexec', 'uwrite', 'uread', 'sticky', 'sgid', 'suid']
        mode_int = int(mode, 8)
        mode_str = ""
        for field in fields:
            if mode_int & 0x01 == 0:
                mode_str = (
                    "<unix:{field} datatype=\"boolean\">false</unix:{field}>\n{mode_str}".format(
                        field=field, mode_str=mode_str))
            mode_int = mode_int >> 1
        data["statemode"] = mode_str.rstrip("\n")
    return data