1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
#!/usr/bin/env bash
# i=0;
# IFS=$'\n'
# for line in `env`; do
# VAR=`echo $line | sed 's/\([A-Za-z_1-9]*\)=.*$/\1/'`
# if [ "x$VAR" == "x_" ] || [ "x$VAR" == "xSHLVL" ]; then
# continue;
# fi
# ENV_VAR[$i]="$VAR";
# VAR_VAL[$i]=`echo $line | sed 's/\([A-Za-z_1-9]*\)=\(.*\)$/\2/'`
# i=$[$i+1];
# done
ENV_VAR=(`env | sed -n 's|^\([A-Z]*\)=[a-zA-Z0-9/]\{1,\}$|\1|p' | egrep -v SHLVL`)
I=0
while [ $I -lt ${#ENV_VAR[@]} ]; do
eval "VAL=\$${ENV_VAR[$I]}"
VAR_VAL[$I]=$VAL
I=$[$I+1]
done
C=$I
cat <<EOF
<?xml version="1.0"?>
<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#independent" 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#independent independent-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">
<generator>
<oval:product_name>environmentvariable</oval:product_name>
<oval:product_version>1.0</oval:product_version>
<oval:schema_version>5.4</oval:schema_version>
<oval:timestamp>2008-03-31T00:00:00-00:00</oval:timestamp>
</generator>
<definitions>
<definition class="compliance" version="1" id="oval:1:def:1"> <!-- comment="true" -->
<metadata>
<title></title>
<description></description>
</metadata>
<criteria>
<criteria operator="AND">
EOF
I=0
while [ $I -lt ${#ENV_VAR[@]} ]; do
echo "<criterion test_ref=\"oval:1:tst:$[$I+1]\"/>"
echo "<criterion test_ref=\"oval:1:tst:$[$C+$I+1]\"/>"
I=$[$I+1]
done
I=0
while [ $I -lt $(( ${#ENV_VAR[@]} - 1 )) ]; do
echo "<criterion test_ref=\"oval:1:tst:$[$C+$C+$I+1]\"/>"
I=$[$I+1]
done
cat <<EOF
</criteria>
</criteria>
</definition>
</definitions>
<tests>
<!-- DEFAULT STATELESS OBJECT -->
<!-- check="all" -->
EOF
I=0
while [ $I -lt ${#ENV_VAR[@]} ]; do
cat <<EOF
<environmentvariable_test version="1" id="oval:1:tst:$[$I+1]" check="at least one" comment="true" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent">
<object object_ref="oval:1:obj:$[$I+1]"/>
<state state_ref="oval:1:ste:$[$I+1]"/>
</environmentvariable_test>
<environmentvariable_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#independent">
<object object_ref="oval:1:obj:$[$C+1]"/>
<state state_ref="oval:1:ste:$[$C+$I+1]"/>
</environmentvariable_test>
EOF
I=$[$I+1]
done
I=0
while [ $I -lt $(( ${#ENV_VAR[@]} - 1 )) ]; do
cat <<EOF
<environmentvariable_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#independent">
<object object_ref="oval:1:obj:$[$C+2]"/>
<state state_ref="oval:1:ste:$[$C+$C+$I+1]"/>
</environmentvariable_test>
EOF
I=$[$I+1]
done
cat <<EOF
</tests>
<objects>
EOF
I=0
while [ $I -lt ${#ENV_VAR[@]} ]; do
cat <<EOF
<environmentvariable_object version="1" id="oval:1:obj:$[$I+1]" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent">
<name>${ENV_VAR[$I]}</name>
</environmentvariable_object>
EOF
I=$[$I+1]
done
cat <<EOF
<environmentvariable_object version="1" id="oval:1:obj:$[$I+1]" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent">
<name operation="pattern match">.*</name>
</environmentvariable_object>
<environmentvariable_object version="1" id="oval:1:obj:$[$I+2]" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent">
<name operation="not equal">${ENV_VAR[$I-1]}</name>
</environmentvariable_object>
EOF
cat <<EOF
</objects>
<states>
EOF
I=0
while [ $I -lt ${#ENV_VAR[@]} ]; do
cat <<EOF
<environmentvariable_state version="1" id="oval:1:ste:$[$I+1]" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent">
<name>${ENV_VAR[$I]}</name>
<value>${VAR_VAL[$I]}</value>
</environmentvariable_state>
<environmentvariable_state version="1" id="oval:1:ste:$[$C+$I+1]" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent">
<name>${ENV_VAR[$I]}</name>
<value>${VAR_VAL[$I]}</value>
</environmentvariable_state>
EOF
I=$[$I+1]
done
I=0
while [ $I -lt $(( ${#ENV_VAR[@]} - 1 )) ]; do
cat <<EOF
<environmentvariable_state version="1" id="oval:1:ste:$[$C+$C+$I+1]" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent">
<name>${ENV_VAR[$I]}</name>
<value>${VAR_VAL[$I]}</value>
</environmentvariable_state>
EOF
I=$[$I+1]
done
cat <<EOF
</states>
</oval_definitions>
EOF
exit $(( 3 * ${#ENV_VAR[@]} - 1))
|