## <summary>Document database server.</summary>

########################################
## <summary>
##	Read couchdb log files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`couchdb_read_log_files',`
	gen_require(`
		type couchdb_log_t;
	')

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

########################################
## <summary>
##	Read, write, and create couchdb lib files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`couchdb_manage_lib_files',`
	gen_require(`
		type couchdb_var_lib_t;
	')

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

########################################
## <summary>
##	Read couchdb config files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`couchdb_read_conf_files',`
	gen_require(`
		type couchdb_conf_t;
	')

	files_search_etc($1)
	read_files_pattern($1, couchdb_conf_t, couchdb_conf_t)
')

########################################
## <summary>
##	Read couchdb pid files.  (Deprecated)
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`couchdb_read_pid_files',`
	refpolicywarn(`$0($*) has been deprecated, please use couchdb_read_runtime_files() instead.')
	couchdb_read_runtime_files($1)
')

########################################
## <summary>
##	Read couchdb runtime files.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
#
interface(`couchdb_read_runtime_files',`
	gen_require(`
		type couchdb_runtime_t;
	')

	files_search_runtime($1)
	read_files_pattern($1, couchdb_runtime_t, couchdb_runtime_t)
')

########################################
## <summary>
##	All of the rules required to
##	administrate an couchdb environment.
## </summary>
## <param name="domain">
##	<summary>
##	Domain allowed access.
##	</summary>
## </param>
## <param name="role">
##	<summary>
##	Role allowed access.
##	</summary>
## </param>
## <rolecap/>
#
interface(`couchdb_admin',`
	gen_require(`
		type couchdb_t, couchdb_conf_t, couchdb_initrc_exec_t;
		type couchdb_log_t, couchdb_var_lib_t, couchdb_runtime_t;
		type couchdb_tmp_t;
	')

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

	init_startstop_service($1, $2, couchdb_t, couchdb_initrc_exec_t)

	files_search_etc($1)
	admin_pattern($1, couchdb_conf_t)

	logging_search_logs($1)
	admin_pattern($1, couchdb_log_t)

	files_search_tmp($1)
	admin_pattern($1, couchdb_tmp_t)

	files_search_var_lib($1)
	admin_pattern($1, couchdb_var_lib_t)

	files_search_runtime($1)
	admin_pattern($1, couchdb_runtime_t)
')
