4.3. Creating Access Control Lists with PAM
Problem
You would like to apply an access control list (ACL) to an existing service that does not explicitly support ACLs (e.g., telnetd, imapd, etc.).
Solution
Use the listfile PAM module.
First, make sure the server in question uses PAM for authentication, and find out which PAM service name it uses. This may be in the server documentation, or it may be clear from examining the server itself and perusing the contents of /etc/pam.d. For example, suppose you’re dealing with the IMAP mail server. First notice that there is a file called /etc/pam.d/imap. Further, the result of:
# locate imapd ... /usr/sbin/imapd
shows that the IMAP server is in /usr/sbin/imapd, and:
# ldd /usr/sbin/imapd libpam.so.0 => /lib/libpam.so.0 (0x40027000) ...
shows that the server is dynamically linked against the PAM library (libpam.so), also suggesting that it uses PAM. In fact, the Red Hat 8.0 IMAP server uses PAM via that service name and control file (“imap”).
Continuing with this example, create an ACL file for the IMAP service, let’s say /etc/imapd.acl, and make sure it is not world-writable:
# chmod o-w /etc/imapd.acl
Edit this file, and place in it the usernames of those accounts authorized to use the IMAP server, one name per line. Then, add the following to /etc/pam.d/imap:
account required /lib/security/pam_listfile.so file=/etc/imapd.acl \ item=user sense=allow onerr=fail
With this configuration, only those users listed in the ACL file will be allowed access ...