policy_module(bacula)

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

attribute_role bacula_admin_roles;

type bacula_t;
type bacula_exec_t;
init_daemon_domain(bacula_t, bacula_exec_t)

type bacula_initrc_exec_t;
init_script_file(bacula_initrc_exec_t)

type bacula_etc_t;
files_type(bacula_etc_t)

type bacula_log_t;
logging_log_file(bacula_log_t)

type bacula_runtime_t alias bacula_var_run_t;
files_runtime_file(bacula_runtime_t)

type bacula_spool_t;
files_type(bacula_spool_t)

type bacula_store_t;
files_type(bacula_store_t)
files_mountpoint(bacula_store_t)

type bacula_var_lib_t;
files_type(bacula_var_lib_t)

type bacula_admin_t;
type bacula_admin_exec_t;
application_domain(bacula_admin_t, bacula_admin_exec_t)
role bacula_admin_roles types bacula_admin_t;

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

allow bacula_t self:capability { chown dac_override dac_read_search fowner fsetid };
allow bacula_t self:process signal;
allow bacula_t self:fifo_file rw_fifo_file_perms;
allow bacula_t self:tcp_socket { accept listen };

read_files_pattern(bacula_t, bacula_etc_t, bacula_etc_t)

append_files_pattern(bacula_t, bacula_log_t, bacula_log_t)
create_files_pattern(bacula_t, bacula_log_t, bacula_log_t)
setattr_files_pattern(bacula_t, bacula_log_t, bacula_log_t)

manage_dirs_pattern(bacula_t, bacula_spool_t, bacula_spool_t)
manage_files_pattern(bacula_t, bacula_spool_t, bacula_spool_t)

manage_files_pattern(bacula_t, bacula_store_t, bacula_store_t)
manage_lnk_files_pattern(bacula_t, bacula_store_t, bacula_store_t)
manage_dirs_pattern(bacula_t, bacula_store_t, bacula_store_t)

manage_dirs_pattern(bacula_t, bacula_var_lib_t, bacula_var_lib_t)
manage_files_pattern(bacula_t, bacula_var_lib_t, bacula_var_lib_t)
files_var_lib_filetrans(bacula_t, bacula_var_lib_t, dir)

allow bacula_t bacula_runtime_t:file manage_file_perms;
files_runtime_filetrans(bacula_t, bacula_runtime_t, file)

kernel_read_kernel_sysctls(bacula_t)
kernel_read_system_state(bacula_t)

corecmd_exec_bin(bacula_t)
corecmd_exec_shell(bacula_t)

corenet_all_recvfrom_netlabel(bacula_t)
corenet_tcp_sendrecv_generic_if(bacula_t)
corenet_udp_sendrecv_generic_if(bacula_t)
corenet_tcp_sendrecv_generic_node(bacula_t)
corenet_udp_sendrecv_generic_node(bacula_t)
corenet_tcp_bind_generic_node(bacula_t)
corenet_udp_bind_generic_node(bacula_t)

corenet_sendrecv_generic_server_packets(bacula_t)
corenet_udp_bind_generic_port(bacula_t)

corenet_sendrecv_hplip_server_packets(bacula_t)
corenet_tcp_bind_hplip_port(bacula_t)
corenet_udp_bind_hplip_port(bacula_t)

corenet_sendrecv_all_client_packets(bacula_t)
corenet_tcp_connect_all_ports(bacula_t)

dev_getattr_all_blk_files(bacula_t)
dev_getattr_all_chr_files(bacula_t)

files_dontaudit_getattr_all_sockets(bacula_t)
files_read_all_files(bacula_t)
files_read_all_symlinks(bacula_t)

fs_getattr_xattr_fs(bacula_t)
fs_list_all(bacula_t)

auth_read_shadow(bacula_t)

logging_send_syslog_msg(bacula_t)

sysnet_dns_name_resolve(bacula_t)

optional_policy(`
	mysql_stream_connect(bacula_t)
	mysql_tcp_connect(bacula_t)
')

optional_policy(`
	nis_use_ypbind(bacula_t)
')

optional_policy(`
	sysnet_use_ldap(bacula_t)
	ldap_stream_connect(bacula_t)
')

########################################
#
# Client local policy
#

allow bacula_admin_t self:process signal;
allow bacula_admin_t self:tcp_socket { accept listen };
allow bacula_admin_t self:dgram_socket_class_set create_socket_perms;

read_files_pattern(bacula_admin_t, bacula_etc_t, bacula_etc_t)

corenet_all_recvfrom_netlabel(bacula_admin_t)
corenet_tcp_sendrecv_generic_if(bacula_admin_t)
corenet_tcp_sendrecv_generic_node(bacula_admin_t)
corenet_tcp_bind_generic_node(bacula_admin_t)

corenet_sendrecv_hplip_client_packets(bacula_admin_t)
corenet_tcp_connect_hplip_port(bacula_admin_t)

domain_use_interactive_fds(bacula_admin_t)

files_read_etc_files(bacula_admin_t)

miscfiles_read_localization(bacula_admin_t)

sysnet_dns_name_resolve(bacula_admin_t)

userdom_dontaudit_search_user_home_dirs(bacula_admin_t)
userdom_use_user_ptys(bacula_admin_t)
