Home | History | Annotate | Download | only in docs
      1 <!-- Common Interface Language (CIL) Reference Guide -->
      2            <!-- conditional_statements.xml -->
      3 
      4    <sect1>
      5       <title>Conditional Statements</title>
      6       <sect2 id="boolean">
      7          <title>boolean</title>
      8          <para>Declares a run time boolean as true or false in the current namespace. The <literal><link linkend="booleanif">booleanif</link></literal> statement contains the CIL code that will be in the binary policy file.</para>
      9          <para><emphasis role="bold">Statement definition:</emphasis></para>
     10          <programlisting><![CDATA[(boolean boolean_id true|false)]]></programlisting>
     11          <para><emphasis role="bold">Where:</emphasis></para>
     12          <informaltable frame="all">
     13             <tgroup cols="2">
     14             <colspec colwidth="2 *"/>
     15             <colspec colwidth="6 *"/>
     16                <tbody>
     17                <row>
     18                   <entry>
     19                      <para><literal><link linkend="boolean">boolean</link></literal></para>
     20                   </entry>
     21                   <entry>
     22                      <para>The <literal><link linkend="boolean">boolean</link></literal> keyword.</para>
     23                   </entry>
     24                </row>
     25                <row>
     26                   <entry>
     27                      <para><literal>boolean_id</literal></para>
     28                   </entry>
     29                   <entry>
     30                      <para>The <literal><link linkend="boolean">boolean</link></literal> identifier.</para>
     31                   </entry>
     32                </row>
     33                <row>
     34                   <entry>
     35                      <para><literal>true | false</literal></para>
     36                   </entry>
     37                   <entry>
     38                      <para>The initial state of the boolean. This can be changed at run time using <emphasis role="bold"><literal>setsebool</literal></emphasis><literal>(8)</literal> and its status queried using  <emphasis role="bold"><literal>getsebool</literal></emphasis><literal>(8)</literal>.</para>
     39                   </entry>
     40                </row>
     41             </tbody></tgroup>
     42          </informaltable>
     43          <para><emphasis role="bold">Example:</emphasis></para>
     44          <para>See the <literal><link linkend="booleanif">booleanif</link></literal> statement for an example.</para>
     45       </sect2>
     46 
     47       <sect2 id="booleanif">
     48          <title>booleanif</title>
     49          <para>Contains the run time conditional statements that are instantiated in the binary policy according to the computed boolean identifier(s) state.</para>
     50          <para><literal><link linkend="call">call</link></literal> statements are allowed within a <literal><link linkend="booleanif">booleanif</link></literal>, however the contents of the resulting macro must be limited to those of the <literal><link linkend="booleanif">booleanif</link></literal> statement (i.e. <literal><link linkend="allow">allow</link></literal>, <literal><link linkend="auditallow">auditallow</link></literal>, <literal><link linkend="dontaudit">dontaudit</link></literal>, <literal><link linkend="typemember">typemember</link></literal>, <literal><link linkend="typetransition">typetransition</link></literal>, <literal><link linkend="typechange">typechange</link></literal> and the compile time <literal><link linkend="tunableif">tunableif</link></literal> statement)).</para>
     51          <para><emphasis role="bold">Statement definition:</emphasis></para>
     52          <programlisting><![CDATA[
     53 (booleanif boolean_id | expr ...)
     54     (true
     55         cil_statements
     56         ...)
     57     (false
     58         cil_statements
     59         ...)
     60 )]]>
     61          </programlisting>
     62          <para><emphasis role="bold">Where:</emphasis></para>
     63          <informaltable frame="all">
     64             <tgroup cols="2">
     65             <colspec colwidth="2 *"/>
     66             <colspec colwidth="6 *"/>
     67                <tbody>
     68                <row>
     69                   <entry>
     70                      <para><literal><link linkend="booleanif">booleanif</link></literal></para>
     71                   </entry>
     72                   <entry>
     73                      <para>The <literal><link linkend="booleanif">booleanif</link></literal> keyword.</para>
     74                   </entry>
     75                </row>
     76                <row>
     77                   <entry>
     78                      <para><literal>boolean_id</literal></para>
     79                   </entry>
     80                   <entry>
     81                      <para>Either a single <literal><link linkend="boolean">boolean</link></literal> identifier or one or more <literal>expr</literal>'s.</para>
     82                   </entry>
     83                </row>
     84                <row>
     85                   <entry>
     86                      <para><literal>expr</literal></para>
     87                   </entry>
     88                   <entry>
     89                      <para>Zero or more <literal>expr</literal>'s, the valid operators and syntax are:</para>
     90                      <simpara><literal>    (and (boolean_id boolean_id))</literal></simpara>
     91                      <simpara><literal>    (or  (boolean_id boolean_id))</literal></simpara>
     92                      <simpara><literal>    (xor (boolean_id boolean_id))</literal></simpara>
     93                      <simpara><literal>    (eq  (boolean_id boolean_id))</literal></simpara>
     94                      <simpara><literal>    (neq (boolean_id boolean_id))</literal></simpara>
     95                      <simpara><literal>    (not (boolean_id))</literal></simpara>
     96                   </entry>
     97                </row>
     98                <row>
     99                   <entry>
    100                      <para><literal>true</literal></para>
    101                   </entry>
    102                   <entry>
    103                      <para>An optional set of CIL statements that will be instantiated when the <literal><link linkend="boolean">boolean</link></literal> is evaluated as <literal>true</literal>.</para>
    104                   </entry>
    105                </row>
    106                <row>
    107                   <entry>
    108                      <para><literal>false</literal></para>
    109                   </entry>
    110                   <entry>
    111                      <para>An optional set of CIL statements that will be instantiated when the <literal><link linkend="boolean">boolean</link></literal> is evaluated as <literal>false</literal>.</para>
    112                   </entry>
    113                </row>
    114             </tbody></tgroup>
    115          </informaltable>
    116 
    117          <para><emphasis role="bold">Examples:</emphasis></para>
    118          <para>The second example also shows the kernel policy language equivalent:</para>
    119          <programlisting><![CDATA[
    120 (boolean disableAudio false)
    121 
    122 (booleanif disableAudio
    123     (false
    124         (allow process mediaserver.audio_device (chr_file_set (rw_file_perms)))
    125     )
    126 )]]>
    127          </programlisting>
    128          <programlisting><![CDATA[
    129 (boolean disableAudioCapture false)
    130 
    131 ;;; if(!disableAudio && !disableAudioCapture) {
    132 (booleanif (and (not disableAudio) (not disableAudioCapture))
    133     (true
    134         (allow process mediaserver.audio_capture_device (chr_file_set (rw_file_perms)))
    135     )
    136 )]]>
    137       </programlisting>
    138       </sect2>
    139 
    140       <sect2 id="tunable">
    141          <title>tunable</title>
    142          <para>Tunables are similar to booleans, however they are used to manage areas of CIL statements that may or may not be in the final CIL policy that will be compiled (whereas booleans are embedded in the binary policy and can be enabled or disabled during run-time).</para>
    143          <para>Note that tunables can be treated as booleans by the CIL compiler command line parameter <literal>-P</literal> or <literal>--preserve-tunables</literal> flags.</para>
    144          <para><emphasis role="bold">Statement definition:</emphasis></para>
    145          <programlisting><![CDATA[(tunable tunable_id true|false)]]></programlisting>
    146          <para><emphasis role="bold">Where:</emphasis></para>
    147          <informaltable frame="all">
    148             <tgroup cols="2">
    149             <colspec colwidth="2 *"/>
    150             <colspec colwidth="6 *"/>
    151                <tbody>
    152                <row>
    153                   <entry>
    154                      <para><literal>tunable</literal></para>
    155                   </entry>
    156                   <entry>
    157                      <para>The <literal><link linkend="tunable">tunable</link></literal> keyword.</para>
    158                   </entry>
    159                </row>
    160                <row>
    161                   <entry>
    162                      <para><literal>tunable_id</literal></para>
    163                   </entry>
    164                   <entry>
    165                      <para>The <literal><link linkend="tunable">tunable</link></literal> identifier.</para>
    166                   </entry>
    167                </row>
    168                <row>
    169                   <entry>
    170                      <para><literal>true | false</literal></para>
    171                   </entry>
    172                   <entry>
    173                      <para>The initial state of the <literal><link linkend="tunable">tunable</link></literal>.</para>
    174                   </entry>
    175                </row>
    176             </tbody></tgroup>
    177          </informaltable>
    178          <para><emphasis role="bold">Example:</emphasis></para>
    179          <para>See the <literal><link linkend="tunableif">tunableif</link></literal> statement for an example.</para>
    180       </sect2>
    181 
    182       <sect2 id="tunableif">
    183          <title>tunableif</title>
    184          <para>Compile time conditional statement that may or may not add CIL statements to be compiled.</para>
    185          <para><emphasis role="bold">Statement definition:</emphasis></para>
    186          <programlisting><![CDATA[
    187 (tunableif tunable_id | expr ...)
    188     (true
    189         cil_statements
    190         ...)
    191     (false
    192         cil_statements
    193         ...)
    194 )]]>
    195          </programlisting>
    196          <para><emphasis role="bold">Where:</emphasis></para>
    197          <informaltable frame="all">
    198             <tgroup cols="2">
    199             <colspec colwidth="2 *"/>
    200             <colspec colwidth="6 *"/>
    201                <tbody>
    202                <row>
    203                   <entry>
    204                      <para><literal>tunableif</literal></para>
    205                   </entry>
    206                   <entry>
    207                      <para>The <literal><link linkend="tunableif">tunableif</link></literal> keyword.</para>
    208                   </entry>
    209                </row>
    210                <row>
    211                   <entry>
    212                      <para><literal>tunable_id</literal></para>
    213                   </entry>
    214                   <entry>
    215                      <para>Either a single <literal><link linkend="tunable">tunable</link></literal> identifier or one or more <literal>expr</literal>'s.</para>
    216                   </entry>
    217                </row>
    218                <row>
    219                   <entry>
    220                      <para><literal>expr</literal></para>
    221                   </entry>
    222                   <entry>
    223                      <para>Zero or more <literal>expr</literal>'s, the valid operators and syntax are:</para>
    224                      <simpara><literal>    (and (tunable_id tunable_id))</literal></simpara>
    225                      <simpara><literal>    (or  (tunable_id tunable_id))</literal></simpara>
    226                      <simpara><literal>    (xor (tunable_id tunable_id))</literal></simpara>
    227                      <simpara><literal>    (eq  (tunable_id tunable_id))</literal></simpara>
    228                      <simpara><literal>    (neq (tunable_id tunable_id))</literal></simpara>
    229                      <simpara><literal>    (not (tunable_id))</literal></simpara>
    230                   </entry>
    231                </row>
    232                <row>
    233                   <entry>
    234                      <para><literal>true</literal></para>
    235                   </entry>
    236                   <entry>
    237                      <para>An optional set of CIL statements that will be instantiated when the <literal><link linkend="tunable">tunable</link></literal> is evaluated as <literal>true</literal>.</para>
    238                   </entry>
    239                </row>
    240                <row>
    241                   <entry>
    242                      <para><literal>false</literal></para>
    243                   </entry>
    244                   <entry>
    245                      <para>An optional set of CIL statements that will be instantiated when the <literal><link linkend="tunable">tunable</link></literal> is evaluated as <literal>false</literal>.</para>
    246                   </entry>
    247                </row>
    248             </tbody></tgroup>
    249          </informaltable>
    250 
    251          <para><emphasis role="bold">Example:</emphasis></para>
    252          <para>This example will not add the range transition rule to the binary policy:</para>
    253          <programlisting><![CDATA[
    254 (tunable range_trans_rule false)
    255 
    256 (block init
    257     (class process (process))
    258     (type process)
    259 
    260     (tunableif range_trans_rule
    261         (true
    262             (rangetransition process sshd.exec process low_high)
    263         )
    264     ) ; End tunableif
    265 ) ; End block]]>
    266          </programlisting>
    267       </sect2>
    268 
    269    </sect1>
    270