<def-group oval_version="5.11">
  <definition class="compliance" id="chronyd_or_ntpd_set_maxpoll" version="1">
    {{{ oval_metadata("Configure the maxpoll setting in /etc/ntp.conf or chrony.conf
      to continuously poll the time source servers.") }}}
    <criteria operator="OR">
      <criteria operator="AND">
        <criterion comment="check if maxpoll is set in /etc/ntp.conf"
          test_ref="test_ntp_set_maxpoll" />
        <criterion comment="check if all server entries have maxpoll set in /etc/ntp.conf"
          test_ref="test_ntp_all_server_has_maxpoll"/>
      </criteria>
      <criteria operator="AND">
        <criterion comment="check if maxpoll is set in {{{ chrony_conf_path }}} or {{{ chrony_d_path }}}"
          test_ref="test_chrony_set_maxpoll" />
        <criterion comment="check if all server entries have maxpoll set in {{{ chrony_conf_path }}} or {{{ chrony_d_path }}}"
          test_ref="test_chrony_all_server_has_maxpoll"/>
      </criteria>
    </criteria>
  </definition>

  <ind:textfilecontent54_test check="all" check_existence="all_exist"
  comment="check if maxpoll is set in /etc/ntp.conf"
  id="test_ntp_set_maxpoll" version="1">
    <ind:object object_ref="obj_ntp_set_maxpoll" />
    <ind:state state_ref="state_time_service_set_maxpoll" />
  </ind:textfilecontent54_test>
  <ind:textfilecontent54_object id="obj_ntp_set_maxpoll" version="1">
    <ind:filepath>/etc/ntp.conf</ind:filepath>
    <ind:pattern operation="pattern match">^server[\s]+[\S]+.*maxpoll[\s]+(\d+)</ind:pattern>
    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
  </ind:textfilecontent54_object>

{{% set filepath_regex = "^(" + chrony_conf_path | replace(".", "\.") + "|" + chrony_d_path | replace(".", "\.") + ".+\.conf)$" %}}

  <ind:textfilecontent54_test check="all" check_existence="all_exist"
  comment="check if maxpoll is set in {{{ chrony_conf_path }}} or {{{ chrony_d_path }}}"
  id="test_chrony_set_maxpoll" version="1">
    <ind:object object_ref="obj_chrony_set_maxpoll" />
    <ind:state state_ref="state_time_service_set_maxpoll" />
  </ind:textfilecontent54_test>
  <ind:textfilecontent54_object id="obj_chrony_set_maxpoll" version="1">
    <ind:filepath operation="pattern match">{{{ filepath_regex }}}</ind:filepath>
    <ind:pattern operation="pattern match">^(?:server|pool|peer)[\s]+[\S]+.*maxpoll[\s]+(\d+)</ind:pattern>
    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
  </ind:textfilecontent54_object>

  <ind:textfilecontent54_state id="state_time_service_set_maxpoll" version="1">
    <ind:subexpression operation="less than or equal" var_ref="var_time_service_set_maxpoll" datatype="int" />
  </ind:textfilecontent54_state>

  <external_variable comment="maxpoll value" datatype="int"
  id="var_time_service_set_maxpoll" version="1" />

  <ind:textfilecontent54_test check="all" check_existence="all_exist"
  comment="check if all server entries have maxpoll set in /etc/ntp.conf"
  id="test_ntp_all_server_has_maxpoll" version="1">
    <ind:object object_ref="obj_ntp_all_server_has_maxpoll" />
    <ind:state state_ref="state_server_has_maxpoll" />
  </ind:textfilecontent54_test>
  <ind:textfilecontent54_object id="obj_ntp_all_server_has_maxpoll" version="1">
    <ind:filepath>/etc/ntp.conf</ind:filepath>
    <ind:pattern operation="pattern match">^server[\s]+[\S]+[\s]+(.*)</ind:pattern>
    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
  </ind:textfilecontent54_object>

  <ind:textfilecontent54_test check="all" check_existence="all_exist"
  comment="check if all server entries have maxpoll set in {{{ chrony_conf_path }}} or {{{ chrony_d_path }}}"
  id="test_chrony_all_server_has_maxpoll" version="1">
    <ind:object object_ref="obj_chrony_all_server_has_maxpoll" />
    <ind:state state_ref="state_server_has_maxpoll" />
  </ind:textfilecontent54_test>
  <ind:textfilecontent54_object id="obj_chrony_all_server_has_maxpoll" version="1">
    <ind:filepath operation="pattern match">{{{ filepath_regex }}}</ind:filepath>
    <ind:pattern operation="pattern match">^(?:server|pool|peer)[\s]+[\S]+[\s]+(.*)</ind:pattern>
    <ind:instance operation="greater than or equal" datatype="int">1</ind:instance>
  </ind:textfilecontent54_object>

  <ind:textfilecontent54_state id="state_server_has_maxpoll" version="1">
    <ind:subexpression operation="pattern match" datatype="string">maxpoll \d+</ind:subexpression>
  </ind:textfilecontent54_state>

</def-group>
