<def-group>
  <definition class="compliance" id="{{{ rule_id }}}" version="1">
    {{{ oval_metadata("All Interactive Users Home Directories Must Exist", rule_title=rule_title) }}}
    <criteria operator="OR">
      <criterion test_ref="test_accounts_user_interactive_home_directory_exists"
                 comment="All Interactive Users Home Directories Must Exist"/>
      <criterion test_ref="test_accounts_user_interactive_home_directory_exists_users"
                 comment="Interactive users don't exist on the system"/>
    </criteria>
  </definition>

  {{%- set interactive_users_object = "object_" ~ rule_id ~ "_objects" -%}}
  {{{ create_local_interactive_users_home_dirs_list_object(interactive_users_object) }}}

  <!-- #### create a local variable composed by the list of home dirs from /etc/passwd #### -->
  <local_variable id="var_accounts_user_interactive_home_directory_exists_dirs_list"
                  datatype="string" version="1"
                  comment="Variable including all home dirs from interactive users">
    <object_component item_field="subexpression"
                      object_ref="{{{ interactive_users_object }}}"/>
  </local_variable>

  <!-- #### create a local variable composed by the number of home dirs from /etc/passwd #### -->
  <local_variable id="var_accounts_user_interactive_home_directory_exists_dirs_count"
                  datatype="int" version="1"
                  comment="Variable including expected count of home dirs present on the system">
    <count>
      <variable_component var_ref="var_accounts_user_interactive_home_directory_exists_dirs_list"/>
    </count>
  </local_variable>

  <!-- #### create a file_object to check existence of home dirs on file system #### -->
  <unix:file_object id="object_accounts_user_interactive_home_directory_exists_dirs_fs"
                    version="1">
    <unix:path var_ref="var_accounts_user_interactive_home_directory_exists_dirs_list"
               var_check="at least one"/>
    <unix:filename xsi:nil="true"/>
  </unix:file_object>

  <!-- #### create a local variable with the number of home dirs present on file system #### -->
  <local_variable id="var_accounts_user_interactive_home_directory_exists_dirs_count_fs"
                  datatype="int" version="1"
                  comment="Variable including number of home dirs present on file system">
    <count>
      <object_component item_field="path"
                  object_ref="object_accounts_user_interactive_home_directory_exists_dirs_fs"/>
    </count>
  </local_variable>

  <!-- #### create a variable object with count of home dirs from file system #### -->
  <ind:variable_object id="object_accounts_user_interactive_home_directory_exists_dirs_count_fs"
                       version="1">
    <ind:var_ref>var_accounts_user_interactive_home_directory_exists_dirs_count_fs</ind:var_ref>
  </ind:variable_object>

  <!-- #### create a variable state with count of home dirs from /etc/passwd #### -->
  <ind:variable_state id="state_accounts_user_interactive_home_directory_exists_dirs_count_pw"
                      version="1">
    <ind:value datatype="int" operation="equals" var_check="at least one"
               var_ref="var_accounts_user_interactive_home_directory_exists_dirs_count"/>
  </ind:variable_state>

  <!-- #### test_accounts_user_interactive_home_directory_exists #### -->
  <ind:variable_test id="test_accounts_user_interactive_home_directory_exists" check="all"
                     check_existence="at_least_one_exists" version="1"
                     comment="Check the existence of interactive users.">
    <ind:object object_ref="object_accounts_user_interactive_home_directory_exists_dirs_count_fs"/>
    <ind:state state_ref="state_accounts_user_interactive_home_directory_exists_dirs_count_pw"/>
  </ind:variable_test>

  <!-- #### create of variable object with count of home dirs from /etc/passwd #### -->
  <ind:variable_object id="object_accounts_user_interactive_home_directory_exists_dirs_count_pw"
                       version="1">
    <ind:var_ref>var_accounts_user_interactive_home_directory_exists_dirs_count</ind:var_ref>
  </ind:variable_object>

  <!-- #### test_accounts_user_interactive_home_directory_exists_users #### -->
  <ind:variable_test id="test_accounts_user_interactive_home_directory_exists_users" check="all"
                     check_existence="none_exist" version="1"
                     comment="Check the existence of interactive users.">
    <ind:object object_ref="object_accounts_user_interactive_home_directory_exists_dirs_count_pw"/>
  </ind:variable_test>
</def-group>
