| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | LINES_COUNT=`cat /etc/shadow | wc -l` |
| 4 | |
| 5 | function getField { |
| 6 | LINE=`sed -n "${I}p" /etc/shadow` |
| 7 | case $1 in |
| 8 | 'username' ) |
| 9 | echo $LINE | awk -F':' '{print $1}' |
| 10 | ;; |
| 11 | 'password' ) |
| 12 | echo $LINE | awk -F':' '{print $2}' |
| 13 | ;; |
| 14 | 'chg_lst' ) |
| 15 | local CHGLST=`echo $LINE | awk -F':' '{print $3}'` |
| 16 | if [ "${CHGLST}X" = "X" ]; then echo "-1"; else echo "$CHGLST"; fi |
| 17 | ;; |
| 18 | 'chg_allow' ) |
| 19 | local CHGALLOW=`echo $LINE | awk -F':' '{print $4}'` |
| 20 | if [ "${CHGALLOW}X" = "X" ]; then echo "-1"; else echo "$CHGALLOW"; fi |
| 21 | ;; |
| 22 | 'chg_req' ) |
| 23 | local CHGREQ=`echo $LINE | awk -F':' '{print $5}'` |
| 24 | if [ "${CHGREQ}X" = "X" ]; then echo "-1"; else echo "$CHGREQ"; fi |
| 25 | ;; |
| 26 | 'exp_warn' ) |
| 27 | local EXPWARN=`echo $LINE | awk -F':' '{print $6}'` |
| 28 | if [ "${EXPWARN}X" = "X" ]; then echo "-1"; else echo "$EXPWARN"; fi |
| 29 | ;; |
| 30 | 'exp_inact' ) |
| 31 | local EXPINACT=`echo $LINE | awk -F':' '{print $7}'` |
| 32 | if [ "${EXPINACT}X" = "X" ]; then echo "-1"; else echo "$EXPINACT"; fi |
| 33 | ;; |
| 34 | 'exp_date' ) |
| 35 | local EXPDATE=`echo $LINE | awk -F':' '{print $8}'` |
| 36 | if [ "${EXPDATE}X" = "X" ]; then echo "-1"; else echo "$EXPDATE"; fi |
| 37 | ;; |
| 38 | esac |
| 39 | } |
| 40 | |
| 41 | cat <<EOF |
| 42 | <?xml version="1.0"?> |
| 43 | <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"> |
| 44 | |
| 45 | <generator> |
| 46 | <oval:product_name>shadow</oval:product_name> |
| 47 | <oval:product_version>1.0</oval:product_version> |
| 48 | <oval:schema_version>5.4</oval:schema_version> |
| 49 | <oval:timestamp>2008-03-31T00:00:00-00:00</oval:timestamp> |
| 50 | </generator> |
| 51 | |
| 52 | <definitions> |
| 53 | |
| 54 | <definition class="compliance" version="1" id="oval:1:def:1"> <!-- comment="true" --> |
| 55 | <metadata> |
| 56 | <title></title> |
| 57 | <description></description> |
| 58 | </metadata> |
| 59 | <criteria> |
| 60 | <criteria operator="AND"> |
| 61 | EOF |
| 62 | I=1 |
| 63 | while [ $I -le $LINES_COUNT ]; do |
| 64 | echo "<criterion test_ref=\"oval:1:tst:${I}\"/>" |
| 65 | I=$[$I+1] |
| 66 | done |
| 67 | cat <<EOF |
| 68 | </criteria> |
| 69 | </criteria> |
| 70 | </definition> |
| 71 | |
| 72 | </definitions> |
| 73 | |
| 74 | <tests> |
| 75 | |
| 76 | EOF |
| 77 | |
| 78 | I=1 |
| 79 | while [ $I -le $LINES_COUNT ]; do |
| 80 | cat <<EOF |
| 81 | <shadow_test version="1" id="oval:1:tst:${I}" check="all" comment="true" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix"> |
| 82 | <object object_ref="oval:1:obj:${I}"/> |
| 83 | <state state_ref="oval:1:ste:${I}"/> |
| 84 | </shadow_test> |
| 85 | EOF |
| 86 | I=$[$I+1] |
| 87 | done |
| 88 | |
| 89 | cat <<EOF |
| 90 | </tests> |
| 91 | |
| 92 | <objects> |
| 93 | EOF |
| 94 | |
| 95 | I=1 |
| 96 | while [ $I -le $LINES_COUNT ]; do |
| 97 | cat <<EOF |
| 98 | <shadow_object version="1" id="oval:1:obj:${I}" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix"> |
| 99 | <username>`getField "username" ${I}`</username> |
| 100 | </shadow_object> |
| 101 | EOF |
| 102 | I=$[$I+1] |
| 103 | done |
| 104 | |
| 105 | cat <<EOF |
| 106 | </objects> |
| 107 | |
| 108 | <states> |
| 109 | EOF |
| 110 | |
| 111 | I=1 |
| 112 | while [ $I -le $LINES_COUNT ]; do |
| 113 | cat <<EOF |
| 114 | <shadow_state version="1" id="oval:1:ste:${I}" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix"> |
| 115 | <username>`getField 'username' $I`</username> |
| 116 | <password>`getField 'password' $I`</password> |
| 117 | <chg_lst datatype="int">`getField 'chg_lst' $I`</chg_lst> |
| 118 | <chg_allow datatype="int">`getField 'chg_allow' $I`</chg_allow> |
| 119 | <chg_req datatype="int">`getField 'chg_req' $I`</chg_req> |
| 120 | <exp_warn datatype="int">`getField 'exp_warn' $I`</exp_warn> |
| 121 | <exp_inact datatype="int">`getField 'exp_inact' $I`</exp_inact> |
| 122 | <exp_date datatype="int">`getField 'exp_date' $I`</exp_date> |
| 123 | </shadow_state> |
| 124 | EOF |
| 125 | I=$[$I+1] |
| 126 | done |
| 127 | |
| 128 | cat <<EOF |
| 129 | </states> |
| 130 | |
| 131 | </oval_definitions> |
| 132 | EOF |