Chris PeBenito 948914
## <summary>Run shells with substitute user and group</summary>
Chris PeBenito 948914
Chris PeBenito ac9db9
#######################################
Chris PeBenito ac9db9
## <summary>
Chris PeBenito ac9db9
##	Restricted su domain template.
Chris PeBenito ac9db9
## </summary>
Chris PeBenito ac9db9
## <desc>
Chris PeBenito ac9db9
##	

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

Chris PeBenito ac9db9
## </desc>
Chris PeBenito ac9db9
## <param name="userdomain_prefix">
Chris PeBenito ac9db9
##	<summary>
Chris PeBenito ac9db9
##	The prefix of the user domain (e.g., user
Chris PeBenito ac9db9
##	is the prefix for user_t).
Chris PeBenito ac9db9
##	</summary>
Chris PeBenito ac9db9
## </param>
Chris PeBenito ac9db9
## <param name="user_domain">
Chris PeBenito ac9db9
##	<summary>
Chris PeBenito ac9db9
##	The type of the user domain.
Chris PeBenito ac9db9
##	</summary>
Chris PeBenito ac9db9
## </param>
Chris PeBenito ac9db9
## <param name="user_role">
Chris PeBenito ac9db9
##	<summary>
Chris PeBenito ac9db9
##	The role associated with the user domain.
Chris PeBenito ac9db9
##	</summary>
Chris PeBenito ac9db9
## </param>
Chris PeBenito ac9db9
#
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 15722e
	domain_interactive_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 $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 b0d224
	allow $2 $1_su_t:fifo_file rw_file_perms;
Chris PeBenito b0d224
	allow $2 $1_su_t:process sigchld;
Chris PeBenito bb6763
Chris PeBenito bb6763
	kernel_read_system_state($1_su_t)
