Using tcpd_wrappers with pure-ftpd – September 19, 2007
My external "authentication" script is the following:
#!/bin/sh
checkedIP=$(echo $AUTHD_REMOTE_IP | sed -ne "s~^\([0-9]\{1,3\}\)\.\([0-9]\{1,3\}\)\.\([0-9]\{1,3\}\)\.\([0-9]\{1,3\}\)$~\1.\2.\3.\4~p")
if test "x$checkedIP" = "x"; then
checkedIP="Unknown"
fi
if test "$checkedIP" = "Unknown"; then
# unknown will be allowed for now. Probably should output the ip to see when this happens
echo 'auth_ok:0'
else
# note, this is checking for all services, rather than just a particular one
grep $checkedIP /etc/hosts.deny
if [ "$?" = 0 ]; then
echo 'auth_ok:-1'
else
echo 'auth_ok:0'
fi
fi
echo 'end'
Then you need to start the authd:
pure-authd -B -s /var/run/ftpd.sock -r /etc/pure-ftpd/denyhosts
Then make a file called /etc/pure-ftpd/conf/ExtAuth (I use pure-ftpd-wrapper, since I am on Debian) with the following line:
/var/run/ftpd.sock
And then make a symlink named /etc/pure-ftpd/auth/20extauth that points to /etc/pure-ftpd/conf/ExtAuth
That's it! As you might guess based on the name of the script, I will eventually get this to work automatically with the denyhosts project, which is an excellent program for ssh, and I want to extend it to pure-ftpd as well; just need to get the regular expressions correct.
