policy_module(thumb, 1.0.0)

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

type thumb_t;
type thumb_exec_t;
application_domain(thumb_t, thumb_exec_t)
ubac_constrained(thumb_t)
userdom_home_manager(thumb_t)

type thumb_tmp_t;
files_tmp_file(thumb_tmp_t)
ubac_constrained(thumb_tmp_t)

type thumb_home_t;
userdom_user_home_content(thumb_home_t)

type thumb_tmpfs_t;
files_tmpfs_file(thumb_tmpfs_t)

########################################
#
# thumb local policy
#

allow thumb_t self:process { setsched signal signull setrlimit };
dontaudit thumb_t self:capability { dac_read_search sys_tty_config };
dontaudit thumb_t self:process { setfscreate setsched };

tunable_policy(`deny_execmem',`',`
	allow thumb_t self:process execmem;
')

allow thumb_t self:fifo_file manage_fifo_file_perms;
allow thumb_t self:unix_stream_socket create_stream_socket_perms;
allow thumb_t self:unix_dgram_socket create_socket_perms;
allow thumb_t self:netlink_route_socket r_netlink_socket_perms;
allow thumb_t self:netlink_kobject_uevent_socket create_socket_perms;
allow thumb_t self:udp_socket create_socket_perms;
allow thumb_t self:tcp_socket create_socket_perms;
allow thumb_t self:shm create_shm_perms;
allow thumb_t self:sem create_sem_perms;

manage_dirs_pattern(thumb_t, thumb_home_t, thumb_home_t)
manage_files_pattern(thumb_t, thumb_home_t, thumb_home_t)
userdom_user_home_dir_filetrans(thumb_t, thumb_home_t, dir, ".thumbnails")
userdom_user_home_dir_filetrans(thumb_t, thumb_home_t, file, "missfont.log")
userdom_user_home_dir_filetrans(thumb_t, thumb_home_t, file)
userdom_dontaudit_access_check_user_content(thumb_t)
userdom_rw_inherited_user_tmp_files(thumb_t)
userdom_manage_home_texlive(thumb_t)

manage_files_pattern(thumb_t, thumb_tmp_t, thumb_tmp_t)
manage_dirs_pattern(thumb_t, thumb_tmp_t, thumb_tmp_t)
manage_sock_files_pattern(thumb_t, thumb_tmp_t, thumb_tmp_t)
exec_files_pattern(thumb_t, thumb_tmp_t, thumb_tmp_t)
files_tmp_filetrans(thumb_t, thumb_tmp_t, { file dir sock_file })
userdom_user_tmp_filetrans(thumb_t, thumb_tmp_t, { file dir sock_file })

manage_dirs_pattern(thumb_t, thumb_tmpfs_t, thumb_tmpfs_t)
manage_files_pattern(thumb_t, thumb_tmpfs_t, thumb_tmpfs_t)
fs_tmpfs_filetrans(thumb_t, thumb_tmpfs_t, { dir file })
allow thumb_t thumb_tmpfs_t:file execute;

can_exec(thumb_t, thumb_exec_t)

kernel_read_system_state(thumb_t)
kernel_dgram_send(thumb_t)
kernel_dontaudit_list_all_sysctls(thumb_t)

corecmd_exec_bin(thumb_t)
corecmd_exec_shell(thumb_t)

corenet_tcp_connect_xserver_port(thumb_t)
corenet_dontaudit_tcp_connect_all_ports(thumb_t)

dev_read_sysfs(thumb_t)
dev_read_urand(thumb_t)
dev_dontaudit_rw_dri(thumb_t)
dev_rw_xserver_misc(thumb_t)
dev_read_video_dev(thumb_t)
dev_write_video_dev(thumb_t)

domain_use_interactive_fds(thumb_t)
domain_dontaudit_read_all_domains_state(thumb_t)

files_read_non_security_files(thumb_t)
files_map_non_security_files(thumb_t)
files_watch_etc_dirs(thumb_t)
files_watch_usr_dirs(thumb_t)

fs_getattr_all_fs(thumb_t)
fs_read_dos_files(thumb_t)
fs_rw_inherited_tmpfs_files(thumb_t)
fs_map_dos_files(thumb_t)
fs_mmap_removable_files(thumb_t)
fs_dontaudit_getattr_nsfs_files(thumb_t)

auth_read_passwd(thumb_t)

tunable_policy(`selinuxuser_execmod',`
	libs_legacy_use_shared_libs(thumb_t)
')

libs_dontaudit_setattr_lib_dirs(thumb_t)

logging_send_syslog_msg(thumb_t)

miscfiles_read_fonts(thumb_t)
miscfiles_dontaudit_setattr_fonts_dirs(thumb_t)
miscfiles_dontaudit_setattr_fonts_cache_dirs(thumb_t)

sysnet_read_config(thumb_t)


term_dontaudit_use_unallocated_ttys(thumb_t)

userdom_dontaudit_setattr_user_tmp(thumb_t)
userdom_read_user_tmp_files(thumb_t)
userdom_read_user_home_content_files(thumb_t)
userdom_exec_user_home_content_files(thumb_t)
userdom_dontaudit_write_user_tmp_files(thumb_t)
userdom_dontaudit_delete_user_tmp_files(thumb_t)
userdom_read_home_audio_files(thumb_t)
userdom_home_reader(thumb_t)

userdom_use_user_terminals(thumb_t)

xserver_read_xdm_home_files(thumb_t)
xserver_append_xdm_home_files(thumb_t)
xserver_dontaudit_read_xdm_pid(thumb_t)
xserver_dontaudit_xdm_tmp_dirs(thumb_t)
xserver_stream_connect(thumb_t)
xserver_use_user_fonts(thumb_t)

optional_policy(`
    bumblebee_stream_connect(thumb_t)
')

optional_policy(`
    dbus_exec_dbusd(thumb_t)
    dbus_connect_session_bus(thumb_t)
	dbus_stream_connect_session_bus(thumb_t)
	dbus_chat_session_bus(thumb_t)
	dbus_system_bus_client(thumb_t)
	dbus_write_session_tmp_sock_files(thumb_t)
')

optional_policy(`
	# .config
	gnome_dontaudit_search_config(thumb_t)
	gnome_dontaudit_write_config_files(thumb_t)
    gnome_append_home_config(thumb_t)
	gnome_append_generic_cache_files(thumb_t)
	gnome_read_generic_data_home_files(thumb_t)
	gnome_dontaudit_rw_generic_cache_files(thumb_t)
	gnome_manage_gstreamer_home_files(thumb_t)
	gnome_manage_gstreamer_home_dirs(thumb_t)
	gnome_exec_gstreamer_home_files(thumb_t)
	gnome_create_generic_cache_dir(thumb_t)
    gnome_setattr_cache_home_dir(thumb_t)
    gnome_delete_generic_cache_files(thumb_t)
	gnome_cache_filetrans(thumb_t, thumb_home_t, dir, "thumbnails")
	gnome_cache_filetrans(thumb_t, thumb_home_t, file)
')

optional_policy(`
	sssd_dontaudit_stream_connect(thumb_t)
')

optional_policy(`
	nscd_dontaudit_write_sock_file(thumb_t)
')

optional_policy(`
	nslcd_dontaudit_write_sock_file(thumb_t)
')

optional_policy(`
	lvm_dontaudit_rw_pipes(thumb_t)
')

tunable_policy(`nis_enabled',`
	corenet_dontaudit_udp_bind_all_ports(thumb_t)
	corenet_dontaudit_udp_bind_generic_node(thumb_t)
')

optional_policy(`
    storage_getattr_fixed_disk_dev(thumb_t)
')
