Chris PeBenito ab58ad
# Authors:  Anthony Colatrella (NSA)    Stephen Smalley <sds@epoch.ncsc.mil>
Chris PeBenito ab58ad
#           Russell Coker <russell@coker.com.au>
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# This macro defines the rules for a newrole like program, it is used by
Chris PeBenito ab58ad
# newrole.te and sudo.te, but may be used by other policy at some later time.
Chris PeBenito ab58ad
Chris PeBenito ab58ad
define(`newrole_domain', `
Chris PeBenito ab58ad
# Rules for the $1_t domain.
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
# $1_t is the domain for the program.
Chris PeBenito ab58ad
# $1_exec_t is the type of the executable.
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
type $1_t, domain, privrole, privowner, privlog, auth_chkpwd, nscd_client_domain, privfd, mlsfileread, mlsfilewrite, mlsfileupgrade, mlsfiledowngrade, mlsprocsetsl $2;
Chris PeBenito ab58ad
in_user_role($1_t)
Chris PeBenito ab58ad
role sysadm_r types $1_t;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
general_domain_access($1_t);
Chris PeBenito ab58ad
Chris PeBenito ab58ad
uses_shlib($1_t)
Chris PeBenito ab58ad
read_locale($1_t)
Chris PeBenito ab58ad
read_sysctl($1_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow $1_t self:netlink_audit_socket { create bind write nlmsg_read read };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# for when the user types "exec newrole" at the command line
Chris PeBenito ab58ad
allow $1_t privfd:process sigchld;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Inherit descriptors from the current session.
Chris PeBenito ab58ad
allow $1_t privfd:fd use;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Execute /sbin/pwdb_chkpwd to check the password.
Chris PeBenito ab58ad
allow $1_t sbin_t:dir r_dir_perms;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Execute shells
Chris PeBenito ab58ad
allow $1_t bin_t:dir r_dir_perms;
Chris PeBenito ab58ad
allow $1_t bin_t:lnk_file read;
Chris PeBenito ab58ad
allow $1_t shell_exec_t:file r_file_perms;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow $1_t urandom_device_t:chr_file { getattr read };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Allow $1_t to transition to user domains.
Chris PeBenito ab58ad
domain_trans($1_t, shell_exec_t, unpriv_userdomain)
Chris PeBenito ab58ad
if(!secure_mode)
Chris PeBenito ab58ad
{
Chris PeBenito ab58ad
	# if we are not in secure mode then we can transition to sysadm_t
Chris PeBenito ab58ad
	domain_trans($1_t, shell_exec_t, sysadm_t)
Chris PeBenito ab58ad
}
Chris PeBenito ab58ad
Chris PeBenito ab58ad
can_setexec($1_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow $1_t autofs_t:dir search;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Use capabilities.
Chris PeBenito ab58ad
allow $1_t self:capability { fowner setuid setgid net_bind_service dac_override };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Read the devpts root directory.
Chris PeBenito ab58ad
allow $1_t devpts_t:dir r_dir_perms;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Read the /etc/security/default_type file
Chris PeBenito ab58ad
r_dir_file($1_t, default_context_t)
Chris PeBenito ab58ad
r_dir_file($1_t, selinux_config_t)
Chris PeBenito ab58ad
allow $1_t etc_t:file r_file_perms;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Read /var.
Chris PeBenito ab58ad
r_dir_file($1_t, var_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Read /dev directories and any symbolic links.
Chris PeBenito ab58ad
allow $1_t device_t:dir r_dir_perms;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Relabel terminals.
Chris PeBenito ab58ad
allow $1_t { ttyfile ptyfile }:chr_file { relabelfrom relabelto };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# Access terminals.
Chris PeBenito ab58ad
allow $1_t { ttyfile ptyfile devtty_t }:chr_file rw_file_perms;
Chris PeBenito ab58ad
ifdef(`gnome-pty-helper.te', `allow $1_t gphdomain:fd use;')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
ifdef(`distro_debian', `
Chris PeBenito ab58ad
# for /etc/alternatives
Chris PeBenito ab58ad
allow $1_t etc_t:lnk_file read;
Chris PeBenito ab58ad
')
Chris PeBenito ab58ad
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
# Allow newrole to obtain contexts to relabel TTYs
Chris PeBenito ab58ad
#
Chris PeBenito ab58ad
can_getsecurity($1_t)
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow $1_t fs_t:filesystem getattr;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# for some PAM modules and for cwd
Chris PeBenito ab58ad
dontaudit $1_t { home_root_t home_type }:dir search;
Chris PeBenito ab58ad
Chris PeBenito ab58ad
allow $1_t proc_t:dir search;
Chris PeBenito ab58ad
allow $1_t proc_t:file { getattr read };
Chris PeBenito ab58ad
Chris PeBenito ab58ad
# for when the network connection is killed
Chris PeBenito ab58ad
dontaudit unpriv_userdomain $1_t:process signal;
Chris PeBenito ab58ad
')