#!/bin/sh

# smtpd-setup-chroot	version 1.0
# Copyright John Lines <john@paladin.demon.co.uk> 2004-08-31
# License: Gnu Public License

#
# Sets up the chroot jail for smtpd
#

CHROOTDIR=/var/spool/smtpd

if [ -r /etc/resolv.conf ] ; then
    /bin/cp -f /etc/resolv.conf $CHROOTDIR/etc/resolv.conf
      else
    echo "# No /etc/resolv.conf to copy - set up resolvers here" >/var/spool/smtpd/etc/resolv.conf
 fi

/bin/cp -f /etc/localtime $CHROOTDIR/etc/localtime

# Find the files used by smtpd, and copy them into the chroot under lib

for libfile in $(ldd /usr/sbin/smtpd | cut -d ' ' -f 3); do
  /bin/cp -f -L $libfile $CHROOTDIR/lib
 done

#  We also need some dynamically loaded files

/bin/cp -f -L /lib/libnss_files.so.2 $CHROOTDIR/lib
/bin/cp -f -L /lib/libnss_dns.so.2 $CHROOTDIR/lib

exit 0



