selinux-policy/refpolicy/policy/support/loadable_module.spt

171 lines
3.9 KiB
Cheetah
Raw Normal View History

########################################
#
# Macros for switching between source policy
# and loadable policy module support
#
##############################
#
# For adding the module statement
#
define(`policy_module',`
2006-06-12 17:27:15 +00:00
ifndef(`self_contained_policy',`
module $1 $2;
2005-10-19 14:36:04 +00:00
require {
role system_r;
all_kernel_class_perms
}
')
')
##############################
#
# For use in interfaces, to optionally insert a require block
#
define(`gen_require',`
2006-03-23 21:07:57 +00:00
ifdef(`self_contained_policy',`
ifdef(`__in_optional_policy',`
require {
$1
} # end require
')
',`
require {
$1
2006-03-23 21:07:57 +00:00
} # end require
')
')
# helper function, since m4 wont expand macros
# if a line is a comment (#):
define(`policy_m4_comment',`
##### $2 depth: $1
')dnl
2005-06-08 13:11:47 +00:00
##############################
#
# In the future interfaces should be in loadable modules
2005-06-08 13:11:47 +00:00
#
# template(name,rules)
2005-06-08 13:11:47 +00:00
#
define(`template',` dnl
ifdef(`$1',`errprint(__file__:__line__`: duplicate definition of $1(). Original definition on '$1. __endline__) define(`__if_error')',`define(`$1',__line__)') dnl
`define(`$1',` dnl
define(`policy_temp',incr(policy_call_depth)) dnl
pushdef(`policy_call_depth',policy_temp) dnl
undefine(`policy_temp') dnl
policy_m4_comment(policy_call_depth,begin `$1'(dollarsstar)) dnl
$2 dnl
define(`policy_temp',decr(policy_call_depth)) dnl
pushdef(`policy_call_depth',policy_temp) dnl
undefine(`policy_temp') dnl
policy_m4_comment(policy_call_depth,end `$1'(dollarsstar)) dnl
'')
2005-06-08 13:11:47 +00:00
')
##############################
#
# In the future interfaces should be in loadable modules
#
# interface(name,rules)
#
define(`interface',` dnl
ifdef(`$1',`errprint(__file__:__line__`: duplicate definition of $1(). Original definition on '$1. __endline__) define(`__if_error')',`define(`$1',__line__)') dnl
`define(`$1',` dnl
define(`policy_temp',incr(policy_call_depth)) dnl
pushdef(`policy_call_depth',policy_temp) dnl
undefine(`policy_temp') dnl
policy_m4_comment(policy_call_depth,begin `$1'(dollarsstar)) dnl
$2
define(`policy_temp',decr(policy_call_depth)) dnl
pushdef(`policy_call_depth',policy_temp) dnl
undefine(`policy_temp') dnl
policy_m4_comment(policy_call_depth,end `$1'(dollarsstar)) dnl
'')
')
define(`policy_call_depth',0)
##############################
#
# Optional policy handling
#
define(`optional_policy',`
ifelse(regexp(`$1',`\W'),`-1',`
errprint(__file__:__line__`: deprecated use of module name ($1) as first parameter of optional_policy() block.' __endline__)
optional_policy(shift($*))
',`
optional {`'pushdef(`__in_optional_policy')
$1
2006-06-12 17:27:15 +00:00
ifelse(`$2',`',`',`} else {
$2
2006-06-12 17:27:15 +00:00
')}`'popdef(`__in_optional_policy')`'ifndef(`__in_optional_policy',` # end optional')
')
')
2005-06-07 22:26:39 +00:00
##############################
#
# Determine if we should use the default
# tunable value as specified by the policy
# or if the override value should be used
#
define(`dflt_or_overr',`ifdef(`$1',$1,$2)')
2005-06-07 22:26:39 +00:00
2005-09-21 20:01:40 +00:00
##############################
#
# Extract booleans out of an expression.
# This needs to be reworked so expressions
# with parentheses can work.
define(`delcare_required_symbols',`
ifelse(regexp($1, `\w'), -1, `', `dnl
bool regexp($1, `\(\w+\)', `\1');
delcare_required_symbols(regexp($1, `\w+\(.*\)', `\1'))dnl
') dnl
')
2005-06-07 22:26:39 +00:00
##############################
#
# Tunable declaration
#
define(`gen_tunable',`
2005-09-21 20:01:40 +00:00
ifdef(`self_contained_policy',`
bool $1 dflt_or_overr(`$1'_conf,$2);
2005-08-24 20:00:10 +00:00
',`
2005-09-21 20:01:40 +00:00
# loadable module tunable
# declaration will go here
# instead of bool when
# loadable modules support
# tunables
bool $1 dflt_or_overr(`$1'_conf,$2);
2005-08-24 20:00:10 +00:00
')
2005-06-07 22:26:39 +00:00
')
##############################
#
# Tunable policy handling
#
define(`tunable_policy',`
ifdef(`self_contained_policy',`
if (`$1') {
$2
2006-06-12 17:27:15 +00:00
ifelse(`$3',`',`',`} else {
$3
2006-06-12 17:27:15 +00:00
')}
2005-08-24 20:00:10 +00:00
',`
# structure for tunables
# will go here instead of a
# conditional when loadable
# modules support tunables
2005-09-21 20:01:40 +00:00
gen_require(`
delcare_required_symbols(`$1')
')
2005-08-24 20:18:28 +00:00
if (`$1') {
2005-08-24 20:00:10 +00:00
$2
2006-06-12 17:27:15 +00:00
ifelse(`$3',`',`',`} else {
2005-08-24 20:00:10 +00:00
$3
2006-06-12 17:27:15 +00:00
')}
2005-08-24 20:00:10 +00:00
')
')