policy_module(zarafa, 1.2.0)

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

## <desc>
##  <p>
## Allow zarafa domains to setrlimit/sys_resource.
##  </p>
## </desc>
gen_tunable(zarafa_setrlimit, false)

attribute zarafa_domain;

zarafa_domain_template(deliver)

type zarafa_deliver_tmp_t;
files_tmp_file(zarafa_deliver_tmp_t)

type zarafa_etc_t;
files_config_file(zarafa_etc_t)

zarafa_domain_template(gateway)
zarafa_domain_template(ical)
zarafa_domain_template(indexer)

type zarafa_indexer_tmp_t;
files_tmp_file(zarafa_indexer_tmp_t)

zarafa_domain_template(monitor)
zarafa_domain_template(server)

type zarafa_server_tmp_t;
files_tmp_file(zarafa_server_tmp_t)

type zarafa_share_t;
files_type(zarafa_share_t)

zarafa_domain_template(spooler)

type zarafa_var_lib_t;
files_tmp_file(zarafa_var_lib_t)

########################################
#
# zarafa-deliver local policy
#

manage_dirs_pattern(zarafa_deliver_t, zarafa_deliver_tmp_t, zarafa_deliver_tmp_t)
manage_files_pattern(zarafa_deliver_t, zarafa_deliver_tmp_t, zarafa_deliver_tmp_t)
files_tmp_filetrans(zarafa_deliver_t, zarafa_deliver_tmp_t, { file dir })

auth_use_nsswitch(zarafa_deliver_t)

corenet_tcp_bind_lmtp_port(zarafa_deliver_t)

########################################
#
# zarafa_gateway local policy
#
corenet_all_recvfrom_netlabel(zarafa_gateway_t)
corenet_tcp_sendrecv_generic_if(zarafa_gateway_t)
corenet_tcp_sendrecv_generic_node(zarafa_gateway_t)
corenet_tcp_sendrecv_all_ports(zarafa_gateway_t)
corenet_tcp_bind_generic_node(zarafa_gateway_t)
corenet_tcp_bind_pop_port(zarafa_gateway_t)

######################################
#
# zarafa-indexer local policy
#


manage_dirs_pattern(zarafa_indexer_t, zarafa_indexer_tmp_t, zarafa_indexer_tmp_t)
manage_files_pattern(zarafa_indexer_t, zarafa_indexer_tmp_t, zarafa_indexer_tmp_t)
files_tmp_filetrans(zarafa_indexer_t, zarafa_indexer_tmp_t, { file dir })

manage_dirs_pattern(zarafa_indexer_t, zarafa_var_lib_t, zarafa_var_lib_t)
manage_files_pattern(zarafa_indexer_t, zarafa_var_lib_t, zarafa_var_lib_t)
manage_lnk_files_pattern(zarafa_indexer_t, zarafa_var_lib_t, zarafa_var_lib_t)

auth_use_nsswitch(zarafa_indexer_t)

#######################################
#
# zarafa-ical local policy
#


corenet_all_recvfrom_netlabel(zarafa_ical_t)
corenet_tcp_sendrecv_generic_if(zarafa_ical_t)
corenet_tcp_sendrecv_generic_node(zarafa_ical_t)
corenet_tcp_sendrecv_all_ports(zarafa_ical_t)
corenet_tcp_bind_generic_node(zarafa_ical_t)
corenet_tcp_bind_http_cache_port(zarafa_ical_t)

auth_use_nsswitch(zarafa_ical_t)

######################################
#
# zarafa-monitor local policy
#


auth_use_nsswitch(zarafa_monitor_t)

########################################
#
# zarafa_server local policy
#

allow zarafa_server_t self:capability net_bind_service;

manage_dirs_pattern(zarafa_server_t, zarafa_server_tmp_t, zarafa_server_tmp_t)
manage_files_pattern(zarafa_server_t, zarafa_server_tmp_t, zarafa_server_tmp_t)
files_tmp_filetrans(zarafa_server_t, zarafa_server_tmp_t, { file dir })

manage_dirs_pattern(zarafa_server_t, zarafa_var_lib_t, zarafa_var_lib_t)
manage_files_pattern(zarafa_server_t, zarafa_var_lib_t, zarafa_var_lib_t)
manage_lnk_files_pattern(zarafa_server_t, zarafa_var_lib_t, zarafa_var_lib_t)
files_var_lib_filetrans(zarafa_server_t, zarafa_var_lib_t, { file dir lnk_file })

stream_connect_pattern(zarafa_server_t, zarafa_indexer_var_run_t, zarafa_indexer_var_run_t, zarafa_indexer_t)

corenet_all_recvfrom_netlabel(zarafa_server_t)
corenet_tcp_sendrecv_generic_if(zarafa_server_t)
corenet_tcp_sendrecv_generic_node(zarafa_server_t)
corenet_tcp_sendrecv_all_ports(zarafa_server_t)
corenet_tcp_bind_generic_node(zarafa_server_t)
corenet_tcp_bind_zarafa_port(zarafa_server_t)


auth_use_nsswitch(zarafa_server_t)

logging_send_syslog_msg(zarafa_server_t)
logging_send_audit_msgs(zarafa_server_t)

sysnet_dns_name_resolve(zarafa_server_t)

optional_policy(`
	kerberos_use(zarafa_server_t)
')

optional_policy(`
	mysql_stream_connect(zarafa_server_t)
')

########################################
#
# zarafa_spooler local policy
#

can_exec(zarafa_spooler_t, zarafa_spooler_exec_t)

corenet_all_recvfrom_netlabel(zarafa_spooler_t)
corenet_tcp_sendrecv_generic_if(zarafa_spooler_t)
corenet_tcp_sendrecv_generic_node(zarafa_spooler_t)
corenet_tcp_sendrecv_all_ports(zarafa_spooler_t)
corenet_tcp_connect_smtp_port(zarafa_spooler_t)

auth_use_nsswitch(zarafa_spooler_t)

########################################
#
# zarafa_gateway local policy
#
corenet_tcp_bind_pop_port(zarafa_gateway_t)

#######################################
#
# zarafa-ical local policy
#

corenet_tcp_bind_http_cache_port(zarafa_ical_t)

######################################
#
# zarafa-monitor local policy
#


########################################
#
# zarafa domains local policy
#

# bad permission on /etc/zarafa
allow zarafa_domain self:capability { kill dac_read_search  chown setgid setuid };
allow zarafa_domain self:process { signal_perms };
allow zarafa_domain self:fifo_file rw_fifo_file_perms;
allow zarafa_domain self:tcp_socket create_stream_socket_perms;
allow zarafa_domain self:unix_stream_socket create_stream_socket_perms;

tunable_policy(`zarafa_setrlimit',`
    allow zarafa_domain self:capability sys_resource;
    allow zarafa_domain self:process setrlimit;
')

stream_connect_pattern(zarafa_domain, zarafa_server_var_run_t, zarafa_server_var_run_t, zarafa_server_t)

read_files_pattern(zarafa_domain, zarafa_etc_t, zarafa_etc_t)

dev_read_rand(zarafa_domain)
dev_read_urand(zarafa_domain)

dev_read_sysfs(zarafa_domain)
