#!/bin/sh

# $moftpd: login_script.sh 1251 2005-03-06 22:24:29Z morth $

# An example login script. Consider this in the public domain.
# The echos below show the codes moftpd react to. You can send any of these
# at any time (if the client can handle it).
# You can also send multiline replies, as shown with 230 below.

# The path will be the shell default, so fix it up some.
PATH=/usr/local/bin:/usr/bin:/bin
export PATH

# Only argument is the user logged in.
user=$1

# moftpd reacts to the 331 code and will send us the password.
echo "331 User $user ok. Need password."
# Read it from stdin.
read pass

# Ask for an account as well (to show how to).
echo "332 Password ok. Need account."
# That too comes on stdin.
read acct

if test "$acct" = "foo" -a "$pass" = "bar"; then
  # 230 Is a successful login.
  echo "230-Welcome Mr Foo"
  echo " Have a nice stay."
  echo "230 Login successful."
else
  if test "$acct" = "foo"; then
    # 530 is the failed login reply.
    echo "530 Login failed."
  else
    # 421 boots the client.
    echo "421 Go away."
  fi
fi
