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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
#!/bin/sh
#
# tiger - A UN*X security checking system
# Copyright (C) 1993 Douglas Lee Schales, David K. Hess, David R. Safford
#
# Please see the file `COPYING' for the complete copyright notice.
#
# check_exports - 06/14/93
#
# 04/28/93 dls Add '-L' to 'ls' so we get the permissions from the file
# instead of a symbolic link.
#
#-----------------------------------------------------------------------------
#
#
# Check NFS exports file for:
#
# Anonymous ID = 0 and write access (fail)
# Anonymous ID = 0 and readonly access (warn)
# Exporting the root filesystem (warn)
# Exporting the root filesystem to "world" (fail)
# Exporting the root filesystem with "root" access (fail)
# Exporting a filesystem to "world" with write (fail)
# Exporting a filesystem to "world" (warn)
# Exporting a filesystem with "root" access, the host
# is a diskless client, but the path is "safe" (info)
# Exporting a filesystem with "root" access, the host
# is a diskless client, but the path is "unsafe" (warn)
# Exporting a filesystem with "root" access, the host
# is not a diskless client, and the path is "unsafe" (warn)
#
#------------------------------------------------------------------------
#
TigerInstallDir='.'
#
# Set default base directory.
# Order or preference:
# -B option
# TIGERHOMEDIR environment variable
# TigerInstallDir installed location
#
basedir=${TIGERHOMEDIR:=$TigerInstallDir}
for parm
do
case $parm in
-B) basedir=$2; break;;
esac
done
#
# Verify that a config file exists there, and if it does
# source it.
#
[ ! -r $basedir/config ] && {
echo "--ERROR-- [init002e] No 'config' file in \`$basedir'."
exit 1
}
. $basedir/config
. $BASEDIR/initdefs
#
# If run in test mode (-t) this will verify that all required
# elements are set.
#
[ "$Tiger_TESTMODE" = 'Y' ] && {
haveallcmds AWK GEN_BOOTPARAM_SETS GEN_EXPORT_SETS LS RM SED SORT
haveallfiles BASEDIR WORKDIR || exit 1
haveallvars HOSTNAME
echo "--CONFIG-- [init003c] $0: Configuration ok..."
exit 0
}
#------------------------------------------------------------------------
echo
echo "# Performing NFS exports check..."
haveallcmds GEN_EXPORT_SETS SED AWK || exit 1
haveallfiles BASEDIR WORKDIR || exit 1
haveallvars HOSTNAMESLIST || exit 1
is_safe_path()
{
saveifs=$IFS
IFS=/
set $1
IFS=$saveifs
path=
open=1
for name
do
set `getpermit ${path}/$name` X
shift
shift
shift
[ -n "$9" ] &&
[ "$4" = 0 -a "$5" = 0 -a "$6" = 0 -a \
"$7" = 0 -a "$8" = 0 -a "$9" = 0 ] && { open=0; break; }
path=${path}/$name
done
return $open
}
check_entry()
{
dir=$1
shift
# Assume first a good setup
world=0
root=0
readonly=0
anonid=-1
readmost=0
roothosts=
# TODO: Does not recognise new /etc/exports format
# directory serverA (options) domainB (options)
# Needs to be rewritten or gen_exports modified
for acl
do
case $acl in
-access=*|access=*) world=0;;
-root=*|root=*) root=1;roothosts=`echo $acl|$AWK -F= '{print $2}'`;;
-ro=*|ro=*) readonly=1; world=0;;
-ro|ro) readonly=1;;
-anon=*|anon=*) anonid=`echo $acl | $AWK -F= '{print $2}'`;;
-rw=*|rw=*) readmost=1;;
-rw|rw) world=1;;
esac
done
[ "$anonid" = "0" -a "$readonly" = "0" ] &&
message FAIL nfs001f "" "Anonymous ID == 0, for R/W filesystem $dir"
[ "$anonid" = "0" -a "$readonly" = "1" ] &&
message WARN nfs002w "" "Anonymous ID == 0 for R/O filesystem $dir"
[ "$dir" = "/" ] &&
message WARN nfs003w "" "Exporting the root filesystem (/)."
[ "$dir" = '/usr' -a "$readonly" = '0' ] &&
message WARN nfs014w "" "Exporting the /usr filesystem R/W."
[ $world = 1 ] && {
if [ "$dir" = "/" ]; then
if [ "$readonly" = "0" ]; then
message FAIL nfs004f "" "Exporting the root filesystem (/) R/W to everyone."
else
message FAIL nfs005f "" "Exporting the root filesystem (/) R/O to everyone."
fi
else
if [ "$readonly" = "0" ]; then
message FAIL nfs006f "" "Directory $dir exported R/W to everyone."
else
message WARN nfs007w "" "Directory $dir exported R/O to everyone."
fi
fi
}
[ $root = 1 -a -d $dir ] && {
[ "$dir" = "/" ] && {
if [ "$readonly" = "1" ]; then
message FAIL nfs008f "" "Exporting the root filesystem (/) R/O with root access."
else
message FAIL nfs009f "" "Exporting the root filesystem (/) R/W with root access."
fi
}
IFS=:
set X $roothosts
IFS="$saveifs"
shift
dlclient=1
# roothost is a magic variable name... don't change it.
for roothost
do
eval "case $dir in $casediskless esac"
done
roothosts=`
echo $roothosts |
$SED -e 's/:/, /g' -e 's/,\([^,]*\)$/, and\1/'`
if [ $dlclient = 0 ]; then
if is_safe_path $dir ; then
message INFO nfs010i "" "Directory $dir is exported with root access to host(s) $roothosts."
else
message WARN nfs011w "" "Unprotected directory $dir is exported with root access to host(s) $roothosts."
fi
else
if is_safe_path $dir ; then
:
else
message WARN nfs012w "" "Unprotected directory $dir is exported with root access for diskless client $roothosts."
fi
fi
}
}
parse_bootparam()
{
$AWK '
BEGIN {LINE="";}
$0 ~ /\\$/ {printf("%s ", substr($0, 1, length($0)-1));}
$0 !~ /\\$/ {printf("%s\n", $0);}
END {printf("\n");}
' |
$AWK '{
for(i=2;i<=NF;i++)
if(substr($i, 1,5) == "root="){
x=substr($i, 6, length($i));
split(x, ar, ":");
print $1, ar[1], ar[2];
}
}'
}
casediskless='*) dlclient=0;;'
haveallcmds GEN_BOOTPARAM_SETS && {
casediskless=`
{
$GEN_BOOTPARAM_SETS |
while read bootparam_set
do
parse_bootparam < $bootparam_set
delete $bootparam_set $bootparam_set.src
done
} |
$SORT -u |
while read client server filesys
do
eval "case $server in
$HOSTNAMESLIST)
echo $filesys')
case \\$roothost in
'$client'*) ;;
*) dlclient=0;;
esac;;' ;;
esac"
done
echo '*) dlclient=0;;'
`
}
saveifs="$IFS"
$GEN_EXPORT_SETS |
while read export_set
do
$SED -e 's/#.*$//' $export_set |
$SED -e '/^[ \t]*$/d' |
$AWK '
BEGIN { LINE=""; }
/\\$/ { LINE=LINE " " substr($0,1,length($0)-1); }
!/\\$/ { print LINE $0; LINE="";}
END { if(LINE != "") print LINE; }
' |
$SED -e 's/,/ /g' |
while read dir acl
do
check_entry $dir $acl
done
delete $export_set $export_set.src
done |
$OUTPUTMETHOD
exit 0
#
exit 0
#
exit 0
#
|