17c478bd9Sstevel@tonic-gate#!/bin/sh --
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*f29fbe76Sjc# Common Development and Distribution License (the "License").
7*f29fbe76Sjc# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate
237c478bd9Sstevel@tonic-gate# Check :include: aliases (in files configured in sendmail.cf) and .forward
247c478bd9Sstevel@tonic-gate# files to make sure the files and their parent directory paths all have
257c478bd9Sstevel@tonic-gate# proper permissions.  And check the master alias file(s) too.
267c478bd9Sstevel@tonic-gate#
27*f29fbe76Sjc# See http://www.sendmail.org/vendor/sun/migration.html#Security for details.
287c478bd9Sstevel@tonic-gate#
29*f29fbe76Sjc# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
30*f29fbe76Sjc# Use is subject to license terms.
317c478bd9Sstevel@tonic-gate#
327c478bd9Sstevel@tonic-gate# %W% (Sun) %G%
337c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gatePATH=/bin
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate# Check the group- and world-writable bits on the given file.
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gateanalyze() {
407c478bd9Sstevel@tonic-gate	case "`ls -Lldn $1`" in
417c478bd9Sstevel@tonic-gate		?????w??w?*)
427c478bd9Sstevel@tonic-gate			echo $2: $1 is group and world writable
437c478bd9Sstevel@tonic-gate			bogus_dirs=true ;;
447c478bd9Sstevel@tonic-gate		????????w?*)
457c478bd9Sstevel@tonic-gate			echo $2: $1 is world writable
467c478bd9Sstevel@tonic-gate			bogus_dirs=true ;;
477c478bd9Sstevel@tonic-gate		?????w????*)
487c478bd9Sstevel@tonic-gate			echo $2: $1 is group writable
497c478bd9Sstevel@tonic-gate			bogus_dirs=true ;;
507c478bd9Sstevel@tonic-gate	esac
517c478bd9Sstevel@tonic-gate}
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate# Break down the given file name into its components, and call analyze with
547c478bd9Sstevel@tonic-gate# each of them.  E.g., an argument of /usr/local/aliases/foo.list would call
557c478bd9Sstevel@tonic-gate# analyze in turn with arguments:
567c478bd9Sstevel@tonic-gate# * /usr/local/aliases/foo.list
577c478bd9Sstevel@tonic-gate# * /usr/local/aliases
587c478bd9Sstevel@tonic-gate# * /usr/local
597c478bd9Sstevel@tonic-gate# * /usr
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gatebreak_down() {
627c478bd9Sstevel@tonic-gate	for j in `echo $1 | \
637c478bd9Sstevel@tonic-gate		awk '{
647c478bd9Sstevel@tonic-gate			n = split($0, parts, "/");
657c478bd9Sstevel@tonic-gate			for (i = n; i >= 2; i--){
667c478bd9Sstevel@tonic-gate				string = "";
677c478bd9Sstevel@tonic-gate				for (j = 2; j <= i; j++){
687c478bd9Sstevel@tonic-gate					string = sprintf("%s/%s", string, parts[j]);
697c478bd9Sstevel@tonic-gate				}
707c478bd9Sstevel@tonic-gate				print string
717c478bd9Sstevel@tonic-gate			}
727c478bd9Sstevel@tonic-gate		}'` "/"
737c478bd9Sstevel@tonic-gate	do
747c478bd9Sstevel@tonic-gate		analyze $j $1
757c478bd9Sstevel@tonic-gate	done
767c478bd9Sstevel@tonic-gate}
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gateconfig=/etc/mail/sendmail.cf
797c478bd9Sstevel@tonic-gatebogus_dirs=false
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gateafl1=`grep "^OA" $config | sed 's/^OA//' | sed 's/,/ /g' | sed 's/.*://'`
827c478bd9Sstevel@tonic-gateafl2=`grep "^O AliasFile=" $config | sed 's/^O AliasFile=//' | \
837c478bd9Sstevel@tonic-gate    sed 's/,/ /g' | sed 's/.*://'`
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate# These should be OK themselves, but other packages may have screwed up the
867c478bd9Sstevel@tonic-gate# permissions on /etc or /etc/mail .  And best to check in case non-standard
877c478bd9Sstevel@tonic-gate# alias paths are used.
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gatebreak_down $afl1 $afl2
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate# Find all valid :include: files used in alias files configured in sendmail.cf
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gatefor i in `sed 's/^[#].*$//' $afl1 $afl2 | \
947c478bd9Sstevel@tonic-gate	grep :include: | \
957c478bd9Sstevel@tonic-gate	sed 's/.*:include://' | \
967c478bd9Sstevel@tonic-gate	sed 's/,.*$//'`
977c478bd9Sstevel@tonic-gatedo
987c478bd9Sstevel@tonic-gate	break_down $i
997c478bd9Sstevel@tonic-gatedone
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate# Check .forward files as well.  If the argument "ALL" is given, do it for
1027c478bd9Sstevel@tonic-gate# everyone.  If no argument to the script is given, just do it for the current
1037c478bd9Sstevel@tonic-gate# user.  O/w, do it for all arguments.
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gateif [ $# -eq 0 ] ; then
106*f29fbe76Sjc	arg=`id | nawk -F'(' '{n = split($2,id,")"); print id[1]}'`
1077c478bd9Sstevel@tonic-gateelif [ $1 = "ALL" ] ; then
1087c478bd9Sstevel@tonic-gate	arg=""
1097c478bd9Sstevel@tonic-gateelse
1107c478bd9Sstevel@tonic-gate	arg="$*"
1117c478bd9Sstevel@tonic-gatefi
1127c478bd9Sstevel@tonic-gate
113*f29fbe76Sjcfor i in `getent passwd $arg | nawk -F: '{print $6}'`
1147c478bd9Sstevel@tonic-gatedo
1157c478bd9Sstevel@tonic-gate	if [ -f $i/.forward ] ; then
1167c478bd9Sstevel@tonic-gate		break_down $i/.forward
1177c478bd9Sstevel@tonic-gate	fi
1187c478bd9Sstevel@tonic-gatedone
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate$bogus_dirs || echo "No unsafe directories found."
121