policy_module(pcscd, 1.8.0)

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

type pcscd_t;
type pcscd_exec_t;
init_daemon_domain(pcscd_t, pcscd_exec_t)

type pcscd_initrc_exec_t;
init_script_file(pcscd_initrc_exec_t)

type pcscd_var_run_t;
files_pid_file(pcscd_var_run_t)
init_daemon_run_dir(pcscd_var_run_t, "pcscd")

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

allow pcscd_t self:capability {  dac_read_search fsetid };
dontaudit pcscd_t self:capability { sys_admin };
allow pcscd_t self:capability2 { wake_alarm };
allow pcscd_t self:process { signal signull };
dontaudit pcscd_t self:process setsched;
allow pcscd_t self:fifo_file rw_fifo_file_perms;
allow pcscd_t self:unix_stream_socket create_stream_socket_perms;
allow pcscd_t self:unix_dgram_socket create_socket_perms;
allow pcscd_t self:tcp_socket create_stream_socket_perms;
allow pcscd_t self:netlink_kobject_uevent_socket create_socket_perms;

manage_dirs_pattern(pcscd_t, pcscd_var_run_t, pcscd_var_run_t)
manage_files_pattern(pcscd_t, pcscd_var_run_t, pcscd_var_run_t)
manage_fifo_files_pattern(pcscd_t, pcscd_var_run_t, pcscd_var_run_t)
manage_sock_files_pattern(pcscd_t, pcscd_var_run_t, pcscd_var_run_t)
files_pid_filetrans(pcscd_t, pcscd_var_run_t, { file sock_file dir })

kernel_read_system_state(pcscd_t)
# There is bug in kernel in 4.16 where lot of domains requesting module_request, for now dontauditing
kernel_dontaudit_request_load_module(pcscd_t)

corenet_all_recvfrom_netlabel(pcscd_t)
corenet_tcp_sendrecv_generic_if(pcscd_t)
corenet_tcp_sendrecv_generic_node(pcscd_t)

corenet_sendrecv_http_client_packets(pcscd_t)
corenet_tcp_connect_http_port(pcscd_t)
corenet_tcp_sendrecv_http_port(pcscd_t)

domain_read_all_domains_state(pcscd_t)

dev_rw_generic_usb_dev(pcscd_t)
dev_rw_smartcard(pcscd_t)
dev_rw_usbfs(pcscd_t)
dev_read_sysfs(pcscd_t)

files_read_etc_runtime_files(pcscd_t)

term_use_unallocated_ttys(pcscd_t)
term_dontaudit_getattr_pty_dirs(pcscd_t)

locallogin_use_fds(pcscd_t)

logging_send_syslog_msg(pcscd_t)

sysnet_dns_name_resolve(pcscd_t)

userdom_read_all_users_state(pcscd_t)

optional_policy(`
	dbus_system_bus_client(pcscd_t)

	optional_policy(`
		hal_dbus_chat(pcscd_t)
	')

    optional_policy(`
        policykit_dbus_chat(pcscd_t)
        policykit_dbus_chat_auth(pcscd_t)
    ')

')

optional_policy(`
	policykit_dbus_chat(pcscd_t)
')

optional_policy(`
	openct_stream_connect(pcscd_t)
	openct_read_pid_files(pcscd_t)
	openct_signull(pcscd_t)
')

optional_policy(`
	rpm_use_script_fds(pcscd_t)
')

optional_policy(`
	udev_read_db(pcscd_t)
')

optional_policy(`
	virt_rw_svirt_dev(pcscd_t)
')

