[Raw Msg Headers][Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Remote .forward lookups



> Our site has two main servers: one strictly for mail and one the users log
> into.  Their home directories are housed on their home machine.  Is there
> a way (other than NFS mounting the partitions) to query the users machine
> for their .forward file information?  My guess is that someone has run
> into this problem before and I wouldn't want to "re-invent the wheel". 
> 
> The reason why NFS mounting is not a viable alternative is not easily
> explained and not particularly relevant to the problem, anyway. 
> 
> If it is relevant, we are running SunOS 4.1.4 and Rayan's zmailer.
> 
> Thanks for your time and any hints or pointers.

We have a similar setup here.
We don't want to mount the homedirs on our mail server, because we want
mail to continue working if the main file server goes down.
All our user directories are under /u:

skule% ls -lg /u
total 110
drwxr-xr-x  765 sys        10240 Jun 18 14:50 9T5/
drwxr-xr-x  854 sys        10752 Jun 20 13:24 9T6/
drwxr-xr-x  792 sys        10240 Jun 20 13:19 9T7/
drwxr-xr-x  761 sys         9728 Jun 20 13:17 9T8/
drwxr-xr-x    2 sys          512 May 31 05:00 9T9/
drwxr-xr-x   17 ecf          512 Jun 26 16:27 ecf/
drwxr-xr-x  247 sys         3584 Jul  7 13:41 grad/
drwxr-xr-x   70 sys         1024 Jul  5 17:20 guests/
drwxr-xr-x  187 sys         2560 Jun 21 13:14 prof/
drwxr-xr-x  568 sys         7168 Jun 20 13:15 research/

On our mailserver, /u looks like this:

cannon 88# ls -lg /u
total 9
lrwxr-xr-x    1 sys           20 Feb 15 15:30 9T5 -> /spool/fakehomes/9T5/
lrwxr-xr-x    1 sys           20 Feb 15 15:30 9T6 -> /spool/fakehomes/9T6/
lrwxr-xr-x    1 sys           20 Feb 15 15:30 9T7 -> /spool/fakehomes/9T7/
lrwxr-xr-x    1 sys           20 Feb 15 15:30 9T8 -> /spool/fakehomes/9T8/
lrwxr-xr-x    1 sys           15 Feb 15 15:30 ecf -> /usr/host/u/ecf/
lrwxr-xr-x    1 sys           21 Feb 15 15:30 grad -> /spool/fakehomes/grad/
lrwxr-xr-x    1 sys           23 Feb 15 15:30 guests -> /spool/fakehomes/guests/
lrwxr-xr-x    1 sys           21 Feb 15 15:30 prof -> /spool/fakehomes/prof/
lrwxr-xr-x    1 sys           25 Feb 15 15:30 research -> /spool/fakehomes/research/

Basically, only staff (in /u/ecf) can login to the mail server.
/spool/fakehomes is exported from the mail server, and mounted on our
other systems. From the root crontab, we run the following script
(which will need to be edited to suit local taste) to copy each
user's .forward file from their real homedir to their fake
homedir on the mail server. Note that the script uses gnu-test
to perform an age comparison on the .forward files.

#!/bin/sh
#
# forwards - create a dummy .forward file in /spool/fakehomes for each user
#
# use awk to step through /etc/passwd, reject home dirs that aren't in /u/

PATH=/local/etc:/local/bin:/share/bin:/usr/sbin:/usr/ucb:/bin:/etc:/usr/etc
export PATH
umask 022

tmp=/tmp/forward
trap 'rm -f $tmp' 0

for homedir in `awk -F: '{print $6}' /etc/passwd |grep /u/ |grep -v /u/ecf`; do
	u=`basename $homedir`		# the login name
	f=$homedir/.forward		# path to each user's .forward file
	fake=`echo $homedir | sed s:u:spool/fakehomes:`		# fake home
	#echo homedir for $u is $homedir, fakehome is $fake

	# check if they have a .forward file
	if [ -f $f ]; then
		# skip links, directories, named pipes, and zero-byte files
		if [ -l $f -o -d $f -o -p $f -o ! -s $f ]; then
			echo skipping bad .forward:
			ls -l $f
			continue	# skip it
		fi

		grep '|' $f > $tmp
		if [ -s $tmp ]; then
			echo mail to program disallowed, pipe character in $f:
			cat $f
			( echo your .forward file is being ignored;
			  echo mail to programs disallowed;
			  echo remove it or fix it to stop daily warnings) \
			  | /usr/ucb/mail -s '.forward problem' $u
			continue	# skip it
		fi

		if [ ! -d $fake ]; then
			# create the fake home directory, if it doesn't exist
			mkdir $fake
		fi

		if [ -f $fake/.forward ]; then
			if /local/bin/gnu-test $f -ot $fake/.forward
			then
				continue	# skip it, it hasn't changed
			else
				echo $f has changed, will update $fake/.forward
			fi
		fi

		cp $f $fake
		chown $u $fake/.forward
	else
		if [ ! -d $homedir ]; then
			# maybe the whole disk is offline, so don't touch it
			echo warning, homedir does not exist: $homedir
			continue	# skip it
		fi

		if [ -d $fake ]; then
			echo $u removed .forward file, removing $fake
			rm -rf $fake
		fi
	fi
done