policy_module(setroubleshoot, 1.12.1)

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

type setroubleshootd_t alias setroubleshoot_t;
type setroubleshootd_exec_t;
domain_type(setroubleshootd_t)
init_daemon_domain(setroubleshootd_t, setroubleshootd_exec_t)

type setroubleshoot_fixit_t;
type setroubleshoot_fixit_exec_t;
init_daemon_domain(setroubleshoot_fixit_t, setroubleshoot_fixit_exec_t)

type setroubleshoot_var_lib_t;
files_type(setroubleshoot_var_lib_t)

# log files
type setroubleshoot_var_log_t;
logging_log_file(setroubleshoot_var_log_t)

# pid files
type setroubleshoot_var_run_t;
files_pid_file(setroubleshoot_var_run_t)

type setroubleshoot_tmp_t;
files_tmp_file(setroubleshoot_tmp_t)

type setroubleshoot_tmpfs_t;
files_tmpfs_file(setroubleshoot_tmpfs_t)

type setroubleshoot_fixit_tmp_t;
files_tmp_file(setroubleshoot_fixit_tmp_t)

type setroubleshoot_fixit_tmpfs_t;
files_tmpfs_file(setroubleshoot_fixit_tmpfs_t)

########################################
#
# setroubleshootd local policy
#

allow setroubleshootd_t self:capability { sys_nice sys_ptrace sys_tty_config };
dontaudit setroubleshootd_t self:capability net_admin;

allow setroubleshootd_t self:process { getattr getsched setsched sigkill signull signal };
# if bad library causes setroubleshoot to require these, we want to give it so setroubleshoot can continue to run
allow setroubleshootd_t self:fifo_file rw_fifo_file_perms;
allow setroubleshootd_t self:tcp_socket create_stream_socket_perms;
allow setroubleshootd_t self:unix_stream_socket { create_stream_socket_perms connectto };
allow setroubleshootd_t self:unix_dgram_socket create_socket_perms;


manage_files_pattern(setroubleshootd_t, setroubleshoot_tmp_t, setroubleshoot_tmp_t)
manage_dirs_pattern(setroubleshootd_t, setroubleshoot_tmp_t, setroubleshoot_tmp_t)
files_tmp_filetrans(setroubleshootd_t, setroubleshoot_tmp_t, { file dir })
allow setroubleshootd_t setroubleshoot_tmp_t:file mmap_file_perms;

manage_files_pattern(setroubleshootd_t, setroubleshoot_tmpfs_t, setroubleshoot_tmpfs_t)
manage_dirs_pattern(setroubleshootd_t, setroubleshoot_tmpfs_t, setroubleshoot_tmpfs_t)
fs_tmpfs_filetrans(setroubleshootd_t, setroubleshoot_tmpfs_t, { file dir })
allow setroubleshootd_t setroubleshoot_tmpfs_t:file mmap_file_perms;

manage_files_pattern(setroubleshoot_fixit_t, setroubleshoot_fixit_tmp_t, setroubleshoot_fixit_tmp_t)
manage_dirs_pattern(setroubleshoot_fixit_t, setroubleshoot_fixit_tmp_t, setroubleshoot_fixit_tmp_t)
files_tmp_filetrans(setroubleshoot_fixit_t, setroubleshoot_fixit_tmp_t, { file dir })
allow setroubleshoot_fixit_t setroubleshoot_fixit_tmp_t:file mmap_file_perms;

manage_files_pattern(setroubleshoot_fixit_t, setroubleshoot_fixit_tmpfs_t, setroubleshoot_fixit_tmpfs_t)
manage_dirs_pattern(setroubleshoot_fixit_t, setroubleshoot_fixit_tmpfs_t, setroubleshoot_fixit_tmpfs_t)
fs_tmpfs_filetrans(setroubleshoot_fixit_t, setroubleshoot_fixit_tmpfs_t, { file dir })
allow setroubleshoot_fixit_t setroubleshoot_fixit_tmpfs_t:file mmap_file_perms;

