policy_module(colord, 1.1.0)

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

## <desc>
##	<p>
##	Determine whether Colord can access
##	nfs file systems.
##	</p>
## </desc>
gen_tunable(colord_use_nfs, false)

type colord_t;
type colord_exec_t;
dbus_system_domain(colord_t, colord_exec_t)
init_daemon_domain(colord_t, colord_exec_t)

type colord_tmp_t;
files_tmp_file(colord_tmp_t)

type colord_tmpfs_t;
files_tmpfs_file(colord_tmpfs_t)

type colord_var_lib_t;
files_type(colord_var_lib_t)

type colord_unit_file_t;
systemd_unit_file(colord_unit_file_t)

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

allow colord_t self:capability { dac_read_search  };
dontaudit colord_t self:capability sys_admin;
allow colord_t self:process signal;

allow colord_t self:fifo_file rw_fifo_file_perms;
allow colord_t self:netlink_kobject_uevent_socket create_socket_perms;
allow colord_t self:tcp_socket create_stream_socket_perms;
allow colord_t self:shm create_shm_perms;
allow colord_t self:udp_socket create_socket_perms;
allow colord_t self:unix_dgram_socket create_socket_perms;

manage_dirs_pattern(colord_t, colord_tmp_t, colord_tmp_t)
manage_files_pattern(colord_t, colord_tmp_t, colord_tmp_t)
files_tmp_filetrans(colord_t, colord_tmp_t, { file dir })

manage_dirs_pattern(colord_t, colord_tmpfs_t, colord_tmpfs_t)
manage_files_pattern(colord_t, colord_tmpfs_t, colord_tmpfs_t)
fs_tmpfs_filetrans(colord_t, colord_tmpfs_t, { dir file })

manage_dirs_pattern(colord_t, colord_var_lib_t, colord_var_lib_t)
manage_files_pattern(colord_t, colord_var_lib_t, colord_var_lib_t)
files_var_lib_filetrans(colord_t, colord_var_lib_t, dir)
allow colord_t colord_var_lib_t:dir watch;

kernel_read_crypto_sysctls(colord_t)
kernel_read_device_sysctls(colord_t)
kernel_read_network_state(colord_t)
kernel_read_system_state(colord_t)
kernel_request_load_module(colord_t)

corenet_all_recvfrom_netlabel(colord_t)
corenet_all_recvfrom_unlabeled(colord_t)
corenet_tcp_sendrecv_generic_if(colord_t)
corenet_udp_sendrecv_generic_if(colord_t)
corenet_tcp_sendrecv_generic_node(colord_t)
corenet_udp_sendrecv_generic_node(colord_t)
corenet_udp_bind_generic_node(colord_t)

corenet_sendrecv_ipp_server_packets(colord_t)
corenet_udp_bind_ipp_port(colord_t)
corenet_udp_sendrecv_ipp_port(colord_t)

corenet_sendrecv_ipp_client_packets(colord_t)
corenet_tcp_connect_ipp_port(colord_t)
corenet_tcp_sendrecv_ipp_port(colord_t)

corecmd_exec_bin(colord_t)
corecmd_exec_shell(colord_t)

dev_read_raw_memory(colord_t)
dev_write_raw_memory(colord_t)
dev_read_video_dev(colord_t)
dev_write_video_dev(colord_t)
dev_rw_printer(colord_t)
dev_read_rand(colord_t)
dev_read_urand(colord_t)
dev_read_sysfs(colord_t)
dev_rw_generic_usb_dev(colord_t)

domain_use_interactive_fds(colord_t)

files_list_mnt(colord_t)
files_watch_usr_dirs(colord_t)

fs_getattr_all_fs(colord_t)
fs_list_noxattr_fs(colord_t)
fs_read_noxattr_fs_files(colord_t)
fs_search_all(colord_t)
fs_dontaudit_getattr_all_fs(colord_t)
fs_getattr_tmpfs(colord_t)
fs_read_cgroup_files(colord_t)

storage_getattr_fixed_disk_dev(colord_t)
storage_getattr_removable_dev(colord_t)
storage_read_scsi_generic(colord_t)
storage_write_scsi_generic(colord_t)

init_read_state(colord_t)

auth_use_nsswitch(colord_t)

init_read_state(colord_t)

logging_send_syslog_msg(colord_t)

systemd_read_logind_sessions_files(colord_t)
systemd_hwdb_manage_config(colord_t)

userdom_rw_user_tmp_files(colord_t)
userdom_home_reader(colord_t)
userdom_list_user_home_content(colord_t)
userdom_read_inherited_user_home_content_files(colord_t)
userdom_map_user_home_files(colord_t)

optional_policy(`
	cups_read_config(colord_t)
	cups_read_rw_config(colord_t)
	cups_read_state(colord_t)
	cups_stream_connect(colord_t)
	cups_dbus_chat(colord_t)
	cups_read_state(colord_t)
')

optional_policy(`
	gnome_read_home_icc_data_content(colord_t)
	# Fixes lots of breakage in F16 on upgrade
	gnome_read_generic_data_home_files(colord_t)
    gnome_map_generic_data_home_files(colord_t)
')

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

optional_policy(`
	sysnet_exec_ifconfig(colord_t)
')

optional_policy(`
	systemd_hwdb_read_config(colord_t)
')

optional_policy(`
	udev_read_db(colord_t)
	udev_read_pid_files(colord_t)
')

optional_policy(`
	xserver_dbus_chat_xdm(colord_t)
	xserver_read_xdm_state(colord_t)
	# /var/lib/gdm/.local/share/icc/edid-0a027915105823af34f99b1704e80336.icc
	xserver_read_inherited_xdm_lib_files(colord_t)
    # allow to read /run/initial-setup-$username
    xserver_read_xdm_pid(colord_t)
    xserver_map_xdm_pid(colord_t)
')

optional_policy(`
	zoneminder_rw_tmpfs_files(colord_t)
')

tunable_policy(`colord_use_nfs',`
	fs_manage_nfs_dirs(colord_t)
	fs_manage_nfs_files(colord_t)
	fs_manage_nfs_symlinks(colord_t)
    fs_mmap_nfs_files(colord_t)
')

tunable_policy(`use_ecryptfs_home_dirs',`
	fs_manage_ecryptfs_files(colord_t)
')
