{{% if product in ['ubuntu2404'] %}}
{{% set paths = ('/etc/issue', '/etc/issue.net', '/etc/hosts', '/etc/networks', '/etc/network/', '/etc/netplan/') %}}
{{% elif 'ubuntu' in product or 'debian' in product %}}
{{% set paths = ('/etc/issue', '/etc/issue.net', '/etc/hosts', '/etc/networks', '/etc/network/') %}}
{{% else %}}
{{% set paths = ('/etc/issue', '/etc/issue.net', '/etc/hosts', '/etc/sysconfig/network') %}}
{{% endif %}}

<def-group>
  <definition class="compliance" id="audit_rules_networkconfig_modification" version="1">
    {{{ oval_metadata("The network environment should not be modified by anything other than
      administrator action. Any change to network parameters should be audited.", rule_title=rule_title) }}}

    <criteria operator="OR">

      <!-- Test the augenrules case -->
      <criteria operator="AND">
        <extend_definition comment="audit augenrules" definition_ref="audit_rules_augenrules" />
        {{% for path in paths %}}
        <criterion comment="audit {{{ path }}} augenrules" test_ref="test_arnm_common_{{{ path | escape_id }}}_augenrules" />
        {{% endfor %}}
        <extend_definition comment="audit augenrules sethostname" definition_ref="audit_rules_networkconfig_modification_hostname" />
        <extend_definition comment="audit augenrules setdomainname" definition_ref="audit_rules_networkconfig_modification_domainname" />
      </criteria>

      <!-- Test the auditctl case -->
      <criteria operator="AND">
        <extend_definition comment="audit auditctl" definition_ref="audit_rules_auditctl" />
        {{% for path in paths %}}
        <criterion comment="audit {{{ path }}} auditctl" test_ref="test_arnm_common_{{{ path | escape_id }}}_auditctl" />
        {{% endfor %}}
        <extend_definition comment="audit augenrules sethostname" definition_ref="audit_rules_networkconfig_modification_hostname" />
        <extend_definition comment="audit augenrules setdomainname" definition_ref="audit_rules_networkconfig_modification_domainname" />
      </criteria>

    </criteria>
  </definition>

  {{% for path in paths %}}
  <ind:textfilecontent54_test check="all" comment="audit {{{ path }}} augenrules" id="test_arnm_common_{{{ path | escape_id }}}_augenrules" version="1">
      <ind:object object_ref="obj_arnm_common_{{{ path | escape_id }}}_augenrules" />
  </ind:textfilecontent54_test>
  <ind:textfilecontent54_object id="obj_arnm_common_{{{ path | escape_id }}}_augenrules" version="1">
    <ind:filepath operation="pattern match">^/etc/audit/rules\.d/.*\.rules$</ind:filepath>
    <ind:pattern operation="pattern match">^\-w[\s]+{{{ path | escape_regex }}}[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b.*$</ind:pattern>
    <ind:instance datatype="int">1</ind:instance>
  </ind:textfilecontent54_object>

  <ind:textfilecontent54_test check="all" comment="audit {{{ path }}} auditctl" id="test_arnm_common_{{{ path | escape_id }}}_auditctl" version="1">
    <ind:object object_ref="obj_arnm_common_{{{ path | escape_id }}}_auditctl" />
  </ind:textfilecontent54_test>
  <ind:textfilecontent54_object id="obj_arnm_common_{{{ path | escape_id }}}_auditctl" version="1">
    <ind:filepath>/etc/audit/audit.rules</ind:filepath>
    <ind:pattern operation="pattern match">^\-w[\s]+{{{ path | escape_regex }}}[\s]+\-p[\s]+\b([rx]*w[rx]*a[rx]*|[rx]*a[rx]*w[rx]*)\b.*$</ind:pattern>
    <ind:instance datatype="int">1</ind:instance>
  </ind:textfilecontent54_object>
  {{% endfor %}}

</def-group>
