
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://selinuxproject.org/w/skins/common/feed.css?63"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>ConditionalStatements - Revision history</title>
		<link>http://selinuxproject.org/w/?title=ConditionalStatements&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.10.4</generator>
		<lastBuildDate>Tue, 21 May 2013 16:50:18 GMT</lastBuildDate>
		<item>
			<title>RichardHaines: New page: = Conditional Policy Statements = Conditional policies consist of a bool statement that defines a condition as true or false, with a supporting if / else construct that specifies what rule...</title>
			<link>http://selinuxproject.org/w/?title=ConditionalStatements&amp;diff=841&amp;oldid=prev</link>
			<description>&lt;p&gt;New page: = Conditional Policy Statements = Conditional policies consist of a bool statement that defines a condition as true or false, with a supporting if / else construct that specifies what rule...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Conditional Policy Statements =&lt;br /&gt;
Conditional policies consist of a bool statement that defines a condition as true or false, with a supporting if / else construct that specifies what rules are valid under the condition as shown in the example below:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bool allow_daemons_use_tty true;&lt;br /&gt;
&lt;br /&gt;
if (allow_daemons_use_tty) {&lt;br /&gt;
&amp;lt;nowiki&amp;gt;      # Rules if condition is &amp;lt;/nowiki&amp;gt;true&amp;lt;nowiki&amp;gt;;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   } else {&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;     # Rules if condition is &amp;lt;/nowiki&amp;gt;false&amp;lt;nowiki&amp;gt;;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The bool statement default value can be changed when a policy is active by using the setsebool command as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# This command will set the allow_daemons_use_tty bool to &amp;lt;/nowiki&amp;gt;false,&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# however it will only remain false until the next system &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# re-boot where it will then revert back to its default state&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# (in the above case, this would be &amp;lt;/nowiki&amp;gt;true).&lt;br /&gt;
&lt;br /&gt;
setsebool allow_daemons_use_tty false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# This command will set the allow_daemons_use_tty bool to false,&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# and because the -P option is used (for persistent), the value &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# will remain across system re-boots. Note however that all &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# other pending bool values will become persistent across &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# re-boots as well (see the setsebool (8) man page). &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
setsebool -P allow_daemons_use_tty false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The getsebool command can be used to query the current bool statement value as follows: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# This command will list all bool values in the active policy:&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
getsebool -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# This command will show the current allow_daemons_use_tty bool &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# value in the active policy:&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
getsebool allow_daemons_use_tty&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== bool Statement ==&lt;br /&gt;
The bool statement is used to specify a boolean identifier and its initial state (true or false) that can then be used with the if Statement to form a 'conditional policy' as described in the Conditional Policy section.&lt;br /&gt;
&lt;br /&gt;
'''The statement definition is:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bool bool_id default_value;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where:'''&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|bool&lt;br /&gt;
|The bool keyword.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|bool_id&lt;br /&gt;
|The boolean identifier.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|default_value&lt;br /&gt;
|Either true or false.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''The statement is valid in:'''&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&amp;lt;center&amp;gt;'''Monolithic Policy'''&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;'''Base Policy'''&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;'''Module Policy'''&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;center&amp;gt;Yes&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;Yes&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;Yes&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;center&amp;gt;'''Conditional Policy (if) Statement'''&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;'''optional Statement'''&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;'''require Statement'''&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;center&amp;gt;No&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;Yes&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;Yes&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# Using the &amp;lt;/nowiki&amp;gt;bool statement to allow unconfined executables to&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# make their memory heap executable or not. As the value is&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# &amp;lt;/nowiki&amp;gt;false, then by default they cannot make their heap executable.&lt;br /&gt;
&lt;br /&gt;
bool allow_execheap false;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# Using the &amp;lt;/nowiki&amp;gt;bool statement to allow unconfined executables to &lt;br /&gt;
&amp;lt;nowiki&amp;gt;# make their stack executable or not. As the value is &amp;lt;/nowiki&amp;gt;true,&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# then by default their stacks are executable.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
bool allow_execstack true;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== if Statement ==&lt;br /&gt;
The if statement is used to form a 'conditional block' of statements and rules that are enforced depending on whether one or more boolean identifiers (defined by the bool Statement) evaluate to TRUE or FALSE. An if / else construct is also supported.&lt;br /&gt;
&lt;br /&gt;
The only statements and rules allowed within the if / else construct are:&lt;br /&gt;
&lt;br /&gt;
allow, auditallow, auditdeny, dontaudit, type_member, type_transition, type_change and require.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''The statement definition is:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;if (conditional_expression) { true_list } [ else { false_list } ]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Where:'''&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|if&lt;br /&gt;
|The if keyword.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|conditional_expression&lt;br /&gt;
|One or more bool_name identifiers that have been previously defined by the bool Statement. Multiple identifiers must be separated by the following logical operators: &amp;amp;&amp;amp;, ¦¦, ^, !, ==, !=. &lt;br /&gt;
&lt;br /&gt;
The conditional_expression is enclosed in brackets ().&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|true_list&lt;br /&gt;
|A list of rules enclosed within braces '{}' that will be executed when the conditional_expression is 'true'.&lt;br /&gt;
&lt;br /&gt;
Valid statements and rules are highlighted within each language definition statement.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|else&lt;br /&gt;
|Optional else keyword.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|false_list&lt;br /&gt;
|A list of rules enclosed within braces '{}' that will be executed when the optional 'else' keyword is present and the conditional_expression is 'false'.&lt;br /&gt;
&lt;br /&gt;
Valid statements and rules are highlighted within each language definition statement.&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''The statement is valid in:'''&lt;br /&gt;
{|border=&amp;quot;1&amp;quot;&lt;br /&gt;
|&amp;lt;center&amp;gt;'''Monolithic Policy'''&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;'''Base Policy'''&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;'''Module Policy'''&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;center&amp;gt;Yes&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;Yes&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;Yes&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;center&amp;gt;'''Conditional Policy (if) Statement'''&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;'''optional Statement'''&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;'''require Statement'''&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;center&amp;gt;No - As this is a Conditional Statement and cannot be nested.&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;Yes&amp;lt;/center&amp;gt;&lt;br /&gt;
|&amp;lt;center&amp;gt;No&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# An example showing a &amp;lt;/nowiki&amp;gt;boolean and supporting if statement.&lt;br /&gt;
&lt;br /&gt;
bool allow_execmem false;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# The bool &amp;lt;/nowiki&amp;gt;allow_execmem is FALSE therefore the allow statement &lt;br /&gt;
&amp;lt;nowiki&amp;gt;# is not executed:&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
if (allow_execmem) { &lt;br /&gt;
      allow sysadm_t self:process execmem; &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# An example showing two &amp;lt;/nowiki&amp;gt;booleans and a supporting if statement.&lt;br /&gt;
&lt;br /&gt;
bool allow_execmem false;&lt;br /&gt;
bool allow_execstack true;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# The bool &amp;lt;/nowiki&amp;gt;allow_execmem is FALSE and allow_execstack is TRUE &lt;br /&gt;
&amp;lt;nowiki&amp;gt;# therefore the allow statement is not executed:&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
if (allow_execmem &amp;amp;&amp;amp; allow_execstack) {&lt;br /&gt;
      allow sysadm_t self:process execstack;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# An example of an IF - ELSE statement where t&amp;lt;/nowiki&amp;gt;he bool statement&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# is FALSE, therefore the ELSE statements will be executed.&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;#&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
bool read_untrusted_content false;&lt;br /&gt;
&lt;br /&gt;
if (read_untrusted_content) {&lt;br /&gt;
      allow sysadm_t { sysadm_untrusted_content_t &lt;br /&gt;
      sysadm_untrusted_content_tmp_t }:dir { getattr search read lock ioctl };&lt;br /&gt;
      .....&lt;br /&gt;
&lt;br /&gt;
   } else {&lt;br /&gt;
      dontaudit sysadm_t { sysadm_untrusted_content_t &lt;br /&gt;
      sysadm_untrusted_content_tmp_t }:dir { getattr search read  lock ioctl };&lt;br /&gt;
      ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</description>
			<pubDate>Sun, 29 Nov 2009 16:09:34 GMT</pubDate>			<dc:creator>RichardHaines</dc:creator>			<comments>http://selinuxproject.org/page/Talk:ConditionalStatements</comments>		</item>
	</channel>
</rss>