policy_module(gnome, 2.3.0)

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

attribute gnomedomain;
attribute gnome_home_type;
attribute gkeyringd_domain;
attribute_role gconfd_roles;

type gconf_etc_t;
files_config_file(gconf_etc_t)

type data_home_t, gnome_home_type;
userdom_user_home_content(data_home_t)

type config_home_t, gnome_home_type;
userdom_user_home_content(config_home_t)

type cache_home_t, gnome_home_type;
userdom_user_home_content(cache_home_t)

type gstreamer_home_t, gnome_home_type;
userdom_user_home_content(gstreamer_home_t)

type dbus_home_t, gnome_home_type;
userdom_user_home_content(dbus_home_t)

type icc_data_home_t, gnome_home_type;
userdom_user_home_content(icc_data_home_t)

type gconf_home_t, gnome_home_type;
typealias gconf_home_t alias { user_gconf_home_t staff_gconf_home_t sysadm_gconf_home_t };
typealias gconf_home_t alias { auditadm_gconf_home_t secadm_gconf_home_t };
typealias gconf_home_t alias unconfined_gconf_home_t;
userdom_user_home_content(gconf_home_t)

type gconf_tmp_t;
typealias gconf_tmp_t alias { user_gconf_tmp_t staff_gconf_tmp_t sysadm_gconf_tmp_t };
typealias gconf_tmp_t alias { auditadm_gconf_tmp_t secadm_gconf_tmp_t };
typealias gconf_tmp_t alias unconfined_gconf_tmp_t;
userdom_user_tmp_file(gconf_tmp_t)

type gconfd_t, gnomedomain;
type gconfd_exec_t;
typealias gconfd_t alias { user_gconfd_t staff_gconfd_t sysadm_gconfd_t };
typealias gconfd_t alias { auditadm_gconfd_t secadm_gconfd_t };
userdom_user_application_domain(gconfd_t, gconfd_exec_t)
role gconfd_roles types gconfd_t;

type gnome_home_t, gnome_home_type;
typealias gnome_home_t alias { user_gnome_home_t staff_gnome_home_t sysadm_gnome_home_t };
typealias gnome_home_t alias { auditadm_gnome_home_t secadm_gnome_home_t };
typealias gnome_home_t alias unconfined_gnome_home_t;
userdom_user_home_content(gnome_home_t)

# type KDE /usr/share/config files
type config_usr_t;
files_type(config_usr_t)

type gkeyringd_exec_t;
corecmd_executable_file(gkeyringd_exec_t)

type gkeyringd_gnome_home_t, gnome_home_type;
userdom_user_home_content(gkeyringd_gnome_home_t)

type gkeyringd_tmp_t;
userdom_user_tmp_content(gkeyringd_tmp_t)

type gconfdefaultsm_t;
type gconfdefaultsm_exec_t;
init_daemon_domain(gconfdefaultsm_t, gconfdefaultsm_exec_t)

type gnomesystemmm_t;
type gnomesystemmm_exec_t;
init_daemon_domain(gnomesystemmm_t, gnomesystemmm_exec_t)

# Assistive Technology Service Provider Interface (AT-SPI)
type gnome_atspi_t;
type gnome_atspi_exec_t;
init_daemon_domain(gnome_atspi_t, gnome_atspi_exec_t)
role system_r types gnome_atspi_t;

