m4宏定义
SELinux使用m4宏语言写可重用的策略规则。m4宏定义提供了易用的操作组合,它本身不属于SELinux策略语言的。m4宏语言的用法可查找m4宏语言用户手册http://cm.bell-labs.com/ 7thEdMan/vol2/m4。
下面列出Apache HTTP 宏定义文件$SELINUX_SRC/macros/program/apache_macros.te的前面一些内容:
define(`apache_domain', ` #定义宏apache_domain,后面从符号“`”到“’”是它的定义内容
undefine(`apache_single_user') #取消宏定义apache_single_user
ifdef(`single_userdomain', ` #如果定义了宏single_userdomain
ifelse($1, sys, `', ` #如果参数$1为sys,则返回空,否则定义宏apache_single_user
define(`apache_single_user')
')dnl end if # dnl表示它之后的字符为注释
')dnl end ifdef single_userdomain
ifdef(`apache_single_user', ` #如果定义了apache_single_user
typealias $1_home_t alias httpd_$1_content_t; #定义类型别名
typealias $1_home_t alias httpd_$1_htaccess_t;
typealias $1_home_t alias httpd_$1_script_exec_t;
typealias $1_home_t alias httpd_$1_script_ro_t;
typealias $1_home_t alias httpd_$1_script_rw_t;
typealias $1_home_t alias httpd_$1_script_ra_t;
file_type_auto_trans(httpd_$1_script_t, tmp_t, $1_tmp_t) #调用类型转换宏
', `
#这是网页的类型
type httpd_$1_content_t, file_type, homedirfile, sysadmfile;
ifelse($1, sys, ` #如果参数$1为sys,则进行类型别名定义
typealias httpd_sys_content_t alias httpd_sysadm_content_t;
')
...... #省略了其他规则的定义
')
宏定义apache_domain的使用方法如下:
apache_domain(sys)
宏定义apache_domain调用时,其内容中的$1将用sys替换,例如:
type httpd_$1_htaccess_t, file_type, sysadmfile;
上面一行语句将变为下面一行语句:
type httpd_sys_htaccess_t, file_type, sysadmfile;