xref: /freebsd/usr.sbin/periodic/etc/weekly/340.noid (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1#!/bin/sh -
2#
3# $FreeBSD$
4#
5
6# If there is a global system configuration file, suck it in.
7#
8if [ -r /etc/defaults/periodic.conf ]
9then
10    . /etc/defaults/periodic.conf
11    source_periodic_confs
12fi
13
14case "$weekly_noid_enable" in
15    [Yy][Ee][Ss])
16	echo ""
17	echo "Check for files with an unknown user or group:"
18
19	# Host should not test jailed subtrees as jails have their own
20	# databases of users and groups. Leave them for jailed invocations
21	# of this script.
22
23	exclude=''
24	if [ $(sysctl -n security.jail.jailed) = 0 ]; then
25	    # For jail_conf
26	    . /etc/rc.subr
27	    load_rc_config jail
28
29	    sep=:
30	    OIFS="$IFS"
31	    IFS="$sep"
32	    for param in $(jail -f "$jail_conf" -e "$sep" 2>/dev/null)
33	    do
34		case "$param" in
35		    path=*)
36			_p=${param#path=}
37			if [ -z "$_p" -o "$_p" = / ]; then
38				continue
39			fi
40
41			exclude="$exclude -path $_p -prune -or"
42			;;
43		esac
44	    done
45	    IFS="$OIFS"
46	fi
47
48	rc=$(find -H ${weekly_noid_dirs:-/} \
49	    \( $exclude ! -fstype local -prune -or -name \* \) -and \
50	    \( -nogroup -o -nouser \) -print | sed 's/^/  /' |
51	    tee /dev/stderr | wc -l)
52	[ $rc -gt 1 ] && rc=1
53	;;
54
55    *)  rc=0;;
56esac
57
58exit $rc
59