This HowTo covers Debian Lenny with ispCP 1.0.2. If read carefully it should be portable to any other PAM enabled distribution.

I decided to use libpam-mysql for user authentication and libnss-mysql for session handling and user mapping. Both packages are mature. OpenSSH is able to ChrootDirectory by directive, so this is my first choice.

To have the problems noted before: As it's obviously useful to chroot() into /var/www/virtual/DOMAIN with an enabled FTP user for this directory, OpenSSH refuses to chroot() because /var/www/virtual and /var/www/virtual/DOMAIN are not owned by uid=0 (root) and not umasked 022. It's not possible to change the ownership and umask because we do need access for www-data. I found no way to trick the sshd in a configurable manner, so I patched the OpenSSH package as shown below. If there are better solutions known, any hints are very welcome.

EDIT: As discussed here: http://www.isp-control.net/forum ... 62632.html#pid62632, it is not neccessary to patch OpenSSH. If you change the ownership and umask of the discussed directories, you can skip this step and start with “configuring OpenSSH”

patching OpenSSH
Quick and dirty without and .patch files by now. Warning: As well as this patch isn't done on some sophisticated authentication voodoo code, it affects the whole openssh-server package. You WILL loose the possibility to update openssh-server at ease. If updates and security fixes are available, you'll need to repeat this step.

apt-get install dpkg-dev
cd /usr/local/src
apt-get source openssh-server
apt-get build-dep openssh-server
cd openssh-5.1p1/ # change this to the current version
vi session.c # or use any other editor of your choice
# navigate to the line containing "bad ownership or modes for chroot "
# change the word "fatal" to "logit"
# the line should read like logit("bad ownershiop or modes for chroot "
# save and exit your editor
dpkg-buildpackage
cd ..
dpkg -i ./openssh-server*deb # this replaces your current sshd!
/etc/init.d/sshd stop && /etc/init.d/sshd start

configuring OpenSSH
The configuration in /etc/ssh/sshd_config needs to be modified:

StrictModes no
PasswordAuthentication yes # this is also the default

at the end of the file

Match does not know how to handle negations...

ChrootDirectory %h

Match user root
ChrootDirectory /

Installing and configuring libpam-mysql

apt-get install libpam-mysql
cp /etc/pam.d/sshd /etc/pam.d/sshd.orig # just to have a backup

Modify your /etc/pam.d/sshd to read as following:

Replace VFTP_PASSWORD by your actual vftp mysql password. The current connection settings can be verified by peeking into /etc/proftpd/proftpd.conf

PAM configuration for the Secure Shell service

Read environment variables from /etc/environment and

/etc/security/pam_env.conf.

auth required pam_env.so # [1]

In Debian 4.0 (etch), locale-related environment variables were moved to

/etc/default/locale, so read that as well.

auth required pam_env.so envfile=/etc/default/locale

auth optional pam_mysql.so host=/var/run/mysqld/mysqld.sock user=vftp passwd=VFTP_PASSWORD db=ispcp table=ftp_users usercolumn=userid passwdcolumn=passwd crypt=1
account optional pam_mysql.so host=/var/run/mysqld/mysqld.sock user=vftp passwd=VFTP_PASSWORD db=ispcp table=ftp_users usercolumn=userid passwdcolumn=passwd crypt=1

password sufficient pam_mysql.so host=/var/run/mysqld/mysqld.sock user=vftp passwd=VFTP_PASSWORD db=ispcp table=ftp_users usercolumn=userid passwdcolumn=passwd crypt=1

session optional pam_mysql.so host=/var/run/mysqld/mysqld.sock user=vftp passwd=VFTP_PASSWORD db=ispcp table=ftp_users usercolumn=userid passwdcolumn=passwd crypt=1

Standard Un*x authentication.

#@include common-auth # this commented out, as common-auth REQUIRES pam_unix.so
auth sufficient pam_unix.so nullok_secure

Disallow non-root logins when /etc/nologin exists.

account required pam_nologin.so

Uncomment and edit /etc/security/access.conf if you need to set complex

access limits that are hard to express in sshd_config.

account required pam_access.so

Standard Un*x authorization.

@include common-account

Standard Un*x session setup and teardown.

@include common-session

Print the message of the day upon successful login.

session optional pam_motd.so # [1]

Print the status of the user's mailbox upon successful login.

session optional pam_mail.so standard noenv # [1]

Set up user limits from /etc/security/limits.conf.

session required pam_limits.so

Set up SELinux capabilities (need modified pam)

session required pam_selinux.so multiple

Standard Un*x password updating.

@include common-password

If you're managing this server only via SSH, there's a good reason to check now, if you're able to login as root with an additional session as before. If not, you should NOW move your original /etc/pam.d/sshd.orig to /etc/pam.d/sshd back until you found the bug or typo.

Installing and configuring libnss-mysql

apt-get install libnss-mysql

The configuration files /etc/nss-mysql.conf needs editing. I've stripped off the comments. It should read like below (remind to replace VFTP_PASSWORD to match your configured one)

conf.version = 2;
users.host = unix:/var/run/mysqld/mysqld.sock;
users.database = ispcp;
users.db_user = vftp;
users.db_password = VFTP_PASSWORD;
users.table = ftp_users;
users.user_column = ftp_users.userid;
users.password_column = ftp_users.passwd;
users.userid_column = ftp_users.userid;
users.uid_column = ftp_users.uid;
users.gid_column = ftp_users.gid;
users.realname_column = "ispCP User";
users.homedir_column = ftp_users.homedir;
users.shell_column = ftp_users.shell;