<def-group>
  <definition class="compliance" id="file_ownership_binary_dirs" version="2">
    {{{ oval_metadata("
        Checks that /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin,
        /usr/local/sbin, /usr/libexec, and objects therein, are owned by root.
      ") }}}
    <criteria operator="AND">
      <criterion test_ref="test_ownership_binary_directories" />
      <criterion test_ref="test_ownership_binary_files" />
    </criteria>
  </definition>

  <unix:file_test  check="all" check_existence="none_exist" comment="binary directories uid root" id="test_ownership_binary_directories" version="1">
    <unix:object object_ref="object_file_ownership_binary_directories" />
  </unix:file_test>

  <unix:file_test  check="all" check_existence="none_exist" comment="binary files uid root" id="test_ownership_binary_files" version="1">
    <unix:object object_ref="object_file_ownership_binary_files" />
  </unix:file_test>

  <unix:file_object comment="binary directories" id="object_file_ownership_binary_directories" version="1">
{{% if 'ubuntu' in product %}}
    <!-- Check that files within /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin,
         /usr/local/sbin directories belong to user with uid < 100 (system accounts) -->
    <unix:path operation="pattern match">^\/(|s)bin|^\/usr\/(|local\/)(|s)bin</unix:path>
{{% else %}}
    <!-- Check that /bin, /sbin, /usr/sbin, /usr/sbin, /usr/local/bin,
         /usr/local/sbin, and /usr/libexec directories belong to user with uid 0 (root) -->
    <unix:path operation="pattern match">^\/(|s)bin|^\/usr\/(|local\/)(|s)bin|^\/usr\/libexec</unix:path>
{{% endif %}}
    <unix:filename xsi:nil="true" />
    <filter action="include">state_owner_binaries_not_root</filter>
  </unix:file_object>

  <unix:file_object comment="binary files" id="object_file_ownership_binary_files" version="1">
{{% if 'ubuntu' in product %}}
    <!-- Check that files within /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin,
         /usr/local/sbin directories belong to user with uid < 100 (system accounts) -->
    <unix:path operation="pattern match">^\/(|s)bin|^\/usr\/(|local\/)(|s)bin</unix:path>
{{% else %}}
    <!-- Check that files within /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin,
         /usr/local/sbin, and /usr/libexec directories belong to user with uid 0 (root) -->
    <unix:path operation="pattern match">^\/(|s)bin|^\/usr\/(|local\/)(|s)bin|^\/usr\/libexec</unix:path>
{{% endif %}}
    <unix:filename operation="pattern match">^.*$</unix:filename>
{{% if 'ubuntu' in product %}}
   <filter action="include">state_owner_binaries_not_system_accounts</filter>
{{% else %}}
   <filter action="include">state_owner_binaries_not_root</filter>
{{% endif %}}
  </unix:file_object>

  <unix:file_state id="state_owner_binaries_not_root" version="1" operator="OR">
    <unix:user_id datatype="int" operation="not equal">0</unix:user_id>
  </unix:file_state>

{{% if 'ubuntu' in product %}}
  <unix:file_state id="state_owner_binaries_not_system_accounts" version="1" operator="AND">
    <unix:user_id datatype="int" operation="greater than or equal">100</unix:user_id>
  </unix:file_state>
{{% endif %}}

</def-group>