# database files
allow setroubleshootd_t setroubleshoot_var_lib_t:dir setattr;
manage_files_pattern(setroubleshootd_t, setroubleshoot_var_lib_t, setroubleshoot_var_lib_t)
files_var_lib_filetrans(setroubleshootd_t, setroubleshoot_var_lib_t, { file dir })

# log files
allow setroubleshootd_t setroubleshoot_var_log_t:dir setattr;
manage_files_pattern(setroubleshootd_t, setroubleshoot_var_log_t, setroubleshoot_var_log_t)
manage_sock_files_pattern(setroubleshootd_t, setroubleshoot_var_log_t, setroubleshoot_var_log_t)
logging_log_filetrans(setroubleshootd_t, setroubleshoot_var_log_t, { file dir })

# pid file
manage_dirs_pattern(setroubleshootd_t, setroubleshoot_var_run_t, setroubleshoot_var_run_t)
manage_files_pattern(setroubleshootd_t, setroubleshoot_var_run_t, setroubleshoot_var_run_t)
manage_sock_files_pattern(setroubleshootd_t, setroubleshoot_var_run_t, setroubleshoot_var_run_t)
files_pid_filetrans(setroubleshootd_t, setroubleshoot_var_run_t, { file sock_file dir })


kernel_read_kernel_sysctls(setroubleshootd_t)
kernel_read_system_state(setroubleshootd_t)
kernel_read_net_sysctls(setroubleshootd_t)
kernel_read_network_state(setroubleshootd_t)
kernel_dontaudit_list_all_proc(setroubleshootd_t)
kernel_read_irq_sysctls(setroubleshootd_t)
kernel_read_rpc_sysctls(setroubleshootd_t)
kernel_read_unlabeled_state(setroubleshootd_t)

corecmd_exec_bin(setroubleshootd_t)
corecmd_exec_shell(setroubleshootd_t)
corecmd_read_all_executables(setroubleshootd_t)

corenet_all_recvfrom_netlabel(setroubleshootd_t)
corenet_tcp_sendrecv_generic_if(setroubleshootd_t)
corenet_tcp_sendrecv_generic_node(setroubleshootd_t)
corenet_tcp_sendrecv_all_ports(setroubleshootd_t)
corenet_tcp_bind_generic_node(setroubleshootd_t)
corenet_tcp_connect_smtp_port(setroubleshootd_t)
corenet_sendrecv_smtp_client_packets(setroubleshootd_t)

dev_read_urand(setroubleshootd_t)
dev_read_sysfs(setroubleshootd_t)
dev_getattr_all_blk_files(setroubleshootd_t)
dev_getattr_all_chr_files(setroubleshootd_t)
dev_getattr_mtrr_dev(setroubleshootd_t)

domain_read_all_domains_state(setroubleshootd_t)
domain_signull_all_domains(setroubleshootd_t)

files_list_all(setroubleshootd_t)
files_getattr_all_files(setroubleshootd_t)
files_getattr_all_pipes(setroubleshootd_t)
files_getattr_all_sockets(setroubleshootd_t)
files_read_all_symlinks(setroubleshootd_t)
files_read_mnt_files(setroubleshootd_t)

fs_getattr_all_dirs(setroubleshootd_t)
fs_getattr_all_files(setroubleshootd_t)
fs_read_fusefs_symlinks(setroubleshootd_t)
fs_list_inotifyfs(setroubleshootd_t)
fs_dontaudit_read_nfs_files(setroubleshootd_t)
fs_dontaudit_read_cifs_files(setroubleshootd_t)

selinux_get_enforce_mode(setroubleshootd_t)
selinux_validate_context(setroubleshootd_t)
selinux_read_policy(setroubleshootd_t)

term_dontaudit_use_all_ptys(setroubleshootd_t)
term_dontaudit_use_all_ttys(setroubleshootd_t)

mls_dbus_recv_all_levels(setroubleshootd_t)

auth_use_nsswitch(setroubleshootd_t)

init_read_utmp(setroubleshootd_t)
init_dontaudit_write_utmp(setroubleshootd_t)