Chris PeBenito 445522
	kernel_read_kernel_sysctls($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 049e11
	files_read_etc_files($1_su_t)
Chris PeBenito 049e11
	files_read_etc_runtime_files($1_su_t)
Chris PeBenito 049e11
	files_search_var_lib($1_su_t)
Chris PeBenito 9e04f5
	files_dontaudit_getattr_tmp_dirs($1_su_t)
Chris PeBenito 049e11
Chris PeBenito 29a051
	# for the rootok check
Chris PeBenito 29a051
	selinux_compute_access_vector($1_su_t)
Chris PeBenito 29a051
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 15722e
	domain_use_interactive_fds($1_su_t)
Chris PeBenito bb6763
Chris PeBenito 1c1ac6
	init_dontaudit_use_fds($1_su_t)
Chris PeBenito 1815ba
	init_dontaudit_use_script_ptys($1_su_t)
Chris PeBenito bb6763
	# Write to utmp.
Chris PeBenito 68228b
	init_rw_utmp($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 58a382
	ifdef(`distro_rhel4',`
Chris PeBenito 58a382
		domain_role_change_exemption($1_su_t)
Chris PeBenito 58a382
		domain_subj_id_change_exemption($1_su_t)
Chris PeBenito 58a382
		domain_obj_id_change_exemption($1_su_t)
Chris PeBenito 58a382
Chris PeBenito 58a382
		selinux_get_fs_mount($1_su_t)
Chris PeBenito 58a382
		selinux_validate_context($1_su_t)
Chris PeBenito 58a382
		selinux_compute_access_vector($1_su_t)
Chris PeBenito 58a382
		selinux_compute_create_context($1_su_t)
Chris PeBenito 58a382
		selinux_compute_relabel_context($1_su_t)
Chris PeBenito 58a382
		selinux_compute_user_contexts($1_su_t)
Chris PeBenito 58a382
Chris PeBenito 58a382
		seutil_read_config($1_su_t)
Chris PeBenito 58a382
		seutil_read_default_contexts($1_su_t)
Chris PeBenito 58a382
Chris PeBenito 58a382
		# Only allow transitions to unprivileged user domains.
Chris PeBenito 58a382
		userdom_spec_domtrans_unpriv_users($1_su_t)
Chris PeBenito 58a382
	')
Chris PeBenito 58a382
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 1815ba
		cron_read_pipes($1_su_t)
Chris PeBenito bb6763
	')
Chris PeBenito bb6763
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito bb6763
		kerberos_use($1_su_t)
Chris PeBenito bb6763
	')
Chris PeBenito bb6763
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 1815ba
		nscd_socket_use($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 885b83
##	<summary>
Chris PeBenito b9d7d7
##	The prefix of the user domain (e.g., user
Chris PeBenito b9d7d7
##	is the prefix for user_t).
Chris PeBenito 885b83
##	</summary>
Chris PeBenito b9d7d7
## </param>
Chris PeBenito 451c1e
## <param name="user_domain">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 451c1e
##	The type of the user domain.
Chris PeBenito 885b83
##	</summary>
Chris PeBenito 451c1e
## </param>
Chris PeBenito 451c1e
## <param name="user_role">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 451c1e
##	The role associated with the user domain.
Chris PeBenito 885b83
##	</summary>
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 15722e
	domain_interactive_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 $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 a3cf80
	allow $2 $1_su_t:fifo_file rw_file_perms;
Chris PeBenito a3cf80
	allow $2 $1_su_t:process sigchld;
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	kernel_read_system_state($1_su_t)
Chris PeBenito 445522
	kernel_read_kernel_sysctls($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 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 15722e
	domain_use_interactive_fds($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	files_read_etc_files($1_su_t)
Chris PeBenito a77e65
	files_read_etc_runtime_files($1_su_t)
Chris PeBenito 77f6e2
	files_search_var_lib($1_su_t)
Chris PeBenito 9e04f5
	files_dontaudit_getattr_tmp_dirs($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 1c1ac6
	init_dontaudit_use_fds($1_su_t)
Chris PeBenito 77f6e2
	# Write to utmp.
Chris PeBenito 68228b
	init_rw_utmp($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
	userdom_use_user_terminals($1,$1_su_t)
Chris PeBenito 103fe2
	userdom_search_user_home_dirs($1,$1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 58a382
	ifdef(`distro_rhel4',`
Chris PeBenito 58a382
		domain_role_change_exemption($1_su_t)
Chris PeBenito 58a382
		domain_subj_id_change_exemption($1_su_t)
Chris PeBenito 58a382
		domain_obj_id_change_exemption($1_su_t)
Chris PeBenito 58a382
Chris PeBenito 58a382
		selinux_get_fs_mount($1_su_t)
Chris PeBenito 58a382
		selinux_validate_context($1_su_t)
Chris PeBenito 58a382
		selinux_compute_access_vector($1_su_t)
Chris PeBenito 58a382
		selinux_compute_create_context($1_su_t)
Chris PeBenito 58a382
		selinux_compute_relabel_context($1_su_t)
Chris PeBenito 58a382
		selinux_compute_user_contexts($1_su_t)
Chris PeBenito 58a382
Chris PeBenito 58a382
		# Relabel ttys and ptys.
Chris PeBenito 58a382
		term_relabel_all_user_ttys($1_su_t)
Chris PeBenito 58a382
		term_relabel_all_user_ptys($1_su_t)
Chris PeBenito 58a382
		# Close and re-open ttys and ptys to get the fd into the correct domain.
Chris PeBenito 58a382
		term_use_all_user_ttys($1_su_t)
Chris PeBenito 58a382
		term_use_all_user_ptys($1_su_t)
Chris PeBenito 58a382
Chris PeBenito 58a382
		seutil_read_config($1_su_t)
Chris PeBenito 58a382
		seutil_read_default_contexts($1_su_t)
Chris PeBenito 58a382
Chris PeBenito 58a382
		ifdef(`strict_policy',`
Chris PeBenito 58a382
			if(secure_mode) {
Chris PeBenito 58a382
				# Only allow transitions to unprivileged user domains.
Chris PeBenito 58a382
				userdom_spec_domtrans_unpriv_users($1_su_t)
Chris PeBenito 58a382
			} else {
Chris PeBenito 58a382
				# Allow transitions to all user domains
Chris PeBenito 58a382
				userdom_spec_domtrans_all_users($1_su_t)
Chris PeBenito 58a382
			}
Chris PeBenito 58a382
		')
Chris PeBenito 58a382
Chris PeBenito 58a382
		ifdef(`targeted_policy',`
Chris PeBenito 58a382
			unconfined_domtrans($1_su_t)
Chris PeBenito 58a382
			unconfined_signal($1_su_t)
Chris PeBenito 58a382
		')
Chris PeBenito 58a382
	')
Chris PeBenito 58a382
Chris PeBenito b07eae
	ifdef(`enable_polyinstantiation',`
Chris PeBenito 5e4cbc
		fs_mount_xattr_fs($1_su_t)
Chris PeBenito b07eae
		fs_unmount_xattr_fs($1_su_t)
Chris PeBenito b07eae
	')
Chris PeBenito b07eae
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 103fe2
		userdom_manage_all_users_home_content_files($1_su_t)
Chris PeBenito 103fe2
		userdom_manage_all_users_home_content_symlinks($1_su_t)
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 bb7170
	optional_policy(`
Chris PeBenito 1815ba
		cron_read_pipes($1_su_t)
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 77f6e2
		kerberos_use($1_su_t)
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 1815ba
		nscd_socket_use($1_su_t)
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
Chris PeBenito 02bcb8
	# Modify .Xauthority file (via xauth program).
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 02bcb8
#		file_type_auto_trans($1_su_t, staff_home_dir_t, staff_xauth_home_t, file)
Chris PeBenito 02bcb8
#		file_type_auto_trans($1_su_t, user_home_dir_t, user_xauth_home_t, file)
Chris PeBenito 02bcb8
#		file_type_auto_trans($1_su_t, sysadm_home_dir_t, sysadm_xauth_home_t, file)
Chris PeBenito 02bcb8
		xserver_domtrans_user_xauth($1, $1_su_t)
Chris PeBenito 02bcb8
	')
Chris PeBenito 02bcb8
Chris PeBenito 77f6e2
	ifdef(`TODO',`
Chris PeBenito 77f6e2
	allow $1_su_t $1_home_t:file create_file_perms;
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 885b83
##	<summary>
Chris PeBenito 799a0b
##	Domain allowed access.
Chris PeBenito 885b83
##	</summary>
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
')