Chris PeBenito 7c2f5a
## <summary>SELinux utility to run a shell with a new role</summary>
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
#######################################
Chris PeBenito 7c2f5a
## <summary>
Chris PeBenito 7c2f5a
##	The per user domain template for the userhelper module.
Chris PeBenito 7c2f5a
## </summary>
Chris PeBenito 7c2f5a
## <desc>
Chris PeBenito 7c2f5a
##	

Chris PeBenito 7c2f5a
##	This template creates a derived domains which are used
Chris PeBenito 7c2f5a
##	for userhelper.
Chris PeBenito 7c2f5a
##	

Chris PeBenito 7c2f5a
##	

Chris PeBenito 7c2f5a
##	This template is invoked automatically for each user, and
Chris PeBenito 7c2f5a
##	generally does not need to be invoked directly
Chris PeBenito 7c2f5a
##	by policy writers.
Chris PeBenito 7c2f5a
##	

Chris PeBenito 7c2f5a
## </desc>
Chris PeBenito 7c2f5a
## <param name="userdomain_prefix">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 7c2f5a
##	The prefix of the user domain (e.g., user
Chris PeBenito 7c2f5a
##	is the prefix for user_t).
Chris PeBenito 885b83
##	</summary>
Chris PeBenito 7c2f5a
## </param>
Chris PeBenito 7c2f5a
## <param name="user_domain">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 7c2f5a
##	The type of the user domain.
Chris PeBenito 885b83
##	</summary>
Chris PeBenito 7c2f5a
## </param>
Chris PeBenito 7c2f5a
## <param name="user_role">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 7c2f5a
##	The role associated with the user domain.
Chris PeBenito 885b83
##	</summary>
Chris PeBenito 7c2f5a
## </param>
Chris PeBenito 7c2f5a
#
Chris PeBenito 7c2f5a
template(`userhelper_per_userdomain_template',`
Chris PeBenito 7c2f5a
	gen_require(`
Chris PeBenito 7c2f5a
		type userhelper_exec_t, userhelper_conf_t;
Chris PeBenito 7c2f5a
	')
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	########################################
Chris PeBenito 7c2f5a
	#
Chris PeBenito 7c2f5a
	# Declarations
Chris PeBenito 7c2f5a
	#
Chris PeBenito 1c1ac6
Chris PeBenito 7c2f5a
	type $1_userhelper_t;
Chris PeBenito 7c2f5a
	domain_type($1_userhelper_t)
Chris PeBenito 7c2f5a
	domain_entry_file($1_userhelper_t,userhelper_exec_t)
Chris PeBenito 1815ba
	domain_role_change_exemption($1_userhelper_t)
Chris PeBenito 1815ba
	domain_obj_id_change_exemption($1_userhelper_t)
Chris PeBenito 15722e
	domain_interactive_fd($1_userhelper_t)
Chris PeBenito 1815ba
	domain_subj_id_change_exemption($1_userhelper_t)
Chris PeBenito 7c2f5a
	role system_r types $1_userhelper_t;
Chris PeBenito 7c2f5a
	
Chris PeBenito 7c2f5a
	########################################
Chris PeBenito 7c2f5a
	#
Chris PeBenito 7c2f5a
	# Local policy
Chris PeBenito 7c2f5a
	#
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:capability { setuid setgid net_bind_service dac_override chown sys_tty_config };
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:process ~{ ptrace setcurrent setexec setfscreate setrlimit execmem execstack execheap };
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:fd use;
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:fifo_file rw_file_perms;
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:shm create_shm_perms;
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:sem create_sem_perms;
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:msgq create_msgq_perms;
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:msg { send receive };
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:unix_dgram_socket create_socket_perms;
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:unix_stream_socket create_stream_socket_perms;
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:unix_dgram_socket sendto;
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:unix_stream_socket connectto;
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:sock_file r_file_perms;
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	#Transition to the derived domain.
Chris PeBenito 7c2f5a
	domain_auto_trans($2,userhelper_exec_t,$1_userhelper_t)
Chris PeBenito 7c2f5a
	allow $2 $1_userhelper_t:fd use;
Chris PeBenito 7c2f5a
	allow $1_userhelper_t $2:fd use;
Chris PeBenito 7c2f5a
	allow $1_userhelper_t $2:fifo_file rw_file_perms;
Chris PeBenito 7c2f5a
	allow $1_userhelper_t $2:process sigchld;
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	allow $1_userhelper_t self:process setexec;
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	allow $1_userhelper_t userhelper_conf_t:file rw_file_perms;
Chris PeBenito 7c2f5a
	allow $1_userhelper_t userhelper_conf_t:dir rw_dir_perms;
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	can_exec($1_userhelper_t, userhelper_exec_t)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	dontaudit $2 $1_userhelper_t:process signal;
Chris PeBenito 7c2f5a
	
Chris PeBenito 445522
	kernel_read_all_sysctls($1_userhelper_t)
Chris PeBenito 7c2f5a
	kernel_getattr_debugfs($1_userhelper_t)
Chris PeBenito 7c2f5a
	kernel_read_system_state($1_userhelper_t)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	# Execute shells
Chris PeBenito 7c2f5a
	corecmd_exec_shell($1_userhelper_t)
Chris PeBenito 7c2f5a
	# By default, revert to the calling domain when a program is executed
Chris PeBenito 7c2f5a
	corecmd_bin_domtrans($1_userhelper_t,$2)
Chris PeBenito 7c2f5a
	corecmd_sbin_domtrans($1_userhelper_t,$2)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	# Inherit descriptors from the current session.
Chris PeBenito 15722e
	domain_use_interactive_fds($1_userhelper_t)
Chris PeBenito 7c2f5a
	# for when the user types "exec userhelper" at the command line
Chris PeBenito 15722e
	domain_sigchld_interactive_fds($1_userhelper_t)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	dev_read_urand($1_userhelper_t)
Chris PeBenito 7c2f5a
	# Read /dev directories and any symbolic links.
Chris PeBenito 7c2f5a
	dev_list_all_dev_nodes($1_userhelper_t)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	files_list_var_lib($1_userhelper_t)
Chris PeBenito 7c2f5a
	# Write to utmp.
Chris PeBenito 1c1ac6
	files_pid_filetrans($1_userhelper_t,initrc_var_run_t,file)
Chris PeBenito 7c2f5a
	# Read the /etc/security/default_type file
Chris PeBenito 7c2f5a
	files_read_etc_files($1_userhelper_t)
Chris PeBenito 7c2f5a
	# Read /var.
Chris PeBenito 7c2f5a
	files_read_var_files($1_userhelper_t)
Chris PeBenito 9e04f5
	files_read_var_symlinks($1_userhelper_t)
Chris PeBenito 7c2f5a
	# for some PAM modules and for cwd
Chris PeBenito 7c2f5a
	files_search_home($1_userhelper_t)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	fs_search_auto_mountpoints($1_userhelper_t)
Chris PeBenito 7c2f5a
	fs_read_nfs_files($1_userhelper_t)
Chris PeBenito 7c2f5a
	fs_read_nfs_symlinks($1_userhelper_t)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	# Allow $1_userhelper to obtain contexts to relabel TTYs
Chris PeBenito 7c2f5a
	selinux_get_fs_mount($1_userhelper_t)
Chris PeBenito 7c2f5a
	selinux_validate_context($1_userhelper_t)
Chris PeBenito 7c2f5a
	selinux_compute_access_vector($1_userhelper_t)
Chris PeBenito 7c2f5a
	selinux_compute_create_context($1_userhelper_t)
Chris PeBenito 7c2f5a
	selinux_compute_relabel_context($1_userhelper_t)
Chris PeBenito 7c2f5a
	selinux_compute_user_contexts($1_userhelper_t)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	# Read the devpts root directory.
Chris PeBenito 7c2f5a
	term_list_ptys($1_userhelper_t)
Chris PeBenito 7c2f5a
	# Relabel terminals.
Chris PeBenito 7c2f5a
	term_relabel_all_user_ttys($1_userhelper_t)
Chris PeBenito 7c2f5a
	term_relabel_all_user_ptys($1_userhelper_t)
Chris PeBenito 7c2f5a
	# Access terminals.
Chris PeBenito 7c2f5a
	term_use_all_user_ttys($1_userhelper_t)
Chris PeBenito 7c2f5a
	term_use_all_user_ptys($1_userhelper_t)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	auth_domtrans_chk_passwd($1_userhelper_t)
Chris PeBenito 7c2f5a
	auth_manage_pam_pid($1_userhelper_t)
Chris PeBenito 7c2f5a
	auth_manage_var_auth($1_userhelper_t)
Chris PeBenito 7c2f5a
	auth_search_pam_console_data($1_userhelper_t)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	# Inherit descriptors from the current session.
Chris PeBenito 1c1ac6
	init_use_fds($1_userhelper_t)
Chris PeBenito 7c2f5a
	# Write to utmp.
Chris PeBenito 7c2f5a
	init_manage_utmp($1_userhelper_t)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	libs_use_ld_so($1_userhelper_t)
Chris PeBenito 7c2f5a
	libs_use_shared_libs($1_userhelper_t)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	miscfiles_read_localization($1_userhelper_t)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	seutil_read_config($1_userhelper_t)
Chris PeBenito 7c2f5a
	seutil_read_default_contexts($1_userhelper_t)
Chris PeBenito 7c2f5a
Chris PeBenito 103fe2
	userdom_use_unpriv_users_fds($1_userhelper_t)
Chris PeBenito 7c2f5a
	# Allow $1_userhelper_t to transition to user domains.
Chris PeBenito 7c2f5a
	userdom_bin_spec_domtrans_unpriv_users($1_userhelper_t)
Chris PeBenito 7c2f5a
	userdom_sbin_spec_domtrans_unpriv_users($1_userhelper_t)
Chris PeBenito 7c2f5a
	userdom_entry_spec_domtrans_unpriv_users($1_userhelper_t)
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	ifdef(`distro_redhat',`
Chris PeBenito bb7170
		optional_policy(`
Chris PeBenito 7c2f5a
			# Allow transitioning to rpm_t, for up2date
Chris PeBenito 7c2f5a
			rpm_domtrans($1_userhelper_t)
Chris PeBenito 7c2f5a
		')
Chris PeBenito 7c2f5a
	')
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	tunable_policy(`! secure_mode',`
Chris PeBenito 7c2f5a
		#if we are not in secure mode then we can transition to sysadm_t
Chris PeBenito 7c2f5a
		userdom_bin_spec_domtrans_sysadm($1_userhelper_t)
Chris PeBenito 7c2f5a
		userdom_sbin_spec_domtrans_sysadm($1_userhelper_t)
Chris PeBenito 7c2f5a
		userdom_entry_spec_domtrans_sysadm($1_userhelper_t)
Chris PeBenito 7c2f5a
	')
Chris PeBenito 7c2f5a
	
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 0834f9
		ethereal_domtrans_user_ethereal($1,$1_userhelper_t)
Chris PeBenito 0834f9
	')
Chris PeBenito 7c2f5a
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 7c2f5a
		logging_send_syslog_msg($1_userhelper_t)
Chris PeBenito 7c2f5a
	')
Chris PeBenito 7c2f5a
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 7c2f5a
		nis_use_ypbind($1_userhelper_t)
Chris PeBenito 7c2f5a
	')
Chris PeBenito 7c2f5a
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 1815ba
		nscd_socket_use($1_userhelper_t)
Chris PeBenito 7c2f5a
	')
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
	ifdef(`TODO',`
Chris PeBenito 7c2f5a
		allow $1_userhelper_t xdm_t:fd use;
Chris PeBenito 7c2f5a
		allow $1_userhelper_t xdm_var_run_t:dir search;
Chris PeBenito 7c2f5a
		allow $1_userhelper_t xdm_t:fifo_file { getattr read write ioctl };
Chris PeBenito 7c2f5a
Chris PeBenito bb7170
		optional_policy(`
Chris PeBenito 7c2f5a
			allow $1_userhelper_t gphdomain:fd use;
Chris PeBenito 7c2f5a
		')
Chris PeBenito bb7170
		optional_policy(`
Chris PeBenito 7c2f5a
			domain_auto_trans($1_userhelper_t, xauth_exec_t, $1_xauth_t)
Chris PeBenito 7c2f5a
			allow $1_userhelper_t $1_xauth_home_t:file { getattr read };
Chris PeBenito 7c2f5a
		')
Chris PeBenito bb7170
		optional_policy(`
Chris PeBenito 7c2f5a
			domain_auto_trans($1_mozilla_t, userhelper_exec_t, $1_userhelper_t)
Chris PeBenito 7c2f5a
		')
Chris PeBenito 7c2f5a
		# for when the network connection is killed
Chris PeBenito 7c2f5a
		dontaudit unpriv_userdomain $1_userhelper_t:process signal;
Chris PeBenito 7c2f5a
	')
Chris PeBenito 7c2f5a
')
Chris PeBenito 7c2f5a
Chris PeBenito 7c2f5a
########################################
Chris PeBenito 7c2f5a
## <summary>
Chris PeBenito 2ce6b0
##	Search the userhelper configuration directory.
Chris PeBenito 7c2f5a
## </summary>
Chris PeBenito 7c2f5a
## <param name="domain">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 2ce6b0
##      Domain allowed access.
Chris PeBenito 885b83
##	</summary>
Chris PeBenito 2ce6b0
## </param>
Chris PeBenito 2ce6b0
#
Chris PeBenito 2ce6b0
interface(`userhelper_search_config',`
Chris PeBenito 2ce6b0
	gen_require(`
Chris PeBenito 2ce6b0
		type userhelper_conf_t;
Chris PeBenito 2ce6b0
	')
Chris PeBenito 2ce6b0
Chris PeBenito 2ce6b0
	allow $1 userhelper_conf_t:dir search_dir_perms;
Chris PeBenito 2ce6b0
')
Chris PeBenito 2ce6b0
Chris PeBenito 2ce6b0
########################################
Chris PeBenito 2ce6b0
## <summary>
Chris PeBenito 2ce6b0
##	Do not audit attempts to search 
Chris PeBenito 2ce6b0
##	the userhelper configuration directory.
Chris PeBenito 2ce6b0
## </summary>
Chris PeBenito 2ce6b0
## <param name="domain">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 2ce6b0
##      Domain to not audit.
Chris PeBenito 885b83
##	</summary>
Chris PeBenito 7c2f5a
## </param>
Chris PeBenito 7c2f5a
#
Chris PeBenito 7c2f5a
interface(`userhelper_dontaudit_search_config',`
Chris PeBenito 7c2f5a
	gen_require(`
Chris PeBenito 7c2f5a
		type userhelper_conf_t;
Chris PeBenito 7c2f5a
	')
Chris PeBenito 7c2f5a
Chris PeBenito 2ce6b0
	dontaudit $1 userhelper_conf_t:dir search_dir_perms;
Chris PeBenito 7c2f5a
')
Chris PeBenito 0834f9
Chris PeBenito 0834f9
########################################
Chris PeBenito 0834f9
## <summary>
Chris PeBenito 0834f9
##	Allow domain to use userhelper file descriptor.
Chris PeBenito 0834f9
## </summary>
Chris PeBenito 0834f9
## <param name="prefix">
Chris PeBenito 0834f9
##	<summary>
Chris PeBenito 0834f9
##	The prefix of the domain, example user is the prefix of user_t.
Chris PeBenito 0834f9
##	</summary>
Chris PeBenito 0834f9
## </param>
Chris PeBenito 0834f9
## <param name="domain">
Chris PeBenito 0834f9
##	<summary>
Chris PeBenito 0834f9
##      Domain allowed access.
Chris PeBenito 0834f9
##	</summary>
Chris PeBenito 0834f9
## </param>
Chris PeBenito 0834f9
#
Chris PeBenito 0834f9
template(`userhelper_use_user_fd',`
Chris PeBenito 0834f9
	gen_require(`
Chris PeBenito 0834f9
		type $1_userhelper_t;
Chris PeBenito 0834f9
	')
Chris PeBenito 0834f9
Chris PeBenito 0834f9
	allow $2 $1_userhelper_t:fd use;
Chris PeBenito 0834f9
')
Chris PeBenito 0834f9
########################################
Chris PeBenito 0834f9
## <summary>
Chris PeBenito 0834f9
##	Allow domain to send sigchld to userhelper.
Chris PeBenito 0834f9
## </summary>
Chris PeBenito 0834f9
## <param name="prefix">
Chris PeBenito 0834f9
##	<summary>
Chris PeBenito 0834f9
##	The prefix of the domain, example user is the prefix of user_t.
Chris PeBenito 0834f9
##	</summary>
Chris PeBenito 0834f9
## </param>
Chris PeBenito 0834f9
## <param name="domain">
Chris PeBenito 0834f9
##	<summary>
Chris PeBenito 0834f9
##      Domain allowed access.
Chris PeBenito 0834f9
##	</summary>
Chris PeBenito 0834f9
## </param>
Chris PeBenito 0834f9
#
Chris PeBenito 0834f9
template(`userhelper_sigchld_user',`
Chris PeBenito 0834f9
	gen_require(`
Chris PeBenito 0834f9
		type $1_userhelper_t;
Chris PeBenito 0834f9
	')
Chris PeBenito 0834f9
Chris PeBenito 0834f9
	allow $2 $1_userhelper_t:process sigchld;
Chris PeBenito 0834f9
')