policy_module(tgtd,1.0.0)

type tgtd_t;
type tgtd_exec_t;
init_daemon_domain(tgtd_t, tgtd_exec_t)

type tgtd_var_lib_t;
files_type(tgtd_var_lib_t)

type tgtd_etc_t;
files_config_file(tgtd_etc_t)

type tgtd_initrc_exec_t;
init_script_file(tgtd_initrc_exec_t)

type tgtd_tmp_t;
files_tmp_file(tgtd_tmp_t)

########################################
#
# tgtd script local policy
#

allow tgtd_t self:capability sys_resource;
allow tgtd_t self:fifo_file { read write };
allow tgtd_t self:netlink_route_socket r_netlink_socket_perms;
allow tgtd_t self:process { setrlimit signal };
allow tgtd_t self:shm create_shm_prems;
allow tgtd_t self:tcp_socket create_stream_socket_perms;
allow tgtd_t self:udp_socket create_socket_perms;
allow tgtd_t self:unix_dgram_socket create_socket_perms;

manage_dirs_pattern(tgtd_t, tmp_t, tgtd_tmp_t)
manage_files_pattern(tgtd_t, tmp_t, tgtd_tmp_t)
manage_sock_files_pattern(tgtd_t, tmp_t, tgtd_tmp_t)
filetrans_pattern(tgtd_t, tmp_t, tgtd_tmp_t, { dir file sock_file })

kernel_read_fs_sysctls(tgtd_t)

corenet_all_recvfrom_netlabel(tgtd_t)
corenet_all_recvfrom_unlabeled(tgtd_t)
corenet_tcp_bind_generic_node(tgtd_t)
corenet_tcp_bind_iscsi_port(tgtd_t)
corenet_tcp_sendrecv_iscsi_port(tgtd_t)

# Probably need tgtd_tmpfs_t
fs_rw_tmpfs_files(tgtd_t)
fs_associate_tmpfs(tgtd_t)

storage_getattr_fixed_disk_dev(tgtd_t)

logging_send_syslog_msg(tgtd_t)

# Are you sure it needs this or just read?
miscfiles_rw_localization(tgtd_t)

tgtd_read_config_files(tgtd_t)
tgtd_manage_var_lib(tgtd_t)

#This should not be here, probably whatever process is running initrc_t needs its own policy.

require { type initrc_t; }

allow tgtd_t initrc_t:sem rw_shm_perms;

