policy_module(imaze, 1.8.0)

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

type imazesrv_t;
type imazesrv_exec_t;
application_executable_file(imazesrv_exec_t)
init_daemon_domain(imazesrv_t, imazesrv_exec_t)

type imazesrv_data_t;
files_type(imazesrv_data_t)

type imazesrv_log_t;
logging_log_file(imazesrv_log_t)

type imazesrv_var_run_t;
files_pid_file(imazesrv_var_run_t)

########################################
#
# Local policy
#

dontaudit imazesrv_t self:capability sys_tty_config;
allow imazesrv_t self:process ~{ ptrace setcurrent setexec setfscreate setrlimit execmem execstack execheap };
allow imazesrv_t self:fifo_file rw_fifo_file_perms;
allow imazesrv_t self:tcp_socket { accept listen };
allow imazesrv_t self:unix_dgram_socket sendto;
allow imazesrv_t self:unix_stream_socket { accept connectto listen };

allow imazesrv_t imazesrv_data_t:dir list_dir_perms;
read_files_pattern(imazesrv_t, imazesrv_data_t, imazesrv_data_t)
read_lnk_files_pattern(imazesrv_t, imazesrv_data_t, imazesrv_data_t)

allow imazesrv_t imazesrv_log_t:file { append_file_perms create_file_perms setattr_file_perms };
logging_log_filetrans(imazesrv_t, imazesrv_log_t, file)

manage_files_pattern(imazesrv_t, imazesrv_var_run_t, imazesrv_var_run_t)
files_pid_filetrans(imazesrv_t, imazesrv_var_run_t, file)

kernel_list_proc(imazesrv_t)
kernel_read_kernel_sysctls(imazesrv_t)
kernel_read_proc_symlinks(imazesrv_t)

corenet_all_recvfrom_netlabel(imazesrv_t)
corenet_tcp_sendrecv_generic_if(imazesrv_t)
corenet_udp_sendrecv_generic_if(imazesrv_t)
corenet_tcp_sendrecv_generic_node(imazesrv_t)
corenet_udp_sendrecv_generic_node(imazesrv_t)
corenet_tcp_bind_generic_node(imazesrv_t)
corenet_udp_bind_generic_node(imazesrv_t)

corenet_sendrecv_imaze_server_packets(imazesrv_t)
corenet_tcp_bind_imaze_port(imazesrv_t)
corenet_tcp_sendrecv_imaze_port(imazesrv_t)
corenet_udp_bind_imaze_port(imazesrv_t)
corenet_udp_sendrecv_imaze_port(imazesrv_t)

dev_read_sysfs(imazesrv_t)

domain_use_interactive_fds(imazesrv_t)

fs_getattr_all_fs(imazesrv_t)
fs_search_auto_mountpoints(imazesrv_t)

auth_use_nsswitch(imazesrv_t)

logging_send_syslog_msg(imazesrv_t)

userdom_use_unpriv_users_fds(imazesrv_t)
userdom_dontaudit_search_user_home_dirs(imazesrv_t)

optional_policy(`
	seutil_sigchld_newrole(imazesrv_t)
')

optional_policy(`
	udev_read_db(imazesrv_t)
')
