## <summary>TCP/IP encryption</summary>

########################################
## <summary>
##	Execute ipsec in the ipsec domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
#
interface(`ipsec_domtrans',`
	gen_require(`
		type ipsec_t, ipsec_exec_t;
	')

	domtrans_pattern($1, ipsec_exec_t, ipsec_t)
')

########################################
## <summary>
##	Connect to IPSEC using a unix domain stream socket.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`ipsec_stream_connect',`
	gen_require(`
		type ipsec_t, ipsec_runtime_t;
	')

	files_search_runtime($1)
	stream_connect_pattern($1, ipsec_runtime_t, ipsec_runtime_t, ipsec_t)
')

########################################
## <summary>
##	Execute ipsec in the ipsec mgmt domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`ipsec_domtrans_mgmt',`
	gen_require(`
		type ipsec_mgmt_t, ipsec_mgmt_exec_t;
	')

	domtrans_pattern($1, ipsec_mgmt_exec_t, ipsec_mgmt_t)
')

########################################
## <summary>
##	Connect to racoon using a unix domain stream socket.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`ipsec_stream_connect_racoon',`
	gen_require(`
		type racoon_t, ipsec_runtime_t;
	')

	files_search_runtime($1)
	stream_connect_pattern($1, ipsec_runtime_t, ipsec_runtime_t, racoon_t)
')

########################################
## <summary>
##	Get the attributes of an IPSEC key socket.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`ipsec_getattr_key_sockets',`
	gen_require(`
		type ipsec_t;
	')

	allow $1 ipsec_t:key_socket getattr;
')

########################################
## <summary>
##	Execute the IPSEC management program in the caller domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`ipsec_exec_mgmt',`
	gen_require(`
		type ipsec_exec_t;
	')

	can_exec($1, ipsec_exec_t)
')

########################################
## <summary>
##	Send ipsec mgmt a general signal.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
#
interface(`ipsec_signal_mgmt',`
	gen_require(`
		type ipsec_mgmt_t;
	')

	allow $1 ipsec_mgmt_t:process signal;
')

########################################
## <summary>
##	Send ipsec mgmt a null signal.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
#
interface(`ipsec_signull_mgmt',`
	gen_require(`
		type ipsec_mgmt_t;
	')

	allow $1 ipsec_mgmt_t:process signull;
')

########################################
## <summary>
##	Send ipsec mgmt a kill signal.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
#
interface(`ipsec_kill_mgmt',`
	gen_require(`
		type ipsec_mgmt_t;
	')

	allow $1 ipsec_mgmt_t:process sigkill;
')

######################################
## <summary>
##	Send and receive messages from
##	ipsec-mgmt over dbus.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`ipsec_mgmt_dbus_chat',`
	gen_require(`
		type ipsec_mgmt_t;
		class dbus send_msg;
	')

	allow $1 ipsec_mgmt_t:dbus send_msg;
	allow ipsec_mgmt_t $1:dbus send_msg;
')

########################################
## <summary>
##	Read the IPSEC configuration
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`ipsec_read_config',`
	gen_require(`
		type ipsec_conf_file_t;
	')

	files_search_etc($1)
	allow $1 ipsec_conf_file_t:file read_file_perms;
')

########################################
## <summary>
##	Match the default SPD entry.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`ipsec_match_default_spd',`
	gen_require(`
		type ipsec_spd_t;
	')

	allow $1 ipsec_spd_t:association polmatch;
	allow $1 self:association sendto;
')

########################################
## <summary>
##	Set the context of a SPD entry to
##	the default context.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`ipsec_setcontext_default_spd',`
	gen_require(`
		type ipsec_spd_t;
	')

	allow $1 ipsec_spd_t:association setcontext;
')

########################################
## <summary>
##	write the ipsec_runtime_t files.  (Deprecated)
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`ipsec_write_pid',`
	refpolicywarn(`$0($*) has been deprecated, please use ipsec_write_runtime_files() instead.')
	ipsec_write_runtime_files($1)
')

########################################
## <summary>
##	Create, read, write, and delete the IPSEC pid files.
##	(Deprecated)
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`ipsec_manage_pid',`
	refpolicywarn(`$0($*) has been deprecated, please use ipsec_manage_runtime_files() instead.')
	ipsec_manage_runtime_files($1)
')

########################################
## <summary>
##	Write ipsec runtime files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`ipsec_write_runtime_files',`
	gen_require(`
		type ipsec_runtime_t;
	')

	files_search_runtime($1)
	write_files_pattern($1, ipsec_runtime_t, ipsec_runtime_t)
')

########################################
## <summary>
##	Create, read, write, and delete the IPSEC runtime files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`ipsec_manage_runtime_files',`
	gen_require(`
		type ipsec_runtime_t;
	')

	files_search_runtime($1)
	manage_files_pattern($1, ipsec_runtime_t, ipsec_runtime_t)
')

########################################
## <summary>
##	Execute racoon in the racoon domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
#
interface(`ipsec_domtrans_racoon',`
	gen_require(`
		type racoon_t, racoon_exec_t;
	')

	domtrans_pattern($1, racoon_exec_t, racoon_t)
')

########################################
## <summary>
##	Execute racoon and allow the specified role the domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	Role allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`ipsec_run_racoon',`
	gen_require(`
		type racoon_t;
	')

	ipsec_domtrans_racoon($1)
	role $2 types racoon_t;
')

########################################
## <summary>
##	Execute setkey in the setkey domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
#
interface(`ipsec_domtrans_setkey',`
	gen_require(`
		type setkey_t, setkey_exec_t;
	')

	domtrans_pattern($1, setkey_exec_t, setkey_t)
')

########################################
## <summary>
##	Execute setkey and allow the specified role the domains.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	Role allowed access..
##	</summary>
## </param>
## <rolecap/>
#
interface(`ipsec_run_setkey',`
	gen_require(`
		type setkey_t;
	')

	ipsec_domtrans_setkey($1)
	role $2 types setkey_t;
')

########################################
## <summary>
##	All of the rules required to
##	administrate an ipsec environment.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	Role allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`ipsec_admin',`
	gen_require(`
		type ipsec_t, ipsec_initrc_exec_t, ipsec_conf_file_t;
		type ipsec_key_file_t, ipsec_log_t, ipsec_tmp_t;
		type ipsec_runtime_t, ipsec_mgmt_lock_t;
		type ipsec_mgmt_runtime_t, racoon_tmp_t;
		type ipsec_unit_t;
	')

	allow $1 ipsec_t:process { ptrace signal_perms };
	ps_process_pattern($1, ipsec_t)

	init_startstop_service($1, $2, ipsec_t, ipsec_initrc_exec_t, ipsec_unit_t)

	ipsec_exec_mgmt($1)
	ipsec_stream_connect($1)
	# for lsof
	ipsec_getattr_key_sockets($1)

	files_search_etc($1)
	admin_pattern($1, { ipsec_conf_file_t ipsec_key_file_t })

	files_search_tmp($1)
	admin_pattern($1, { ipsec_tmp_t racoon_tmp_t })

	files_search_runtime($1)
	admin_pattern($1, { ipsec_runtime_t ipsec_mgmt_runtime_t })

	files_search_locks($1)
	admin_pattern($1, ipsec_mgmt_lock_t)

	logging_search_logs($1)
	admin_pattern($1, ipsec_log_t)
')
