| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | BOOLEANS=(`getsebool -a | cut -d " " -f 1 | head -n 3`) |
| 4 | |
| 5 | I=0 |
| 6 | while [ $I -lt ${#BOOLEANS[@]} ]; do |
| 7 | STATE=`getsebool ${BOOLEANS[$I]} | cut -d " " -f 3` |
| 8 | if [ $STATE = "on" ]; then |
| 9 | BOOLEAN_VAR_N=1 |
| 10 | BOOLEAN_VAR_S="true" |
| 11 | else |
| 12 | BOOLEAN_VAR_N=0 |
| 13 | BOOLEAN_VAR_S="false" |
| 14 | fi |
| 15 | eval "BOOLEANS_VAL_N[$I]=$BOOLEAN_VAR_N" |
| 16 | eval "BOOLEANS_VAL_S[$I]=$BOOLEAN_VAR_S" |
| 17 | I=$[$I+1] |
| 18 | done |
| 19 | |
| 20 | C=$I |
| 21 | |
| 22 | cat <<EOF |
| 23 | <?xml version="1.0"?> |
| 24 | <oval_definitions xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ind-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux" xmlns:unix-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" xmlns:lin-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5" xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix unix-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd"> |
| 25 | |
| 26 | <generator> |
| 27 | <oval:product_name>selinuxboolean</oval:product_name> |
| 28 | <oval:product_version>1.0</oval:product_version> |
| 29 | <oval:schema_version>5.8</oval:schema_version> |
| 30 | <oval:timestamp>2011-07-13T00:00:00-00:00</oval:timestamp> |
| 31 | </generator> |
| 32 | |
| 33 | <definitions> |
| 34 | |
| 35 | <definition class="compliance" version="1" id="oval:1:def:1"> <!-- comment="true" --> |
| 36 | <metadata> |
| 37 | <title></title> |
| 38 | <description></description> |
| 39 | </metadata> |
| 40 | <criteria> |
| 41 | <criteria operator="AND"> |
| 42 | EOF |
| 43 | I=0 |
| 44 | while [ $I -lt ${#BOOLEANS[@]} ]; do |
| 45 | echo "<criterion test_ref=\"oval:1:tst:$[$I+1]\"/>" |
| 46 | echo "<criterion test_ref=\"oval:1:tst:$[$C+$I+1]\"/>" |
| 47 | I=$[$I+1] |
| 48 | done |
| 49 | I=0 |
| 50 | while [ $I -lt $(( ${#BOOLEANS[@]} - 1 )) ]; do |
| 51 | echo "<criterion test_ref=\"oval:1:tst:$[$C+$C+$I+1]\"/>" |
| 52 | I=$[$I+1] |
| 53 | done |
| 54 | cat <<EOF |
| 55 | </criteria> |
| 56 | </criteria> |
| 57 | </definition> |
| 58 | |
| 59 | </definitions> |
| 60 | |
| 61 | <tests> |
| 62 | |
| 63 | <!-- DEFAULT STATELESS OBJECT --> |
| 64 | |
| 65 | <!-- check="all" --> |
| 66 | |
| 67 | EOF |
| 68 | |
| 69 | I=0 |
| 70 | while [ $I -lt ${#BOOLEANS[@]} ]; do |
| 71 | cat <<EOF |
| 72 | <selinuxboolean_test version="1" id="oval:1:tst:$[$I+1]" check="at least one" comment="true" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"> |
| 73 | <object object_ref="oval:1:obj:$[$I+1]"/> |
| 74 | <state state_ref="oval:1:ste:$[$I+1]"/> |
| 75 | </selinuxboolean_test> |
| 76 | |
| 77 | <selinuxboolean_test version="1" id="oval:1:tst:$[$C+$I+1]" check="at least one" comment="true" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"> |
| 78 | <object object_ref="oval:1:obj:$[$C+1]"/> |
| 79 | <state state_ref="oval:1:ste:$[$C+$I+1]"/> |
| 80 | </selinuxboolean_test> |
| 81 | EOF |
| 82 | I=$[$I+1] |
| 83 | done |
| 84 | |
| 85 | I=0 |
| 86 | while [ $I -lt $(( ${#BOOLEANS[@]} - 1 )) ]; do |
| 87 | cat <<EOF |
| 88 | <selinuxboolean_test version="1" id="oval:1:tst:$[$C+$C+$I+1]" check="at least one" comment="true" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"> |
| 89 | <object object_ref="oval:1:obj:$[$C+2]"/> |
| 90 | <state state_ref="oval:1:ste:$[$C+$C+$I+1]"/> |
| 91 | </selinuxboolean_test> |
| 92 | EOF |
| 93 | I=$[$I+1] |
| 94 | done |
| 95 | |
| 96 | cat <<EOF |
| 97 | |
| 98 | </tests> |
| 99 | |
| 100 | <objects> |
| 101 | |
| 102 | EOF |
| 103 | |
| 104 | I=0 |
| 105 | while [ $I -lt ${#BOOLEANS[@]} ]; do |
| 106 | cat <<EOF |
| 107 | <selinuxboolean_object version="1" id="oval:1:obj:$[$I+1]" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"> |
| 108 | <name>${BOOLEANS[$I]}</name> |
| 109 | </selinuxboolean_object> |
| 110 | |
| 111 | EOF |
| 112 | I=$[$I+1] |
| 113 | done |
| 114 | |
| 115 | cat <<EOF |
| 116 | <selinuxboolean_object version="1" id="oval:1:obj:$[$I+1]" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"> |
| 117 | <name operation="pattern match">.*</name> |
| 118 | </selinuxboolean_object> |
| 119 | |
| 120 | <selinuxboolean_object version="1" id="oval:1:obj:$[$I+2]" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"> |
| 121 | <name operation="not equal">${BOOLEANS[$I-1]}</name> |
| 122 | </selinuxboolean_object> |
| 123 | |
| 124 | EOF |
| 125 | cat <<EOF |
| 126 | |
| 127 | </objects> |
| 128 | |
| 129 | <states> |
| 130 | |
| 131 | EOF |
| 132 | |
| 133 | I=0 |
| 134 | while [ $I -lt ${#BOOLEANS[@]} ]; do |
| 135 | cat <<EOF |
| 136 | <selinuxboolean_state version="1" id="oval:1:ste:$[$I+1]" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"> |
| 137 | <name>${BOOLEANS[$I]}</name> |
| 138 | <current_status datatype="boolean">${BOOLEANS_VAL_N[$I]}</current_status> |
| 139 | <pending_status datatype="boolean">${BOOLEANS_VAL_N[$I]}</pending_status> |
| 140 | </selinuxboolean_state> |
| 141 | |
| 142 | <selinuxboolean_state version="1" id="oval:1:ste:$[$C+$I+1]" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"> |
| 143 | <name>${BOOLEANS[$I]}</name> |
| 144 | <current_status datatype="boolean">${BOOLEANS_VAL_S[$I]}</current_status> |
| 145 | <pending_status datatype="boolean">${BOOLEANS_VAL_S[$I]}</pending_status> |
| 146 | </selinuxboolean_state> |
| 147 | |
| 148 | EOF |
| 149 | I=$[$I+1] |
| 150 | done |
| 151 | |
| 152 | I=0 |
| 153 | while [ $I -lt $(( ${#BOOLEANS[@]} - 1 )) ]; do |
| 154 | cat <<EOF |
| 155 | <selinuxboolean_state version="1" id="oval:1:ste:$[$C+$C+$I+1]" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux"> |
| 156 | <name>${BOOLEANS[$I]}</name> |
| 157 | <current_status datatype="boolean">${BOOLEANS_VAL_S[$I]}</current_status> |
| 158 | <pending_status datatype="boolean">${BOOLEANS_VAL_N[$I]}</pending_status> |
| 159 | </selinuxboolean_state> |
| 160 | EOF |
| 161 | I=$[$I+1] |
| 162 | done |
| 163 | |
| 164 | cat <<EOF |
| 165 | |
| 166 | </states> |
| 167 | |
| 168 | </oval_definitions> |
| 169 | EOF |
| 170 | |
| 171 | exit $(( 3 * ${#BOOLEANS[@]} - 1)) |