13.1 Each Program Does One Thing

The qmail POP server consists of a set of three cooperating programs (or four if you include the copy of tcpserver that runs the rest of the server):


qmail-popup

Read the username and password from the network connection


checkpassword

Validate the username and password


qmail-pop3d

Handle requests to read and delete mail from the user's Maildir

13.1.1 The Flow of Control

In detail, a POP session proceeds as follows:

  • tcpserver listens for network connections on the POP3 port 110 and spawns qmail-popup.

  • qmail-popup inherits the environment variables and the socket created by tcpserver. (qmail-popup actually has no idea that it is connected to a socket; it merely reads from stdin and writes to stdout knowing this comes in handy when we want to test the POP Server.) qmail-popup performs one very simple function. It understands just enough of the POP protocol to read the username and password sent across the network. Once this data is read, qmail-popup spawns checkpassword, passing it the username and password. qmail-popup has now completed its part in this session.

  • checkpassword checks the username and password against the password file. (It uses getpwnam( ) which usually reads /etc/passwd, but this detail varies considerably from one version of Unix to the next.) If the password is correct, checkpassword extracts information about that user from the password file, does enough of a login process to permit qmail-pop3d to do its work, and now spawns qmail-pop3d.

  • qmail-pop3d handles the rest of the POP3 session with the client. When qmail-pop3d exits, the POP session is completed.

13.1.2 Functional Partitioning

Using four programs to establish each POP session might seem like a lot of needless work. But each program is small and consequently easy to understand, easy to test, and creates very little load on a Unix system.

Clean functional partitioning is not just a theoretical ideal. It has two very practical benefits: flexibility and testability.

13.1.2.1 Flexibility

The clean functional boundary between the different parts makes it very easy to replace any part with a program that meets your specific needs.

checkpassword is the most obvious and popular candidate for replacement, especially by large installations that tend to use a network directory service such as LDAP or a proprietary database such as Oracle for their repository of username and password information. (See POP Servers and POP-before-SMTP later in this chapter.) Given that the core of checkpassword is less than 150 lines of C code, writing a replacement program is not hard. Anything you might want to do on a per-user basis is possible by replacing one small program, checkpassword.

13.1.2.2 Testability

The qmail POP server is very stable and very reliable. When installed correctly it does work and it does work well. Almost invariably, a new installation doesn't work because the installation instructions haven't been followed precisely.

The qmail POP server consists of four components rather than just one, so each component can be tested individually to identify problems. For example, test checkpassword separately from the network, test qmail-pop3d separately from checkpassword, and so on.



qmail
qmail
ISBN: 1565926285
EAN: 2147483647
Year: 2006
Pages: 152

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net