libs_exec_ld_so(setroubleshootd_t)
libs_exec_ldconfig(setroubleshootd_t)

locallogin_dontaudit_use_fds(setroubleshootd_t)

logging_send_audit_msgs(setroubleshootd_t)
logging_send_syslog_msg(setroubleshootd_t)
logging_stream_connect_dispatcher(setroubleshootd_t)
logging_stream_connect_syslog(setroubleshootd_t)

seutil_read_bin_policy(setroubleshootd_t)
seutil_read_config(setroubleshootd_t)
seutil_read_default_contexts(setroubleshootd_t)
seutil_read_file_contexts(setroubleshootd_t)

userdom_dontaudit_read_user_home_content_files(setroubleshootd_t)

optional_policy(`
	abrt_dbus_chat(setroubleshootd_t)
')

optional_policy(`
	locate_read_lib_files(setroubleshootd_t)
')

optional_policy(`
	mock_getattr_lib(setroubleshootd_t)
')

optional_policy(`
	modutils_read_module_config(setroubleshootd_t)
')

optional_policy(`
	dbus_system_domain(setroubleshootd_t, setroubleshootd_exec_t)
')

optional_policy(`
	rpm_exec(setroubleshootd_t)
	rpm_signull(setroubleshootd_t)
	rpm_read_db(setroubleshootd_t)
	rpm_dontaudit_manage_db(setroubleshootd_t)
	rpm_use_script_fds(setroubleshootd_t)
')

########################################
#
# setroubleshoot_fixit local policy
#

allow setroubleshoot_fixit_t self:capability sys_nice;
allow setroubleshoot_fixit_t self:process { setsched getsched };
dontaudit setroubleshoot_fixit_t self:process execmem;
allow setroubleshoot_fixit_t self:fifo_file rw_fifo_file_perms;
allow setroubleshoot_fixit_t self:unix_dgram_socket create_socket_perms;

allow setroubleshoot_fixit_t setroubleshootd_t:process signull;

setroubleshoot_dbus_chat(setroubleshoot_fixit_t)
setroubleshoot_stream_connect(setroubleshoot_fixit_t)

kernel_read_system_state(setroubleshoot_fixit_t)
kernel_read_network_state(setroubleshoot_fixit_t)

corecmd_exec_bin(setroubleshoot_fixit_t)
corecmd_exec_shell(setroubleshoot_fixit_t)
corecmd_getattr_all_executables(setroubleshoot_fixit_t)

dev_read_rand(setroubleshoot_fixit_t)
dev_read_sysfs(setroubleshoot_fixit_t)
dev_read_urand(setroubleshoot_fixit_t)

selinux_read_policy(setroubleshoot_fixit_t)

seutil_domtrans_setfiles(setroubleshoot_fixit_t)
seutil_domtrans_setsebool(setroubleshoot_fixit_t)
seutil_read_module_store(setroubleshoot_fixit_t)

files_list_tmp(setroubleshoot_fixit_t)

auth_use_nsswitch(setroubleshoot_fixit_t)

logging_send_audit_msgs(setroubleshoot_fixit_t)
logging_send_syslog_msg(setroubleshoot_fixit_t)

userdom_dontaudit_search_admin_dir(setroubleshoot_fixit_t)
userdom_signull_unpriv_users(setroubleshoot_fixit_t)

optional_policy(`
	dbus_system_domain(setroubleshoot_fixit_t, setroubleshoot_fixit_exec_t)
')

optional_policy(`
	gnome_dontaudit_search_config(setroubleshoot_fixit_t)
')

optional_policy(`
	rpm_exec(setroubleshoot_fixit_t)
	rpm_signull(setroubleshoot_fixit_t)
	rpm_read_db(setroubleshoot_fixit_t)
	rpm_dontaudit_manage_db(setroubleshoot_fixit_t)
	rpm_use_script_fds(setroubleshoot_fixit_t)
')

optional_policy(`
	policykit_dbus_chat(setroubleshoot_fixit_t)
	userdom_read_all_users_state(setroubleshoot_fixit_t)
')
