<def-group>
  <definition class="compliance" id="file_ownership_library_dirs" version="1">
    <metadata>
      <title>Verify that Shared Library Files Have Root Ownership</title>
      <affected family="unix">
        <platform>multi_platform_rhel</platform>
        <platform>multi_platform_fedora</platform>
      </affected>
      <description>
        Checks that /lib, /lib64, /usr/lib, /usr/lib64, /lib/modules, and
        objects therein, are owned by root.
      </description>
      <reference source="JL" ref_id="FEDORA20_20150522" ref_url="test_attestation" />
    </metadata>
    <criteria operator="AND">
      <criterion test_ref="test_ownership_lib_dir" />
      <criterion test_ref="test_ownership_lib_files" />
    </criteria>
  </definition>

  <unix:file_test  check="all" check_existence="none_exist" comment="library directories uid root" id="test_ownership_lib_dir" version="1">
    <unix:object object_ref="object_file_ownership_lib_dir" />
  </unix:file_test>

  <unix:file_test  check="all" check_existence="none_exist" comment="library files uid root" id="test_ownership_lib_files" version="1">
    <unix:object object_ref="object_file_ownership_lib_files" />
  </unix:file_test>

  <unix:file_object comment="library directories" id="object_file_ownership_lib_dir" version="1">
    <!-- Check that /lib, /lib64, /usr/lib, and /usr/lib64 directories belong to user with uid 0 (root) -->
    <unix:path operation="pattern match">^\/lib(|64)\/|^\/usr\/lib(|64)\/</unix:path>
    <unix:filename xsi:nil="true" />
    <filter action="include">state_owner_libraries_not_root</filter>
  </unix:file_object>

  <unix:file_object comment="library files" id="object_file_ownership_lib_files" version="1">
    <!-- Check that files within /lib, /lib64, /usr/lib, and /usr/lib64 directories belong to user with uid 0 (root) -->
    <unix:path operation="pattern match">^\/lib(|64)\/|^\/usr\/lib(|64)\/</unix:path>
    <unix:filename operation="pattern match">^.*$</unix:filename>
   <filter action="include">state_owner_libraries_not_root</filter>
  </unix:file_object>

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

</def-group>
