policy_module(bitlbee)

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

type bitlbee_t;
type bitlbee_exec_t;
init_daemon_domain(bitlbee_t, bitlbee_exec_t)
inetd_tcp_service_domain(bitlbee_t, bitlbee_exec_t)

type bitlbee_conf_t;
files_config_file(bitlbee_conf_t)

type bitlbee_initrc_exec_t;
init_script_file(bitlbee_initrc_exec_t)

type bitlbee_runtime_t alias bitlbee_var_run_t;
files_runtime_file(bitlbee_runtime_t)

type bitlbee_tmp_t;
files_tmp_file(bitlbee_tmp_t)

type bitlbee_var_t;
files_type(bitlbee_var_t)

type bitlbee_log_t;
logging_log_file(bitlbee_log_t)

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

allow bitlbee_t self:capability { dac_override kill setgid setuid sys_nice };
allow bitlbee_t self:process { setsched signal };
allow bitlbee_t self:fifo_file rw_fifo_file_perms;
allow bitlbee_t self:tcp_socket { accept listen };
allow bitlbee_t self:unix_stream_socket { accept listen };

allow bitlbee_t bitlbee_conf_t:dir list_dir_perms;
allow bitlbee_t bitlbee_conf_t:file read_file_perms;

manage_dirs_pattern(bitlbee_t, bitlbee_log_t, bitlbee_log_t)
append_files_pattern(bitlbee_t, bitlbee_log_t, bitlbee_log_t)
create_files_pattern(bitlbee_t, bitlbee_log_t, bitlbee_log_t)
setattr_files_pattern(bitlbee_t, bitlbee_log_t, bitlbee_log_t)

manage_files_pattern(bitlbee_t, bitlbee_tmp_t, bitlbee_tmp_t)
manage_dirs_pattern(bitlbee_t, bitlbee_tmp_t, bitlbee_tmp_t)
files_tmp_filetrans(bitlbee_t, bitlbee_tmp_t, { dir file })

manage_files_pattern(bitlbee_t, bitlbee_var_t, bitlbee_var_t)
files_var_lib_filetrans(bitlbee_t, bitlbee_var_t, file)

manage_dirs_pattern(bitlbee_t, bitlbee_runtime_t, bitlbee_runtime_t)
manage_files_pattern(bitlbee_t, bitlbee_runtime_t, bitlbee_runtime_t)
manage_sock_files_pattern(bitlbee_t, bitlbee_runtime_t, bitlbee_runtime_t)
files_runtime_filetrans(bitlbee_t, bitlbee_runtime_t, { dir file sock_file })

kernel_read_kernel_sysctls(bitlbee_t)
kernel_read_system_state(bitlbee_t)

corenet_all_recvfrom_netlabel(bitlbee_t)
corenet_tcp_sendrecv_generic_if(bitlbee_t)
corenet_tcp_sendrecv_generic_node(bitlbee_t)
corenet_tcp_bind_generic_node(bitlbee_t)

corenet_sendrecv_jabber_client_client_packets(bitlbee_t)
corenet_tcp_connect_jabber_client_port(bitlbee_t)

corenet_sendrecv_aol_client_packets(bitlbee_t)
corenet_tcp_connect_aol_port(bitlbee_t)

corenet_sendrecv_gatekeeper_client_packets(bitlbee_t)
corenet_tcp_connect_gatekeeper_port(bitlbee_t)

corenet_sendrecv_mmcc_client_packets(bitlbee_t)
corenet_tcp_connect_mmcc_port(bitlbee_t)

corenet_sendrecv_msnp_client_packets(bitlbee_t)
corenet_tcp_connect_msnp_port(bitlbee_t)

corenet_sendrecv_http_client_packets(bitlbee_t)
corenet_tcp_connect_http_port(bitlbee_t)

corenet_sendrecv_http_cache_client_packets(bitlbee_t)
corenet_tcp_connect_http_cache_port(bitlbee_t)

corenet_sendrecv_ircd_server_packets(bitlbee_t)
corenet_tcp_bind_ircd_port(bitlbee_t)
corenet_sendrecv_ircd_client_packets(bitlbee_t)
corenet_tcp_connect_ircd_port(bitlbee_t)

corenet_sendrecv_interwise_server_packets(bitlbee_t)
corenet_tcp_bind_interwise_port(bitlbee_t)

dev_read_rand(bitlbee_t)
dev_read_urand(bitlbee_t)

files_read_usr_files(bitlbee_t)

libs_legacy_use_shared_libs(bitlbee_t)

auth_use_nsswitch(bitlbee_t)

logging_send_syslog_msg(bitlbee_t)

miscfiles_read_localization(bitlbee_t)

ifdef(`init_systemd', `
	# For /run/systemd/dynamic-uid/
	init_list_runtime(bitlbee_t)

	optional_policy(`
		dbus_system_bus_client(bitlbee_t)
		# For GetDynamicUser() of org.freedesktop.systemd1.Manager
		init_dbus_chat(bitlbee_t)
	')
')

optional_policy(`
	tcpd_wrapped_domain(bitlbee_t, bitlbee_exec_t)
')
