<def-group>
  <definition class="compliance" id="{{{ rule_id }}}" version="2">
    {{{ oval_metadata("The default umask for all users should be set correctly") }}}
    <criteria operator="AND">
      <extend_definition definition_ref="var_accounts_user_umask_as_number"
        comment="get value of var_accounts_user_umask variable as octal number"/>
      <criterion test_ref="tst_accounts_umask_etc_profile"/>
    </criteria>
  </definition>

  <ind:textfilecontent54_object id="obj_umask_from_etc_profile" version="1"
    comment="umask value retrieved from profile configuration files">
    <ind:filepath operation="pattern match">^\/etc\/profile(?:\.d\/.*\.sh|\.d\/sh\.local)?$</ind:filepath>
    <ind:pattern operation="pattern match">^[\s]*umask[\s]+([^#\s]*)</ind:pattern>
    <ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
  </ind:textfilecontent54_object>

  <local_variable id="var_first_digit_of_umask_from_etc_profile" version="1"
    datatype="int" comment="first octal digit of umask value(s)">
    <substring substring_start="1" substring_length="1">
      <object_component item_field="subexpression" object_ref="obj_umask_from_etc_profile"/>
    </substring>
  </local_variable>

  <local_variable id="var_second_digit_of_umask_from_etc_profile" version="1"
    datatype="int" comment="second octal digit of umask value(s)">
    <substring substring_start="2" substring_length="1">
      <object_component item_field="subexpression" object_ref="obj_umask_from_etc_profile"/>
    </substring>
  </local_variable>

  <local_variable id="var_third_digit_of_umask_from_etc_profile" version="1"
    datatype="int" comment="third octal digit of umask value(s)">
    <substring substring_start="3" substring_length="1">
      <object_component item_field="subexpression" object_ref="obj_umask_from_etc_profile"/>
    </substring>
  </local_variable>

  <local_variable id="var_etc_profile_umask_as_number" version="1"
    datatype="int" comment="umask value converted from string to a number">
    <arithmetic arithmetic_operation="add">
      <arithmetic arithmetic_operation="multiply">
        <literal_component datatype="int">64</literal_component>
        <variable_component var_ref="var_first_digit_of_umask_from_etc_profile"/>
      </arithmetic>
      <arithmetic arithmetic_operation="multiply">
        <literal_component datatype="int">8</literal_component>
        <variable_component var_ref="var_second_digit_of_umask_from_etc_profile"/>
      </arithmetic>
      <variable_component var_ref="var_third_digit_of_umask_from_etc_profile"/>
    </arithmetic>
  </local_variable>

  <ind:variable_test id="tst_accounts_umask_etc_profile" version="1"
    check="all" comment="umask value(s) from profile configuration files match the requirement">
    <ind:object object_ref="obj_accounts_umask_etc_profile" />
    <ind:state state_ref="ste_accounts_umask_etc_profile" />
  </ind:variable_test>

  <ind:variable_object id="obj_accounts_umask_etc_profile" version="1">
    <ind:var_ref>var_etc_profile_umask_as_number</ind:var_ref>
  </ind:variable_object>

  <!-- The 'var_accounts_user_umask_umask_as_number' variable is created by evaluation of
       the referenced 'var_accounts_user_umask_as_number' OVAL definition -->
  <ind:variable_state id="ste_accounts_umask_etc_profile" version="1">
    <ind:value datatype="int" operation="bitwise and"
      var_ref="var_accounts_user_umask_umask_as_number"/>
  </ind:variable_state>
</def-group>
