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