policy_module(psad, 1.1.0)

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

type psad_t;
type psad_exec_t;
init_daemon_domain(psad_t, psad_exec_t)

type psad_etc_t;
files_config_file(psad_etc_t)

type psad_initrc_exec_t;
init_script_file(psad_initrc_exec_t)

type psad_var_lib_t;
files_type(psad_var_lib_t)

type psad_var_log_t;
logging_log_file(psad_var_log_t)

type psad_var_run_t;
files_pid_file(psad_var_run_t)

type psad_tmp_t;
files_tmp_file(psad_tmp_t)

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

allow psad_t self:capability { net_admin net_raw setuid setgid dac_read_search  };
dontaudit psad_t self:capability sys_tty_config;
allow psad_t self:process { setrlimit signal_perms };
allow psad_t self:fifo_file rw_fifo_file_perms;
allow psad_t self:rawip_socket create_socket_perms;
allow psad_t self:netlink_tcpdiag_socket create_netlink_socket_perms;

allow psad_t psad_etc_t:dir list_dir_perms;
allow psad_t psad_etc_t:file read_file_perms;
allow psad_t psad_etc_t:lnk_file read_lnk_file_perms;

manage_dirs_pattern(psad_t, psad_var_log_t, psad_var_log_t)
append_files_pattern(psad_t, psad_var_log_t, psad_var_log_t)
create_files_pattern(psad_t, psad_var_log_t, psad_var_log_t)
setattr_files_pattern(psad_t, psad_var_log_t, psad_var_log_t)
logging_log_filetrans(psad_t, psad_var_log_t, { file dir })

manage_dirs_pattern(psad_t, psad_var_run_t, psad_var_run_t)
manage_files_pattern(psad_t, psad_var_run_t, psad_var_run_t)
manage_sock_files_pattern(psad_t, psad_var_run_t, psad_var_run_t)
files_pid_filetrans(psad_t, psad_var_run_t, { dir file sock_file })

manage_dirs_pattern(psad_t, psad_tmp_t, psad_tmp_t)
manage_files_pattern(psad_t, psad_tmp_t, psad_tmp_t)
files_tmp_filetrans(psad_t, psad_tmp_t, { file dir })

manage_fifo_files_pattern(psad_t, psad_var_lib_t, psad_var_lib_t)

kernel_read_system_state(psad_t)
kernel_read_network_state(psad_t)
kernel_read_net_sysctls(psad_t)

corecmd_exec_bin(psad_t)
corecmd_exec_shell(psad_t)

corenet_all_recvfrom_netlabel(psad_t)
corenet_tcp_sendrecv_generic_if(psad_t)
corenet_tcp_sendrecv_generic_node(psad_t)

corenet_sendrecv_whois_client_packets(psad_t)
corenet_tcp_connect_whois_port(psad_t)
corenet_tcp_sendrecv_whois_port(psad_t)

dev_read_urand(psad_t)

domain_read_all_domains_state(psad_t)

files_read_etc_runtime_files(psad_t)

fs_getattr_all_fs(psad_t)

auth_use_nsswitch(psad_t)

logging_read_generic_logs(psad_t)
logging_read_syslog_config(psad_t)
logging_send_syslog_msg(psad_t)
logging_mmap_journal(psad_t)

sysnet_exec_ifconfig(psad_t)

optional_policy(`
    dbus_stream_connect_system_dbusd(psad_t)
    dbus_send_system_bus(psad_t)
')

optional_policy(`
	iptables_domtrans(psad_t)
')

optional_policy(`
    journalctl_exec(psad_t)
')

optional_policy(`
	mta_send_mail(psad_t)
	mta_read_queue(psad_t)
')
