policy_module(openhpid, 1.0.0)

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

type openhpid_t;
type openhpid_exec_t;
init_daemon_domain(openhpid_t, openhpid_exec_t)

type openhpid_initrc_exec_t;
init_script_file(openhpid_initrc_exec_t)

type openhpid_log_t;
logging_log_file(openhpid_log_t)

type openhpid_var_lib_t;
files_type(openhpid_var_lib_t)

type openhpid_var_run_t;
files_pid_file(openhpid_var_run_t)

########################################
#
# openhpid local policy
#

allow openhpid_t self:capability { kill };
allow openhpid_t self:process signal_perms;

allow openhpid_t self:fifo_file rw_fifo_file_perms;
allow openhpid_t self:netlink_route_socket r_netlink_socket_perms;
allow openhpid_t self:unix_stream_socket create_stream_socket_perms;
allow openhpid_t self:tcp_socket create_stream_socket_perms;
allow openhpid_t self:udp_socket create_socket_perms;


manage_files_pattern(openhpid_t, openhpid_log_t, openhpid_log_t)
logging_log_filetrans(openhpid_t, openhpid_log_t, file)

manage_dirs_pattern(openhpid_t, openhpid_var_lib_t, openhpid_var_lib_t)
manage_files_pattern(openhpid_t, openhpid_var_lib_t, openhpid_var_lib_t)
files_var_lib_filetrans(openhpid_t, openhpid_var_lib_t, { dir file })

manage_files_pattern(openhpid_t, openhpid_var_run_t, openhpid_var_run_t)
files_pid_filetrans(openhpid_t, openhpid_var_run_t, { file })

kernel_read_system_state(openhpid_t)

corenet_tcp_bind_generic_node(openhpid_t)
corenet_tcp_bind_openhpid_port(openhpid_t)
corenet_tcp_connect_http_port(openhpid_t)

dev_read_urand(openhpid_t)
dev_rw_watchdog(openhpid_t)

logging_send_syslog_msg(openhpid_t)

miscfiles_read_generic_certs(openhpid_t)

sysnet_read_config(openhpid_t)

optional_policy(`
	snmp_manage_var_lib_files(openhpid_t)
	snmp_manage_var_lib_dirs(openhpid_t)
')
