Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
define(`apache_domain', `
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#This type is for webpages
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
type httpd_$1_content_t, file_type, httpdcontent, sysadmfile, customizable;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# This type is used for .htaccess files
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
type httpd_$1_htaccess_t, file_type, sysadmfile, customizable;
Chris PeBenito 31b7c0
allow httpd_t httpd_$1_htaccess_t: file r_file_perms;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# This type is used for executable scripts files
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
type httpd_$1_script_exec_t, file_type, sysadmfile, customizable;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# Type that CGI scripts run as
Chris PeBenito 31b7c0
type httpd_$1_script_t, domain, privmail, nscd_client_domain;
Chris PeBenito 31b7c0
role system_r types httpd_$1_script_t;
Chris PeBenito 31b7c0
uses_shlib(httpd_$1_script_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
if (httpd_enable_cgi) {
Chris PeBenito 31b7c0
domain_auto_trans(httpd_t, httpd_$1_script_exec_t, httpd_$1_script_t)
Chris PeBenito 31b7c0
allow httpd_t httpd_$1_script_t:process { signal sigkill sigstop };
Chris PeBenito 31b7c0
allow httpd_t httpd_$1_script_exec_t:dir r_dir_perms;
Chris PeBenito 31b7c0
allow httpd_t httpd_$1_script_exec_t:file r_file_perms;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow httpd_$1_script_t httpd_t:fd use;
Chris PeBenito 31b7c0
allow httpd_$1_script_t httpd_t:process sigchld;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow httpd_$1_script_t { usr_t lib_t }:file { getattr read ioctl };
Chris PeBenito 31b7c0
allow httpd_$1_script_t usr_t:lnk_file { getattr read };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow httpd_$1_script_t self:process { fork signal_perms };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow httpd_$1_script_t devtty_t:chr_file { getattr read write };
Chris PeBenito 31b7c0
allow httpd_$1_script_t urandom_device_t:chr_file { getattr read };
Chris PeBenito 31b7c0
allow httpd_$1_script_t etc_runtime_t:file { getattr read };
Chris PeBenito 31b7c0
read_locale(httpd_$1_script_t)
Chris PeBenito 31b7c0
allow httpd_$1_script_t fs_t:filesystem getattr;
Chris PeBenito 31b7c0
allow httpd_$1_script_t self:unix_stream_socket { create_stream_socket_perms connectto };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow httpd_$1_script_t { self proc_t }:file r_file_perms;
Chris PeBenito 31b7c0
allow httpd_$1_script_t { self proc_t }:dir r_dir_perms;
Chris PeBenito 31b7c0
allow httpd_$1_script_t { self proc_t }:lnk_file read;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow httpd_$1_script_t device_t:dir { getattr search };
Chris PeBenito 31b7c0
allow httpd_$1_script_t null_device_t:chr_file rw_file_perms;
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
if (httpd_enable_cgi && httpd_can_network_connect) {
Chris PeBenito 31b7c0
can_network_client(httpd_$1_script_t)
Chris PeBenito 31b7c0
allow httpd_$1_script_t port_type:tcp_socket name_connect;
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
ifdef(`ypbind.te', `
Chris PeBenito 31b7c0
if (httpd_enable_cgi && allow_ypbind) {
Chris PeBenito 31b7c0
uncond_can_ypbind(httpd_$1_script_t)
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
# The following are the only areas that 
Chris PeBenito 31b7c0
# scripts can read, read/write, or append to
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
type httpd_$1_script_ro_t, file_type, httpdcontent, sysadmfile, customizable;
Chris PeBenito 31b7c0
type httpd_$1_script_rw_t, file_type, httpdcontent, sysadmfile, customizable;
Chris PeBenito 31b7c0
type httpd_$1_script_ra_t, file_type, httpdcontent, sysadmfile, customizable;
Chris PeBenito 31b7c0
file_type_auto_trans(httpd_$1_script_t, tmp_t, httpd_$1_script_rw_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#########################################################
Chris PeBenito 31b7c0
# Permissions for running child processes and scripts
Chris PeBenito 31b7c0
##########################################################
Chris PeBenito 31b7c0
allow httpd_suexec_t { httpd_$1_content_t httpd_$1_script_ro_t httpd_$1_script_rw_t httpd_$1_script_exec_t }:dir { getattr search };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
domain_auto_trans(httpd_suexec_t, httpd_$1_script_exec_t, httpd_$1_script_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow httpd_$1_script_t httpd_t:fifo_file write;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow httpd_$1_script_t self:fifo_file rw_file_perms;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow httpd_$1_script_t { urandom_device_t random_device_t }:chr_file r_file_perms;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
###########################################################################
Chris PeBenito 31b7c0
# Allow the script interpreters to run the scripts.  So
Chris PeBenito 31b7c0
# the perl executable will be able to run a perl script
Chris PeBenito 31b7c0
#########################################################################
Chris PeBenito 31b7c0
allow httpd_$1_script_t httpd_$1_script_exec_t:dir r_dir_perms;
Chris PeBenito 31b7c0
can_exec_any(httpd_$1_script_t)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow httpd_$1_script_t etc_t:file { getattr read };
Chris PeBenito 31b7c0
dontaudit httpd_$1_script_t selinux_config_t:dir search;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
############################################################################
Chris PeBenito 31b7c0
# Allow the script process to search the cgi directory, and users directory
Chris PeBenito 31b7c0
##############################################################################
Chris PeBenito 31b7c0
allow httpd_$1_script_t httpd_$1_script_exec_t:dir { search getattr };
Chris PeBenito 31b7c0
can_exec(httpd_$1_script_t, httpd_$1_script_exec_t)
Chris PeBenito 31b7c0
allow httpd_$1_script_t home_root_t:dir { getattr search };
Chris PeBenito 31b7c0
allow httpd_$1_script_t httpd_$1_content_t:dir { getattr search };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#############################################################################
Chris PeBenito 31b7c0
# Allow the scripts to read, read/write, append to the specified directories
Chris PeBenito 31b7c0
# or files
Chris PeBenito 31b7c0
############################################################################
Chris PeBenito 31b7c0
read_fonts(httpd_$1_script_t)
Chris PeBenito 31b7c0
r_dir_file(httpd_$1_script_t, httpd_$1_script_ro_t)
Chris PeBenito 31b7c0
create_dir_file(httpd_$1_script_t, httpd_$1_script_rw_t)
Chris PeBenito 31b7c0
allow httpd_$1_script_t httpd_$1_script_rw_t:sock_file rw_file_perms;
Chris PeBenito 31b7c0
ra_dir_file(httpd_$1_script_t, httpd_$1_script_ra_t)
Chris PeBenito 31b7c0
anonymous_domain(httpd_$1_script)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
if (httpd_enable_cgi && httpd_unified ifdef(`targeted_policy', ` && ! httpd_disable_trans')) {
Chris PeBenito 31b7c0
create_dir_file(httpd_$1_script_t, httpdcontent)
Chris PeBenito 31b7c0
can_exec(httpd_$1_script_t, httpdcontent)
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
# If a user starts a script by hand it gets the proper context
Chris PeBenito 31b7c0
#
Chris PeBenito 31b7c0
ifdef(`targeted_policy', `', `
Chris PeBenito 31b7c0
if (httpd_enable_cgi) {
Chris PeBenito 31b7c0
domain_auto_trans(sysadm_t, httpd_$1_script_exec_t, httpd_$1_script_t)
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
role sysadm_r types httpd_$1_script_t;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
dontaudit httpd_$1_script_t sysctl_kernel_t:dir search;
Chris PeBenito 31b7c0
dontaudit httpd_$1_script_t sysctl_t:dir search;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
############################################
Chris PeBenito 31b7c0
# Allow scripts to append to http logs
Chris PeBenito 31b7c0
#########################################
Chris PeBenito 31b7c0
allow httpd_$1_script_t { var_t var_log_t httpd_log_t }:dir  search;
Chris PeBenito 31b7c0
allow httpd_$1_script_t httpd_log_t:file { getattr append };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# apache should set close-on-exec
Chris PeBenito 31b7c0
dontaudit  httpd_$1_script_t httpd_t:unix_stream_socket { read write };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
################################################################
Chris PeBenito 31b7c0
# Allow the web server to run scripts and serve pages
Chris PeBenito 31b7c0
##############################################################
Chris PeBenito 31b7c0
if (httpd_builtin_scripting) {
Chris PeBenito 31b7c0
r_dir_file(httpd_t, httpd_$1_script_ro_t)
Chris PeBenito 31b7c0
create_dir_file(httpd_t, httpd_$1_script_rw_t)
Chris PeBenito 31b7c0
allow httpd_t httpd_$1_script_rw_t:sock_file rw_file_perms;
Chris PeBenito 31b7c0
ra_dir_file(httpd_t, httpd_$1_script_ra_t)
Chris PeBenito 31b7c0
r_dir_file(httpd_t, httpd_$1_content_t)
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
define(`apache_user_domain', `
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
apache_domain($1)
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
typeattribute httpd_$1_content_t $1_file_type;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
if (httpd_enable_cgi && httpd_unified ifdef(`targeted_policy', ` && ! httpd_disable_trans')) {
Chris PeBenito 31b7c0
domain_auto_trans($1_t, httpdcontent, httpd_$1_script_t)
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
if (httpd_enable_cgi ifdef(`targeted_policy', ` && ! httpd_disable_trans')) {
Chris PeBenito 31b7c0
# If a user starts a script by hand it gets the proper context
Chris PeBenito 31b7c0
domain_auto_trans($1_t, httpd_$1_script_exec_t, httpd_$1_script_t)
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
role $1_r types httpd_$1_script_t;
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#######################################
Chris PeBenito 31b7c0
# Allow user to create or edit web content
Chris PeBenito 31b7c0
#########################################
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
create_dir_file($1_t, { httpd_$1_content_t httpd_$1_script_exec_t })
Chris PeBenito 31b7c0
allow $1_t { httpd_$1_content_t httpd_$1_script_exec_t }:{ dir file lnk_file } { relabelto relabelfrom };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
######################################################################
Chris PeBenito 31b7c0
# Allow the user to create htaccess files
Chris PeBenito 31b7c0
#####################################################################
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
allow $1_t httpd_$1_htaccess_t:file { create_file_perms relabelto relabelfrom };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
#########################################################################
Chris PeBenito 31b7c0
# Allow user to create files or directories 
Chris PeBenito 31b7c0
# that scripts are able to read, write, or append to
Chris PeBenito 31b7c0
###########################################################################
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
create_dir_file($1_t, { httpd_$1_script_ro_t httpd_$1_script_rw_t httpd_$1_script_ra_t })
Chris PeBenito 31b7c0
allow $1_t { httpd_$1_script_ro_t httpd_$1_script_rw_t httpd_$1_script_ra_t }:{ file dir lnk_file } { relabelto relabelfrom };
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
# allow accessing files/dirs below the users home dir
Chris PeBenito 31b7c0
if (httpd_enable_homedirs) {
Chris PeBenito 31b7c0
allow { httpd_t httpd_suexec_t httpd_$1_script_t } $1_home_dir_t:dir { getattr search };
Chris PeBenito 31b7c0
ifdef(`nfs_home_dirs', `
Chris PeBenito 31b7c0
r_dir_file(httpd_$1_script_t, nfs_t)
Chris PeBenito 31b7c0
')dnl end if nfs_home_dirs
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
ifdef(`crond.te', `
Chris PeBenito 31b7c0
create_dir_file($1_crond_t, httpd_$1_content_t)
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
ifdef(`ftpd.te', `
Chris PeBenito 31b7c0
if (ftp_home_dir) {
Chris PeBenito 31b7c0
create_dir_file(ftpd_t, httpd_$1_content_t)
Chris PeBenito 31b7c0
}
Chris PeBenito 31b7c0
')
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
Chris PeBenito 31b7c0
')