#!/bin/sh

# shellcheck disable=SC1090
# shellcheck disable=SC2034
# shellcheck disable=SC2154

# audit_process_accounting
#
# Refer to Section(s) 10.1 Page(s) 137-8 CIS Solaris 10 Benchmark v1.1.0
#.

audit_process_accounting () {
  print_function "audit_process_accounting"
  string="Process Accounting"
  check_message  "${string}"
  if [ "${os_name}" = "SunOS" ]; then
    check_file="/etc/rc3.d/S99acct"
    init_file="/etc/init.d/acct"
    log_file="${work_dir}/acct.log"
    if [ ! -f "${check_file}" ]; then
      if [ "${audit_mode}" = 1 ]; then
        inc_insecure "Process accounting not enabled"
      fi
      if [ "${audit_mode}" = 0 ]; then
        set_message  "Process accounting to enabled"
        echo  "disabled" > "${log_file}"
        ln -s "${init_file}" "${check_file}"
        notice_message "Starting Process accounting"
        eval  "${init_file} start > /dev/null 2>&1"
      fi
    else
      if [ "${audit_mode}" = 1 ]; then
        inc_secure "Process accounting not enabled"
      fi
      if [ "${audit_mode}" = 2 ]; then
        log_file="${restore_dir}/acct.log"
        if [ -f "${log_file}" ]; then
          if [ -f "${check_file}" ]; then
            rm "${check_file}"
          fi
          restore_message "Process accounting to disabled"
          notice_message  "Stoping Process accounting"
          eval "${init_file} stop > /dev/null 2>&1"
        fi
      fi
    fi
  else
    na_message "${string}"
  fi
}
