ftpaddhost.sh revision 7c478bd95313f5f23a4c958a745db2134aa03244
#
# ident "%Z%%M% %I% %E% SMI"
#
# Copyright (c) 1997-2001 by Sun Microsystems, Inc.
# All rights reserved.
#
#
# This script sets up a virtual FTP host.
#
# Usage:
# ftpaddhost -c|-l [-b] [ -x xferlog ] hostname root_dir
#
# ftpaddhost configures virtual host hostname under directory root_dir.
# An IP address can be used for hostname.
#
# The -c (complete) option configures complete virtual hosting, which allows
# each virtual host to have its own version of the ftpaccess, ftpconversions,
# ftpgroups, ftphosts and ftpusers files. The master version of each of these
# exists it is appended to the virtual ftpusers file. If a virtual host lacks
# its own version of a configuration file, the master version is used.
#
# The -l (limited) option configures limited virtual hosting, which only
# allows a small number of parameters to be configured differently for a
# virtual host (see the virtual keyword on the ftpaccess(4) manual page).
#
# When the -b (banner) option is supplied, ftpaddhost creates a banner for
# the virtual host, useful to see that the virtual host is working.
#
# When the -x xferlog option is supplied, ftpaddhost creates a logfile entry
# which causes the transfer logs for the virtual host to be written to the
# specified file.
#
# Exit codes: 0 - success
# 1 - usage
# 2 - command failure
#
usage()
{
exit 1
}
{
# Verify caller has a real user ID of 0.
set `id`
if [ "$1" != "uid=0(root)" ]
then
exit 1
fi
}
# Make directory $1 with mode $2 and ownership $3.
make_dir()
{
if [ ! -d "$1" ]
then
fi
chmod "$2" "$1"
chown "$3" "$1"
}
{
# Update the virtual host configuration file.
if [ -f $vhconfig ]
then
# Remove any existing entries for the virtual host.
fi
# Make copies of the master configuration files.
do
then
fi
done
then
target="/etc/ftpd/virtual-ftpd/$hostname/ftpusers"
fi
vhftpaccess="/etc/ftpd/virtual-ftpd/$hostname/ftpaccess"
rm -f "$vhftpaccess"
# Remove any existing root or logfile entries.
sed "/^[ ]*root[ ]/d
# Add the virtual host root.
# Add a banner to show the virtual host configuration worked.
then
# Add a banner entry if there isn't already one.
if [ $? -eq 0 ]
then
printf "$fmt\n" "$vhftpaccess"
else
then
else
fi
fi
fi
# Add the transfer logfile.
then
fi
chmod 644 "$vhftpaccess"
}
{
# Check complete virtual hosting is not configured for the host.
if [ $? -eq 0 ]
then
exit 1
fi
# Update the ftpaccess file.
# Remove any existing entries for the virtual host.
mv -f $ftpaccess.tmp.$$ $ftpaccess || exit 2
# Add a limited virtual hosting entry for the virtual host.
# Add a banner to show the virtual host configuration worked.
then
then
else
fi
fi
# Add the transfer logfile.
then
fi
chmod 644 $ftpaccess
}
# Execution starts here.
IFS="
"
do
b) banner=1;;
c) complete=1;;
l) limited=1;;
\?) usage;;
esac
done
# Check arguments.
hostname="$1"
vhroot="$2"
if [ $? -eq 0 ]
then
fi
if [ $? -ne 0 ]
then
fi
if [ -n "$logfile" ]
then
if [ $? -ne 0 ]
then
fi
fi
if [ ! -f $ftpaccess ]
then
exit 2
fi
if [ $? -ne 0 ]
then
fi
# Ignore certain signals.
trap '' 1 2 3 15
umask 022
if [ -n "$complete" ]
then
else
fi
if [ $? -ne 0 ]
then
exit 2
fi
exit 0