Chris PeBenito 948914
## <summary>Run shells with substitute user and group</summary>
Chris PeBenito 948914
Chris PeBenito bb6763
template(`su_restricted_domain_template', `
Chris PeBenito bb6763
	gen_require(`
Chris PeBenito bb6763
		type su_exec_t;
Chris PeBenito bb6763
	')
Chris PeBenito bb6763
Chris PeBenito bb6763
	type $1_su_t;
Chris PeBenito bb6763
	domain_entry_file($1_su_t,su_exec_t)
Chris PeBenito bb6763
	domain_type($1_su_t)
Chris PeBenito bb6763
	domain_role_change_exempt($1_su_t)
Chris PeBenito bb6763
	domain_subj_id_change_exempt($1_su_t)
Chris PeBenito bb6763
	domain_obj_id_change_exempt($1_su_t)
Chris PeBenito bb6763
	domain_wide_inherit_fd($1_su_t)
Chris PeBenito bb6763
	role $3 types $1_su_t;
Chris PeBenito bb6763
Chris PeBenito bb6763
	allow $2 $1_su_t:process signal;
Chris PeBenito bb6763
Chris PeBenito bb6763
	allow $1_su_t self:capability { audit_control audit_write setuid setgid net_bind_service chown dac_override fowner sys_nice sys_resource };
Chris PeBenito bb6763
	dontaudit $1_su_t self:capability sys_tty_config;
Chris PeBenito bb6763
	allow $1_su_t self:process { setexec setsched setrlimit };
Chris PeBenito bb6763
	allow $1_su_t self:fifo_file rw_file_perms;
Chris PeBenito bb6763
	allow $1_su_t self:netlink_audit_socket { nlmsg_relay create_netlink_socket_perms };
Chris PeBenito 2e0a88
	allow $1_su_t self:unix_stream_socket create_stream_socket_perms;
Chris PeBenito bb6763
Chris PeBenito bb6763
	# Transition from the user domain to this domain.
Chris PeBenito bb6763
	domain_auto_trans($2, su_exec_t, $1_su_t)
Chris PeBenito bb6763
	allow $2 $1_su_t:fd use;
Chris PeBenito bb6763
	allow $1_su_t $2:fd use;
Chris PeBenito bb6763
	allow $1_su_t $2:fifo_file rw_file_perms;
Chris PeBenito bb6763
	allow $1_su_t $2:process sigchld;
Chris PeBenito bb6763
Chris PeBenito bb6763
	# By default, revert to the calling domain when a shell is executed.
Chris PeBenito bb6763
	corecmd_shell_domtrans($1_su_t,$2)
Chris PeBenito bb6763
	allow $2 $1_su_t:fd use;
Chris PeBenito bb6763
	allow $1_su_t $2:fd use;
Chris PeBenito bb6763
	allow $1_su_t $2:fifo_file rw_file_perms;
Chris PeBenito bb6763
	allow $1_su_t $2:process sigchld;
Chris PeBenito bb6763
Chris PeBenito bb6763
	kernel_read_system_state($1_su_t)
Chris PeBenito bb6763
	kernel_read_kernel_sysctl($1_su_t)
Chris PeBenito bb6763
Chris PeBenito bb6763
	# for SSP
Chris PeBenito bb6763
	dev_read_urand($1_su_t)
Chris PeBenito bb6763
Chris PeBenito bb6763
	selinux_get_fs_mount($1_su_t)
Chris PeBenito bb6763
	selinux_validate_context($1_su_t)
Chris PeBenito bb6763
	selinux_compute_access_vector($1_su_t)
Chris PeBenito bb6763
	selinux_compute_create_context($1_su_t)
Chris PeBenito bb6763
	selinux_compute_relabel_context($1_su_t)
Chris PeBenito bb6763
	selinux_compute_user_contexts($1_su_t)
Chris PeBenito bb6763
Chris PeBenito bb6763
	auth_domtrans_chk_passwd($1_su_t)
Chris PeBenito bb6763
	auth_dontaudit_read_shadow($1_su_t)
Chris PeBenito bb6763
	auth_use_nsswitch($1_su_t)
Chris PeBenito bb6763
Chris PeBenito 30705b
	domain_use_wide_inherit_fd($1_su_t)
Chris PeBenito bb6763
Chris PeBenito bb6763
	files_read_etc_files($1_su_t)
Chris PeBenito 725926
	files_search_var_lib($1_su_t)
Chris PeBenito bb6763
Chris PeBenito 725926
	init_dontaudit_use_fd($1_su_t)
Chris PeBenito 725926
	init_dontaudit_use_script_pty($1_su_t)
Chris PeBenito bb6763
	# Write to utmp.
Chris PeBenito bb6763
	init_rw_script_pid($1_su_t)
Chris PeBenito bb6763
Chris PeBenito bb6763
	libs_use_ld_so($1_su_t)
Chris PeBenito bb6763
	libs_use_shared_libs($1_su_t)
Chris PeBenito bb6763
Chris PeBenito bb6763
	logging_send_syslog_msg($1_su_t)
Chris PeBenito bb6763
Chris PeBenito bb6763
	miscfiles_read_localization($1_su_t)
Chris PeBenito bb6763
Chris PeBenito bb6763
	seutil_read_config($1_su_t)
Chris PeBenito bb6763
	seutil_read_default_contexts($1_su_t)
Chris PeBenito bb6763
Chris PeBenito bb6763
	# Only allow transitions to unprivileged user domains.
Chris PeBenito bb6763
	userdom_spec_domtrans_unpriv_users($1_su_t)
Chris PeBenito bb6763
Chris PeBenito 725926
	optional_policy(`cron.te',`
Chris PeBenito bb6763
		cron_read_pipe($1_su_t)
Chris PeBenito bb6763
	')
Chris PeBenito bb6763
Chris PeBenito bb6763
	optional_policy(`kerberos.te',`
Chris PeBenito bb6763
		kerberos_use($1_su_t)
Chris PeBenito bb6763
	')
Chris PeBenito bb6763
Chris PeBenito bb6763
	optional_policy(`nscd.te',`
Chris PeBenito bb6763
		nscd_use_socket($1_su_t)
Chris PeBenito bb6763
	')
Chris PeBenito bb6763
Chris PeBenito bb6763
	ifdef(`TODO',`
Chris PeBenito bb6763
	# Caused by su - init scripts
Chris PeBenito bb6763
	dontaudit $1_su_t initrc_devpts_t:chr_file { getattr ioctl };
Chris PeBenito bb6763
	') dnl end TODO
Chris PeBenito bb6763
')
Chris PeBenito bb6763
Chris PeBenito b9d7d7
#######################################
Chris PeBenito b9d7d7
## <summary>
Chris PeBenito b9d7d7
##	The per user domain template for the su module.
Chris PeBenito b9d7d7
## </summary>
Chris PeBenito b9d7d7
## <desc>
Chris PeBenito b9d7d7
##	

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

Chris PeBenito b9d7d7
##	

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

Chris PeBenito b9d7d7
## </desc>
Chris PeBenito b9d7d7
## <param name="userdomain_prefix">
Chris PeBenito b9d7d7
##	The prefix of the user domain (e.g., user
Chris PeBenito b9d7d7
##	is the prefix for user_t).
Chris PeBenito b9d7d7
## </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 b9d7d7
#
Chris PeBenito 948914
template(`su_per_userdomain_template',`
Chris PeBenito 77f6e2
	gen_require(`
Chris PeBenito 77f6e2
		type su_exec_t;
Chris PeBenito 0efe52
		bool secure_mode;
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	type $1_su_t;
Chris PeBenito 77f6e2
	domain_entry_file($1_su_t,su_exec_t)
Chris PeBenito 77f6e2
	domain_type($1_su_t)
Chris PeBenito 77f6e2
	domain_role_change_exempt($1_su_t)
Chris PeBenito 77f6e2
	domain_subj_id_change_exempt($1_su_t)
Chris PeBenito 77f6e2
	domain_obj_id_change_exempt($1_su_t)
Chris PeBenito 77f6e2
	domain_wide_inherit_fd($1_su_t)
Chris PeBenito 77f6e2
	role $3 types $1_su_t;
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	allow $2 $1_su_t:process signal;
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	allow $1_su_t self:capability { audit_control audit_write setuid setgid net_bind_service chown dac_override fowner sys_nice sys_resource };
Chris PeBenito 77f6e2
	dontaudit $1_su_t self:capability sys_tty_config;
Chris PeBenito 77f6e2
	allow $1_su_t self:process { setexec setsched setrlimit };
Chris PeBenito 77f6e2
	allow $1_su_t self:fifo_file rw_file_perms;
Chris PeBenito 77f6e2
	allow $1_su_t self:netlink_audit_socket { nlmsg_relay create_netlink_socket_perms };
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	# Transition from the user domain to this domain.
Chris PeBenito 77f6e2
	domain_auto_trans($2, su_exec_t, $1_su_t)
Chris PeBenito 77f6e2
	allow $2 $1_su_t:fd use;
Chris PeBenito 77f6e2
	allow $1_su_t $2:fd use;
Chris PeBenito 77f6e2
	allow $1_su_t $2:fifo_file rw_file_perms;
Chris PeBenito 77f6e2
	allow $1_su_t $2:process sigchld;
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	# By default, revert to the calling domain when a shell is executed.
Chris PeBenito 77f6e2
	corecmd_shell_domtrans($1_su_t,$2)
Chris PeBenito 77f6e2
	allow $2 $1_su_t:fd use;
Chris PeBenito 77f6e2
	allow $1_su_t $2:fd use;
Chris PeBenito 77f6e2
	allow $1_su_t $2:fifo_file rw_file_perms;
Chris PeBenito 77f6e2
	allow $1_su_t $2:process sigchld;
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	kernel_read_system_state($1_su_t)
Chris PeBenito 77f6e2
	kernel_read_kernel_sysctl($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	# for SSP
Chris PeBenito 77f6e2
	dev_read_urand($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	fs_search_auto_mountpoints($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	selinux_get_fs_mount($1_su_t)
Chris PeBenito 77f6e2
	selinux_validate_context($1_su_t)
Chris PeBenito 77f6e2
	selinux_compute_access_vector($1_su_t)
Chris PeBenito 77f6e2
	selinux_compute_create_context($1_su_t)
Chris PeBenito 77f6e2
	selinux_compute_relabel_context($1_su_t)
Chris PeBenito 77f6e2
	selinux_compute_user_contexts($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	# Relabel ttys and ptys.
Chris PeBenito 77f6e2
	term_relabel_all_user_ttys($1_su_t)
Chris PeBenito 77f6e2
	term_relabel_all_user_ptys($1_su_t)
Chris PeBenito 77f6e2
	# Close and re-open ttys and ptys to get the fd into the correct domain.
Chris PeBenito 77f6e2
	term_use_all_user_ttys($1_su_t)
Chris PeBenito 77f6e2
	term_use_all_user_ptys($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 30705b
	auth_domtrans_user_chk_passwd($1,$1_su_t)
Chris PeBenito 77f6e2
	auth_dontaudit_read_shadow($1_su_t)
Chris PeBenito d8636f
	auth_use_nsswitch($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 83e451
	corecmd_search_bin($1_su_t)
Chris PeBenito 83e451
	corecmd_search_sbin($1_su_t)
Chris PeBenito 83e451
Chris PeBenito 30705b
	domain_use_wide_inherit_fd($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	files_read_etc_files($1_su_t)
Chris PeBenito 77f6e2
	files_search_var_lib($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	init_dontaudit_use_fd($1_su_t)
Chris PeBenito 77f6e2
	# Write to utmp.
Chris PeBenito 77f6e2
	init_rw_script_pid($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	libs_use_ld_so($1_su_t)
Chris PeBenito 77f6e2
	libs_use_shared_libs($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	logging_send_syslog_msg($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	miscfiles_read_localization($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	seutil_read_config($1_su_t)
Chris PeBenito 77f6e2
	seutil_read_default_contexts($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	userdom_use_user_terminals($1,$1_su_t)
Chris PeBenito 9aca49
	userdom_search_user_home($1,$1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito b4e1eb
	ifdef(`targeted_policy',`
Chris PeBenito 1d697c
		# allow user to suspend terminal.
Chris PeBenito 1d697c
		# does not work in strict since the
Chris PeBenito 1d697c
		# parent may not be able to use
Chris PeBenito 1d697c
		# the terminal if we newrole,
Chris PeBenito 1d697c
		# which relabels the terminal.
Chris PeBenito 1d697c
		allow $1_su_t self:process sigstop;
Chris PeBenito 1d697c
Chris PeBenito b4e1eb
		corecmd_exec_bin($1_su_t)
Chris PeBenito 2c216c
		userdom_manage_all_user_files($1_su_t)
Chris PeBenito 2c216c
		userdom_manage_all_user_symlinks($1_su_t)
Chris PeBenito 73ef29
Chris PeBenito 73ef29
		# newrole does not make any sense in
Chris PeBenito 73ef29
		# the targeted policy.  This is to
Chris PeBenito 73ef29
		# make sediff easier.
Chris PeBenito 73ef29
		if(!secure_mode) {
Chris PeBenito 73ef29
			unconfined_domtrans($1_su_t)
Chris PeBenito 1d697c
			unconfined_signal($1_su_t)
Chris PeBenito 73ef29
		}
Chris PeBenito 73ef29
	',`
Chris PeBenito 73ef29
		if(secure_mode) {
Chris PeBenito 73ef29
			# Only allow transitions to unprivileged user domains.
Chris PeBenito 73ef29
			userdom_spec_domtrans_unpriv_users($1_su_t)
Chris PeBenito 73ef29
		} else {
Chris PeBenito 73ef29
			# Allow transitions to all user domains
Chris PeBenito 73ef29
			userdom_spec_domtrans_all_users($1_su_t)
Chris PeBenito 73ef29
		}
Chris PeBenito b4e1eb
	')
Chris PeBenito b4e1eb
Chris PeBenito 77f6e2
	tunable_policy(`use_nfs_home_dirs',`
Chris PeBenito 77f6e2
		fs_search_nfs($1_su_t)
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	tunable_policy(`use_samba_home_dirs',`
Chris PeBenito 77f6e2
		fs_search_cifs($1_su_t)
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
Chris PeBenito 30705b
	optional_policy(`cron.te',`
Chris PeBenito 77f6e2
		cron_read_pipe($1_su_t)
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	optional_policy(`kerberos.te',`
Chris PeBenito 77f6e2
		kerberos_use($1_su_t)
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	optional_policy(`nscd.te',`
Chris PeBenito 77f6e2
		nscd_use_socket($1_su_t)
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	ifdef(`TODO',`
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	ifdef(`support_polyinstantiation', `
Chris PeBenito 77f6e2
	mls_file_read_up($1_su_t)
Chris PeBenito 77f6e2
	mls_file_write_down($1_su_t)
Chris PeBenito 77f6e2
	mls_file_upgrade($1_su_t)
Chris PeBenito 77f6e2
	mls_file_downgrade($1_su_t)
Chris PeBenito 77f6e2
	mls_process_set_level($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	# Su can polyinstantiate
Chris PeBenito 77f6e2
	polyinstantiater($1_su_t)
Chris PeBenito 77f6e2
	# Su has to unmount polyinstantiated directories (like home)
Chris PeBenito 77f6e2
	# that should not be polyinstantiated under the new user
Chris PeBenito 77f6e2
	allow $1_su_t fs_t:filesystem unmount;
Chris PeBenito 77f6e2
	# Su needs additional permission to mount over a previous mount
Chris PeBenito 77f6e2
	allow $1_su_t polymember:dir mounton;
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	# Caused by su - init scripts
Chris PeBenito 77f6e2
	dontaudit $1_su_t initrc_devpts_t:chr_file { getattr ioctl };
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	# Inherit and use descriptors from gnome-pty-helper.
Chris PeBenito 77f6e2
	ifdef(`gnome-pty-helper.te', `allow $1_su_t $1_gph_t:fd use;')
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	allow $1_su_t $1_home_t:file create_file_perms;
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	ifdef(`user_canbe_sysadm', `
Chris PeBenito 77f6e2
	allow $1_su_t home_dir_type:dir { search write };
Chris PeBenito 77f6e2
	', `
Chris PeBenito 77f6e2
	dontaudit $1_su_t home_dir_type:dir { search write };
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	# Modify .Xauthority file (via xauth program).
Chris PeBenito 77f6e2
	ifdef(`xauth.te', `
Chris PeBenito 77f6e2
	file_type_auto_trans($1_su_t, staff_home_dir_t, staff_xauth_home_t, file)
Chris PeBenito 77f6e2
	file_type_auto_trans($1_su_t, user_home_dir_t, user_xauth_home_t, file)
Chris PeBenito 77f6e2
	file_type_auto_trans($1_su_t, sysadm_home_dir_t, sysadm_xauth_home_t, file)
Chris PeBenito 77f6e2
	domain_auto_trans($1_su_t, xauth_exec_t, $1_xauth_t)
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	ifdef(`cyrus.te', `
Chris PeBenito 77f6e2
	allow $1_su_t cyrus_var_lib_t:dir search;
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
	ifdef(`ssh.te', `
Chris PeBenito 77f6e2
	# Access sshd cookie files.
Chris PeBenito 77f6e2
	allow $1_su_t sshd_tmp_t:file rw_file_perms;
Chris PeBenito 77f6e2
	file_type_auto_trans($1_su_t, sshd_tmp_t, $1_tmp_t)
Chris PeBenito 948914
	')
Chris PeBenito 77f6e2
	') dnl end TODO
Chris PeBenito 948914
')
Chris PeBenito 799a0b
Chris PeBenito 799a0b
#######################################
Chris PeBenito 799a0b
## <summary>
Chris PeBenito 799a0b
##	Execute su in the caller domain.
Chris PeBenito 799a0b
## </summary>
Chris PeBenito 799a0b
## <param name="domain">
Chris PeBenito 799a0b
##	Domain allowed access.
Chris PeBenito 799a0b
## </param>
Chris PeBenito 799a0b
#
Chris PeBenito 799a0b
interface(`su_exec',`
Chris PeBenito 799a0b
	gen_require(`
Chris PeBenito 799a0b
		type su_exec_t;
Chris PeBenito 799a0b
	')
Chris PeBenito 799a0b
Chris PeBenito 799a0b
	can_exec($1,su_exec_t)
Chris PeBenito 799a0b
')