policy_module(prelude, 1.4.0)

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

type prelude_t;
type prelude_exec_t;
init_daemon_domain(prelude_t, prelude_exec_t)

type prelude_initrc_exec_t;
init_script_file(prelude_initrc_exec_t)

type prelude_spool_t;
files_spool_file(prelude_spool_t)

type prelude_log_t;
logging_log_file(prelude_log_t)

type prelude_var_run_t;
files_pid_file(prelude_var_run_t)

type prelude_var_lib_t;
files_type(prelude_var_lib_t)

type prelude_audisp_t;
type prelude_audisp_exec_t;
init_daemon_domain(prelude_audisp_t, prelude_audisp_exec_t)
logging_dispatcher_domain(prelude_audisp_t, prelude_audisp_exec_t)

type prelude_audisp_var_run_t;
files_pid_file(prelude_audisp_var_run_t)

type prelude_correlator_t;
type prelude_correlator_exec_t;
init_daemon_domain(prelude_correlator_t, prelude_correlator_exec_t)

type prelude_correlator_config_t;
files_config_file(prelude_correlator_config_t)

type prelude_lml_t;
type prelude_lml_exec_t;
init_daemon_domain(prelude_lml_t, prelude_lml_exec_t)

type prelude_lml_tmp_t;
files_tmp_file(prelude_lml_tmp_t)

type prelude_lml_var_run_t;
files_pid_file(prelude_lml_var_run_t)

########################################
#
# Prelude local policy
#

allow prelude_t self:capability { dac_read_search  sys_tty_config };
allow prelude_t self:fifo_file rw_fifo_file_perms;
allow prelude_t self:unix_stream_socket { accept listen };
allow prelude_t self:tcp_socket { accept listen };

allow prelude_t prelude_log_t:dir setattr_dir_perms;
append_files_pattern(prelude_t, prelude_log_t, prelude_log_t)
create_files_pattern(prelude_t, prelude_log_t, prelude_log_t)
setattr_files_pattern(prelude_t, prelude_log_t, prelude_log_t)
logging_log_filetrans(prelude_t, prelude_log_t, file)

manage_dirs_pattern(prelude_t, prelude_spool_t, prelude_spool_t)
manage_files_pattern(prelude_t, prelude_spool_t, prelude_spool_t)

manage_dirs_pattern(prelude_t, prelude_var_lib_t, prelude_var_lib_t)
manage_files_pattern(prelude_t, prelude_var_lib_t, prelude_var_lib_t)

manage_dirs_pattern(prelude_t, prelude_var_run_t, prelude_var_run_t)
manage_files_pattern(prelude_t, prelude_var_run_t, prelude_var_run_t)
manage_sock_files_pattern(prelude_t, prelude_var_run_t, prelude_var_run_t)
files_pid_filetrans(prelude_t, prelude_var_run_t, { dir file })

kernel_read_system_state(prelude_t)
kernel_read_sysctl(prelude_t)

corecmd_search_bin(prelude_t)

corenet_all_recvfrom_netlabel(prelude_t)
corenet_tcp_sendrecv_generic_if(prelude_t)
corenet_tcp_sendrecv_generic_node(prelude_t)
corenet_tcp_bind_generic_node(prelude_t)

corenet_sendrecv_prelude_server_packets(prelude_t)
corenet_tcp_bind_prelude_port(prelude_t)
corenet_sendrecv_prelude_client_packets(prelude_t)
corenet_tcp_connect_prelude_port(prelude_t)
corenet_tcp_sendrecv_prelude_port(prelude_t)

dev_read_rand(prelude_t)
dev_read_urand(prelude_t)

files_read_etc_runtime_files(prelude_t)
files_search_spool(prelude_t)
files_search_tmp(prelude_t)

fs_rw_anon_inodefs_files(prelude_t)

auth_use_nsswitch(prelude_t)

logging_send_audit_msgs(prelude_t)
logging_send_syslog_msg(prelude_t)

