1ec3d1a
## <summary>SELinux utility to run a shell with a new role</summary>
1ec3d1a
1ec3d1a
#######################################
1ec3d1a
## <summary>
1ec3d1a
##	The role template for the userhelper module.
1ec3d1a
## </summary>
1ec3d1a
## <param name="userrole_prefix">
1ec3d1a
##	<summary>
1ec3d1a
##	The prefix of the user role (e.g., user
1ec3d1a
##	is the prefix for user_r).
1ec3d1a
##	</summary>
1ec3d1a
## </param>
1ec3d1a
## <param name="user_role">
1ec3d1a
##	<summary>
1ec3d1a
##	The user role.
1ec3d1a
##	</summary>
1ec3d1a
## </param>
1ec3d1a
## <param name="user_domain">
1ec3d1a
##	<summary>
1ec3d1a
##	The user domain associated with the role.
1ec3d1a
##	</summary>
1ec3d1a
## </param>
1ec3d1a
#
1ec3d1a
template(`userhelper_role_template',`
1ec3d1a
	gen_require(`
1ec3d1a
		attribute userhelper_type;
1ec3d1a
		type userhelper_exec_t, userhelper_conf_t;
1ec3d1a
		class dbus send_msg;
1ec3d1a
	')
1ec3d1a
1ec3d1a
	########################################
1ec3d1a
	#
1ec3d1a
	# Declarations
1ec3d1a
	#
1ec3d1a
1ec3d1a
	type $1_userhelper_t, userhelper_type;
Chris PeBenito 66b26ac
	userdom_user_application_domain($1_userhelper_t, userhelper_exec_t)
1ec3d1a
	domain_role_change_exemption($1_userhelper_t)
1ec3d1a
	domain_obj_id_change_exemption($1_userhelper_t)
1ec3d1a
	domain_interactive_fd($1_userhelper_t)
1ec3d1a
	domain_subj_id_change_exemption($1_userhelper_t)
1ec3d1a
	role $2 types $1_userhelper_t;
1ec3d1a
1ec3d1a
	########################################
1ec3d1a
	#
1ec3d1a
	# Local policy
1ec3d1a
	#
1ec3d1a
	allow $1_userhelper_t self:capability { setuid setgid net_bind_service dac_override chown sys_tty_config };
1ec3d1a
	allow $1_userhelper_t self:process ~{ ptrace setcurrent setexec setfscreate setrlimit execmem execstack execheap };
1ec3d1a
	allow $1_userhelper_t self:process setexec;
1ec3d1a
	allow $1_userhelper_t self:fd use;
1ec3d1a
	allow $1_userhelper_t self:fifo_file rw_fifo_file_perms;
1ec3d1a
	allow $1_userhelper_t self:shm create_shm_perms;
1ec3d1a
	allow $1_userhelper_t self:sem create_sem_perms;
1ec3d1a
	allow $1_userhelper_t self:msgq create_msgq_perms;
1ec3d1a
	allow $1_userhelper_t self:msg { send receive };
1ec3d1a
	allow $1_userhelper_t self:unix_dgram_socket create_socket_perms;
1ec3d1a
	allow $1_userhelper_t self:unix_stream_socket create_stream_socket_perms;
1ec3d1a
	allow $1_userhelper_t self:unix_dgram_socket sendto;
1ec3d1a
	allow $1_userhelper_t self:unix_stream_socket connectto;
1ec3d1a
	allow $1_userhelper_t self:sock_file read_sock_file_perms;
1ec3d1a
1ec3d1a
	#Transition to the derived domain.
1ec3d1a
	domtrans_pattern($3, userhelper_exec_t, $1_userhelper_t)
1ec3d1a
1ec3d1a
	allow $1_userhelper_t userhelper_conf_t:dir rw_dir_perms;
1ec3d1a
	rw_files_pattern($1_userhelper_t, userhelper_conf_t, userhelper_conf_t)
1ec3d1a
1ec3d1a
	can_exec($1_userhelper_t, userhelper_exec_t)
1ec3d1a
1ec3d1a
	dontaudit $3 $1_userhelper_t:process signal;
1ec3d1a
1ec3d1a
	kernel_read_all_sysctls($1_userhelper_t)
1ec3d1a
	kernel_getattr_debugfs($1_userhelper_t)
1ec3d1a
	kernel_read_system_state($1_userhelper_t)
1ec3d1a
1ec3d1a
	# Execute shells
1ec3d1a
	corecmd_exec_shell($1_userhelper_t)
1ec3d1a
	# By default, revert to the calling domain when a program is executed
1ec3d1a
	corecmd_bin_domtrans($1_userhelper_t, $3)
1ec3d1a
1ec3d1a
	# Inherit descriptors from the current session.
1ec3d1a
	domain_use_interactive_fds($1_userhelper_t)
1ec3d1a
	# for when the user types "exec userhelper" at the command line
1ec3d1a
	domain_sigchld_interactive_fds($1_userhelper_t)
1ec3d1a
1ec3d1a
	dev_read_urand($1_userhelper_t)
1ec3d1a
	# Read /dev directories and any symbolic links.
1ec3d1a
	dev_list_all_dev_nodes($1_userhelper_t)
1ec3d1a
1ec3d1a
	files_list_var_lib($1_userhelper_t)
1ec3d1a
	# Read the /etc/security/default_type file
4a1862e
	files_read_etc_files($1_userhelper_t)
1ec3d1a
	# Read /var.
1ec3d1a
	files_read_var_files($1_userhelper_t)
1ec3d1a
	files_read_var_symlinks($1_userhelper_t)
1ec3d1a
	# for some PAM modules and for cwd
1ec3d1a
	files_search_home($1_userhelper_t)
1ec3d1a
1ec3d1a
	fs_search_auto_mountpoints($1_userhelper_t)
1ec3d1a
	fs_read_nfs_files($1_userhelper_t)
1ec3d1a
	fs_read_nfs_symlinks($1_userhelper_t)
1ec3d1a
1ec3d1a
	# Allow $1_userhelper to obtain contexts to relabel TTYs
1ec3d1a
	selinux_get_fs_mount($1_userhelper_t)
1ec3d1a
	selinux_validate_context($1_userhelper_t)
1ec3d1a
	selinux_compute_access_vector($1_userhelper_t)
1ec3d1a
	selinux_compute_create_context($1_userhelper_t)
1ec3d1a
	selinux_compute_relabel_context($1_userhelper_t)
1ec3d1a
	selinux_compute_user_contexts($1_userhelper_t)
1ec3d1a
1ec3d1a
	# Read the devpts root directory.
1ec3d1a
	term_list_ptys($1_userhelper_t)
1ec3d1a
	# Relabel terminals.
1ec3d1a
	term_relabel_all_ttys($1_userhelper_t)
1ec3d1a
	term_relabel_all_ptys($1_userhelper_t)
1ec3d1a
	# Access terminals.
1ec3d1a
	term_use_all_ttys($1_userhelper_t)
1ec3d1a
	term_use_all_ptys($1_userhelper_t)
1ec3d1a
1ec3d1a
	auth_domtrans_chk_passwd($1_userhelper_t)
1ec3d1a
	auth_manage_pam_pid($1_userhelper_t)
1ec3d1a
	auth_manage_var_auth($1_userhelper_t)
1ec3d1a
	auth_search_pam_console_data($1_userhelper_t)
1ec3d1a
	auth_use_nsswitch($1_userhelper_t)
1ec3d1a
1ec3d1a
	logging_send_syslog_msg($1_userhelper_t)
1ec3d1a
1ec3d1a
	# Inherit descriptors from the current session.
1ec3d1a
	init_use_fds($1_userhelper_t)
1ec3d1a
	# Write to utmp.
1ec3d1a
	init_manage_utmp($1_userhelper_t)
1ec3d1a
	init_pid_filetrans_utmp($1_userhelper_t)
1ec3d1a
1ec3d1a
1ec3d1a
	seutil_read_config($1_userhelper_t)
1ec3d1a
	seutil_read_default_contexts($1_userhelper_t)
1ec3d1a
1ec3d1a
	# Allow $1_userhelper_t to transition to user domains.
1ec3d1a
	userdom_bin_spec_domtrans_unpriv_users($1_userhelper_t)
1ec3d1a
	userdom_entry_spec_domtrans_unpriv_users($1_userhelper_t)
1ec3d1a
1ec3d1a
	ifdef(`distro_redhat',`
1ec3d1a
		optional_policy(`
1ec3d1a
			# Allow transitioning to rpm_t, for up2date
1ec3d1a
			rpm_domtrans($1_userhelper_t)
1ec3d1a
		')
1ec3d1a
	')
1ec3d1a
1ec3d1a
	optional_policy(`
1ec3d1a
		tunable_policy(`! secure_mode',`
1ec3d1a
			#if we are not in secure mode then we can transition to sysadm_t
1ec3d1a
			sysadm_bin_spec_domtrans($1_userhelper_t)
1ec3d1a
			sysadm_entry_spec_domtrans($1_userhelper_t)
1ec3d1a
		')
1ec3d1a
	')
1ec3d1a
')
1ec3d1a
1ec3d1a
########################################
1ec3d1a
## <summary>
1ec3d1a
##	Search the userhelper configuration directory.
1ec3d1a
## </summary>
1ec3d1a
## <param name="domain">
1ec3d1a
##	<summary>
1ec3d1a
##	Domain allowed access.
1ec3d1a
##	</summary>
1ec3d1a
## </param>
1ec3d1a
#
1ec3d1a
interface(`userhelper_search_config',`
1ec3d1a
	gen_require(`
1ec3d1a
		type userhelper_conf_t;
1ec3d1a
	')
1ec3d1a
1ec3d1a
	allow $1 userhelper_conf_t:dir search_dir_perms;
1ec3d1a
')
1ec3d1a
1ec3d1a
########################################
1ec3d1a
## <summary>
1ec3d1a
##	Do not audit attempts to search
1ec3d1a
##	the userhelper configuration directory.
1ec3d1a
## </summary>
1ec3d1a
## <param name="domain">
1ec3d1a
##	<summary>
1ec3d1a
##	Domain to not audit.
1ec3d1a
##	</summary>
1ec3d1a
## </param>
1ec3d1a
#
1ec3d1a
interface(`userhelper_dontaudit_search_config',`
1ec3d1a
	gen_require(`
1ec3d1a
		type userhelper_conf_t;
1ec3d1a
	')
1ec3d1a
1ec3d1a
	dontaudit $1 userhelper_conf_t:dir search_dir_perms;
1ec3d1a
')
1ec3d1a
1ec3d1a
########################################
1ec3d1a
## <summary>
1ec3d1a
##	Allow domain to use userhelper file descriptor.
1ec3d1a
## </summary>
1ec3d1a
## <param name="domain">
1ec3d1a
##	<summary>
1ec3d1a
##	Domain allowed access.
1ec3d1a
##	</summary>
1ec3d1a
## </param>
1ec3d1a
#
1ec3d1a
interface(`userhelper_use_fd',`
1ec3d1a
	gen_require(`
1ec3d1a
		attribute userhelper_type;
1ec3d1a
	')
1ec3d1a
1ec3d1a
	allow $1 userhelper_type:fd use;
1ec3d1a
')
1ec3d1a
1ec3d1a
########################################
1ec3d1a
## <summary>
1ec3d1a
##	Allow domain to send sigchld to userhelper.
1ec3d1a
## </summary>
1ec3d1a
## <param name="domain">
1ec3d1a
##	<summary>
1ec3d1a
##	Domain allowed access.
1ec3d1a
##	</summary>
1ec3d1a
## </param>
1ec3d1a
#
1ec3d1a
interface(`userhelper_sigchld',`
1ec3d1a
	gen_require(`
1ec3d1a
		attribute userhelper_type;
1ec3d1a
	')
1ec3d1a
1ec3d1a
	allow $1 userhelper_type:process sigchld;
1ec3d1a
')
1ec3d1a
1ec3d1a
########################################
1ec3d1a
## <summary>
1ec3d1a
##	Execute the userhelper program in the caller domain.
1ec3d1a
## </summary>
1ec3d1a
## <param name="domain">
1ec3d1a
##	<summary>
1ec3d1a
##	Domain allowed access.
1ec3d1a
##	</summary>
1ec3d1a
## </param>
1ec3d1a
#
1ec3d1a
interface(`userhelper_exec',`
1ec3d1a
	gen_require(`
1ec3d1a
		type userhelper_exec_t;
1ec3d1a
	')
1ec3d1a
1ec3d1a
	can_exec($1, userhelper_exec_t)
1ec3d1a
')
1ec3d1a
1ec3d1a
#######################################
1ec3d1a
## <summary>
1ec3d1a
##	The role template for the consolehelper module.
1ec3d1a
## </summary>
1ec3d1a
## <desc>
1ec3d1a
##	

1ec3d1a
##	This template creates a derived domains which are used
1ec3d1a
##	for consolehelper applications.
1ec3d1a
##	

1ec3d1a
## </desc>
1ec3d1a
## <param name="role_prefix">
1ec3d1a
##	<summary>
1ec3d1a
##	The prefix of the user domain (e.g., user
1ec3d1a
##	is the prefix for user_t).
1ec3d1a
##	</summary>
1ec3d1a
## </param>
1ec3d1a
## <param name="user_role">
1ec3d1a
##	<summary>
1ec3d1a
##	The role associated with the user domain.
1ec3d1a
##	</summary>
1ec3d1a
## </param>
1ec3d1a
## <param name="user_domain">
1ec3d1a
##	<summary>
1ec3d1a
##	The type of the user domain.
1ec3d1a
##	</summary>
1ec3d1a
## </param>
1ec3d1a
#
1ec3d1a
template(`userhelper_console_role_template',`
1ec3d1a
	gen_require(`
1ec3d1a
		type consolehelper_exec_t;
1ec3d1a
		attribute consolehelper_domain;
1ec3d1a
		class dbus send_msg;
1ec3d1a
	')
1ec3d1a
	type $1_consolehelper_t, consolehelper_domain;
1ec3d1a
	domain_type($1_consolehelper_t)
1ec3d1a
	domain_entry_file($1_consolehelper_t, consolehelper_exec_t)
1ec3d1a
	role $2 types $1_consolehelper_t;
1ec3d1a
1ec3d1a
	domtrans_pattern($3, consolehelper_exec_t, $1_consolehelper_t)
1ec3d1a
1ec3d1a
	allow $3 $1_consolehelper_t:process signal;
1ec3d1a
	allow $3 $1_consolehelper_t:dbus send_msg;
1ec3d1a
	allow $1_consolehelper_t $3:dbus send_msg;
05c08f8
	allow $1_consolehelper_t $3:unix_stream_socket connectto;
1ec3d1a
1bafb67
	kernel_read_system_state($1_consolehelper_t)
1bafb67
1ec3d1a
	auth_use_pam($1_consolehelper_t)
1ec3d1a
1ec3d1a
	userdom_manage_tmpfs_role($2, $1_consolehelper_t)
1ec3d1a
1ec3d1a
	optional_policy(`
1ec3d1a
		dbus_connect_session_bus($1_consolehelper_t)
1ec3d1a
	')
1ec3d1a
1ec3d1a
	optional_policy(`
1ec3d1a
		shutdown_run($1_consolehelper_t, $2)
1ec3d1a
		shutdown_send_sigchld($3)
1ec3d1a
	')
1ec3d1a
1ec3d1a
	optional_policy(`
1ec3d1a
		mock_run($1_consolehelper_t, $2)
1ec3d1a
	')
1ec3d1a
1ec3d1a
	optional_policy(`
1ec3d1a
		xserver_run_xauth($1_consolehelper_t, $2)
1ec3d1a
		xserver_read_xdm_pid($1_consolehelper_t)
1ec3d1a
	')
1ec3d1a
')
1ec3d1a
1ec3d1a
########################################
1ec3d1a
## <summary>
1ec3d1a
##	Execute the consolehelper program in the caller domain.
1ec3d1a
## </summary>
1ec3d1a
## <param name="domain">
1ec3d1a
##	<summary>
1ec3d1a
##	Domain allowed access.
1ec3d1a
##	</summary>
1ec3d1a
## </param>
1ec3d1a
#
1ec3d1a
interface(`userhelper_exec_console',`
1ec3d1a
	gen_require(`
1ec3d1a
		type consolehelper_exec_t;
1ec3d1a
	')
1ec3d1a
1ec3d1a
	can_exec($1, consolehelper_exec_t)
1ec3d1a
')