policy_module(kismet, 1.7.0)

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

attribute_role kismet_roles;

type kismet_t;
type kismet_exec_t;
init_system_domain(kismet_t, kismet_exec_t)
role kismet_roles types kismet_t;

type kismet_initrc_exec_t;
init_script_file(kismet_initrc_exec_t)

type kismet_home_t;
userdom_user_home_content(kismet_home_t)

type kismet_log_t;
logging_log_file(kismet_log_t)

type kismet_tmp_t;
files_tmp_file(kismet_tmp_t)

type kismet_tmpfs_t;
files_tmp_file(kismet_tmpfs_t)

type kismet_var_lib_t;
files_type(kismet_var_lib_t)

type kismet_var_run_t;
files_pid_file(kismet_var_run_t)

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

allow kismet_t self:capability { dac_read_search  kill net_admin net_raw setuid setgid };
allow kismet_t self:process signal_perms;
allow kismet_t self:fifo_file rw_fifo_file_perms;
allow kismet_t self:packet_socket create_socket_perms;
allow kismet_t self:unix_dgram_socket { create_socket_perms sendto };
allow kismet_t self:unix_stream_socket create_stream_socket_perms;
allow kismet_t self:tcp_socket { accept listen };

manage_dirs_pattern(kismet_t, kismet_home_t, kismet_home_t)
manage_files_pattern(kismet_t, kismet_home_t, kismet_home_t)
manage_lnk_files_pattern(kismet_t, kismet_home_t, kismet_home_t)
userdom_user_home_dir_filetrans(kismet_t, kismet_home_t, dir)

allow kismet_t kismet_log_t:dir setattr_dir_perms;
append_files_pattern(kismet_t, kismet_log_t, kismet_log_t)
create_files_pattern(kismet_t, kismet_log_t, kismet_log_t)
getattr_files_pattern(kismet_t, kismet_log_t, kismet_log_t)
logging_log_filetrans(kismet_t, kismet_log_t, dir)

manage_dirs_pattern(kismet_t, kismet_tmp_t, kismet_tmp_t)
manage_files_pattern(kismet_t, kismet_tmp_t, kismet_tmp_t)
manage_sock_files_pattern(kismet_t, kismet_tmp_t, kismet_tmp_t)
files_tmp_filetrans(kismet_t, kismet_tmp_t, { file dir sock_file })

manage_dirs_pattern(kismet_t, kismet_tmpfs_t, kismet_tmpfs_t)
manage_files_pattern(kismet_t, kismet_tmpfs_t, kismet_tmpfs_t)
fs_tmpfs_filetrans(kismet_t, kismet_tmpfs_t, { dir file })

allow kismet_t kismet_var_lib_t:file manage_file_perms;
allow kismet_t kismet_var_lib_t:dir manage_dir_perms;
files_var_lib_filetrans(kismet_t, kismet_var_lib_t, { file dir })

allow kismet_t kismet_var_run_t:dir manage_dir_perms;
files_pid_filetrans(kismet_t, kismet_var_run_t, file)

can_exec(kismet_t, kismet_exec_t)

kernel_search_debugfs(kismet_t)
kernel_read_system_state(kismet_t)
kernel_read_network_state(kismet_t)

corecmd_exec_bin(kismet_t)

corenet_all_recvfrom_netlabel(kismet_t)
corenet_tcp_sendrecv_generic_if(kismet_t)
corenet_tcp_sendrecv_generic_node(kismet_t)
corenet_tcp_bind_generic_node(kismet_t)

corenet_tcp_connect_pulseaudio_port(kismet_t)

corenet_sendrecv_rtsclient_server_packets(kismet_t)
corenet_tcp_bind_rtsclient_port(kismet_t)
corenet_sendrecv_rtsclient_client_packets(kismet_t)
corenet_tcp_connect_rtsclient_port(kismet_t)

auth_use_nsswitch(kismet_t)

userdom_use_inherited_user_terminals(kismet_t)
userdom_read_user_tmp_files(kismet_t)

optional_policy(`
	dbus_system_bus_client(kismet_t)

	optional_policy(`
		networkmanager_dbus_chat(kismet_t)
	')
')
