<def-group>
  <definition class="compliance" id="{{{ rule_id }}}" version="2">
    {{{ oval_metadata("Checks for correct permissions for all audit log files.") }}}
    <criteria operator="OR">
      <criteria operator="AND" comment="log_file set">
        <extend_definition comment="log_file set in auditd.conf" definition_ref="auditd_conf_log_file_not_set" negate="true" />
        <criterion test_ref="test_{{{ rule_id }}}" negate="true" />
      </criteria>
      <criteria operator="AND" comment="log_file not set">
        <extend_definition comment="log_file not set in auditd.conf" definition_ref="auditd_conf_log_file_not_set"/>
        <criterion test_ref="test_{{{ rule_id }}}_default" negate="true" />
      </criteria>
    </criteria>
  </definition>

  <unix:file_test check="all" check_existence="at_least_one_exists"
      comment="audit log files mode 0600"
      id="test_{{{ rule_id }}}" version="1">
    <unix:object object_ref="object_{{{ rule_id }}}" />
    <unix:state state_ref="state_{{{ rule_id }}}_not_mode_0600" />
  </unix:file_test>

  <unix:file_object comment="audit log files" id="object_{{{ rule_id }}}" version="1">
    <unix:path operation="equals" var_ref="audit_log_file_dir" />
    <unix:filename operation="pattern match">^.*$</unix:filename>
    <filter action="include">state_{{{ rule_id }}}_not_mode_0600</filter>
  </unix:file_object>

  <unix:file_test check="all" check_existence="at_least_one_exists"
      comment="default audit log files mode 0600"
      id="test_{{{ rule_id }}}_default" version="1">
    <unix:object object_ref="object_{{{ rule_id }}}_default" />
    <unix:state state_ref="state_{{{ rule_id }}}_not_mode_0600" />
  </unix:file_test>

  <unix:file_object comment="default audit log files" id="object_{{{ rule_id }}}_default" version="1">
    <unix:path operation="equals">/var/log/audit/</unix:path>
    <unix:filename operation="pattern match">^.*$</unix:filename>
    <filter action="include">state_{{{ rule_id }}}_not_mode_0600</filter>
  </unix:file_object>

  <unix:file_state id="state_{{{ rule_id }}}_not_mode_0600" version="1" operator="OR">
    <!-- if any one of these is true then mode is NOT 0600 (hence the OR operator) -->
    <unix:suid datatype="boolean">true</unix:suid>
    <unix:sgid datatype="boolean">true</unix:sgid>
    <unix:sticky datatype="boolean">true</unix:sticky>
    <unix:uexec datatype="boolean">true</unix:uexec>
    <unix:gread datatype="boolean">true</unix:gread>
    <unix:gwrite datatype="boolean">true</unix:gwrite>
    <unix:gexec datatype="boolean">true</unix:gexec>
    <unix:oread datatype="boolean">true</unix:oread>
    <unix:owrite datatype="boolean">true</unix:owrite>
    <unix:oexec datatype="boolean">true</unix:oexec>
  </unix:file_state>

  <!-- extract dirname from path -->
  <local_variable id="audit_log_file_dir" datatype="string" version="1" comment="dirname of audit log files">
    <regex_capture pattern="^(/.*/)[^/]*$">
      <variable_component var_ref="audit_log_file_path" />
    </regex_capture>
  </local_variable>
</def-group>
