policy_module(alsa, 1.22.0)

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

attribute_role alsa_roles;

type alsa_t;
type alsa_exec_t;
init_system_domain(alsa_t, alsa_exec_t)
role alsa_roles types alsa_t;

type alsa_etc_t;
files_config_file(alsa_etc_t)

type alsa_home_t;
userdom_user_home_content(alsa_home_t)

type alsa_runtime_t;
files_runtime_file(alsa_runtime_t)

type alsa_tmp_t;
files_tmp_file(alsa_tmp_t)

type alsa_tmpfs_t;
files_tmpfs_file(alsa_tmpfs_t)

type alsa_unit_t;
init_unit_file(alsa_unit_t)

type alsa_var_lib_t;
files_type(alsa_var_lib_t)

type alsa_var_lock_t;
files_lock_file(alsa_var_lock_t)

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

allow alsa_t self:capability { dac_override dac_read_search ipc_owner setgid setuid };
# kill : kill pulseaudio
dontaudit alsa_t self:capability { kill sys_admin };
allow alsa_t self:process { getsched setsched signal };
allow alsa_t self:sem create_sem_perms;
allow alsa_t self:shm create_shm_perms;
allow alsa_t self:unix_stream_socket { accept listen };

allow alsa_t alsa_home_t:file read_file_perms;

list_dirs_pattern(alsa_t, alsa_etc_t, alsa_etc_t)
read_files_pattern(alsa_t, alsa_etc_t, alsa_etc_t)
read_lnk_files_pattern(alsa_t, alsa_etc_t, alsa_etc_t)
allow alsa_t alsa_etc_t:file map;

can_exec(alsa_t, alsa_exec_t)

allow alsa_t alsa_runtime_t:dir manage_dir_perms;
allow alsa_t alsa_runtime_t:file manage_file_perms;
allow alsa_t alsa_runtime_t:lnk_file manage_lnk_file_perms;
files_runtime_filetrans(alsa_t, alsa_runtime_t, { dir file })

manage_dirs_pattern(alsa_t, alsa_tmp_t, alsa_tmp_t)
manage_files_pattern(alsa_t, alsa_tmp_t, alsa_tmp_t)
files_tmp_filetrans(alsa_t, alsa_tmp_t, { dir file })
userdom_user_tmp_filetrans(alsa_t, alsa_tmp_t, { dir file })

allow alsa_t alsa_tmpfs_t:file { manage_file_perms map };
fs_tmpfs_filetrans(alsa_t, alsa_tmpfs_t, file)

manage_dirs_pattern(alsa_t, alsa_var_lib_t, alsa_var_lib_t)
manage_files_pattern(alsa_t, alsa_var_lib_t, alsa_var_lib_t)

allow alsa_t alsa_var_lock_t:file manage_file_perms;
files_lock_filetrans(alsa_t, alsa_var_lock_t, file)

kernel_read_system_state(alsa_t)

corecmd_exec_bin(alsa_t)

dev_getattr_fs(alsa_t)
dev_read_input(alsa_t)
dev_read_sound(alsa_t)
dev_read_sysfs(alsa_t)
dev_read_urand(alsa_t)
dev_write_sound(alsa_t)

files_read_usr_files(alsa_t)
files_search_var_lib(alsa_t)

fs_getattr_tmpfs(alsa_t)

term_dontaudit_use_console(alsa_t)
term_dontaudit_use_generic_ptys(alsa_t)
term_dontaudit_use_all_ptys(alsa_t)

auth_use_nsswitch(alsa_t)

logging_send_syslog_msg(alsa_t)

miscfiles_read_localization(alsa_t)

userdom_manage_unpriv_user_semaphores(alsa_t)
userdom_manage_unpriv_user_shared_mem(alsa_t)
userdom_search_user_home_dirs(alsa_t)
