policy_module(smartmon)

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

## <desc>
##	<p>
##	Determine whether smartmon can support
##	devices on 3ware controllers.
##	</p>
## </desc>
gen_tunable(smartmon_3ware, false)

type fsdaemon_t;
type fsdaemon_exec_t;
init_daemon_domain(fsdaemon_t, fsdaemon_exec_t)

type fsdaemon_initrc_exec_t;
init_script_file(fsdaemon_initrc_exec_t)

type fsdaemon_runtime_t alias fsdaemon_var_run_t;
files_runtime_file(fsdaemon_runtime_t)

type fsdaemon_var_lib_t;
files_type(fsdaemon_var_lib_t)

type fsdaemon_tmp_t;
files_tmp_file(fsdaemon_tmp_t)

ifdef(`enable_mls',`
	init_ranged_daemon_domain(fsdaemon_t, fsdaemon_exec_t, mls_systemhigh)
')

type smartmon_update_drivedb_t;
type smartmon_update_drivedb_exec_t;
init_system_domain(smartmon_update_drivedb_t, smartmon_update_drivedb_exec_t)

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

allow fsdaemon_t self:capability { dac_override kill setgid setpcap setuid sys_admin sys_rawio };
dontaudit fsdaemon_t self:capability { net_admin sys_tty_config };
allow fsdaemon_t self:process { getcap setcap signal_perms };
allow fsdaemon_t self:fifo_file rw_fifo_file_perms;
allow fsdaemon_t self:unix_stream_socket { accept listen };

manage_dirs_pattern(fsdaemon_t, fsdaemon_tmp_t, fsdaemon_tmp_t)
manage_files_pattern(fsdaemon_t, fsdaemon_tmp_t, fsdaemon_tmp_t)
files_tmp_filetrans(fsdaemon_t, fsdaemon_tmp_t, { file dir })

manage_files_pattern(fsdaemon_t, fsdaemon_runtime_t, fsdaemon_runtime_t)
files_runtime_filetrans(fsdaemon_t, fsdaemon_runtime_t, file)

manage_files_pattern(fsdaemon_t, fsdaemon_var_lib_t, fsdaemon_var_lib_t)

kernel_read_kernel_sysctls(fsdaemon_t)
kernel_read_network_state(fsdaemon_t)
kernel_read_software_raid_state(fsdaemon_t)
kernel_read_system_state(fsdaemon_t)

corecmd_exec_all_executables(fsdaemon_t)

dev_read_sysfs(fsdaemon_t)
dev_read_urand(fsdaemon_t)

domain_use_interactive_fds(fsdaemon_t)

files_exec_etc_files(fsdaemon_t)
files_read_etc_files(fsdaemon_t)
files_read_etc_runtime_files(fsdaemon_t)
files_search_var_lib(fsdaemon_t)

fs_getattr_all_fs(fsdaemon_t)
fs_search_auto_mountpoints(fsdaemon_t)

mls_file_read_all_levels(fsdaemon_t)

storage_raw_read_fixed_disk(fsdaemon_t)
storage_raw_write_fixed_disk(fsdaemon_t)
storage_raw_read_removable_device(fsdaemon_t)
storage_read_scsi_generic(fsdaemon_t)
storage_write_scsi_generic(fsdaemon_t)

term_dontaudit_search_ptys(fsdaemon_t)

application_signull(fsdaemon_t)

init_read_utmp(fsdaemon_t)

libs_exec_ld_so(fsdaemon_t)
libs_exec_lib_files(fsdaemon_t)

logging_send_syslog_msg(fsdaemon_t)

miscfiles_read_localization(fsdaemon_t)

sysnet_dns_name_resolve(fsdaemon_t)

userdom_dontaudit_use_unpriv_user_fds(fsdaemon_t)
userdom_dontaudit_search_user_home_dirs(fsdaemon_t)

tunable_policy(`smartmon_3ware',`
	allow fsdaemon_t self:process setfscreate;

	storage_create_fixed_disk_dev(fsdaemon_t)
	storage_delete_fixed_disk_dev(fsdaemon_t)
	storage_dev_filetrans_fixed_disk(fsdaemon_t, blk_file)

	selinux_validate_context(fsdaemon_t)

	seutil_read_file_contexts(fsdaemon_t)
')

optional_policy(`
	fstools_read_fsadm_db_files(fsdaemon_t)
')

optional_policy(`
	mta_send_mail(fsdaemon_t)
')

optional_policy(`
	seutil_sigchld_newrole(fsdaemon_t)
')

########################################
#
# smartmon_update_drivedb policy
#

allow smartmon_update_drivedb_t self:fifo_file rw_fifo_file_perms;
allow smartmon_update_drivedb_t self:unix_stream_socket connectto;

corecmd_exec_bin(smartmon_update_drivedb_t)
corecmd_exec_shell(smartmon_update_drivedb_t)

corenet_sendrecv_http_client_packets(smartmon_update_drivedb_t)
corenet_tcp_connect_http_port(smartmon_update_drivedb_t)

files_read_etc_files(smartmon_update_drivedb_t)

kernel_dontaudit_read_system_state(smartmon_update_drivedb_t)

miscfiles_read_generic_certs(smartmon_update_drivedb_t)
miscfiles_read_localization(smartmon_update_drivedb_t)

sysnet_dns_name_resolve(smartmon_update_drivedb_t)

ifdef(`distro_gentoo',`
	fstools_manage_fsadm_db_files(smartmon_update_drivedb_t)
	fstools_watch_fsadm_db_dirs(smartmon_update_drivedb_t)
')

optional_policy(`
	cron_rw_inherited_system_job_tmp_files(smartmon_update_drivedb_t)
	cron_system_entry(smartmon_update_drivedb_t, smartmon_update_drivedb_exec_t)
')

optional_policy(`
	fstools_exec(smartmon_update_drivedb_t)
')

optional_policy(`
	gpg_exec_agent(smartmon_update_drivedb_t)
	gpg_exec(smartmon_update_drivedb_t)
')

optional_policy(`
	xdg_read_config_files(smartmon_update_drivedb_t)
')
