policy_module(dirmngr)

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

type dirmngr_t;
type dirmngr_exec_t;
init_daemon_domain(dirmngr_t, dirmngr_exec_t)

type dirmngr_conf_t;
files_config_file(dirmngr_conf_t)

type dirmngr_initrc_exec_t;
init_script_file(dirmngr_initrc_exec_t)

type dirmngr_log_t;
logging_log_file(dirmngr_log_t)

type dirmngr_runtime_t alias dirmngr_var_run_t;
files_runtime_file(dirmngr_runtime_t)

type dirmngr_tmp_t;
userdom_user_tmp_file(dirmngr_tmp_t)
userdom_user_runtime_content(dirmngr_tmp_t)

type dirmngr_var_lib_t;
files_type(dirmngr_var_lib_t)

type dirmngr_home_t;
userdom_user_home_content(dirmngr_home_t)

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

allow dirmngr_t self:fifo_file rw_fifo_file_perms;
allow dirmngr_t self:unix_stream_socket rw_stream_socket_perms;

allow dirmngr_t dirmngr_conf_t:dir list_dir_perms;
allow dirmngr_t dirmngr_conf_t:file read_file_perms;
allow dirmngr_t dirmngr_conf_t:lnk_file read_lnk_file_perms;

manage_files_pattern(dirmngr_t, dirmngr_home_t, dirmngr_home_t)
allow dirmngr_t dirmngr_home_t:dir { add_entry_dir_perms create_dir_perms list_dir_perms };

manage_dirs_pattern(dirmngr_t, dirmngr_log_t, dirmngr_log_t)
append_files_pattern(dirmngr_t, dirmngr_log_t, dirmngr_log_t)
create_files_pattern(dirmngr_t, dirmngr_log_t, dirmngr_log_t)
setattr_files_pattern(dirmngr_t, dirmngr_log_t, dirmngr_log_t)
logging_log_filetrans(dirmngr_t, dirmngr_log_t, dir)

manage_dirs_pattern(dirmngr_t, dirmngr_var_lib_t, dirmngr_var_lib_t)
manage_files_pattern(dirmngr_t, dirmngr_var_lib_t, dirmngr_var_lib_t)
manage_lnk_files_pattern(dirmngr_t, dirmngr_var_lib_t, dirmngr_var_lib_t)
files_var_lib_filetrans(dirmngr_t, dirmngr_var_lib_t, dir)

manage_sock_files_pattern(dirmngr_t, dirmngr_tmp_t, dirmngr_tmp_t)

manage_dirs_pattern(dirmngr_t, dirmngr_runtime_t, dirmngr_runtime_t)
manage_files_pattern(dirmngr_t, dirmngr_runtime_t, dirmngr_runtime_t)
manage_sock_files_pattern(dirmngr_t, dirmngr_runtime_t, dirmngr_runtime_t)
files_runtime_filetrans(dirmngr_t, dirmngr_runtime_t, { dir file })

dev_read_rand(dirmngr_t)
dev_read_urand(dirmngr_t)

sysnet_dns_name_resolve(dirmngr_t)

corenet_tcp_connect_http_port(dirmngr_t)
corenet_tcp_connect_pgpkeyserver_port(dirmngr_t)
corenet_tcp_connect_tor_port(dirmngr_t)
corenet_udp_bind_generic_node(dirmngr_t)

files_read_etc_files(dirmngr_t)
files_read_usr_files(dirmngr_t)

miscfiles_read_localization(dirmngr_t)
miscfiles_read_generic_certs(dirmngr_t)

userdom_search_user_home_dirs(dirmngr_t)
userdom_search_user_runtime(dirmngr_t)
userdom_user_runtime_filetrans(dirmngr_t, dirmngr_tmp_t, dir)

optional_policy(`
	gpg_agent_tmp_filetrans(dirmngr_t, dirmngr_tmp_t, sock_file)
	gpg_runtime_filetrans(dirmngr_t, dirmngr_tmp_t, sock_file)
	gpg_secret_filetrans(dirmngr_t, dirmngr_home_t, dir)
	gpg_stream_connect_agent(dirmngr_t)
')
