#! /bin/csh -f

# make-anonftp  -- create an anonymous ftp account on this host.  
#
# Author:  Tony Facca (tfacca@lerc.nasa.gov)
# Date:    September 30, 1991
#
# Maintenance:  March 01, 1994
#               April 13, 1994  IRIX 5.2
#               April 15, 1994  Miscellaneous cleanup

set FTPDIR=/usr/people/ftp    # Location of anonymous ftp directory
set FTPUID=800            # UID of ftp
set FTPVER=1.0            # Oh no, a version number

if (! -o /bin/su) then
   echo "You must be superuser to run this script"
   exit 1
endif

# Create an anonymous ftp password entry if one does not already exist.

if ( `egrep -c ^ftp: /etc/passwd`) then
   echo " "
   echo "It appears that an anonymous ftp account has already been created."
   echo "If you would like to create a new one, remove the following"
   echo "line from your /etc/passwd file and run this script again:"
   echo " "
   egrep ^ftp: /etc/passwd
   echo " "
   exit 1
else     
   echo "ftp:*:${FTPUID}:${FTPUID}:Anonymous ftp:${FTPDIR}:/dev/null" >> /etc/passwd
endif

# Make a home directory for the anonymous ftp account
mkdir -p ${FTPDIR}

# Set permissions for the ftp account
chmod 555 ${FTPDIR}
chown 0.0 ${FTPDIR}

# Create chroot file system
mkdir -p ${FTPDIR}/{anyone,bin,dev,etc,lib,pub}

# Set permissions for these directories
chown 0.0            ${FTPDIR}/{bin,dev,etc,lib,pub}
chmod 555            ${FTPDIR}/{bin,dev,etc,lib,pub}

chown ${FTPUID}.${FTPUID}    ${FTPDIR}/anyone
chmod 1777            ${FTPDIR}/anyone    # Set sticky bit

# The ls command needs these files --
cp /lib/rld /lib/libc.so.1 ${FTPDIR}/lib
chmod 555 ${FTPDIR}/lib/rld ${FTPDIR}/lib/libc.so.1

# rld requires /dev/zero
/etc/mknod ${FTPDIR}/dev/zero c 37 0 >& /dev/null
chmod 444  ${FTPDIR}/dev/zero

# Get the ls command into the ftp account 
cp /bin/ls ${FTPDIR}/bin
chown 0.0  ${FTPDIR}/bin/ls
chmod 111  ${FTPDIR}/bin/ls

cat << EOF > ${FTPDIR}/etc/group
root:*:0:root
sys:*:0:root,bin,sys
bin:*:2:root,bin
ftp:*:${FTPUID}:ftp
EOF
chmod 444 ${FTPDIR}/etc/group

cat << EOF > ${FTPDIR}/etc/passwd
root:*:0:0:Superuser::
bin:*:2:2:::
sys:*:4:0:::
ftp:*:${FTPUID}:${FTPUID}:Anonymous FTP::
EOF
chmod 444 ${FTPDIR}/etc/passwd

cat << EOF
   Okay.  A secure anonymous ftp account has been created.  If you would
   would like to have a message printed everytime someone logs in
   create a README file in ${FTPDIR}
EOF
