Before delving too deeply into further configuration and tailoring of qmail, it is important to understand the basic structure of qmail. Qmail is often referred to as merely a mail server software package. While this may be accurate in one sense, it is more accurate to think of qmail as a mail delivery architecture whose architect has thoughtfully provided a basic implementation of all the components of that architecture. 在深入探索qmail的配置和調節之前,了解一些qmail的基礎架構是重要的。Qmail經常被僅僅歸類為一個郵件伺服器軟體包。這可能只在某一點上是正確的,將qmail考慮為一個郵件分發體系會更加準確,這個體系結構的構建者為這個體系的所有組件深入的提供了一些基礎接口。
Qmail is very modular—it consists of a series of simple programs communicating via specific and limited interfaces. Each simple program has a specific and limited task to perform. This architecture allows each component program to be easily replaced or new programs to be inserted between the basic components. Qmail是非常模組化的——它包含了一系列通過特定且受限的接口來互相溝通的簡單程式。每個簡單的程式都有一個特定且受限的任務需要完成。這個體系結構允許每個組件都被容易的替代或讓新的程式插入到基礎組件之中。
Additionally, this architecture limits the security impact of any one of the components. Each program is further separated from the others, whenever possible, by giving each program a different UNIX user and specific permissions so that it can"t affect anything it is not supposed to. Because the communication interfaces are limited, it is significantly more difficult to attack the software and achieve much—attacking a component that does not have enough privileges to do anything other than what it is supposed to do is much less useful for an attacker. 另外,這個體系限制了所有組件的安全影響。任何一個程式都與另外的程式隔離開來,在任何可能的情況,給每個程式一個不同的UNIX用戶和特定許可權來確保它不會做任何它不應該做的事。因為通訊接口被限制了,因此顯然更難去攻擊軟體或更多別的——攻擊一個沒有足夠許可權來做任何它不應該做的事的組件對攻擊者來說是很沒有用處的。
The simplest example is receiving email from the network. The trail of programs in basic qmail is as follows: tcpserver to qmail-smtpd to qmail-queue. The tcpserver program has two tasks: open up a port to listen to the network, and run qmail-smtpd as the appropriate user for every connection. Because listening to low ports (such as the SMTP port, 25) requires root permissions, tcpserver generally runs as root. However, because tcpserver doesn"t attempt to understand the communication, it is very difficult to attack. The qmail-smtpd program has only two tasks as well: speaking the SMTP protocol sufficiently to receive email messages, and sending these email messages to qmail-queue. As such, qmail-smtpd need not do anything with the on-disk queue or the network. This allows qmail-smtpd to be run as a user with very limited permissions, and also allows qmail-smtpd to be a much simpler, and easier to verify and debug, program than it would be otherwise, even though it has to interact directly with user (or attacker) input. The qmail-queue program has only one task—to write messages to the on-disk queue prepended with a Received header. It need not talk to the network, or understand the contents of the messages it writes to disk, making the program simple and easy to verify and thus hard for an attacker to break. 最簡單的例子是從網路上收郵件。一個基礎的qmail實驗如下:tcpserver到qmail-smtpd到qmail-queue。tcpserver程式有兩個任務:打開一個連線埠來監聽網路,並對每個連線以正確的用戶來啟動qmail-smtpd。因為監聽低連線埠(如SMTP的連線埠:25)要求root許可權,所以tcpserver通常以root用戶運行。然而,因為tcpserver並不試圖理解通訊,所以很難被攻擊。qmail-smtpd程式也只有兩個任務需要運行:充分使用SMTP協定來接收訊息,並傳送這些郵件訊息到qmail-queue。就這個而言,qmail-smtpd本身並不需要對磁碟上的佇列或網路做任何事情。這允許qmail-smtpd能被一個許可權非常受限的用戶來運行,而且允許qmail-smtpd成為一個非常簡單,而且容易被驗證和排錯的程式,即使它需要與用戶(或攻擊者)輸入直接溝通。qmail-queue程式則只有一個任務——將訊息寫到已經有了接收頭的磁碟佇列上。它無需和網路溝通,或者了解它寫到磁碟上的訊息的內容,使得程式簡單並容易被驗證,從而使得攻擊者更難破壞它。Note that this architecture can be easily extended. The tcpserver program can execute any program, which can in turn execute qmail-smtpd as necessary. This might be useful, for example, to make decisions about whether to permit a connection to reach qmail-smtpd or to set and unset environment variables before qmail-smtpd is executed. It could even be used to sanitize data before it gets to qmail-smtpd. Similarly, while qmail-smtpd normally executes qmail-queue, it may invoke any program. This program can then execute qmail-queue as necessary, which might be useful, for example, to filter out email messages that contain viruses. 要注意的是這個體系結構很容易被擴展。tcpserver程式可以執行輪流執行所需的qmail-smtpd的任何程式。這可能很有幫助,例如,決定在qmail-smtpd被運行前是否允許一個連線到達qmail-smtpd或設定或取消一個環境變數。它甚至可以用來對數據在到達qmail-smtpd前進行安全過濾。類似的,當qmail-smtpd正常的運行qmail-queue時,它可以調用任何程式。這個程式可以執行所需的qmail-queue,這可能會有用,來過濾哪些包含病毒的郵件訊息。
As another example, the qmail-start program executes several programs: qmail-send, qmail-lspawn, qmail-rspawn, and qmail-clean. Each of these programs has a specific task. qmail-send must monitor the on-disk queue of mail and route mail appropriately by commanding either qmail-lspawn or qmail-rspawn to deliver the message depending on whether the message should be delivered to a local user or a remote user, respectively. Once messages have been delivered, it commands qmail-clean to remove the message from the queue. Both qmail-lspawn and qmail-rspawn receive delivery commands and spawn the necessary number of instances of qmail-local and qmail-remote to do the actual delivery. The qmail-remote program is a simple program that reads an email from standard input, and delivers it to the hosts and recipients specifi ed to it by arguments. It does not have sufficient permissions to read out of the queue itself, and so must be handed the message to deliver. It can even be used alone as follows:
The qmail-local program is also simple; its task is to read an email from standard input and deliver it to the specified local user, using the procedures detailed in that user"s .qmail files. Like qmail-remote, it does not have sufficient permissions to read or modify the on-disk queue. qmail-local程式也很簡單,它的任務是讀取來自標準輸入的郵件並將之傳送給指定的本地用戶,依據這個用戶的.qmail檔案所描述的具體步驟。和qmail-remote一樣,它也沒有足夠的許可權去讀取或修改
Each of these programs is independent of the others, and relies only on the interface provided to it. By restricting the permissions that each component has, both attacking the system as well as achieving much with a single compromised component is made significantly more difficult. This is the fundamental concept behind the privilege-separation security technique employed by qmail.