Skip to content

Commit 0eead3d

Browse files
committed
accounting: Check if the shadow file could be read
This reduce lot of error log when using YASAT as non-root. Signed-off-by: Corentin Labbe <[email protected]>
1 parent 218f2a1 commit 0eead3d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Diff for: plugins/accounting.test

+13-2
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,17 @@ if [ ! -e "$SHADOW_FILE" ];then
144144
Display --indent 2 --text "$SHADOW_FILE not found, trying /etc/passwd" --result NOSHADOW --color BLUE
145145
SHADOW_FILE="`echo $SCAN_ROOT/etc/passwd |sed 's,//*,/,g'`"
146146
fi
147-
if [ -e "$SHADOW_FILE" ];then
147+
check_shadow() {
148148
Display --indent 2 --text "$SHADOW_FILE" --result FOUND --color BLUE
149149
TMPFILE_ACCT="${TEMPYASATDIR}/shadow.tmp"
150-
grep -v '^#' "$SHADOW_FILE" |cut -d\: -f1,2 > $TMPFILE_ACCT
150+
# check if $SHADOW_FILE could be read
151+
head -n1 $SHADOW_FILE 2>/dev/null >/dev/null
152+
if [ $? -ne 0 ];then
153+
Display --indent 2 --text "$SHADOW_FILE could not be read" --result EPERM --color RED
154+
return 0
155+
fi
156+
157+
grep -v '^#' "$SHADOW_FILE" | cut -d\: -f1,2 > $TMPFILE_ACCT
151158
while read line
152159
do
153160
HASH_METHOD="`echo $line |cut -d\: -f2 | cut -c1,2`"
@@ -189,6 +196,10 @@ if [ -e "$SHADOW_FILE" ];then
189196
#TODO Blowfish $2a
190197
done < $TMPFILE_ACCT
191198
rm $TMPFILE_ACCT
199+
}
200+
201+
if [ -e "$SHADOW_FILE" ];then
202+
check_shadow
192203
fi
193204

194205
#TODO need more work

0 commit comments

Comments
 (0)