ftpconfig.sh revision 7c478bd95313f5f23a4c958a745db2134aa03244
#
# ident "%Z%%M% %I% %E% SMI"
#
# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# This script sets up anonymous FTP on the current host.
#
# Usage:
# ftpconfig [ftpdir]
# ftpconfig -d ftpdir
#
# ftpconfig without any arguments updates the files required by anonymous FTP
# in an existing ftp users home directory.
#
# If ftpdir (which must be an absolute pathname) is supplied, ftpconfig
# creates an ftp user account with a home directory of ftpdir, or updates
# an existing ftp user account to have a home directory of ftpdir.
#
# If ftpdir already exists, the files it contains which are required by
# anonymous FTP are updated, otherwise ftpdir is created containing the files
# required by anonymous FTP.
#
# The -d (directory only) option just creates a new or updates an existing
# ftpdir without creating or updating the ftp user account. This is useful
# when creating guest FTP user accounts.
#
# 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 under $home_dir with mode $2 and ownership $3.
make_dir()
{
# Make a special case of creating $home_dir itself
if [ -z "$1" ]
then
else
fi
then
fi
}
# Copy file $1 to under $home_dir with mode $2 and ownership $3.
{
if [ -f "$1" ]
then
fi
}
add_user()
{
then
# No existing ftp account.
then
exit 1
fi
# Create a new ftp account.
comment="Anonymous FTP"
else
# ftp account already exists.
then
then
exit 2
fi
else
# Update an existing ftp account.
then
fi
fi
fi
}
{
# Produce a list of the PAM session management modules.
then
awk '($1 == "ftp" || $1 == "other") && $2 == "session" {
print $4
fi
}
{
# Produce a list of the commands specified in the conversions file.
if [ -f /etc/ftpd/ftpconversions ]
then
fi
}
{
# Produce a list of the required dynamic libraries.
do
done | sort -u
}
{
then
exit 1
fi
then
then
exit 2
else
fi
fi
}
{
# Preserve an existing etc directory.
# Create a stripped down password file.
awk -F: '$1 ~ /^root$|^bin$|^sys$|^ftpadm$|^ftp$/ { print $1":x:"$3":"$4":::" }' </etc/passwd >"$home_dir/etc/passwd"
# Create a stripped down group file.
awk -F: '$1 ~ /^root$|^other$|^bin$|^sys$|^ftpadm$/ { print $1"::"$3":" }' </etc/group >"$home_dir/etc/group"
then
fi
# Copy in files used for hostname resolution
copy_file /etc/resolv.conf 444 root:sys
}
{
# Preserve an existing usr directory.
then
fi
then
fi
# Copy required dynamic libraries and PAM session management modules.
do
then
then
fi
fi
done
# Copy required commands.
do
then
then
fi
fi
done
# Copy timezone files.
then
fi
do
then
fi
done
}
{
# Preserve an existing dev directory.
# Copy devices.
do
done
/dev/conslog
/dev/null
/dev/udp
/dev/udp6
/dev/zero
EOF
if [ $? -ne 0 ]
then
exit 2
fi
}
{
# Preserve an existing pub directory.
}
{
}
# Execution starts here.
IFS="
"
while getopts d arg
do
d) directory_only=1;;
\?) usage;;
esac
done
# Check arguments.
home_dir="$1"
if [ -n "$directory_only" -a -z "$home_dir" ]
then
fi
if [ -n "$home_dir" ]
then
if [ $? -ne 0 ]
then
fi
fi
# Ignore certain signals.
trap '' 1 2 3 15
umask 022
[ -z "$directory_only" ] && add_user
exit 0