policy_module(radius, 1.13.0)

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

## <desc>
##      <p>
##      Determine whether radius can use JIT compiler.
##      </p>
## </desc>
gen_tunable(radius_use_jit, false)

type radiusd_t;
type radiusd_exec_t;
init_daemon_domain(radiusd_t, radiusd_exec_t)
init_nnp_daemon_domain(radiusd_t)

type radiusd_etc_t;
files_config_file(radiusd_etc_t)
systemd_mount_dir(radiusd_etc_t)

type radiusd_etc_rw_t;
files_type(radiusd_etc_rw_t)

type radiusd_initrc_exec_t;
init_script_file(radiusd_initrc_exec_t)

type radiusd_log_t;
logging_log_file(radiusd_log_t)
systemd_mount_dir(radiusd_log_t)

type radiusd_var_lib_t;
files_type(radiusd_var_lib_t)

type radiusd_var_run_t;
files_pid_file(radiusd_var_run_t)
systemd_mount_dir(radiusd_var_run_t)

type radiusd_unit_file_t;
systemd_unit_file(radiusd_unit_file_t)

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

allow radiusd_t self:capability { chown dac_read_search dac_override fsetid net_raw kill setgid setuid sys_resource sys_tty_config sys_ptrace };
dontaudit radiusd_t self:capability sys_tty_config;
allow radiusd_t self:process { getsched setrlimit setsched sigkill signal};
allow radiusd_t self:fifo_file rw_fifo_file_perms;
allow radiusd_t self:unix_stream_socket { accept listen };
allow radiusd_t self:tcp_socket { accept listen };

allow radiusd_t radiusd_etc_t:dir list_dir_perms;
allow radiusd_t radiusd_etc_t:file read_file_perms;
allow radiusd_t radiusd_etc_t:lnk_file read_lnk_file_perms;

