Subject: Re: guestgroup

From: [email-masked] (Alan J Rosenthal)
Date: Wed, 29 Oct 1997 11:29:20 -0500

>Do I have to staticaly link ls to all of their home dirs?

Yes, but you can make these copies of ls the same if they're on the same
disk partition with hard links ("ln").  Symlinks won't work, because under a
chroot, symlink following happens with respect to the new root directory.
But hard links work fine.  But hard links are only available within the same
filesystem.

---

From: Philip Hallstrom <[email-masked]>
Date: Wed, 29 Oct 1997 09:21:25 -0800 (PST)

Hi all,
	I'm sure many people have already done this, and there are
probably scripts out there already, but it seems this topic pops up over
and over again so I figured I'd post mine...

Basically you'd call it like:

% makeftpchroot -v 2 /path_to_ftp_root/foo/bar/ftp_chroot

The -v is verbosity... 1 will just tell you a bit what's going on, 2 will
spit out a lot of junk you probably don't want to see :)

/path_to_ftp_root is wherever your ftp root directory is.
/foo/bar/ftp_chroot is the directory you'd like to have chrooted. (Note
this script won't create any users... I've got another one if you're
interested in that, but it's a mess :)

This works on Solaris 2.5.1 (Sparc).  It assumes you've set up an
anonymous ftp site already...  Anyway no promises, no guarantees...

-----------------------------------------------------------------------
#!/bin/sh

USAGE="
% $0 [-v n] directory
"

###

srcDir="/sierra/ftp" #change this to your anonymous ftp root.

mkdir=/usr/bin/mkdir
ln=/usr/bin/ln
find=/usr/bin/find
ls=/usr/bin/ls
chown=/usr/bin/chown
chmod=/usr/bin/chmod
mknod=/usr/sbin/mknod
echon="/usr/ucb/echo -n"

VERBOSE=0

###

while getopts v: opt
do
	case $opt in
		v)	VERBOSE=$OPTARG
				;;
		\?) echo $USAGE
				exit
				;;
	esac
done
shift `expr $OPTIND - 1`

dir=$1

subDir=`cd $dir;pwd | grep "^$srcDir"`
if [ -z "$subDir" ]; then
	echo "ERROR: FTP chroot directory must be underneath $srcDir."
	echo $USAGE
	exit
fi

if [ ! -d "$dir" ]; then
	$echon "Directory '$dir' does not exist.  Create it? (y/n) [n]: "
	read createDir
	if [ "$createDir" = "y" -o "$createDir" = "Y" ]; then
		mkdir $dir
	else
		exit
	fi
fi

cd $dir

#
# Make all the directories.
#
if [ $VERBOSE -ge 1 ]; then
	$echon "Making directories..."
fi
	
for dir in `cd $srcDir ; $find dev etc usr -type d -print`
do
	if [ $VERBOSE -ge 2 ]; then
		$echon " $dir"
	fi

	$mkdir $dir
	$chown -h root:other $dir
	$chmod 0555 $dir
done

if [ $VERBOSE -ge 1 ]; then
	echo ""
fi

#
# Make all the hard links.
#
if [ $VERBOSE -ge 1 ]; then
	$echon "Making hard links..."
fi

for file in `cd $srcDir ; $find dev etc usr -type f -print`
do
	if [ $VERBOSE -ge 2 ]; then
		$echon " $file"
	fi

	$ln $srcDir/$file $file
	$chown -h root:other $file
	$chmod 0555 $file
done

if [ $VERBOSE -ge 1 ]; then
	echo ""
fi

#
# Make all the sym links.
#
if [ $VERBOSE -ge 1 ]; then
	$echon "Making sym links..."
fi

for sl in `cd $srcDir ; $find dev etc usr -type l -print`
do
	if [ $VERBOSE -ge 2 ]; then
		$echon " $sl"
	fi

	link=`$ls -l $srcDir/$sl | sed 's/^.* -> //'`
	$ln -s $link $sl
done

#Symlink bin...
$ln -s usr/bin bin
	if [ $VERBOSE -ge 2 ]; then
	$echon " bin"
fi

if [ $VERBOSE -ge 1 ]; then
	echo ""
fi

#
# Make all the character devices.
#
if [ $VERBOSE -ge 1 ]; then
	$echon "Making character devices..."
fi

$mknod dev/null c 13 2
$mknod dev/tcp c 11 42
$mknod dev/ticotsord c 105 1
$mknod dev/udp c 11 41
$mknod dev/zero c 13 12

for cdev in "null" "tcp" "ticotsord" "udp" "zero"
do
	if [ $VERBOSE -ge 2 ]; then
		$echon " dev/$cdev"
	fi

	$chown -h root:other dev/$cdev
	$chmod 0666 dev/$cdev
done

if [ $VERBOSE -ge 1 ]; then
	echo ""
	echo "Success!"
	echo ""
fi
#--------------------------------------------------------------------