policy_module(inetd, 1.18.0)

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

type inetd_t;
type inetd_exec_t;
init_daemon_domain(inetd_t, inetd_exec_t)

type inetd_log_t;
logging_log_file(inetd_log_t)

type inetd_tmp_t;
files_tmp_file(inetd_tmp_t)

type inetd_runtime_t;
files_runtime_file(inetd_runtime_t)

type inetd_child_t;
type inetd_child_exec_t;
inetd_service_domain(inetd_child_t, inetd_child_exec_t)

type inetd_child_runtime_t alias inetd_child_var_run_t;
files_runtime_file(inetd_child_runtime_t)

type inetd_child_tmp_t;
files_tmp_file(inetd_child_tmp_t)

ifdef(`enable_mcs',`
	init_ranged_daemon_domain(inetd_t, inetd_exec_t, s0 - mcs_systemhigh)
')

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

allow inetd_t self:capability { setgid setuid sys_resource };
dontaudit inetd_t self:capability sys_tty_config;
allow inetd_t self:process { setsched setexec setrlimit };
allow inetd_t self:fifo_file rw_fifo_file_perms;
allow inetd_t self:tcp_socket { accept listen };
allow inetd_t self:fd use;

allow inetd_t inetd_log_t:file { append_file_perms create_file_perms setattr_file_perms };
logging_log_filetrans(inetd_t, inetd_log_t, file)

manage_dirs_pattern(inetd_t, inetd_tmp_t, inetd_tmp_t)
manage_files_pattern(inetd_t, inetd_tmp_t, inetd_tmp_t)
files_tmp_filetrans(inetd_t, inetd_tmp_t, { file dir })

allow inetd_t inetd_runtime_t:file manage_file_perms;
files_runtime_filetrans(inetd_t, inetd_runtime_t, file)

kernel_read_kernel_sysctls(inetd_t)
kernel_list_proc(inetd_t)
kernel_read_proc_symlinks(inetd_t)
kernel_read_system_state(inetd_t)

corecmd_bin_domtrans(inetd_t, inetd_child_t)
corecmd_bin_entry_type(inetd_child_t)

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

corenet_sendrecv_all_client_packets(inetd_t)
corenet_tcp_connect_all_ports(inetd_t)

corenet_sendrecv_amanda_server_packets(inetd_t)
corenet_tcp_bind_amanda_port(inetd_t)
corenet_udp_bind_amanda_port(inetd_t)

corenet_sendrecv_auth_server_packets(inetd_t)
corenet_tcp_bind_auth_port(inetd_t)

corenet_sendrecv_comsat_server_packets(inetd_t)
corenet_udp_bind_comsat_port(inetd_t)

corenet_sendrecv_dbskkd_server_packets(inetd_t)
corenet_tcp_bind_dbskkd_port(inetd_t)
corenet_udp_bind_dbskkd_port(inetd_t)

corenet_sendrecv_ftp_server_packets(inetd_t)
corenet_tcp_bind_ftp_port(inetd_t)
corenet_udp_bind_ftp_port(inetd_t)

corenet_sendrecv_inetd_child_server_packets(inetd_t)
corenet_tcp_bind_inetd_child_port(inetd_t)
corenet_udp_bind_inetd_child_port(inetd_t)

corenet_sendrecv_ircd_server_packets(inetd_t)
corenet_tcp_bind_ircd_port(inetd_t)

corenet_sendrecv_ktalkd_server_packets(inetd_t)
corenet_udp_bind_ktalkd_port(inetd_t)

corenet_sendrecv_pop_server_packets(inetd_t)
corenet_tcp_bind_pop_port(inetd_t)

corenet_sendrecv_printer_server_packets(inetd_t)
corenet_tcp_bind_printer_port(inetd_t)

corenet_sendrecv_rlogind_server_packets(inetd_t)
corenet_udp_bind_rlogind_port(inetd_t)

corenet_sendrecv_rsh_server_packets(inetd_t)
corenet_udp_bind_rsh_port(inetd_t)
corenet_tcp_bind_rsh_port(inetd_t)

corenet_sendrecv_rsync_server_packets(inetd_t)
corenet_tcp_bind_rsync_port(inetd_t)
corenet_udp_bind_rsync_port(inetd_t)

corenet_sendrecv_stunnel_server_packets(inetd_t)
corenet_tcp_bind_stunnel_port(inetd_t)

corenet_sendrecv_swat_server_packets(inetd_t)
corenet_tcp_bind_swat_port(inetd_t)
corenet_udp_bind_swat_port(inetd_t)

corenet_sendrecv_telnetd_server_packets(inetd_t)
corenet_tcp_bind_telnetd_port(inetd_t)

corenet_sendrecv_tftp_server_packets(inetd_t)
corenet_udp_bind_tftp_port(inetd_t)

corenet_sendrecv_ssh_server_packets(inetd_t)
corenet_tcp_bind_ssh_port(inetd_t)

corenet_sendrecv_git_server_packets(inetd_t)
corenet_tcp_bind_git_port(inetd_t)
corenet_udp_bind_git_port(inetd_t)

dev_read_sysfs(inetd_t)

domain_use_interactive_fds(inetd_t)

fs_getattr_all_fs(inetd_t)
fs_search_auto_mountpoints(inetd_t)

selinux_validate_context(inetd_t)
selinux_compute_create_context(inetd_t)

files_read_etc_runtime_files(inetd_t)

auth_use_nsswitch(inetd_t)

logging_send_syslog_msg(inetd_t)

miscfiles_read_localization(inetd_t)

mls_fd_share_all_levels(inetd_t)
mls_socket_read_to_clearance(inetd_t)
mls_socket_write_to_clearance(inetd_t)
mls_net_outbound_all_levels(inetd_t)
mls_process_set_level(inetd_t)

userdom_dontaudit_use_unpriv_user_fds(inetd_t)
userdom_dontaudit_search_user_home_dirs(inetd_t)

ifdef(`distro_redhat',`
	optional_policy(`
		unconfined_domain(inetd_t)
	')
')

ifdef(`enable_mls',`
	corenet_tcp_recvfrom_netlabel(inetd_t)
	corenet_udp_recvfrom_netlabel(inetd_t)
')

optional_policy(`
	amanda_search_lib(inetd_t)
')

optional_policy(`
	seutil_sigchld_newrole(inetd_t)
')

optional_policy(`
	tftp_read_config_files(inetd_t)
')

optional_policy(`
	unconfined_domtrans(inetd_t)
')

########################################
#
# Child local policy
#

allow inetd_child_t self:capability { setgid setuid };
allow inetd_child_t self:process signal_perms;
allow inetd_child_t self:fifo_file rw_fifo_file_perms;
allow inetd_child_t self:tcp_socket { accept listen };

manage_dirs_pattern(inetd_child_t, inetd_child_tmp_t, inetd_child_tmp_t)
manage_files_pattern(inetd_child_t, inetd_child_tmp_t, inetd_child_tmp_t)
files_tmp_filetrans(inetd_child_t, inetd_child_tmp_t, { file dir })

manage_files_pattern(inetd_child_t, inetd_child_runtime_t, inetd_child_runtime_t)
files_runtime_filetrans(inetd_child_t, inetd_child_runtime_t, file)

kernel_read_kernel_sysctls(inetd_child_t)
kernel_read_network_state(inetd_child_t)
kernel_read_system_state(inetd_child_t)

dev_read_urand(inetd_child_t)

fs_getattr_xattr_fs(inetd_child_t)

files_read_etc_runtime_files(inetd_child_t)

auth_use_nsswitch(inetd_child_t)

logging_send_syslog_msg(inetd_child_t)

miscfiles_read_localization(inetd_child_t)

optional_policy(`
	unconfined_domain(inetd_child_t)
')