tunable_policy(`deny_ptrace',`',`
	allow radiusd_t self:process ptrace;
')

manage_dirs_pattern(radiusd_t, radiusd_etc_rw_t, radiusd_etc_rw_t)
manage_files_pattern(radiusd_t, radiusd_etc_rw_t, radiusd_etc_rw_t)
manage_lnk_files_pattern(radiusd_t, radiusd_etc_rw_t, radiusd_etc_rw_t)
filetrans_pattern(radiusd_t, radiusd_etc_t, radiusd_etc_rw_t, { dir file lnk_file })
allow radiusd_t radiusd_etc_rw_t:file map;

manage_dirs_pattern(radiusd_t, radiusd_log_t, radiusd_log_t)
manage_files_pattern(radiusd_t, radiusd_log_t, radiusd_log_t)
logging_log_filetrans(radiusd_t, radiusd_log_t, { file dir })

manage_files_pattern(radiusd_t, radiusd_var_lib_t, radiusd_var_lib_t)

manage_sock_files_pattern(radiusd_t, radiusd_var_run_t, radiusd_var_run_t)
manage_dirs_pattern(radiusd_t, radiusd_var_run_t, radiusd_var_run_t)
manage_files_pattern(radiusd_t, radiusd_var_run_t, radiusd_var_run_t)
files_pid_filetrans(radiusd_t, radiusd_var_run_t, { file sock_file dir })

kernel_read_kernel_sysctls(radiusd_t)
kernel_read_system_state(radiusd_t)
kernel_read_net_sysctls(radiusd_t)
kernel_search_network_sysctl(radiusd_t)

corenet_all_recvfrom_netlabel(radiusd_t)
corenet_tcp_sendrecv_generic_if(radiusd_t)
corenet_udp_sendrecv_generic_if(radiusd_t)
corenet_tcp_sendrecv_generic_node(radiusd_t)
corenet_udp_sendrecv_generic_node(radiusd_t)
corenet_tcp_sendrecv_all_ports(radiusd_t)
corenet_udp_sendrecv_all_ports(radiusd_t)
corenet_udp_bind_generic_node(radiusd_t)

corenet_sendrecv_bfd_control_server_packets(radiusd_t)
corenet_udp_bind_bfd_control_port(radiusd_t)
corenet_udp_sendrecv_bfd_control_port(radiusd_t)

corenet_sendrecv_bfd_echo_server_packets(radiusd_t)
corenet_udp_bind_bfd_echo_port(radiusd_t)
corenet_udp_sendrecv_bfd_echo_port(radiusd_t)

corenet_sendrecv_dhcpc_server_packets(radiusd_t)
corenet_udp_bind_dhcpc_port(radiusd_t)
corenet_udp_sendrecv_dhcpc_port(radiusd_t)

corenet_sendrecv_dhcpd_server_packets(radiusd_t)
corenet_udp_bind_dhcpd_port(radiusd_t)
corenet_udp_sendrecv_dhcpd_port(radiusd_t)

corenet_tcp_connect_postgresql_port(radiusd_t)
corenet_tcp_connect_http_port(radiusd_t)

corenet_sendrecv_radacct_server_packets(radiusd_t)
corenet_tcp_bind_radacct_port(radiusd_t)
corenet_udp_bind_radacct_port(radiusd_t)

corenet_sendrecv_radius_server_packets(radiusd_t)
corenet_tcp_bind_radius_port(radiusd_t)
corenet_udp_bind_radius_port(radiusd_t)

corenet_sendrecv_radsec_server_packets(radiusd_t)
corenet_tcp_bind_radsec_port(radiusd_t)
corenet_udp_bind_radsec_port(radiusd_t)
corenet_tcp_connect_radsec_port(radiusd_t)

corenet_sendrecv_snmp_client_packets(radiusd_t)
corenet_tcp_connect_snmp_port(radiusd_t)

corenet_sendrecv_vqp_server_packets(radiusd_t)
corenet_udp_bind_vqp_port(radiusd_t)
corenet_udp_sendrecv_vqp_port(radiusd_t)

corenet_sendrecv_generic_server_packets(radiusd_t)
corenet_udp_bind_generic_port(radiusd_t)
corenet_dontaudit_udp_bind_all_ports(radiusd_t)

corecmd_exec_bin(radiusd_t)
corecmd_exec_shell(radiusd_t)

dev_read_sysfs(radiusd_t)

domain_use_interactive_fds(radiusd_t)

fs_getattr_all_fs(radiusd_t)
fs_search_auto_mountpoints(radiusd_t)

files_read_etc_runtime_files(radiusd_t)
files_dontaudit_list_tmp(radiusd_t)

auth_use_nsswitch(radiusd_t)
auth_read_shadow(radiusd_t)
auth_domtrans_chk_passwd(radiusd_t)

libs_exec_lib_files(radiusd_t)

logging_send_syslog_msg(radiusd_t)

miscfiles_read_generic_certs(radiusd_t)

sysnet_use_ldap(radiusd_t)

userdom_dontaudit_use_unpriv_user_fds(radiusd_t)
userdom_dontaudit_search_user_home_dirs(radiusd_t)

tunable_policy(`radius_use_jit',`
    allow radiusd_t self:process execmem;
',`
    dontaudit radiusd_t self:process execmem;
')

optional_policy(`
	cron_system_entry(radiusd_t, radiusd_exec_t)
')

optional_policy(`
	gssproxy_stream_connect(radiusd_t)
')

optional_policy(`
    kerberos_tmp_filetrans_host_rcache(radiusd_t, "host_0")
    kerberos_manage_host_rcache(radiusd_t)
')

optional_policy(`
	logrotate_exec(radiusd_t)
')

optional_policy(`
	mysql_read_config(radiusd_t)
	mysql_stream_connect(radiusd_t)
	mysql_tcp_connect(radiusd_t)
')

optional_policy(`
    postgresql_stream_connect(radiusd_t)
    postgresql_tcp_connect(radiusd_t)
')

optional_policy(`
	samba_domtrans_winbind_helper(radiusd_t)
')

optional_policy(`
	seutil_sigchld_newrole(radiusd_t)
')

optional_policy(`
    snmp_read_snmp_var_lib_files(radiusd_t)
    snmp_read_snmp_var_lib_files(radiusd_t)
')

optional_policy(`
	udev_read_db(radiusd_t)
')
