policy_module(bitlbee, 1.5.0)

########################################
#
# 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_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)

type bitlbee_var_run_t;
files_pid_file(bitlbee_var_run_t)

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

allow bitlbee_t self:capability { dac_read_search  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:udp_socket create_socket_perms;
allow bitlbee_t self:tcp_socket { create_stream_socket_perms connected_stream_socket_perms };
allow bitlbee_t self:unix_stream_socket create_stream_socket_perms;
allow bitlbee_t self:netlink_route_socket r_netlink_socket_perms;

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)
read_files_pattern(bitlbee_t, bitlbee_log_t, bitlbee_log_t)
setattr_files_pattern(bitlbee_t, bitlbee_log_t, bitlbee_log_t)
logging_log_filetrans(bitlbee_t, bitlbee_log_t, { dir file })

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)
manage_dirs_pattern(bitlbee_t, bitlbee_var_t, bitlbee_var_t)
files_var_lib_filetrans(bitlbee_t, bitlbee_var_t,{dir file})

manage_dirs_pattern(bitlbee_t, bitlbee_var_run_t, bitlbee_var_run_t)
manage_files_pattern(bitlbee_t, bitlbee_var_run_t, bitlbee_var_run_t)
manage_sock_files_pattern(bitlbee_t, bitlbee_var_run_t, bitlbee_var_run_t)
files_pid_filetrans(bitlbee_t, bitlbee_var_run_t, { dir file sock_file })

kernel_read_system_state(bitlbee_t)
kernel_read_kernel_sysctls(bitlbee_t)

corenet_all_recvfrom_unlabeled(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_tcp_sendrecv_jabber_client_port(bitlbee_t)

corenet_sendrecv_aol_client_packets(bitlbee_t)
corenet_tcp_connect_aol_port(bitlbee_t)
corenet_tcp_sendrecv_aol_port(bitlbee_t)

corenet_sendrecv_gatekeeper_client_packets(bitlbee_t)
corenet_tcp_connect_gatekeeper_port(bitlbee_t)
corenet_tcp_sendrecv_gatekeeper_port(bitlbee_t)

corenet_sendrecv_mmcc_client_packets(bitlbee_t)
corenet_tcp_connect_mmcc_port(bitlbee_t)
corenet_tcp_sendrecv_mmcc_port(bitlbee_t)

corenet_sendrecv_msnp_client_packets(bitlbee_t)
corenet_tcp_connect_msnp_port(bitlbee_t)
corenet_tcp_sendrecv_msnp_port(bitlbee_t)

corenet_sendrecv_http_client_packets(bitlbee_t)
corenet_tcp_connect_http_port(bitlbee_t)
corenet_tcp_sendrecv_http_port(bitlbee_t)

corenet_sendrecv_http_cache_client_packets(bitlbee_t)
corenet_tcp_connect_http_cache_port(bitlbee_t)
corenet_tcp_sendrecv_http_cache_port(bitlbee_t)

corenet_sendrecv_ircd_server_packets(bitlbee_t)
corenet_tcp_bind_ircd_port(bitlbee_t)
corenet_tcp_bind_interwise_port(bitlbee_t)
corenet_sendrecv_ircd_client_packets(bitlbee_t)
corenet_tcp_connect_interwise_port(bitlbee_t)
corenet_tcp_connect_ircd_port(bitlbee_t)
corenet_tcp_sendrecv_ircd_port(bitlbee_t)

corenet_sendrecv_interwise_server_packets(bitlbee_t)
corenet_tcp_bind_interwise_port(bitlbee_t)
corenet_tcp_sendrecv_interwise_port(bitlbee_t)

dev_read_rand(bitlbee_t)
dev_read_urand(bitlbee_t)

libs_legacy_use_shared_libs(bitlbee_t)

auth_use_nsswitch(bitlbee_t)

logging_send_syslog_msg(bitlbee_t)

optional_policy(`
    dbus_system_bus_client(bitlbee_t)
')

optional_policy(`
	tcpd_wrapped_domain(bitlbee_t, bitlbee_exec_t)
')

