## <summary>policy for zoneminder</summary>

########################################
## <summary>
##	Transition to zoneminder.
## </summary>
## <param name="domain">
## <summary>
##	Domain allowed to transition.
## </summary>
## </param>
#
interface(`zoneminder_domtrans',`
	gen_require(`
		type zoneminder_t, zoneminder_exec_t;
	')

	corecmd_search_bin($1)
	domtrans_pattern($1, zoneminder_exec_t, zoneminder_t)
')

########################################
## <summary>
##	Allow the specified domain to execute zoneminder
##	in the caller domain.
## </summary>
## <param name="domain">
## <summary>
##	Domain allowed to transition.
## </summary>
## </param>
#
interface(`zoneminder_exec',`
	gen_require(`
		type zoneminder_exec_t;
	')

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


########################################
## <summary>
##	Execute zoneminder server in the zoneminder domain.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`zoneminder_initrc_domtrans',`
	gen_require(`
		type zoneminder_initrc_exec_t;
	')

	init_labeled_script_domtrans($1, zoneminder_initrc_exec_t)
')


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

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

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

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

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

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

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

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

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

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

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

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

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

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

########################################
## <summary>
##  Manage zoneminder sock_files files.
## </summary>
## <param name="domain">
##  <summary>
##  Domain allowed access.
##  </summary>
## </param>
#
interface(`zoneminder_manage_lib_sock_files',`
    gen_require(`
        type zoneminder_var_lib_t;
    ')
    files_search_var_lib($1)
    manage_sock_files_pattern($1, zoneminder_var_lib_t, zoneminder_var_lib_t)
')

########################################
## <summary>
##	Search zoneminder spool directories.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`zoneminder_search_spool',`
	gen_require(`
		type zoneminder_spool_t;
	')

	allow $1 zoneminder_spool_t:dir search_dir_perms;
	files_search_spool($1)
')

########################################
## <summary>
##	Read zoneminder spool files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`zoneminder_read_spool_files',`
	gen_require(`
		type zoneminder_spool_t;
	')

	files_search_spool($1)
	read_files_pattern($1, zoneminder_spool_t, zoneminder_spool_t)
')

########################################
## <summary>
##	Manage zoneminder spool files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`zoneminder_manage_spool_files',`
	gen_require(`
		type zoneminder_spool_t;
	')

	files_search_spool($1)
	manage_files_pattern($1, zoneminder_spool_t, zoneminder_spool_t)
')

########################################
## <summary>
##	Manage zoneminder spool dirs.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`zoneminder_manage_spool_dirs',`
	gen_require(`
		type zoneminder_spool_t;
	')

	files_search_spool($1)
	manage_dirs_pattern($1, zoneminder_spool_t, zoneminder_spool_t)
')

########################################
## <summary>
##	Connect to zoneminder over a unix stream socket.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`zoneminder_stream_connect',`
	gen_require(`
		type zoneminder_t, zoneminder_var_lib_t;
	')

	files_search_pids($1)
	stream_connect_pattern($1, zoneminder_var_lib_t, zoneminder_var_lib_t, zoneminder_t)
')

######################################
## <summary>
##  Read/write zonerimender tmpfs files.
## </summary>
## <param name="domain">
##  <summary>
##  Domain allowed access.
##  </summary>
## </param>
#
interface(`zoneminder_rw_tmpfs_files',`
    gen_require(`
        type zoneminder_tmpfs_t;
    ')

    fs_search_tmpfs($1)
    rw_files_pattern($1, zoneminder_tmpfs_t, zoneminder_tmpfs_t)
')

########################################
## <summary>
##	All of the rules required to administrate
##	an zoneminder environment
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	Role allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`zoneminder_admin',`
	gen_require(`
		type zoneminder_t;
	type zoneminder_initrc_exec_t;
	type zoneminder_log_t;
	type zoneminder_var_lib_t;
	type zoneminder_spool_t;
	')

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

	zoneminder_initrc_domtrans($1)
	domain_system_change_exemption($1)
	role_transition $2 zoneminder_initrc_exec_t system_r;
	allow $2 system_r;

	logging_search_logs($1)
	admin_pattern($1, zoneminder_log_t)

	files_search_var_lib($1)
	admin_pattern($1, zoneminder_var_lib_t)

	files_search_spool($1)
	admin_pattern($1, zoneminder_spool_t)

')

