policy_module(rhev,1.0)

########################################
#
# Declarations
#

type rhev_agentd_t;
type rhev_agentd_exec_t;
init_daemon_domain(rhev_agentd_t, rhev_agentd_exec_t)

type rhev_agentd_unit_file_t;
systemd_unit_file(rhev_agentd_unit_file_t)

type rhev_agentd_var_run_t;
files_pid_file(rhev_agentd_var_run_t)

type rhev_agentd_tmp_t;
files_tmp_file(rhev_agentd_tmp_t)

type rhev_agentd_log_t;
logging_log_file(rhev_agentd_log_t)

########################################
#
# rhev_agentd_t local policy
#

allow rhev_agentd_t self:capability { setuid setgid sys_nice };
allow rhev_agentd_t self:process setsched;

allow rhev_agentd_t self:fifo_file rw_fifo_file_perms;
allow rhev_agentd_t self:unix_stream_socket create_stream_socket_perms;

manage_dirs_pattern(rhev_agentd_t, rhev_agentd_var_run_t, rhev_agentd_var_run_t)
manage_files_pattern(rhev_agentd_t, rhev_agentd_var_run_t, rhev_agentd_var_run_t)
manage_sock_files_pattern(rhev_agentd_t, rhev_agentd_var_run_t, rhev_agentd_var_run_t)
files_pid_filetrans(rhev_agentd_t, rhev_agentd_var_run_t, { dir file sock_file })

manage_files_pattern(rhev_agentd_t, rhev_agentd_log_t, rhev_agentd_log_t)
manage_dirs_pattern(rhev_agentd_t, rhev_agentd_log_t, rhev_agentd_log_t)
logging_log_filetrans(rhev_agentd_t, rhev_agentd_log_t, { dir file })

manage_dirs_pattern(rhev_agentd_t, rhev_agentd_tmp_t, rhev_agentd_tmp_t)
manage_files_pattern(rhev_agentd_t, rhev_agentd_tmp_t, rhev_agentd_tmp_t)
files_tmp_filetrans(rhev_agentd_t, rhev_agentd_tmp_t, { file dir })
can_exec(rhev_agentd_t, rhev_agentd_tmp_t)

kernel_read_system_state(rhev_agentd_t)
kernel_read_kernel_sysctls(rhev_agentd_t)

corecmd_exec_bin(rhev_agentd_t)
corecmd_exec_shell(rhev_agentd_t)

dev_read_urand(rhev_agentd_t)

term_use_virtio_console(rhev_agentd_t)

fs_getattr_all_fs(rhev_agentd_t)

files_getattr_all_mountpoints(rhev_agentd_t)
files_search_all_mountpoints(rhev_agentd_t)

auth_use_nsswitch(rhev_agentd_t)

init_read_utmp(rhev_agentd_t)

libs_exec_ldconfig(rhev_agentd_t)
logging_send_syslog_msg(rhev_agentd_t)

optional_policy(`
	rpm_read_db(rhev_agentd_t)
	rpm_dontaudit_manage_db(rhev_agentd_t)
')

optional_policy(`
	ssh_signull(rhev_agentd_t)
')

optional_policy(`
    dbus_system_bus_client(rhev_agentd_t)
    dbus_connect_system_bus(rhev_agentd_t)
	dbus_session_bus_client(rhev_agentd_t)

    optional_policy(`
        systemd_dbus_chat_logind(rhev_agentd_t)
    ')

    optional_policy(`
        xserver_dbus_chat_xdm(rhev_agentd_t)
    ')

')

optional_policy(`
    udev_read_db(rhev_agentd_t)
')

optional_policy(`
   xserver_stream_connect(rhev_agentd_t)
')

######################################
#
# rhev_agentd_t consolehelper local policy
#

optional_policy(`
	userhelper_console_role_template(rhev_agentd, system_r, rhev_agentd_t)

	allow rhev_agentd_consolehelper_t rhev_agentd_log_t:file rw_inherited_file_perms;
	allow rhev_agentd_consolehelper_t rhev_agentd_tmp_t:file rw_inherited_file_perms;

	can_exec(rhev_agentd_consolehelper_t, rhev_agentd_exec_t)
	kernel_read_system_state(rhev_agentd_consolehelper_t)

	term_use_virtio_console(rhev_agentd_consolehelper_t)

	corenet_tcp_connect_xserver_port(rhev_agentd_consolehelper_t)

	optional_policy(`
		dbus_session_bus_client(rhev_agentd_consolehelper_t)
	')

	optional_policy(`
		unconfined_dbus_chat(rhev_agentd_consolehelper_t)
	')
')
