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