policy_module(dspam, 1.1.0)

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

type dspam_t;
type dspam_exec_t;
init_daemon_domain(dspam_t, dspam_exec_t)

type dspam_initrc_exec_t;
init_script_file(dspam_initrc_exec_t)

type dspam_log_t;
logging_log_file(dspam_log_t)

type dspam_var_lib_t;
files_type(dspam_var_lib_t)

type dspam_var_run_t;
files_pid_file(dspam_var_run_t)

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

allow dspam_t self:capability net_admin;
allow dspam_t self:process signal;

allow dspam_t self:tcp_socket { listen accept };

allow dspam_t self:fifo_file rw_fifo_file_perms;
allow dspam_t self:unix_stream_socket { accept listen };

manage_dirs_pattern(dspam_t, dspam_log_t, dspam_log_t)
append_files_pattern(dspam_t, dspam_log_t, dspam_log_t)
create_files_pattern(dspam_t, dspam_log_t, dspam_log_t)
setattr_files_pattern(dspam_t, dspam_log_t, dspam_log_t)
logging_log_filetrans(dspam_t, dspam_log_t, dir)

manage_dirs_pattern(dspam_t, dspam_var_lib_t, dspam_var_lib_t)
manage_files_pattern(dspam_t, dspam_var_lib_t, dspam_var_lib_t)
files_var_lib_filetrans(dspam_t, dspam_var_lib_t, dir)

manage_dirs_pattern(dspam_t, dspam_var_run_t, dspam_var_run_t)
manage_files_pattern(dspam_t, dspam_var_run_t, dspam_var_run_t)
manage_sock_files_pattern(dspam_t, dspam_var_run_t, dspam_var_run_t)
files_pid_filetrans(dspam_t, dspam_var_run_t, dir)

corenet_all_recvfrom_unlabeled(dspam_t)
corenet_all_recvfrom_netlabel(dspam_t)
corenet_tcp_sendrecv_generic_if(dspam_t)
corenet_tcp_sendrecv_generic_node(dspam_t)
corenet_tcp_bind_generic_node(dspam_t)

corenet_sendrecv_spamd_client_packets(dspam_t)
corenet_sendrecv_spamd_server_packets(dspam_t)
corenet_tcp_bind_spamd_port(dspam_t)
corenet_tcp_connect_spamd_port(dspam_t)
corenet_tcp_sendrecv_spamd_port(dspam_t)
corenet_tcp_bind_lmtp_port(dspam_t)
corenet_tcp_connect_lmtp_port(dspam_t)

kernel_read_system_state(dspam_t)

corecmd_exec_shell(dspam_t)

files_search_spool(dspam_t)

auth_use_nsswitch(dspam_t)

logging_send_syslog_msg(dspam_t)

optional_policy(`
	apache_content_template(dspam)
	apache_content_alias_template(dspam, dspam)

    manage_dirs_pattern(dspam_t, dspam_rw_content_t, dspam_rw_content_t)
    manage_files_pattern(dspam_t, dspam_rw_content_t, dspam_rw_content_t)
    allow dspam_t dspam_rw_content_t:file map;

	read_files_pattern(dspam_script_t, dspam_var_lib_t, dspam_var_lib_t)

    auth_read_passwd(dspam_script_t)

	files_search_var_lib(dspam_script_t)

	domain_dontaudit_read_all_domains_state(dspam_script_t)

	term_dontaudit_search_ptys(dspam_script_t)
	term_dontaudit_getattr_all_ttys(dspam_script_t)
	term_dontaudit_getattr_all_ptys(dspam_script_t)

	init_read_utmp(dspam_script_t)

	logging_send_syslog_msg(dspam_script_t)

	mta_send_mail(dspam_script_t)

	optional_policy(`
	    mysql_tcp_connect(dspam_script_t)
	    mysql_stream_connect(dspam_script_t)
	')
')

optional_policy(`
	mysql_stream_connect(dspam_t)
	mysql_read_config(dspam_t)

	mysql_tcp_connect(dspam_t)
')

optional_policy(`
	postgresql_stream_connect(dspam_t)
	postgresql_unpriv_client(dspam_t)

	postgresql_tcp_connect(dspam_t)
')

optional_policy(`
    postfix_rw_inherited_master_pipes(dspam_t)
    postfix_list_spool(dspam_t)
')

optional_policy(`
    procmail_domtrans(dspam_t)
')
