policy_module(ctdb, 1.7.0)

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

type ctdbd_t;
type ctdbd_exec_t;
init_daemon_domain(ctdbd_t, ctdbd_exec_t)

type ctdbd_initrc_exec_t;
init_script_file(ctdbd_initrc_exec_t)

type ctdbd_log_t;
logging_log_file(ctdbd_log_t)

type ctdbd_runtime_t alias ctdbd_var_run_t;
files_runtime_file(ctdbd_runtime_t)

type ctdbd_spool_t;
files_type(ctdbd_spool_t)

type ctdbd_tmp_t;
files_tmp_file(ctdbd_tmp_t)

type ctdbd_var_lib_t;
files_type(ctdbd_var_lib_t)

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

allow ctdbd_t self:capability { chown ipc_lock net_admin net_raw sys_nice };
allow ctdbd_t self:process { setpgid signal_perms setsched };
allow ctdbd_t self:fifo_file rw_fifo_file_perms;
allow ctdbd_t self:unix_stream_socket { accept connectto listen };
allow ctdbd_t self:netlink_route_socket r_netlink_socket_perms;
allow ctdbd_t self:packet_socket create_socket_perms;
allow ctdbd_t self:tcp_socket create_stream_socket_perms;

append_files_pattern(ctdbd_t, ctdbd_log_t, ctdbd_log_t)
create_files_pattern(ctdbd_t, ctdbd_log_t, ctdbd_log_t)
setattr_files_pattern(ctdbd_t, ctdbd_log_t, ctdbd_log_t)
logging_log_filetrans(ctdbd_t, ctdbd_log_t, file)

manage_files_pattern(ctdbd_t, ctdbd_tmp_t, ctdbd_tmp_t)
manage_sock_files_pattern(ctdbd_t, ctdbd_tmp_t, ctdbd_tmp_t)
files_tmp_filetrans(ctdbd_t, ctdbd_tmp_t, { file sock_file })

manage_dirs_pattern(ctdbd_t, ctdbd_spool_t, ctdbd_spool_t)
manage_files_pattern(ctdbd_t, ctdbd_spool_t, ctdbd_spool_t)
manage_lnk_files_pattern(ctdbd_t, ctdbd_spool_t, ctdbd_spool_t)
files_spool_filetrans(ctdbd_t, ctdbd_spool_t, dir)

exec_files_pattern(ctdbd_t, ctdbd_var_lib_t, ctdbd_var_lib_t)
manage_dirs_pattern(ctdbd_t, ctdbd_var_lib_t, ctdbd_var_lib_t)
manage_files_pattern(ctdbd_t, ctdbd_var_lib_t, ctdbd_var_lib_t)
files_var_lib_filetrans(ctdbd_t, ctdbd_var_lib_t, dir)

manage_dirs_pattern(ctdbd_t, ctdbd_runtime_t, ctdbd_runtime_t)
manage_files_pattern(ctdbd_t, ctdbd_runtime_t, ctdbd_runtime_t)
files_runtime_filetrans(ctdbd_t, ctdbd_runtime_t, dir)

kernel_read_network_state(ctdbd_t)
kernel_read_system_state(ctdbd_t)
kernel_rw_net_sysctls(ctdbd_t)

corenet_all_recvfrom_netlabel(ctdbd_t)
corenet_tcp_sendrecv_generic_if(ctdbd_t)
corenet_tcp_sendrecv_generic_node(ctdbd_t)
corenet_tcp_bind_generic_node(ctdbd_t)

corenet_sendrecv_ctdb_server_packets(ctdbd_t)
corenet_tcp_bind_ctdb_port(ctdbd_t)

corecmd_exec_bin(ctdbd_t)
corecmd_exec_shell(ctdbd_t)

dev_read_sysfs(ctdbd_t)
dev_read_urand(ctdbd_t)

domain_dontaudit_read_all_domains_state(ctdbd_t)

files_read_etc_files(ctdbd_t)
files_search_all_mountpoints(ctdbd_t)

fs_getattr_all_fs(ctdbd_t)

logging_send_syslog_msg(ctdbd_t)

miscfiles_read_localization(ctdbd_t)
miscfiles_read_public_files(ctdbd_t)

optional_policy(`
	consoletype_exec(ctdbd_t)
')

optional_policy(`
	hostname_exec(ctdbd_t)
')

optional_policy(`
	iptables_domtrans(ctdbd_t)
')

optional_policy(`
	samba_initrc_domtrans(ctdbd_t)
	samba_domtrans_net(ctdbd_t)
	samba_rw_var_files(ctdbd_t)
')

optional_policy(`
	sysnet_domtrans_ifconfig(ctdbd_t)
')
