Chris PeBenito e78430
## <summary>Execute a command with a substitute user</summary>
Chris PeBenito e78430
Chris PeBenito e78430
#######################################
Chris PeBenito e78430
## <summary>
Chris PeBenito e78430
##	The per user domain template for the sudo module.
Chris PeBenito e78430
## </summary>
Chris PeBenito e78430
## <desc>
Chris PeBenito e78430
##	

Chris PeBenito e78430
##	This template creates a derived domain which is allowed
Chris PeBenito e78430
##	to change the linux user id, to run commands as a different
Chris PeBenito e78430
##	user.
Chris PeBenito e78430
##	

Chris PeBenito e78430
##	

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

Chris PeBenito e78430
## </desc>
Chris PeBenito e78430
## <param name="userdomain_prefix">
Chris PeBenito e78430
##	The prefix of the user domain (e.g., user
Chris PeBenito e78430
##	is the prefix for user_t).
Chris PeBenito e78430
## </param>
Chris PeBenito 451c1e
## <param name="user_domain">
Chris PeBenito 451c1e
##	The type of the user domain.
Chris PeBenito 451c1e
## </param>
Chris PeBenito 451c1e
## <param name="user_role">
Chris PeBenito 451c1e
##	The role associated with the user domain.
Chris PeBenito 451c1e
## </param>
Chris PeBenito e78430
#
Chris PeBenito e78430
template(`sudo_per_userdomain_template',`
Chris PeBenito e78430
Chris PeBenito e78430
	##############################
Chris PeBenito e78430
	#
Chris PeBenito e78430
	# Declarations
Chris PeBenito e78430
	#
Chris PeBenito e78430
Chris PeBenito e78430
	type $1_sudo_t; #, mlsfileread, mlsfilewrite, mlsfileupgrade, mlsfiledowngrade, mlsprocsetsl;
Chris PeBenito e78430
	domain_type($1_sudo_t)
Chris PeBenito e78430
	domain_entry_file($1_sudo_t,sudo_exec_t)
Chris PeBenito e78430
	domain_wide_inherit_fd($1_sudo_t)
Chris PeBenito e78430
	domain_subj_id_change_exempt($1_sudo_t)
Chris PeBenito e78430
	domain_role_change_exempt($1_sudo_t)
Chris PeBenito e78430
	domain_obj_id_change_exempt($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito 451c1e
	role $3 types $1_sudo_t;
Chris PeBenito e78430
Chris PeBenito e78430
	##############################
Chris PeBenito e78430
	#
Chris PeBenito e78430
	# Local Policy
Chris PeBenito e78430
	#
Chris PeBenito e78430
Chris PeBenito e78430
	# Use capabilities.
Chris PeBenito e78430
	allow $1_sudo_t self:capability { setuid setgid dac_override sys_resource };
Chris PeBenito 9d3bdc
	allow $1_sudo_t self:process ~{ ptrace setcurrent setexec setfscreate setrlimit execmem execstack execheap };
Chris PeBenito e78430
	allow $1_sudo_t self:process { setexec setrlimit };
Chris PeBenito e78430
	allow $1_sudo_t self:fd use;
Chris PeBenito e78430
	allow $1_sudo_t self:fifo_file rw_file_perms;
Chris PeBenito e78430
	allow $1_sudo_t self:unix_dgram_socket create_socket_perms;
Chris PeBenito e78430
	allow $1_sudo_t self:unix_stream_socket create_stream_socket_perms;
Chris PeBenito e78430
	allow $1_sudo_t self:unix_dgram_socket sendto;
Chris PeBenito e78430
	allow $1_sudo_t self:unix_stream_socket connectto;
Chris PeBenito e78430
	allow $1_sudo_t self:shm create_shm_perms;
Chris PeBenito e78430
	allow $1_sudo_t self:sem create_sem_perms;
Chris PeBenito e78430
	allow $1_sudo_t self:msgq create_msgq_perms;
Chris PeBenito e78430
	allow $1_sudo_t self:msg { send receive };
Chris PeBenito e78430
Chris PeBenito e78430
	# Enter this derived domain from the user domain
Chris PeBenito 451c1e
	domain_auto_trans($2, sudo_exec_t, $1_sudo_t)
Chris PeBenito 451c1e
	allow $1_sudo_t $2:fd use;
Chris PeBenito 451c1e
	allow $2 $1_sudo_t:fd use;
Chris PeBenito 451c1e
	allow $2 $1_sudo_t:fifo_file rw_file_perms;
Chris PeBenito 451c1e
	allow $2 $1_sudo_t:process sigchld;
Chris PeBenito e78430
Chris PeBenito e78430
	# By default, revert to the calling domain when a shell is executed.
Chris PeBenito 451c1e
	corecmd_shell_domtrans($1_sudo_t,$2)
Chris PeBenito 451c1e
	allow $2 $1_sudo_t:fd use;
Chris PeBenito 451c1e
	allow $1_sudo_t $2:fd use;
Chris PeBenito 451c1e
	allow $1_sudo_t $2:fifo_file rw_file_perms;
Chris PeBenito 451c1e
	allow $1_sudo_t $2:process sigchld;
Chris PeBenito e78430
Chris PeBenito e78430
	kernel_read_kernel_sysctl($1_sudo_t)
Chris PeBenito e78430
	kernel_read_system_state($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	dev_read_urand($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	fs_search_auto_mountpoints($1_sudo_t)
Chris PeBenito e78430
	fs_getattr_xattr_fs($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	selinux_get_fs_mount($1_sudo_t)
Chris PeBenito e78430
	selinux_validate_context($1_sudo_t)
Chris PeBenito e78430
	selinux_compute_access_vector($1_sudo_t)
Chris PeBenito e78430
	selinux_compute_create_context($1_sudo_t)
Chris PeBenito e78430
	selinux_compute_relabel_context($1_sudo_t)
Chris PeBenito e78430
	selinux_compute_user_contexts($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	term_use_all_user_ttys($1_sudo_t)
Chris PeBenito e78430
	term_use_all_user_ptys($1_sudo_t)
Chris PeBenito e78430
	term_relabel_all_user_ttys($1_sudo_t)
Chris PeBenito e78430
	term_relabel_all_user_ptys($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	auth_domtrans_chk_passwd($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	corecmd_getattr_bin_file($1_sudo_t)
Chris PeBenito e78430
	corecmd_read_sbin_symlink($1_sudo_t)
Chris PeBenito e78430
	corecmd_getattr_sbin_file($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	domain_use_wide_inherit_fd($1_sudo_t)
Chris PeBenito e78430
	domain_sigchld_wide_inherit_fd($1_sudo_t)
Chris PeBenito e78430
	domain_getattr_all_entry_files($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	files_read_etc_files($1_sudo_t)
Chris PeBenito e78430
	files_read_var_files($1_sudo_t)
Chris PeBenito e78430
	files_read_usr_symlinks($1_sudo_t)
Chris PeBenito e78430
	files_getattr_usr_files($1_sudo_t)
Chris PeBenito e78430
	# for some PAM modules and for cwd
Chris PeBenito e78430
	files_dontaudit_search_home($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	init_rw_script_pid($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	libs_use_ld_so($1_sudo_t)
Chris PeBenito e78430
	libs_use_shared_libs($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	logging_send_syslog_msg($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	miscfiles_read_localization($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	seutil_read_config($1_sudo_t)
Chris PeBenito e78430
	seutil_read_default_contexts($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito 451c1e
	userdom_manage_user_home_subdir_files($1,$1_sudo_t)
Chris PeBenito 451c1e
	userdom_manage_user_home_subdir_symlinks($1,$1_sudo_t)
Chris PeBenito 451c1e
	userdom_manage_user_tmp_files($1,$1_sudo_t)
Chris PeBenito 451c1e
	userdom_manage_user_tmp_symlinks($1,$1_sudo_t)
Chris PeBenito e78430
	userdom_use_unpriv_users_fd($1_sudo_t)
Chris PeBenito e78430
	# for some PAM modules and for cwd
Chris PeBenito e78430
	userdom_dontaudit_search_all_users_home($1_sudo_t)
Chris PeBenito e78430
Chris PeBenito e78430
	# if secure mode is enabled, then sudo
Chris PeBenito e78430
	# can only transition to unprivileged users
Chris PeBenito e78430
	if(secure_mode) {
Chris PeBenito e78430
		userdom_spec_domtrans_unpriv_users($1_sudo_t)
Chris PeBenito e78430
	} else {
Chris PeBenito e78430
		userdom_spec_domtrans_all_users($1_sudo_t)
Chris PeBenito e78430
	}
Chris PeBenito e78430
Chris PeBenito e78430
	optional_policy(`nis.te',`
Chris PeBenito e78430
		nis_use_ypbind($1_sudo_t)
Chris PeBenito e78430
	')
Chris PeBenito e78430
Chris PeBenito e78430
	optional_policy(`nscd.te',`
Chris PeBenito e78430
		nscd_use_socket($1_sudo_t)
Chris PeBenito e78430
	')
Chris PeBenito e78430
Chris PeBenito e78430
	ifdef(`TODO',`
Chris PeBenito e78430
	ifdef(`gnome-pty-helper.te', `allow $1_sudo_t gphdomain:fd use;')
Chris PeBenito e78430
Chris PeBenito e78430
	# for when the network connection is killed
Chris PeBenito e78430
	dontaudit unpriv_userdomain $1_sudo_t:process signal;
Chris PeBenito e78430
Chris PeBenito e78430
	ifdef(`mta.te', `
Chris PeBenito e78430
	domain_auto_trans($1_sudo_t, sendmail_exec_t, $1_mail_t)
Chris PeBenito e78430
	allow $1_mail_t $1_sudo_t:fifo_file rw_file_perms;
Chris PeBenito e78430
	')
Chris PeBenito e78430
Chris PeBenito e78430
	ifdef(`pam.te', `
Chris PeBenito e78430
	allow $1_sudo_t pam_var_run_t:dir create_dir_perms;
Chris PeBenito e78430
	allow $1_sudo_t pam_var_run_t:file create_file_perms;
Chris PeBenito e78430
	')
Chris PeBenito e78430
	') dnl end TODO
Chris PeBenito e78430
')