Added new script modified from the FreeBSD release to avoid kernel panics.
[zfs-nexenta/.git] / 100.chksetuid
1 #!/bin/sh -
2
3 # Description: FreeBSD comes with the following script that is run
4 #              weekly as part of its periodic weekly security scripts.
5 #              However, their version of the script does NOT ignore
6 #              .zfs/snapshot directories. On a system with limited
7 #              resources, this can lead to a "kmem_map too small" 
8 #              kernel panic when this script runs. Somehow, ZFS
9 #              kernel memory usage explodes when performing recursive
10 #              find operations on .zfs snapshot locations. This
11 #              is the modified version of that script, which excludes
12 #              searching in .zfs snapshot directories.
13 #
14 # Copyright (c) 2001  The FreeBSD Project
15 # All rights reserved.
16 #
17 # Redistribution and use in source and binary forms, with or without
18 # modification, are permitted provided that the following conditions
19 # are met:
20 # 1. Redistributions of source code must retain the above copyright
21 #    notice, this list of conditions and the following disclaimer.
22 # 2. Redistributions in binary form must reproduce the above copyright
23 #    notice, this list of conditions and the following disclaimer in the
24 #    documentation and/or other materials provided with the distribution.
25 #
26 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
27 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
30 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 # SUCH DAMAGE.
37 #
38 # $FreeBSD: src/etc/periodic/security/100.chksetuid,v 1.8.14.1 2008/01/29 00:22:33 dougb Exp $
39 #
40
41 # If there is a global system configuration file, suck it in.
42 #
43 if [ -r /etc/defaults/periodic.conf ]
44 then
45     . /etc/defaults/periodic.conf
46     source_periodic_confs
47 fi
48
49 . /etc/periodic/security/security.functions
50
51 rc=0
52
53 case "$daily_status_security_chksetuid_enable" in
54     [Yy][Ee][Ss])
55         echo ""
56         echo 'Checking setuid files and devices:'
57         # XXX Note that there is the possibility of overrunning the args to ls
58         MP=`mount -t ufs,zfs | egrep -v " no(suid|exec)" | awk '{ print $3 }' | sort`
59         if [ -n "${MP}" ]
60         then
61             set ${MP}
62             while [ $# -ge 1 ]; do
63                 mount=$1
64                 shift
65                 dotzfs=`echo "$mount" | grep "\.zfs"`
66                 [ -n "$dotzfs" ] && continue;
67                 find $mount -xdev -type f \
68                         \( -perm -u+x -or -perm -g+x -or -perm -o+x \) \
69                         \( -perm -u+s -or -perm -g+s \) -print0
70             done | xargs -0 -n 20 ls -liTd | sed 's/^ *//' | sort -k 11 |
71               check_diff setuid - "${host} setuid diffs:"
72             rc=$?
73         fi;;
74     *)  rc=0;;
75 esac
76
77 exit $rc