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 0bfccd
	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 8708d9
	allow $1_su_t self:key { search write };
Chris PeBenito bb6763
	allow $1_su_t self:process { setexec setsched setrlimit };
Chris PeBenito c0868a
	allow $1_su_t self:fifo_file rw_fifo_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 c0868a
	domtrans_pattern($2, su_exec_t, $1_su_t)
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 8708d9
	kernel_search_key($1_su_t)
Chris PeBenito 6b19be
	kernel_link_key($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 d9845a
	auth_rw_faillog($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
	logging_send_syslog_msg($1_su_t)
Chris PeBenito bb6763
Chris PeBenito bb6763
	miscfiles_read_localization($1_su_t)
Chris PeBenito bb6763
Chris PeBenito 9e7a33
	ifdef(`distro_redhat',`
Chris PeBenito 9e7a33
		# RHEL5 and possibly newer releases incl. Fedora
Chris PeBenito 9e7a33
		auth_domtrans_upd_passwd($1_su_t)
Chris PeBenito 9e7a33
Chris PeBenito 9e7a33
		optional_policy(`
Chris PeBenito 9e7a33
			locallogin_search_keys($1_su_t)
Chris PeBenito 9e7a33
		')
Chris PeBenito 9e7a33
	')
Chris PeBenito 9e7a33
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 f7e341
	ifdef(`hide_broken_symptoms',`
Chris PeBenito f7e341
		# dontaudit leaked sockets from parent
Chris PeBenito f7e341
		dontaudit $1_su_t $2:socket_class_set { read write };
Chris PeBenito f7e341
	')
Chris PeBenito f7e341
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 c7dc1c
	optional_policy(`
Chris PeBenito c7dc1c
		# used when the password has expired
Chris PeBenito c7dc1c
		usermanage_read_crack_db($1_su_t)
Chris PeBenito c7dc1c
	')
Chris PeBenito c7dc1c
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 296273
##	The role template for the su module.
Chris PeBenito b9d7d7
## </summary>
Chris PeBenito 296273
## <param name="role_prefix">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 296273
##	The prefix of the user role (e.g., user
Chris PeBenito 296273
##	is the prefix for user_r).
Chris PeBenito 885b83
##	</summary>
Chris PeBenito b9d7d7
## </param>
Chris PeBenito 296273
## <param name="user_role">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 296273
##	The role associated with the user domain.
Chris PeBenito 885b83
##	</summary>
Chris PeBenito 451c1e
## </param>
Chris PeBenito 296273
## <param name="user_domain">
Chris PeBenito 885b83
##	<summary>
Chris PeBenito 296273
##	The type of the user domain.
Chris PeBenito 885b83
##	</summary>
Chris PeBenito 451c1e
## </param>
Chris PeBenito b9d7d7
#
Chris PeBenito 296273
template(`su_role_template',`
Chris PeBenito 77f6e2
	gen_require(`
Chris PeBenito 6b19be
		attribute su_domain_type;
Chris PeBenito 77f6e2
		type su_exec_t;
Chris PeBenito 0efe52
		bool secure_mode;
Chris PeBenito 77f6e2
	')
Chris PeBenito 77f6e2
Chris PeBenito 6b19be
	type $1_su_t, su_domain_type;
Chris PeBenito 3f67f7
	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 296273
	ubac_constrained($1_su_t)
Chris PeBenito 296273
	role $2 types $1_su_t;
Chris PeBenito 77f6e2
Chris PeBenito 296273
	allow $3 $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 c0868a
	allow $1_su_t self:fifo_file rw_fifo_file_perms;
Chris PeBenito 77f6e2
	allow $1_su_t self:netlink_audit_socket { nlmsg_relay create_netlink_socket_perms };
Chris PeBenito 6b19be
	allow $1_su_t self:key { search write };
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	# Transition from the user domain to this domain.
Chris PeBenito 296273
	domtrans_pattern($3, su_exec_t, $1_su_t)
Chris PeBenito 296273
Chris PeBenito 296273
	ps_process_pattern($3, $1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 77f6e2
	# By default, revert to the calling domain when a shell is executed.
Chris PeBenito 296273
	corecmd_shell_domtrans($1_su_t, $3)
Chris PeBenito 296273
	allow $3 $1_su_t:fd use;
Chris PeBenito 296273
	allow $3 $1_su_t:fifo_file rw_file_perms;
Chris PeBenito 296273
	allow $3 $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 6b19be
	kernel_search_key($1_su_t)
Chris PeBenito 6b19be
	kernel_link_key($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 6b19be
	# needed for pam_rootok
Chris PeBenito 6b19be
	selinux_compute_access_vector($1_su_t)
Chris PeBenito 6b19be
Chris PeBenito 296273
	auth_domtrans_chk_passwd($1_su_t)
Chris PeBenito 77f6e2
	auth_dontaudit_read_shadow($1_su_t)
Chris PeBenito d8636f
	auth_use_nsswitch($1_su_t)
Chris PeBenito b4beb0
	auth_rw_faillog($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 83e451
	corecmd_search_bin($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 f8233a
	mls_file_write_all_levels($1_su_t)
Chris PeBenito 6b19be
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 296273
	userdom_use_user_terminals($1_su_t)
Chris PeBenito 296273
	userdom_search_user_home_dirs($1_su_t)
Chris PeBenito 77f6e2
Chris PeBenito 9e7a33
	ifdef(`distro_redhat',`
Chris PeBenito 9e7a33
		# RHEL5 and possibly newer releases incl. Fedora
Chris PeBenito 9e7a33
		auth_domtrans_upd_passwd($1_su_t)
Chris PeBenito 9e7a33
Chris PeBenito 9e7a33
		optional_policy(`
Chris PeBenito 9e7a33
			locallogin_search_keys($1_su_t)
Chris PeBenito 9e7a33
		')
Chris PeBenito 9e7a33
	')
Chris PeBenito 9e7a33
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_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 c3c753
		term_relabel_all_ttys($1_su_t)
Chris PeBenito 91cbcc
		term_relabel_all_ptys($1_su_t)
Chris PeBenito 58a382
		# Close and re-open ttys and ptys to get the fd into the correct domain.
Chris PeBenito c3c753
		term_use_all_ttys($1_su_t)
Chris PeBenito 91cbcc
		term_use_all_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 350b6a
		if(secure_mode) {
Chris PeBenito 350b6a
			# Only allow transitions to unprivileged user domains.
Chris PeBenito 350b6a
			userdom_spec_domtrans_unpriv_users($1_su_t)
Chris PeBenito 350b6a
		} else {
Chris PeBenito 350b6a
			# Allow transitions to all user domains
Chris PeBenito 350b6a
			userdom_spec_domtrans_all_users($1_su_t)
Chris PeBenito 350b6a
		}
Chris PeBenito 350b6a
Chris PeBenito 350b6a
		optional_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 f7e341
	ifdef(`hide_broken_symptoms',`
Chris PeBenito f7e341
		# dontaudit leaked sockets from parent
Chris PeBenito f7e341
		dontaudit $1_su_t $3:socket_class_set { read write };
Chris PeBenito f7e341
	')
Chris PeBenito f7e341
Chris PeBenito d9845a
	tunable_policy(`allow_polyinstantiation',`
Chris PeBenito d9845a
		fs_mount_xattr_fs($1_su_t)
Chris PeBenito d9845a
		fs_unmount_xattr_fs($1_su_t)
Chris PeBenito d9845a
	')
Chris PeBenito d9845a
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 c7dc1c
	optional_policy(`
Chris PeBenito c7dc1c
		# used when the password has expired
Chris PeBenito c7dc1c
		usermanage_read_crack_db($1_su_t)
Chris PeBenito c7dc1c
	')
Chris PeBenito c7dc1c
Chris PeBenito 02bcb8
	# Modify .Xauthority file (via xauth program).
Chris PeBenito bb7170
	optional_policy(`
Chris PeBenito 296273
		xserver_user_home_dir_filetrans_user_xauth($1_su_t)
Chris PeBenito 296273
		xserver_domtrans_xauth($1_su_t)
Chris PeBenito 02bcb8
	')
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 0bfccd
	can_exec($1, su_exec_t)
Chris PeBenito 799a0b
')