
## <summary>Jetty - HTTP server and Servlet container</summary>

########################################
## <summary>
##	Execute jetty_exec_t in the jetty domain.
## </summary>
## <param name="domain">
## <summary>
##	Domain allowed to transition.
## </summary>
## </param>
#
interface(`jetty_domtrans',`
	gen_require(`
		type jetty_t, jetty_exec_t;
	')

	corecmd_search_bin($1)
	domtrans_pattern($1, jetty_exec_t, jetty_t)
')

######################################
## <summary>
##	Execute jetty in the caller domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_exec',`
	gen_require(`
		type jetty_exec_t;
	')

	corecmd_search_bin($1)
	can_exec($1, jetty_exec_t)
')

########################################
## <summary>
##	Search jetty cache directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_search_cache',`
	gen_require(`
		type jetty_cache_t;
	')

	allow $1 jetty_cache_t:dir search_dir_perms;
	files_search_var($1)
')

########################################
## <summary>
##	Read jetty cache files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_read_cache_files',`
	gen_require(`
		type jetty_cache_t;
	')

	files_search_var($1)
	read_files_pattern($1, jetty_cache_t, jetty_cache_t)
')

########################################
## <summary>
##	Create, read, write, and delete
##	jetty cache files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_manage_cache_files',`
	gen_require(`
		type jetty_cache_t;
	')

	files_search_var($1)
	manage_files_pattern($1, jetty_cache_t, jetty_cache_t)
')

########################################
## <summary>
##	Manage jetty cache dirs.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_manage_cache_dirs',`
	gen_require(`
		type jetty_cache_t;
	')

	files_search_var($1)
	manage_dirs_pattern($1, jetty_cache_t, jetty_cache_t)
')

########################################
## <summary>
##	Read jetty's log files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`jetty_read_log',`
	gen_require(`
		type jetty_log_t;
	')

	logging_search_logs($1)
	read_files_pattern($1, jetty_log_t, jetty_log_t)
')

########################################
## <summary>
##	Append to jetty log files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_append_log',`
	gen_require(`
		type jetty_log_t;
	')

	logging_search_logs($1)
	append_files_pattern($1, jetty_log_t, jetty_log_t)
')

########################################
## <summary>
##	Manage jetty log files
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_manage_log',`
	gen_require(`
		type jetty_log_t;
	')

	logging_search_logs($1)
	manage_dirs_pattern($1, jetty_log_t, jetty_log_t)
	manage_files_pattern($1, jetty_log_t, jetty_log_t)
	manage_lnk_files_pattern($1, jetty_log_t, jetty_log_t)
')

########################################
## <summary>
##	Do not audit attempts to read,
##	jetty tmp files
## </summary>
## <param name="domain">
##	<summary>
##	Domain to not audit.
##	</summary>
## </param>
#
interface(`jetty_dontaudit_read_tmp_files',`
	gen_require(`
		type jetty_tmp_t;
	')

	dontaudit $1 jetty_tmp_t:file read_file_perms;
')

########################################
## <summary>
##	Read jetty tmp files
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_read_tmp_files',`
	gen_require(`
		type jetty_tmp_t;
	')

	files_search_tmp($1)
	read_files_pattern($1, jetty_tmp_t, jetty_tmp_t)
')

########################################
## <summary>
##	Manage jetty tmp files
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_manage_tmp',`
	gen_require(`
		type jetty_tmp_t;
	')

	files_search_tmp($1)
	manage_dirs_pattern($1, jetty_tmp_t, jetty_tmp_t)
	manage_files_pattern($1, jetty_tmp_t, jetty_tmp_t)
	manage_lnk_files_pattern($1, jetty_tmp_t, jetty_tmp_t)
')

########################################
## <summary>
##	Search jetty lib directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_search_lib',`
	gen_require(`
		type jetty_var_lib_t;
	')

	allow $1 jetty_var_lib_t:dir search_dir_perms;
	files_search_var_lib($1)
')

########################################
## <summary>
##	Read jetty lib files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_read_lib_files',`
	gen_require(`
		type jetty_var_lib_t;
	')

	files_search_var_lib($1)
	read_files_pattern($1, jetty_var_lib_t, jetty_var_lib_t)
')

########################################
## <summary>
##	Manage jetty lib files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_manage_lib_files',`
	gen_require(`
		type jetty_var_lib_t;
	')

	files_search_var_lib($1)
	manage_files_pattern($1, jetty_var_lib_t, jetty_var_lib_t)
')

########################################
## <summary>
##	Manage jetty lib directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_manage_lib_dirs',`
	gen_require(`
		type jetty_var_lib_t;
	')

	files_search_var_lib($1)
	manage_dirs_pattern($1, jetty_var_lib_t, jetty_var_lib_t)
')

########################################
## <summary>
##	Read jetty PID files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`jetty_read_pid_files',`
	gen_require(`
		type jetty_var_run_t;
	')

	files_search_pids($1)
	read_files_pattern($1, jetty_var_run_t, jetty_var_run_t)
')

########################################
## <summary>
##	Execute jetty server in the jetty domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed to transition.
##	</summary>
## </param>
#
interface(`jetty_systemctl',`
	gen_require(`
		type jetty_t;
		type jetty_unit_file_t;
	')

	systemd_exec_systemctl($1)
        systemd_read_fifo_file_passwd_run($1)
	allow $1 jetty_unit_file_t:file read_file_perms;
	allow $1 jetty_unit_file_t:service manage_service_perms;

	ps_process_pattern($1, jetty_t)
')


########################################
## <summary>
##	All of the rules required to administrate
##	an jetty environment
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	Role allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`jetty_admin',`
	gen_require(`
		type jetty_t;
		type jetty_cache_t;
		type jetty_log_t;
		type jetty_tmp_t;
		type jetty_var_lib_t;
		type jetty_var_run_t;
	type jetty_unit_file_t;
	')

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

    tunable_policy(`deny_ptrace',`',`
        allow $1 jetty_t:process ptrace;
    ')

	files_search_var($1)
	admin_pattern($1, jetty_cache_t)

	logging_search_logs($1)
	admin_pattern($1, jetty_log_t)

	files_search_tmp($1)
	admin_pattern($1, jetty_tmp_t)

	files_search_var_lib($1)
	admin_pattern($1, jetty_var_lib_t)

	files_search_pids($1)
	admin_pattern($1, jetty_var_run_t)

	jetty_systemctl($1)
	admin_pattern($1, jetty_unit_file_t)
	allow $1 jetty_unit_file_t:service all_service_perms;
	optional_policy(`
		systemd_passwd_agent_exec($1)
		systemd_read_fifo_file_passwd_run($1)
	')
')
