Chris PeBenito a08248
# Content access macros
Chris PeBenito a08248
Chris PeBenito a08248
# FIXME: After nested booleans are supported, replace NFS/CIFS
Chris PeBenito a08248
# w/ read_network_home, and write_network_home macros from global
Chris PeBenito a08248
Chris PeBenito a08248
# FIXME: If true/false constant booleans are supported, replace
Chris PeBenito a08248
# ugly $3 ifdefs with if(true), if(false)...
Chris PeBenito a08248
Chris PeBenito a08248
# FIXME: Do we want write to imply read?
Chris PeBenito a08248
Chris PeBenito a08248
############################################################
Chris PeBenito a08248
# read_content(domain, role_prefix, bool_prefix)
Chris PeBenito a08248
#
Chris PeBenito a08248
# Allow the given domain to read content.
Chris PeBenito a08248
# Content may be trusted or untrusted,
Chris PeBenito a08248
# Reading anything is subject to a controlling boolean based on bool_prefix.
Chris PeBenito a08248
# Reading untrusted content is additionally subject to read_untrusted_content
Chris PeBenito a08248
# Reading default_t is additionally subject to read_default_t
Chris PeBenito a08248
Chris PeBenito a08248
define(`read_content', `
Chris PeBenito a08248
Chris PeBenito a08248
# Declare controlling boolean
Chris PeBenito a08248
ifelse($3, `', `', `
Chris PeBenito a08248
ifdef(`$3_read_content_defined', `', `
Chris PeBenito a08248
define(`$3_read_content_defined')
Chris PeBenito a08248
bool $3_read_content false;
Chris PeBenito a08248
') dnl ifdef 
Chris PeBenito a08248
') dnl ifelse
Chris PeBenito a08248
Chris PeBenito a08248
# Handle nfs home dirs
Chris PeBenito a08248
ifelse($3, `', 
Chris PeBenito a08248
`if (use_nfs_home_dirs) { ', 
Chris PeBenito a08248
`if ($3_read_content && use_nfs_home_dirs) {')
Chris PeBenito a08248
allow $1 { autofs_t home_root_t }:dir { read search getattr };
Chris PeBenito a08248
r_dir_file($1, nfs_t)
Chris PeBenito a08248
} else {
Chris PeBenito a08248
dontaudit $1 { autofs_t home_root_t }:dir { read search getattr };
Chris PeBenito a08248
dontaudit $1 nfs_t:file r_file_perms;
Chris PeBenito a08248
dontaudit $1 nfs_t:dir r_dir_perms;
Chris PeBenito a08248
}
Chris PeBenito a08248
Chris PeBenito a08248
# Handle samba home dirs
Chris PeBenito a08248
ifelse($3, `',
Chris PeBenito a08248
`if (use_samba_home_dirs) { ',
Chris PeBenito a08248
`if ($3_read_content && use_samba_home_dirs) {')
Chris PeBenito a08248
allow $1 { autofs_t home_root_t }:dir { read search getattr };
Chris PeBenito a08248
r_dir_file($1, cifs_t)
Chris PeBenito a08248
} else {
Chris PeBenito a08248
dontaudit $1 { autofs_t home_root_t }:dir { read search getattr };
Chris PeBenito a08248
dontaudit $1 cifs_t:file r_file_perms;
Chris PeBenito a08248
dontaudit $1 cifs_t:dir r_dir_perms;
Chris PeBenito a08248
}
Chris PeBenito a08248
Chris PeBenito a08248
# Handle removable media, /tmp, and /home
Chris PeBenito a08248
ifelse($3, `', `', 
Chris PeBenito a08248
`if ($3_read_content) {')
Chris PeBenito a08248
allow $1 { tmp_t home_root_t $2_home_dir_t }:dir { read getattr search };
Chris PeBenito a08248
r_dir_file($1, { $2_tmp_t $2_home_t } )
Chris PeBenito a08248
ifdef(`mls_policy', `', `
Chris PeBenito a08248
r_dir_file($1, removable_t)
Chris PeBenito a08248
')
Chris PeBenito a08248
Chris PeBenito a08248
ifelse($3, `', `', 
Chris PeBenito a08248
`} else {
Chris PeBenito a08248
dontaudit $1 { tmp_t home_root_t $2_home_dir_t }:dir { read getattr search };
Chris PeBenito a08248
dontaudit $1 { removable_t $2_tmp_t $2_home_t }:dir r_dir_perms;
Chris PeBenito a08248
dontaudit $1 { removable_t $2_tmp_t $2_home_t }:file r_file_perms;
Chris PeBenito a08248
}') 
Chris PeBenito a08248
Chris PeBenito a08248
# Handle default_t content
Chris PeBenito a08248
ifelse($3, `',
Chris PeBenito a08248
`if (read_default_t) { ',
Chris PeBenito a08248
`if ($3_read_content && read_default_t) {')
Chris PeBenito a08248
r_dir_file($1, default_t)
Chris PeBenito a08248
} else {
Chris PeBenito a08248
dontaudit $1 default_t:file r_file_perms;
Chris PeBenito a08248
dontaudit $1 default_t:dir r_dir_perms;
Chris PeBenito a08248
} 
Chris PeBenito a08248
Chris PeBenito a08248
# Handle untrusted content
Chris PeBenito a08248
ifelse($3, `',
Chris PeBenito a08248
`if (read_untrusted_content) { ',
Chris PeBenito a08248
`if ($3_read_content && read_untrusted_content) {')
Chris PeBenito a08248
allow $1 { tmp_t home_root_t $2_home_dir_t }:dir { read getattr search };
Chris PeBenito a08248
r_dir_file($1, { $2_untrusted_content_t $2_untrusted_content_tmp_t })
Chris PeBenito a08248
} else {
Chris PeBenito a08248
dontaudit $1 { tmp_t home_root_t $2_home_dir_t }:dir { read getattr search };
Chris PeBenito a08248
dontaudit $1 { $2_untrusted_content_t $2_untrusted_content_tmp_t }:dir r_dir_perms;
Chris PeBenito a08248
dontaudit $1 { $2_untrusted_content_t $2_untrusted_content_tmp_t }:file r_file_perms;
Chris PeBenito a08248
}
Chris PeBenito a08248
') dnl read_content
Chris PeBenito a08248
Chris PeBenito a08248
#################################################
Chris PeBenito a08248
# write_trusted(domain, role_prefix, bool_prefix)
Chris PeBenito a08248
#
Chris PeBenito a08248
# Allow the given domain to write trusted content.
Chris PeBenito a08248
# This is subject to a controlling boolean based
Chris PeBenito a08248
# on bool_prefix.
Chris PeBenito a08248
Chris PeBenito a08248
define(`write_trusted', `
Chris PeBenito a08248
Chris PeBenito a08248
# Declare controlling boolean
Chris PeBenito a08248
ifelse($3, `', `', `
Chris PeBenito a08248
ifdef(`$3_write_content_defined', `', `
Chris PeBenito a08248
define(`$3_write_content_defined')
Chris PeBenito a08248
bool $3_write_content false;
Chris PeBenito a08248
') dnl ifdef
Chris PeBenito a08248
') dnl ifelse
Chris PeBenito a08248
Chris PeBenito a08248
# Handle nfs homedirs
Chris PeBenito a08248
ifelse($3, `',
Chris PeBenito a08248
`if (use_nfs_home_dirs) { ',
Chris PeBenito a08248
`if ($3_write_content && use_nfs_home_dirs) {')
Chris PeBenito a08248
allow $1 { autofs_t home_root_t }:dir { read search getattr };
Chris PeBenito a08248
create_dir_file($1, nfs_t)
Chris PeBenito a08248
} else {
Chris PeBenito a08248
dontaudit $1 { autofs_t home_root_t }:dir { read search getattr };
Chris PeBenito a08248
dontaudit $1 nfs_t:file create_file_perms;
Chris PeBenito a08248
dontaudit $1 nfs_t:dir create_dir_perms;
Chris PeBenito a08248
}
Chris PeBenito a08248
Chris PeBenito a08248
# Handle samba homedirs
Chris PeBenito a08248
ifelse($3, `',
Chris PeBenito a08248
`if (use_samba_home_dirs) { ',
Chris PeBenito a08248
`if ($3_write_content && use_samba_home_dirs) {')
Chris PeBenito a08248
allow $1 { autofs_t home_root_t }:dir { read search getattr };
Chris PeBenito a08248
create_dir_file($1, cifs_t)
Chris PeBenito a08248
} else {
Chris PeBenito a08248
dontaudit $1 { autofs_t home_root_t }:dir { read search getattr };
Chris PeBenito a08248
dontaudit $1 cifs_t:file create_file_perms;
Chris PeBenito a08248
dontaudit $1 cifs_t:dir create_dir_perms;
Chris PeBenito a08248
}
Chris PeBenito a08248
Chris PeBenito a08248
# Handle /tmp and /home
Chris PeBenito a08248
ifelse($3, `', `', 
Chris PeBenito a08248
`if ($3_write_content) {') 
Chris PeBenito a08248
allow $1 home_root_t:dir { read getattr search };
Chris PeBenito a08248
file_type_auto_trans($1, tmp_t, $2_tmp_t, { dir file });
Chris PeBenito a08248
file_type_auto_trans($1, $2_home_dir_t, $2_home_t, { dir file });
Chris PeBenito a08248
ifelse($3, `', `', 
Chris PeBenito a08248
`} else {
Chris PeBenito a08248
dontaudit $1 { tmp_t home_root_t $2_home_dir_t }:dir { read getattr search };
Chris PeBenito a08248
dontaudit $1 { $2_tmp_t $2_home_t }:file create_file_perms;
Chris PeBenito a08248
dontaudit $1 { $2_tmp_t $2_home_t }:dir create_dir_perms;
Chris PeBenito a08248
}')
Chris PeBenito a08248
Chris PeBenito a08248
') dnl write_trusted
Chris PeBenito a08248
Chris PeBenito a08248
#########################################
Chris PeBenito a08248
# write_untrusted(domain, role_prefix)
Chris PeBenito a08248
#
Chris PeBenito a08248
# Allow the given domain to write untrusted content. 
Chris PeBenito a08248
# This is subject to the global boolean write_untrusted.
Chris PeBenito a08248
Chris PeBenito a08248
define(`write_untrusted', `
Chris PeBenito a08248
Chris PeBenito a08248
# Handle nfs homedirs
Chris PeBenito a08248
if (write_untrusted_content && use_nfs_home_dirs) {
Chris PeBenito a08248
allow $1 { autofs_t home_root_t }:dir { read search getattr };
Chris PeBenito a08248
create_dir_file($1, nfs_t)
Chris PeBenito a08248
} else {
Chris PeBenito a08248
dontaudit $1 { autofs_t home_root_t }:dir { read search getattr };
Chris PeBenito a08248
dontaudit $1 nfs_t:file create_file_perms;
Chris PeBenito a08248
dontaudit $1 nfs_t:dir create_dir_perms;
Chris PeBenito a08248
}
Chris PeBenito a08248
Chris PeBenito a08248
# Handle samba homedirs
Chris PeBenito a08248
if (write_untrusted_content && use_samba_home_dirs) {
Chris PeBenito a08248
allow $1 { autofs_t home_root_t }:dir { read search getattr };
Chris PeBenito a08248
create_dir_file($1, cifs_t)
Chris PeBenito a08248
} else {
Chris PeBenito a08248
dontaudit $1 { autofs_t home_root_t }:dir { read search getattr };
Chris PeBenito a08248
dontaudit $1 cifs_t:file create_file_perms;
Chris PeBenito a08248
dontaudit $1 cifs_t:dir create_dir_perms;
Chris PeBenito a08248
}
Chris PeBenito a08248
Chris PeBenito a08248
# Handle /tmp and /home
Chris PeBenito a08248
if (write_untrusted_content) {
Chris PeBenito a08248
allow $1 home_root_t:dir { read getattr search };
Chris PeBenito a08248
file_type_auto_trans($1, { tmp_t $2_tmp_t }, $2_untrusted_content_tmp_t, { dir file })
Chris PeBenito a08248
file_type_auto_trans($1, { $2_home_dir_t $2_home_t }, $2_untrusted_content_t, { dir file })
Chris PeBenito a08248
} else {
Chris PeBenito a08248
dontaudit $1 { tmp_t home_root_t $2_home_dir_t }:dir { read getattr search };
Chris PeBenito a08248
dontaudit $1 { $2_tmp_t $2_home_t }:file create_file_perms;
Chris PeBenito a08248
dontaudit $1 { $2_tmp_t $2_home_t }:dir create_dir_perms;
Chris PeBenito a08248
}
Chris PeBenito a08248
Chris PeBenito a08248
') dnl write_untrusted