optional_policy(`
	xserver_read_xdm_pid(gnome_atspi_t)
	xserver_map_xdm_pid(gnome_atspi_t)
')

##############################
#
# Local Policy
#

allow gconfd_t self:process getsched;
allow gconfd_t self:fifo_file rw_fifo_file_perms;

manage_dirs_pattern(gconfd_t, gconf_home_t, gconf_home_t)
manage_files_pattern(gconfd_t, gconf_home_t, gconf_home_t)
userdom_user_home_dir_filetrans(gconfd_t, gconf_home_t, dir)

manage_dirs_pattern(gconfd_t, gconf_tmp_t, gconf_tmp_t)
manage_files_pattern(gconfd_t, gconf_tmp_t, gconf_tmp_t)
userdom_user_tmp_filetrans(gconfd_t, gconf_tmp_t, { dir file })

allow gconfd_t gconf_etc_t:dir list_dir_perms;
read_files_pattern(gconfd_t, gconf_etc_t, gconf_etc_t)

dev_read_urand(gconfd_t)



logging_send_syslog_msg(gconfd_t)

userdom_manage_user_tmp_sockets(gconfd_t)
userdom_manage_user_tmp_dirs(gconfd_t)
userdom_tmp_filetrans_user_tmp(gconfd_t, dir)

optional_policy(`
	nscd_dontaudit_search_pid(gconfd_t)
')

optional_policy(`
	xserver_use_xdm_fds(gconfd_t)
	xserver_rw_xdm_pipes(gconfd_t)
')

#######################################
#
# gconf-defaults-mechanisms local policy
#

allow gconfdefaultsm_t self:capability { dac_read_search  sys_nice };
allow gconfdefaultsm_t self:process getsched;
allow gconfdefaultsm_t self:fifo_file rw_fifo_file_perms;

corecmd_search_bin(gconfdefaultsm_t)

auth_read_passwd(gconfdefaultsm_t)

gnome_manage_gconf_home_files(gconfdefaultsm_t)
gnome_manage_gconf_config(gconfdefaultsm_t)

userdom_read_all_users_state(gconfdefaultsm_t)
userdom_search_user_home_dirs(gconfdefaultsm_t)

userdom_dontaudit_search_admin_dir(gconfdefaultsm_t)

optional_policy(`
	consolekit_dbus_chat(gconfdefaultsm_t)
')

optional_policy(`
	dbus_system_domain(gconfdefaultsm_t, gconfdefaultsm_exec_t)
')

optional_policy(`
	nscd_dontaudit_search_pid(gconfdefaultsm_t)
')

optional_policy(`
	policykit_domtrans_auth(gconfdefaultsm_t)
	policykit_dbus_chat(gconfdefaultsm_t)
	policykit_read_lib(gconfdefaultsm_t)
	policykit_read_reload(gconfdefaultsm_t)
')

userdom_home_manager(gconfdefaultsm_t)

#######################################
#
# gnome-system-monitor-mechanisms local policy
#

allow gnomesystemmm_t self:capability { sys_admin sys_nice };
allow gnomesystemmm_t self:fifo_file rw_fifo_file_perms;

rw_files_pattern(gnomesystemmm_t, config_usr_t, config_usr_t)

kernel_read_system_state(gnomesystemmm_t)

corecmd_search_bin(gnomesystemmm_t)

domain_kill_all_domains(gnomesystemmm_t)
domain_search_all_domains_state(gnomesystemmm_t)
domain_setpriority_all_domains(gnomesystemmm_t)
domain_signal_all_domains(gnomesystemmm_t)
domain_sigstop_all_domains(gnomesystemmm_t)

fs_getattr_xattr_fs(gnomesystemmm_t)

auth_read_passwd(gnomesystemmm_t)

logging_send_syslog_msg(gnomesystemmm_t)

userdom_read_all_users_state(gnomesystemmm_t)
userdom_dontaudit_search_admin_dir(gnomesystemmm_t)

optional_policy(`
	consolekit_dbus_chat(gnomesystemmm_t)
')

optional_policy(`
	dbus_system_domain(gnomesystemmm_t, gnomesystemmm_exec_t)
')

optional_policy(`
 	gnome_manage_home_config(gnomesystemmm_t)
')

optional_policy(`
	nscd_dontaudit_search_pid(gnomesystemmm_t)
')

optional_policy(`
	policykit_dbus_chat(gnomesystemmm_t)
	policykit_domtrans_auth(gnomesystemmm_t)
	policykit_read_lib(gnomesystemmm_t)
	policykit_read_reload(gnomesystemmm_t)
')

######################################
#
# gnome-keyring-daemon local policy
#

allow gkeyringd_domain self:capability ipc_lock;
allow gkeyringd_domain self:process { getcap getsched setcap signal };
allow gkeyringd_domain self:fifo_file rw_fifo_file_perms;
allow gkeyringd_domain self:unix_stream_socket { connectto accept listen };

manage_files_pattern(gkeyringd_domain, config_home_t, config_home_t)

manage_dirs_pattern(gkeyringd_domain, gkeyringd_gnome_home_t, gkeyringd_gnome_home_t)
manage_files_pattern(gkeyringd_domain, gkeyringd_gnome_home_t, gkeyringd_gnome_home_t)
allow gkeyringd_domain data_home_t:dir create_dir_perms;
allow gkeyringd_domain gconf_home_t:dir create_dir_perms;
filetrans_pattern(gkeyringd_domain, gconf_home_t, data_home_t, dir, "share")
filetrans_pattern(gkeyringd_domain, gnome_home_t, gkeyringd_gnome_home_t, dir, "keyrings")
filetrans_pattern(gkeyringd_domain, data_home_t, gkeyringd_gnome_home_t, dir, "keyrings")

manage_dirs_pattern(gkeyringd_domain, gkeyringd_tmp_t, gkeyringd_tmp_t)
manage_sock_files_pattern(gkeyringd_domain, gkeyringd_tmp_t, gkeyringd_tmp_t)
files_tmp_filetrans(gkeyringd_domain, gkeyringd_tmp_t, dir)
fs_tmpfs_filetrans(gkeyringd_domain, gkeyringd_tmp_t, dir)
userdom_user_tmp_filetrans(gkeyringd_domain, gkeyringd_tmp_t, { sock_file dir })

kernel_read_crypto_sysctls(gkeyringd_domain)

corecmd_search_bin(gkeyringd_domain)

dev_read_rand(gkeyringd_domain)
dev_read_urand(gkeyringd_domain)
dev_read_sysfs(gkeyringd_domain)

# for nscd?
files_search_pids(gkeyringd_domain)

fs_getattr_xattr_fs(gkeyringd_domain)
fs_getattr_tmpfs(gkeyringd_domain)

userdom_user_home_dir_filetrans(gkeyringd_domain, gconf_home_t, dir, ".local")

optional_policy(`
	xserver_append_xdm_home_files(gkeyringd_domain)
	xserver_read_xdm_home_files(gkeyringd_domain)
	xserver_use_xdm_fds(gkeyringd_domain)
')

optional_policy(`
	dbus_dontaudit_stream_connect_system_dbusd(gkeyringd_domain)
	dbus_write_session_tmp_sock_files(gkeyringd_domain)
')

optional_policy(`
    gnome_create_home_config_dirs(gkeyringd_domain)
	gnome_read_home_config(gkeyringd_domain)
    gnome_manage_generic_cache_files(gkeyringd_domain)
	gnome_manage_cache_home_dir(gkeyringd_domain)
	gnome_manage_generic_cache_sockets(gkeyringd_domain)
')

optional_policy(`
	ssh_read_user_home_files(gkeyringd_domain)
')

domain_use_interactive_fds(gnomedomain)

userdom_use_inherited_user_terminals(gnomedomain)

######################################
#
# at-spi local policy
#

allow gnome_atspi_t self:tcp_socket create_stream_socket_perms;

files_map_read_etc_files(gnome_atspi_t)
fs_getattr_cgroup(gnome_atspi_t)

optional_policy(`
	dbus_acquire_svc_system_dbusd(gnome_atspi_t)
	dbus_exec_system_dbusd(gnome_atspi_t)
	dbus_rw_tmp_sock_files(gnome_atspi_t)
	dbus_send_system_bus(gnome_atspi_t)
	dbus_signal(gnome_atspi_t)
	dbus_stream_connect_session_bus(gnome_atspi_t)
	dbus_system_bus_client(gnome_atspi_t)
')

optional_policy(`
	gnome_manage_home_config(gnome_atspi_t)
')

optional_policy(`
	userdom_write_user_tmp_files(gnome_atspi_t)
')

optional_policy(`
	xserver_dbus_chat_xdm(gnome_atspi_t)
	xserver_search_xdm_lib(gnome_atspi_t)
	xserver_read_inherited_xdm_lib_files(gnome_atspi_t)
	xserver_read_xdm_lib_files(gnome_atspi_t)
	xserver_stream_connect(gnome_atspi_t)
')
