#!/bin/bash
SFTP_JAIL_DIR='/var/opt/nortel/base/jail'

/usr/bin/perl -I/opt/nortel/base/lib -e 'use base_accounts; exit(is_ftp_account($ARGV[0]));' $USER;

#do not allow FTP users login via sftp or ssh
if [ "$?" == "1" ]; then
   exit
fi

sftp=0

for i in $@; do
   #Determine if shell is to be invoked for SFTP server
   if [ "$i" == "/usr/libexec/openssh/sftp-server" ]; then
      sftp=1
   fi
done

if [ "$sftp" == "1" ]; then

   #spawn no-restricted shell with SFTP server. Put user in the jail
   /usr/bin/sudo /opt/nortel/base/bin/sudo_nortel sftp_login $USER
else
   #If it is not case of SFTP shell - spawn restricted shell
   exec /bin/bash -r -l
fi

