policy_module(mandb, 1.1.1)

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

attribute_role mandb_roles;
roleattribute system_r mandb_roles;

type mandb_t;
type mandb_exec_t;
init_daemon_domain(mandb_t, mandb_exec_t)
role mandb_roles types mandb_t;

type mandb_cache_t;
files_type(mandb_cache_t)

type mandb_home_t;
userdom_user_home_content(mandb_home_t)

type mandb_lock_t;
files_lock_file(mandb_lock_t)

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

allow mandb_t self:capability { dac_read_search dac_override setuid setgid fsetid };
allow mandb_t self:process { setsched signal };
allow mandb_t self:fifo_file rw_fifo_file_perms;
allow mandb_t self:unix_stream_socket create_stream_socket_perms;

manage_dirs_pattern(mandb_t, mandb_cache_t, mandb_cache_t)
manage_files_pattern(mandb_t, mandb_cache_t, mandb_cache_t)
manage_lnk_files_pattern(mandb_t, mandb_cache_t, mandb_cache_t)
files_var_filetrans(mandb_t, mandb_cache_t, { dir file lnk_file })
can_exec(mandb_t, mandb_exec_t)
allow mandb_t mandb_cache_t:file map;

userdom_search_user_home_dirs(mandb_t)
allow mandb_t mandb_home_t:file read_file_perms;

allow mandb_t mandb_lock_t:file manage_file_perms;
files_lock_filetrans(mandb_t, mandb_lock_t, file)

kernel_read_kernel_sysctls(mandb_t)
kernel_read_system_state(mandb_t)

auth_read_passwd(mandb_t)

corecmd_exec_bin(mandb_t)
corecmd_exec_shell(mandb_t)

dev_search_sysfs(mandb_t)

domain_use_interactive_fds(mandb_t)

files_search_locks(mandb_t)
files_dontaudit_search_all_mountpoints(mandb_t)

fs_getattr_all_fs(mandb_t)

miscfiles_manage_man_cache(mandb_t)
miscfiles_setattr_man_pages(mandb_t)
miscfiles_read_man_pages(mandb_t)

ifdef(`distro_debian',`
	optional_policy(`
		apt_exec(mandb_t)
		apt_read_db(mandb_t)
	')

	optional_policy(`
		dpkg_exec(mandb_t)
		dpkg_read_db(mandb_t)
		userdom_dontaudit_search_user_home_dirs(mandb_t)
	')
')

optional_policy(`
	cron_system_entry(mandb_t, mandb_exec_t)
')

optional_policy(`
    sssd_read_public_files(mandb_t)
    sssd_stream_connect(mandb_t)
')
