Mon, 20 Jul 2009 20:44:18 +0200
Fixed join sorting, removed device checks
5 | 1 | #!/bin/bash |
2 | # | |
3 | ############################################################################# | |
7 | 4 | # Copyright (C) 2005-2009 |
5 | 5 | # |
7 | 6 | # Michiel Broek <mbse@mbse.eu> |
5 | 7 | # Beekmansbos 10 |
8 | # 1971 BV IJmuiden | |
9 | # the Netherlands | |
10 | # | |
11 | # This file is part of SlackSecCheckSripts. | |
12 | # | |
13 | # This package is free software; you can redistribute it and/or modify it | |
14 | # under the terms of the GNU General Public License as published by the | |
15 | # Free Software Foundation; either version 2, or (at your option) any | |
16 | # later version. | |
17 | # | |
18 | # SlackSecCheckSripts is distributed in the hope that it will be useful, but | |
19 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 | # General Public License for more details. | |
22 | # | |
23 | # You should have received a copy of the GNU General Public License | |
24 | # along with MBSE BBS; see the file COPYING. If not, write to the Free | |
25 | # Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
26 | ############################################################################# | |
27 | ||
28 | ||
29 | PATH=/sbin:/usr/sbin:/bin:/usr/bin | |
30 | ||
31 | umask 077 | |
32 | TZ=UTC; export TZ | |
33 | LANG=C; export LANG | |
34 | ||
35 | max_loginlen=${max_loginlen:-32} | |
36 | ||
37 | MP=/etc/passwd | |
38 | SP=/etc/shadow | |
39 | ||
40 | ||
41 | SECUREDIR=`mktemp -d /tmp/_securedir.XXXXXX` || exit 1 | |
42 | ||
43 | trap "/bin/rm -rf $SECUREDIR ; exit 0" EXIT INT QUIT PIPE | |
44 | ||
45 | if ! cd "$SECUREDIR"; then | |
46 | echo "Can not cd to $SECUREDIR". | |
47 | exit 1 | |
48 | fi | |
49 | ||
50 | TMP2=secure1.$$ | |
51 | MPBYUID=secure2.$$ | |
52 | COMBINED=secure3.$$ | |
53 | OUTPUT=secure4.$$ | |
54 | ||
55 | # Combine passwd and shadow files. | |
56 | # | |
7 | 57 | join --nocheck-order -t : -j 1 $MP $SP > $COMBINED |
5 | 58 | |
59 | ||
60 | # These are used several times. | |
61 | # | |
62 | awk -F: '!/^+/ { print $1 " " $3 }' $MP | sort -k2n > $MPBYUID | |
63 | ||
64 | ||
65 | # Check the master password file syntax. | |
66 | # Usernames may have a $ character at the end for Samba | |
67 | # machine and trust accounts. | |
68 | # | |
69 | awk -v "len=$max_loginlen" ' | |
70 | BEGIN { | |
71 | while ( getline < "/etc/shells" > 0 ) { | |
72 | if ($0 ~ /^\#/ || $0 ~ /^$/ ) | |
73 | continue; | |
74 | shells[$1]++; | |
75 | } | |
76 | FS=":"; | |
77 | } | |
78 | ||
79 | { | |
80 | if ($0 ~ /^[ ]*$/) { | |
81 | printf "\tLine %d is a blank line.\n", NR; | |
82 | next; | |
83 | } | |
84 | if (NF != 15 && ($1 != "+" || NF != 1)) | |
85 | printf "\tLine %d has the wrong number of fields.\n", NR; | |
86 | if ($1 == "+" ) { | |
87 | if (NF != 1 && $3 == 0) | |
88 | printf "\tLine %d includes entries with uid 0.\n", NR; | |
89 | next; | |
90 | } | |
91 | if ($1 !~ /^[A-Za-z0-9]([-A-Za-z0-9]*[A-Za-z0-9\$])*$/) | |
92 | printf "\tLogin %s has non-alphanumeric characters.\n", $1; | |
93 | if (length($1) > len) | |
94 | printf "\tLogin %s has more than "len" characters.\n", $1; | |
95 | if ($7 == "" && $8 !~ /!/ && $8 != "*") | |
96 | printf "\tLogin %s does not have a shell\n", $1; | |
97 | if ($7 != "" && ! shells[$7] && $8 !~ /!/ && $8 != "*") | |
98 | printf "\tLogin %s does not have a valid shell (%s)\n", $1, $7; | |
99 | if ($7 != "" && shells[$7] && ($8 ~ /!/ && $8 = "*")) | |
100 | printf "\tLogin %s account is locked.\n", $1; | |
101 | if ($8 == "") | |
102 | printf "\tLogin %s has no password.\n", $1; | |
103 | if ($9 == "0") | |
104 | printf "\tLogin %s password is expired.\n", $1; | |
105 | if ($3 == 0 && $1 != "root" && $1 != "toor") | |
106 | printf "\tLogin %s has a user id of 0.\n", $1; | |
107 | if ($3 < 0) | |
108 | printf "\tLogin %s has a negative user id.\n", $1; | |
109 | if ($4 < 0) | |
110 | printf "\tLogin %s has a negative group id.\n", $1; | |
111 | }' < $COMBINED > $OUTPUT | |
112 | if [ -s $OUTPUT ] ; then | |
113 | printf "\nChecking the $MP and $SP files:\n" | |
114 | cat $OUTPUT | |
115 | fi | |
116 | ||
117 | awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT | |
118 | if [ -s $OUTPUT ] ; then | |
119 | printf "\n$MP has duplicate user names.\n" | |
120 | column $OUTPUT | |
121 | fi | |
122 | ||
123 | # To not exclude 'toor', a standard duplicate root account, from the duplicate | |
124 | # account test, uncomment the line below (without egrep in it)and comment | |
125 | # out the line (with egrep in it) below it. | |
126 | # | |
127 | #< $MPBYUID uniq -d -f 1 | awk '{ print $2 }' > $TMP2 | |
128 | < $MPBYUID egrep -v '^toor ' | uniq -d -f 1 | awk '{ print $2 }' > $TMP2 | |
129 | if [ -s $TMP2 ] ; then | |
130 | printf "\n$MP has duplicate user id's.\n" | |
131 | while read uid; do | |
132 | grep -w $uid $MPBYUID | |
133 | done < $TMP2 | column | |
134 | fi | |
135 | ||
136 |