optional_policy(`
	mysql_stream_connect(prelude_t)
	mysql_tcp_connect(prelude_t)
')

optional_policy(`
	postgresql_stream_connect(prelude_t)
	postgresql_tcp_connect(prelude_t)
')

########################################
#
# Audisp local policy
#

allow prelude_audisp_t self:capability { dac_read_search  ipc_lock setpcap };
allow prelude_audisp_t self:process { getcap setcap };
allow prelude_audisp_t self:fifo_file rw_fifo_file_perms;
allow prelude_audisp_t self:unix_stream_socket { accept listen };

manage_dirs_pattern(prelude_audisp_t, prelude_spool_t, prelude_spool_t)
manage_files_pattern(prelude_audisp_t, prelude_spool_t, prelude_spool_t)

manage_sock_files_pattern(prelude_audisp_t, prelude_audisp_var_run_t, prelude_audisp_var_run_t)
files_pid_filetrans(prelude_audisp_t, prelude_audisp_var_run_t, sock_file)

kernel_read_sysctl(prelude_audisp_t)
kernel_read_system_state(prelude_audisp_t)

corecmd_search_bin(prelude_audisp_t)

corenet_all_recvfrom_netlabel(prelude_audisp_t)
corenet_tcp_sendrecv_generic_if(prelude_audisp_t)
corenet_tcp_sendrecv_generic_node(prelude_audisp_t)

corenet_sendrecv_prelude_client_packets(prelude_audisp_t)
corenet_tcp_connect_prelude_port(prelude_audisp_t)
corenet_tcp_sendrecv_prelude_port(prelude_audisp_t)

dev_read_rand(prelude_audisp_t)
dev_read_urand(prelude_audisp_t)

domain_use_interactive_fds(prelude_audisp_t)

files_read_etc_runtime_files(prelude_audisp_t)
files_search_spool(prelude_audisp_t)
files_search_tmp(prelude_audisp_t)

logging_send_syslog_msg(prelude_audisp_t)

sysnet_dns_name_resolve(prelude_audisp_t)

########################################
#
# Correlator local policy
#

allow prelude_correlator_t self:capability { dac_read_search  };
allow prelude_correlator_t self:tcp_socket { accept listen };

manage_dirs_pattern(prelude_correlator_t, prelude_spool_t, prelude_spool_t)
manage_files_pattern(prelude_correlator_t, prelude_spool_t, prelude_spool_t)

allow prelude_correlator_t prelude_correlator_config_t:dir list_dir_perms;
read_files_pattern(prelude_correlator_t, prelude_correlator_config_t, prelude_correlator_config_t)

kernel_read_sysctl(prelude_correlator_t)

corecmd_search_bin(prelude_correlator_t)

corenet_all_recvfrom_netlabel(prelude_correlator_t)
corenet_tcp_sendrecv_generic_if(prelude_correlator_t)
corenet_tcp_sendrecv_generic_node(prelude_correlator_t)

corenet_sendrecv_prelude_client_packets(prelude_correlator_t)
corenet_tcp_connect_prelude_port(prelude_correlator_t)
corenet_tcp_sendrecv_prelude_port(prelude_correlator_t)

dev_read_rand(prelude_correlator_t)
dev_read_urand(prelude_correlator_t)

files_search_spool(prelude_correlator_t)

logging_send_syslog_msg(prelude_correlator_t)

sysnet_dns_name_resolve(prelude_correlator_t)

########################################
#
# Lml local declarations
#

allow prelude_lml_t self:capability { dac_read_search  };
allow prelude_lml_t self:tcp_socket { setopt create_socket_perms };
allow prelude_lml_t self:unix_dgram_socket create_socket_perms;
allow prelude_lml_t self:fifo_file rw_fifo_file_perms;
allow prelude_lml_t self:unix_stream_socket connectto;

manage_dirs_pattern(prelude_lml_t, prelude_lml_tmp_t, prelude_lml_tmp_t)
manage_files_pattern(prelude_lml_t, prelude_lml_tmp_t, prelude_lml_tmp_t)
files_tmp_filetrans(prelude_lml_t, prelude_lml_tmp_t, { file dir })

manage_dirs_pattern(prelude_lml_t, prelude_spool_t, prelude_spool_t)
manage_files_pattern(prelude_lml_t, prelude_spool_t, prelude_spool_t)

manage_dirs_pattern(prelude_lml_t, prelude_var_lib_t, prelude_var_lib_t)
manage_files_pattern(prelude_lml_t, prelude_var_lib_t, prelude_var_lib_t)

manage_files_pattern(prelude_lml_t, prelude_lml_var_run_t, prelude_lml_var_run_t)
files_pid_filetrans(prelude_lml_t, prelude_lml_var_run_t, file)

kernel_read_system_state(prelude_lml_t)
kernel_read_sysctl(prelude_lml_t)

corecmd_exec_bin(prelude_lml_t)

corenet_all_recvfrom_unlabeled(prelude_lml_t)
corenet_all_recvfrom_netlabel(prelude_lml_t)
corenet_tcp_sendrecv_generic_if(prelude_lml_t)
corenet_tcp_sendrecv_generic_node(prelude_lml_t)

corenet_sendrecv_prelude_client_packets(prelude_lml_t)
corenet_tcp_connect_prelude_port(prelude_lml_t)
corenet_tcp_sendrecv_prelude_port(prelude_lml_t)

dev_read_rand(prelude_lml_t)
dev_read_urand(prelude_lml_t)

files_list_etc(prelude_lml_t)
files_list_tmp(prelude_lml_t)
files_read_etc_runtime_files(prelude_lml_t)
files_search_spool(prelude_lml_t)

fs_getattr_all_fs(prelude_lml_t)
fs_list_inotifyfs(prelude_lml_t)
fs_rw_anon_inodefs_files(prelude_lml_t)

auth_use_nsswitch(prelude_lml_t)

libs_exec_lib_files(prelude_lml_t)
libs_read_lib_files(prelude_lml_t)

logging_send_syslog_msg(prelude_lml_t)
logging_read_generic_logs(prelude_lml_t)

userdom_read_all_users_state(prelude_lml_t)

optional_policy(`
	apache_search_sys_content(prelude_lml_t)
	apache_read_log(prelude_lml_t)
')

########################################
#
# Cgi Declarations
#

optional_policy(`
	apache_content_template(prewikka)
	apache_content_alias_template(prewikka, prewikka)

	can_exec(prewikka_script_t, prewikka_script_exec_t)

	files_search_tmp(prewikka_script_t)

	kernel_read_sysctl(prewikka_script_t)
	kernel_search_network_sysctl(prewikka_script_t)

	auth_use_nsswitch(prewikka_script_t)

	logging_send_syslog_msg(prewikka_script_t)

	apache_search_sys_content(prewikka_script_t)

	optional_policy(`
		mysql_stream_connect(prewikka_script_t)
		mysql_tcp_connect(prewikka_script_t)
	')

	optional_policy(`
		postgresql_stream_connect(prewikka_script_t)
		postgresql_tcp_connect(prewikka_script_t)
	')
')
