Chris PeBenito 948914
## <summary>Run shells with substitute user and group</summary>
Chris PeBenito 948914
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 cff75c
	# in optional since loadable modules do not natively
Chris PeBenito cff75c
	# support per-userdomain templates yet.
Chris PeBenito cff75c
	optional_policy(`su.te',`
Chris PeBenito cff75c
		gen_require(`
Chris PeBenito cff75c
			type su_exec_t;
Chris PeBenito cff75c
		')
Chris PeBenito cff75c
Chris PeBenito cff75c
		type $1_su_t;
Chris PeBenito cff75c
		domain_entry_file($1_su_t,su_exec_t)
Chris PeBenito cff75c
		domain_type($1_su_t)
Chris PeBenito cff75c
		domain_role_change_exempt($1_su_t)
Chris PeBenito cff75c
		domain_subj_id_change_exempt($1_su_t)
Chris PeBenito cff75c
		domain_obj_id_change_exempt($1_su_t)
Chris PeBenito cff75c
		domain_wide_inherit_fd($1_su_t)
Chris PeBenito cff75c
		role $3 types $1_su_t;
Chris PeBenito cff75c
Chris PeBenito cff75c
		allow $2 $1_su_t:process signal;
Chris PeBenito cff75c
Chris PeBenito cff75c
		allow $1_su_t self:capability { audit_control setuid setgid net_bind_service chown dac_override fowner sys_nice sys_resource };
Chris PeBenito cff75c
		dontaudit $1_su_t self:capability sys_tty_config;
Chris PeBenito cff75c
		allow $1_su_t self:process { setexec setsched setrlimit };
Chris PeBenito cff75c
		allow $1_su_t self:fifo_file rw_file_perms;
Chris PeBenito cff75c
		allow $1_su_t self:netlink_audit_socket { nlmsg_relay create_netlink_socket_perms };
Chris PeBenito cff75c
Chris PeBenito cff75c
		# Transition from the user domain to this domain.
Chris PeBenito cff75c
		domain_auto_trans($2, su_exec_t, $1_su_t)
Chris PeBenito cff75c
		allow $2 $1_su_t:fd use;
Chris PeBenito cff75c
		allow $1_su_t $2:fd use;
Chris PeBenito cff75c
		allow $1_su_t $2:fifo_file rw_file_perms;
Chris PeBenito cff75c
		allow $1_su_t $2:process sigchld;
Chris PeBenito cff75c
Chris PeBenito cff75c
		# By default, revert to the calling domain when a shell is executed.
Chris PeBenito cff75c
		corecmd_shell_domtrans($1_su_t,$2)
Chris PeBenito cff75c
		allow $2 $1_su_t:fd use;
Chris PeBenito cff75c
		allow $1_su_t $2:fd use;
Chris PeBenito cff75c
		allow $1_su_t $2:fifo_file rw_file_perms;
Chris PeBenito cff75c
		allow $1_su_t $2:process sigchld;
Chris PeBenito cff75c
Chris PeBenito cff75c
		kernel_read_system_state($1_su_t)
Chris PeBenito cff75c
		kernel_read_kernel_sysctl($1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		# for SSP
Chris PeBenito cff75c
		dev_read_urand($1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		fs_search_auto_mountpoints($1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		selinux_get_fs_mount($1_su_t)
Chris PeBenito cff75c
		selinux_validate_context($1_su_t)
Chris PeBenito cff75c
		selinux_compute_access_vector($1_su_t)
Chris PeBenito cff75c
		selinux_compute_create_context($1_su_t)
Chris PeBenito cff75c
		selinux_compute_relabel_context($1_su_t)
Chris PeBenito cff75c
		selinux_compute_user_contexts($1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		# Relabel ttys and ptys.
Chris PeBenito cff75c
		term_relabel_all_user_ttys($1_su_t)
Chris PeBenito cff75c
		term_relabel_all_user_ptys($1_su_t)
Chris PeBenito cff75c
		# Close and re-open ttys and ptys to get the fd into the correct domain.
Chris PeBenito cff75c
		term_use_all_user_ttys($1_su_t)
Chris PeBenito cff75c
		term_use_all_user_ptys($1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		auth_domtrans_user_chk_passwd($1_su_t,$1)
Chris PeBenito cff75c
		auth_dontaudit_read_shadow($1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		domain_wide_inherit_fd($1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		files_read_etc_files($1_su_t)
Chris PeBenito cff75c
		files_search_var_lib($1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		init_dontaudit_use_fd($1_su_t)
Chris PeBenito cff75c
		# Write to utmp.
Chris PeBenito cff75c
		init_rw_script_pid($1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		libs_use_ld_so($1_su_t)
Chris PeBenito cff75c
		libs_use_shared_libs($1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		logging_send_syslog_msg($1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		miscfiles_read_localization($1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		seutil_read_config($1_su_t)
Chris PeBenito cff75c
		seutil_read_default_contexts($1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		userdom_use_user_terminals($1,$1_su_t)
Chris PeBenito cff75c
Chris PeBenito cff75c
		if(secure_mode)
Chris PeBenito cff75c
		{
Chris PeBenito cff75c
			# Only allow transitions to unprivileged user domains.
Chris PeBenito cff75c
			userdom_spec_domtrans_unpriv_users($1_su_t)
Chris PeBenito cff75c
		} else {
Chris PeBenito cff75c
			# Allow transitions to all user domains
Chris PeBenito cff75c
			userdom_spec_domtrans_all_users($1_su_t)
Chris PeBenito cff75c
		}
Chris PeBenito cff75c
Chris PeBenito cff75c
		if (use_nfs_home_dirs) {
Chris PeBenito cff75c
			fs_search_nfs($1_su_t)
Chris PeBenito cff75c
		}
Chris PeBenito cff75c
Chris PeBenito cff75c
		if (use_samba_home_dirs) {
Chris PeBenito cff75c
			fs_search_cifs($1_su_t)
Chris PeBenito cff75c
		}
Chris PeBenito cff75c
Chris PeBenito cff75c
		optional_policy(`crond.te',`
Chris PeBenito cff75c
			cron_read_pipe($1_su_t)
Chris PeBenito cff75c
		')
Chris PeBenito cff75c
Chris PeBenito cff75c
		optional_policy(`kerberos.te',`
Chris PeBenito cff75c
			kerberos_use($1_su_t)
Chris PeBenito cff75c
		')
Chris PeBenito cff75c
Chris PeBenito cff75c
		optional_policy(`nis.te',`
Chris PeBenito cff75c
			nis_use_ypbind($1_su_t)
Chris PeBenito cff75c
		')
Chris PeBenito cff75c
Chris PeBenito cff75c
		optional_policy(`nscd.te',`
Chris PeBenito cff75c
			nscd_use_socket($1_su_t)
Chris PeBenito cff75c
		')
Chris PeBenito cff75c
Chris PeBenito cff75c
		ifdef(`TODO',`
Chris PeBenito cff75c
Chris PeBenito cff75c
		ifdef(`support_polyinstantiation', `
Chris PeBenito f0574f
		mls_file_read_up($1_su_t)
Chris PeBenito f0574f
		mls_file_write_down($1_su_t)
Chris PeBenito f0574f
		mls_file_upgrade($1_su_t)
Chris PeBenito f0574f
		mls_file_downgrade($1_su_t)
Chris PeBenito f0574f
		mls_process_set_level($1_su_t)
Chris PeBenito f0574f
Chris PeBenito cff75c
		# Su can polyinstantiate
Chris PeBenito cff75c
		polyinstantiater($1_su_t)
Chris PeBenito cff75c
		# Su has to unmount polyinstantiated directories (like home)
Chris PeBenito cff75c
		# that should not be polyinstantiated under the new user
Chris PeBenito cff75c
		allow $1_su_t fs_t:filesystem unmount;
Chris PeBenito cff75c
		# Su needs additional permission to mount over a previous mount
Chris PeBenito cff75c
		allow $1_su_t polymember:dir mounton;
Chris PeBenito cff75c
		')
Chris PeBenito cff75c
Chris PeBenito cff75c
		# Caused by su - init scripts
Chris PeBenito cff75c
		dontaudit $1_su_t initrc_devpts_t:chr_file { getattr ioctl };
Chris PeBenito cff75c
Chris PeBenito cff75c
		# Inherit and use descriptors from gnome-pty-helper.
Chris PeBenito cff75c
		ifdef(`gnome-pty-helper.te', `allow $1_su_t $1_gph_t:fd use;')
Chris PeBenito cff75c
Chris PeBenito cff75c
		allow $1_su_t { home_root_t $1_home_dir_t }:dir search;
Chris PeBenito cff75c
		allow $1_su_t $1_home_t:file create_file_perms;
Chris PeBenito cff75c
Chris PeBenito cff75c
		ifdef(`user_canbe_sysadm', `
Chris PeBenito cff75c
		allow $1_su_t home_dir_type:dir { search write };
Chris PeBenito cff75c
		', `
Chris PeBenito cff75c
		dontaudit $1_su_t home_dir_type:dir { search write };
Chris PeBenito cff75c
		')
Chris PeBenito cff75c
Chris PeBenito cff75c
		# Modify .Xauthority file (via xauth program).
Chris PeBenito cff75c
		ifdef(`xauth.te', `
Chris PeBenito cff75c
		file_type_auto_trans($1_su_t, staff_home_dir_t, staff_xauth_home_t, file)
Chris PeBenito cff75c
		file_type_auto_trans($1_su_t, user_home_dir_t, user_xauth_home_t, file)
Chris PeBenito cff75c
		file_type_auto_trans($1_su_t, sysadm_home_dir_t, sysadm_xauth_home_t, file)
Chris PeBenito cff75c
		domain_auto_trans($1_su_t, xauth_exec_t, $1_xauth_t)
Chris PeBenito cff75c
		')
Chris PeBenito cff75c
Chris PeBenito cff75c
		ifdef(`cyrus.te', `
Chris PeBenito cff75c
		allow $1_su_t cyrus_var_lib_t:dir search;
Chris PeBenito cff75c
		')
Chris PeBenito cff75c
		ifdef(`ssh.te', `
Chris PeBenito cff75c
		# Access sshd cookie files.
Chris PeBenito cff75c
		allow $1_su_t sshd_tmp_t:file rw_file_perms;
Chris PeBenito cff75c
		file_type_auto_trans($1_su_t, sshd_tmp_t, $1_tmp_t)
Chris PeBenito cff75c
		')
Chris PeBenito cff75c
		') dnl end TODO
Chris PeBenito 948914
	')
Chris PeBenito 948914
')