comparison thesis/tex/4-MasqmailsFuture.tex @ 185:1611abd5443b

restructuring and new content (a large commit)
author meillo@marmaro.de
date Mon, 29 Dec 2008 14:06:50 +0100
parents e35c7962d84f
children 7f4d97584a6f
comparison
equal deleted inserted replaced
184:b0adae481138 185:1611abd5443b
1 \chapter{\masqmail's present and future} 1 \chapter{\masqmail's present and future}
2 2
3 This chapter \dots %fixme write text here
4
5
6
7
3 \section{Existing code base} 8 \section{Existing code base}
9
4 Here regarded is version 0.2.21 of \masqmail. This is the last version released by Oliver \person{Kurth}, and the basis for my thesis. 10 Here regarded is version 0.2.21 of \masqmail. This is the last version released by Oliver \person{Kurth}, and the basis for my thesis.
11
12
13 \subsubsection*{The source code}
14
15 \masqmail\ is written in the C programming language. The program, as of version 0.2.21, consists of 34 source code and eight header files, containing about 9,000 lines of code\footnote{Measured with \name{sloccount} by David A.\ Wheeler.}. Additionally, it includes a \name{base64} implementation (about 300 lines) and \name{md5} code (about 150 lines). For systems that do not provide \name{libident}, this library is distributed as well (circa 600 lines); an available shared library however has higher precedence in linking.
16
17 The only mandatory dependency is \name{glib}---a cross-platform software utility library, originated in the \NAME{GTK+} project. It provides safer replacements for many standard library functions. It also offers handy data containers, easy-to-use implementations of data structures, and much more.
18
19 With \masqmail\ comes the small tool \path{mservdetect}; it helps setting up a configuration that uses the \name{mserver} system to detect the online state. Two other binaries get compiled for testing purposes: \path{readtest} and \path{smtpsend}. All three programms use \masqmail\ source code; they only add a file with a \verb+main()+ function each.
20
21 \masqmail\ does not provide an interface to plug in modules with additional functionality. There exists no add-on or module system. The code is only separated by function to the various source files. Some functional parts can be included or excluded by defining symbols. Adding maildir support at compile time, means giving the option \verb+--enable-maildir+ to the \path{configure} call. This preserves the concerning code to get removed by the preprocessor. Unfortunately the \verb+#ifdef+s are scattered through all the source, leading to source code that is hard to read.
22 %fixme: refer to ifdef-considered-harmful ?
23
5 24
6 25
7 \subsubsection*{Features} 26 \subsubsection*{Features}
8 27
9 \masqmail\ accepts mail on the command line and via \SMTP. Mail queueing and alias expansion is supported. \masqmail\ is able to deliver mail to local mailboxes (in \name{mbox} or \name{maildir} format) or pass it to a \name{mail delivery agent} (like \name{procmail}). Mail destinated to remote locations is sent using \SMTP\ or can be piped to commands, being gatesways to \NAME{UUCP} or \NAME{FAX} for example. 28 \masqmail\ accepts mail on the command line and via \SMTP. Mail queueing and alias expansion is supported. \masqmail\ is able to deliver mail to local mailboxes (in \name{mbox} or \name{maildir} format) or pass it to a \name{mail delivery agent} (like \name{procmail}). Mail destinated to remote locations is sent using \SMTP\ or can be piped to commands, being gatesways to \NAME{UUCP} or \NAME{FAX} for example.
18 %sendmail: hoststat, mailq, newaliases, purgestat, smtpd 37 %sendmail: hoststat, mailq, newaliases, purgestat, smtpd
19 38
20 Additional to the \mta\ job, \masqmail\ also offers mail retrieval services with being a \NAME{POP3} client. It can fetch mail from different remote locations, dependent on the active online route. 39 Additional to the \mta\ job, \masqmail\ also offers mail retrieval services with being a \NAME{POP3} client. It can fetch mail from different remote locations, dependent on the active online route.
21 40
22 41
23 \subsubsection*{The code}
24
25 \masqmail\ is written in the C programming language. The program, as of version 0.2.21, consists of 34 source code and eight header files, containing about 9,000 lines of code\footnote{Measured with \name{sloccount} by David A.\ Wheeler.}. Additionally, it includes a \name{base64} implementation (about 300 lines) and \name{md5} code (about 150 lines). For systems that do not provide \name{libident}, this library is distributed as well (circa 600 lines); an available shared library however has higher precedence in linking.
26
27 The only mandatory dependency is \name{glib}---a cross-platform software utility library, originated in the \NAME{GTK+} project. It provides safer replacements for many standard library functions. It also offers handy data containers, easy-to-use implementations of data structures, and much more.
28
29
30 With \masqmail\ comes the small tool \path{mservdetect}; it helps setting up a configuration that uses the \name{mserver} system to detect the online state. Two other binaries get compiled for testing purposes: \path{readtest} and \path{smtpsend}. All three programms use \masqmail\ source code; they only add a file with a \verb+main()+ function each.
31
32
33 \masqmail\ does not provide an interface to plug in modules with additional functionality. There exists no add-on or module system. The code is only separated by function to the various source files. Some functional parts can be included or excluded by defining symbols. Adding maildir support at compile time, means giving the option \verb+--enable-maildir+ to the \path{configure} call. This preserves the concerning code to get removed by the preprocessor. Unfortunately the \verb+#ifdef+s are scattered through all the source, leading to a FIXME(holperig) code base.
34
35 42
36 43
37 44
38 45
39 \section{Requirements} 46 \section{Requirements}
40 47
41 This section identifies the requirements for future version of \masqmail. Most of them will apply to modern \MTA{}s in general. 48 This section identifies the requirements for a modern \masqmail. Most of them will apply to modern \MTA{}s in general.
49
50
42 51
43 \subsection{General requirements} 52 \subsection{General requirements}
44 53
45 Following is a list of current and future requirements to make \masqmail\ ready for the future. 54 The following list of general requirements applies not only to \masqmail, but to all kinds of programs in similar environment doing similar jobs with the same intention. These requirements can be covered by the term ``quality''.
55 %fixme: add cites
56 %fixme: refer to ch01 and ch02
57 General requirements specify the non-functional properties of the software, thus they are also called \name{non-functional requirements}.
46 58
47 59
48 \subsubsection*{Security} 60 \subsubsection*{Security}
49 \MTA{}s are critical points for computer security, as they are accessable from external networks. They must be secured with high effort. Properties like high priviledge level, work load influenced from extern, work on unsafe data, and demand for reliability, increase the security needed. Unsecure and unreliable \mta{}s are of no value. \masqmail\ needs to b e secure enough for its target field of operation. 61 \MTA{}s are critical points for computer security, as they are accessable from external networks. They must be secured with high effort. Properties like high priviledge level, work load influenced from extern, work on unsafe data, and demand for reliability, increase the security needed. Unsecure and unreliable \mta{}s are of no value. \masqmail\ needs to b e secure enough for its target field of operation.
50 62
70 82
71 83
72 84
73 85
74 86
75 \subsection{Discussion on architecture} 87
88 \subsection{Functional requirements}
89
90 This section identifies the needed functionality for a modern \MTA. The basic job of a \mta\ is to tranport mail from a sender to a recipient. This is the definition of such kind of software and this is how \MTA{}s are generally seen \cite[page 19]{dent04} \cite[pages 3-5]{hafiz05}.
91
92 An \MTA\ therefore needs at least a mail receiving facility and a mail sending facility.
93
94
95
96 \subsubsection*{Incoming channels}
97
98 \sendmail-compatible \mta{}s must support at least two incoming channels: mail submitted using the \sendmail\ command, and mail received via the \SMTP\ daemon. Thus it is common to split the incoming channel into local and remote. This is done by \qmail\ and \postfix. The same way is \person{Hafiz}'s view. \SMTP\ is the primary mail transport protocol today, but with the increasing need for new protocols\ref{FIXME} in mind, support for more than just \SMTP\ is good to have. This leads to more than one remote channel.
99
100
101 \subsubsection*{Outgoing channels}
102
103 Outgoing mail is commonly either sent using \SMTP, piped into local commands (for example \texttt{uucp}), or delivered locally by appending to a mailbox.
104
105 Outgoing channels are similar for \qmail, \postfix, and \name{sendmail X}: All of them have a module to send mail using \SMTP, and one for writing into a local mailbox. Local mail delivery is a job that requires root priveledge to be able to switch to any user in order to write to his mailbox.
106
107 As mail delivery to local users, is \emph{not} included in the basic job of an \MTA{}, why should it care about it? In order to keep the system simple and to have programs that do one job well, the local delivery job should be handed over to a specialist: the \name{mail delivery agent}. \NAME{MDA}s know about the various mailbox formats and are aware of the problems of concurrent write access and thelike. Hence handling the message and the responsiblity over to a \NAME{MDA}, like \name{procmail} or \name{maildrop}, seems to be the right way to go.
108
109 This means an outgoing connection that pipes mail into local commands is required. Other outgoing channels, one for each supportet protocol, may be designed like it was done in other \MTA{}s.
110
111
112
113 \subsubsection*{Mail queue}
114
115 Additionally to the mail receiving and sending facilities, mail queues are a basic feature. A mail queue removes the need to deliver intantly as a message is received. They provide fail-safe storage of mails until they are delivered. Mail queues are probably used in all \mta{}s, excluding the simple forwarders. A mail queue is a essential requirement for \masqmail, as it is to be used for non-permanent online connections. This means, mail must be queued until a online connection is available to send the message.
116
117 The mail queue and the module to manage it are the central part of the whole system. This demands especially for robustness and reliability, as a failure here can lead to loosing mail. An \MTA\ takes over responsibility for mail in accepting it, hence loosing mail messages is absolutely to avoid. This covers any kind of crash situation too. The worst thing acceptable to happen is a mail to be sent twice.
118
119 \sendmail, \exim, \qmail, \name{sendmail X}, and \masqmail\ feature one single mail queue. \postfix\ has three of them: \name{incoming}, \name{active}, and \name{deferred}. (The \name{maildrop} queue is excluded, as it is only used for the \texttt{sendmail} command.)
120
121 \MTA\ setups that do external content scanning tend to require two separate queues. To use \sendmail\ in such setups requires two independent instances, with two separate queues, running. \exim\ can handle it with special \name{router} and \name{transport} rules, but the data flow gets complicated. Having two independent queues seems to be preferable.
122
123
124
125
126 \subsubsection*{Header sanitizing}
127
128 Mail coming into the system often lacks important header lines. At least the required ones must be added from the \MTA. One example is the \texttt{Date:} header, another is the, not required but recommended \texttt{Message-ID:} header. Apart from adding missing headers, rewriting headers is important too, to change the locally known domain part of email addresses to globally known ones for example. \masqmail\ needs also the ability to rewrite the domain part dependent on the route used to send the message.
129
130 Generating the envelope is a related job. The envelope specifies the actual recipient of the mail, no matter what the \texttt{To:}, \texttt{Cc:}, and \texttt{Bcc:} headers tell. Multiple reciptients lead to multiple different envelopes, containing all the same mail message.
131
132
133
134
135 \subsubsection*{Aliasing}
136
137 Email addresses can have aliases and need to be expanded. Aliases can be of different kind: different local user, remote user, list of local and/or remote users, or a command. Most important are the aliases in the \path{aliases} file, usually located at \path{/etc/aliases}. Addresses expanding to lists of users lead to more envelopes. Aliases changing the reciptients domain part may require a different route to use.
138
139
140
141
142 \subsubsection*{Choose route to use}
143
144 One key feature of \masqmail\ is its ability to send mail out in different ways. The decision is based on the current online state and whether a route may be used for a message or not. The online state can be retrieved in tree ways, explained in \ref{sec:fixme}. A route to send is found by checking every available route for being able to transfer the current message, until one matches.
145
146
147
148
149 \subsubsection*{Authentication}
150
151 One thing to avoid is being an \name{open relay}. Open relays allow to relay mail from everywhere to everywhere. This is a major source of spam. The solution is restricting relay\footnote{Relaying is passing mail, that is not from and not for the own system, through it.} access.
152
153 Several ways to restrict access are available. The most simple one is restrictiction relaying by the \NAME{IP} address. No extra complexity is added this way, but static \NAME{IP} addresses are needed.
154
155 If static access restriction is not possible, for example mail from locations with changing \NAME{IP} addresses, some kind of authentication mechanism is required. Three common kinds exist:
156 \begin{itemize}
157 \item \SMTP-after-\NAME{POP}: Uses authenication on the \NAME{POP} protocol to permit incoming \SMTP\ connections for a limited time afterwards.
158 \item \SMTP authentication: An extension to \SMTP. Authentication can be requested before mail is accepted.
159 \item Certificates: They confirm the identity of someone.
160 \end{itemize}
161
162
163
164 \subsubsection*{Encryption}
165
166 Electronic mail is very weak to sniffing attacks, because all data transfer is unencrypted. This concerns the message's content, as well as the email addresses in header and envelope, but also authentication dialogs that may transfer plain text passwords (\NAME{PLAIN} and \NAME{LOGIN} are examples). Thus encryption is wanted.
167
168 The common way to encrypt \SMTP\ dialogs is using \name{Transport Layer Security} (short: \TLS, successor of \NAME{SSL}). \TLS\ encrypts the datagrams of the \name{transport layer}. This means it works below the application protocols and can be used by any of them\citeweb{wikipedia:tls}.
169
170 Outgoing \SMTP\ connections can get encrypted using a secure tunnel, created by an external application. Incoming connections, can not use this technique because the remote \NAME{IP} address is hidden then; \NAME{STARTTLS}---defined in \RFC2487---is what \mta{}s implement.
171
172
173
174 \subsubsection*{Spam prevention}
175
176 Spam is a major threat nowadays, but it is a war in which the good guys tend to lose. Putting much effort in fighting spam results in few gain. Real success will only be possible with new---better---protocols and abandonning the weak legacy technologies. The goal is to provide state-of-the-art spam protection, but not more (see section \ref{sec:swot-analysis}). As spam is not just a nuisance for end users, but also for the infrastructure---the \mta{}s---by increasing the amount of mail messages, \MTA{}s need to protect themself.
177
178 Filtering spam can be done in two ways: Refusing spam during the \SMTP\ dialog or checking for spam after the mail was accepted and queued. Both have advantages and disadvantages, so modern \MTA{}s use them in combination. Spam is identified by the results of a set of checks. Static rules, querying databases (\NAME{DNS} blacklists), requesting special client behavior (\name{greylisting}, \name{hashcash}), or statistical analysis (\name{bogofilter}) are checks that may be used. Running more checks leads to better results, but takes more system resources and time.
179
180 Doing some basic checks during the \SMTP\ dialog seems to be a must.
181
182
183
184 \subsubsection*{Virus checking}
185
186 Related to spam is malicous content (short: \name{malware}) like viruses, worms, trojan horses. They, in contrast to spam, do not affect the \MTA\ itself, as they are in the mail body. \MTA{}s searching for malware is equal to real world's post offices opening letters to check if they contain something that could harm the recipient. This is not a mail transport job. But the last \MTA---the one responsible for the recipient---seems to be at a good position to do this work.
187
188 In any way should malware checking be done by external programs that may be invoked by the \mta. But using mail deliver and processing agents, like \name{procmail}, a better suited locations to invoke content scanners.
189
190 A popular email filter framework is \name{amavis} which integrates various spam and virus scanners. The common setup includes a receiving \MTA\ which sends it to \name{amavis} using \SMTP, \name{amavis} processes the mail and sends it then to a second \MTA\ that does the outgoing transfer. Having interfaces to such scanners is, for sure, good to have.
191
192
193
194 \subsubsection*{Archiving}
195
196 Mail archiving and auditability become more important as electronic mail becomes more important. The ability to archive verbatim copies of every mail coming into and every mail going out of the system, with relation between them, appears to be a goal to achieve.
197
198 \postfix\ for example has a \texttt{always\_bcc} feature, to send a copy of every mail to a definable reciptient. At least this funtionality should be given, although a more complete approach is preferable.
199
200
201
202
203
204
205
206
207 \section{Work to do}
208
209 What exists, what is missing, what needs to be done?
210
211 auth, enc, archiving
212
213 \masqmail\ is already able to encrypt outgoing connections, but encryption of incoming connections, using \NAME{STARTTLS} should be implemented. This only affects the \SMTP\ server module.
214
215
216
217
218 \subsubsection*{Discussion on architecture}
76 219
77 A program's architecture is probably the most influencing design decision, and has the greatest impact on the program's future capabilities. %fixme: search quote ... check if good 220 A program's architecture is probably the most influencing design decision, and has the greatest impact on the program's future capabilities. %fixme: search quote ... check if good
78 221
79 \masqmail's current artitecture is monolitic like \sendmail's and \exim's. But more than the other two, is it one block of interweaved code. \sendmail\ provides now, with its \name{milter} interface, standardized connection channels to external modules. \exim\ has a highly structured code with many internal interfaces, like the one for supported authentication ``modules''. \masqmail\ has none of them; it is what \sendmail\ was in the beginning: a single large block. 222 \masqmail's current artitecture is monolitic like \sendmail's and \exim's. But more than the other two, is it one block of interweaved code. \sendmail\ provides now, with its \name{milter} interface, standardized connection channels to external modules. \exim\ has a highly structured code with many internal interfaces, like the one for supported authentication ``modules''. \masqmail\ has none of them; it is what \sendmail\ was in the beginning: a single large block.
80 223
114 257
115 All this leads to one logical step: The rewrite of \masqmail\ using a modern, modular architecture, to get a modern \MTA\ satisfying nowadays needs. 258 All this leads to one logical step: The rewrite of \masqmail\ using a modern, modular architecture, to get a modern \MTA\ satisfying nowadays needs.
116 259
117 260
118 261
119 262 \subsubsection*{A design from scratch?}
120 263
121 264 << what would be needed (effort) >>
122 http://fanf.livejournal.com/50917.html %how not to design an mta - the sendmail command 265
123 http://fanf.livejournal.com/51349.html %how not to design an mta - partitioning for security 266 The next section is a design
124 http://fanf.livejournal.com/61132.html %how not to design an mta - local delivery 267
125 http://fanf.livejournal.com/64941.html %how not to design an mta - spool file format 268
126 http://fanf.livejournal.com/65203.html %how not to design an mta - spool file logistics 269
127 http://fanf.livejournal.com/65911.html %how not to design an mta - more about log-structured MTA queues 270
128 http://fanf.livejournal.com/67297.html %how not to design an mta - more log-structured MTA queues 271
129 http://fanf.livejournal.com/70432.html %how not to design an mta - address verification 272
130 http://fanf.livejournal.com/72258.html %how not to design an mta - content scanning 273
131 274 \section{A design from scratch}
132 275
133 276 The last sections identified the jobs that need to be done by a modern \MTA; problems and prefered choices were mentioned too. Now the various jobs are assigned to modules, of which an architecture is created. It is inpired by existing ones and driven by the identified jobs and requirements.
134 277
135 278
136 279
137 280
138 \subsection{Jobs of an MTA} 281 \subsection{Design decisions}
139 282
140 This section tries to identify the needed modules for a modern \MTA. They are later the pieces of which the new architecture is built of. 283 One major design idea of the design were:
141 284 \begin{itemize}
142 The basic job of a \mta\ is to tranport mail from a sender to a recipient. This is the definition of such a program and this is how \person{Dent}\cite[page 19]{dent04} and \person{Hafiz} \cite[pages 3-5]{hafiz05} generally see its design. 285 \item free the internal system from in and out channels
143 286 \item arbitrary protocol handlers have to be addable afterwards
144 An \MTA\ therefor needs at least a mail receiving facility and a mail sending facility. Additionally probably all \MTA\ developers (excluded the only forwarders), see the need for a mail queue. A mail queue removes the need to deliver at once a message is received. They also provide fail-safe storage of mails until they are delivered. 287 \item a single facility for scanning (all mail goes through it)
145 288 \item concentrate on mail transfer
289 \end{itemize}
146 290
147 291
148 \subsubsection*{Incoming channels} 292 \subsubsection*{Incoming channels}
149 293
150 \sendmail-compatible \mta{}s must support at least two incoming channels: mail submitted using the \sendmail\ command, and mail received via the \SMTP\ daemon. It is therefor common to split the incoming channel into local and remote. This is done by \qmail\ and \postfix. The same way is \person{Hafiz}'s view. 294 \sendmail-compatible \mta{}s must support at least two incoming channels: mail submitted using the \sendmail\ command, and mail received via the \SMTP\ daemon. It is therefor common to split the incoming channel into local and remote. This is done by \qmail\ and \postfix. The same way is \person{Hafiz}'s view.
189 Mail coming into the system often lacks important header lines. At least the required ones must be added from the \MTA. A good example is the \texttt{Message-Id:} header. 333 Mail coming into the system often lacks important header lines. At least the required ones must be added from the \MTA. A good example is the \texttt{Message-Id:} header.
190 334
191 In \postfix, this is done by the \name{cleanup} module, which invokes \name{rewrite}. The position in the message flow is after coming from one of the several incoming channels and before the message is stored into the \name{incoming} queue. Modules that handle incoming channels may also add headers, for example the \texttt{From:} and \texttt{Date:} headers. \name{cleanup}, however, does a complete check to make the mail header complete and valid. 335 In \postfix, this is done by the \name{cleanup} module, which invokes \name{rewrite}. The position in the message flow is after coming from one of the several incoming channels and before the message is stored into the \name{incoming} queue. Modules that handle incoming channels may also add headers, for example the \texttt{From:} and \texttt{Date:} headers. \name{cleanup}, however, does a complete check to make the mail header complete and valid.
192 336
193 Apart from deciding where to sanitize the mail header, is the question where to generate the envelope. The envelope specifies the actual recipient of the mail, no matter what the \texttt{To:}, \texttt{Cc:}, and \texttt{Bcc:} headers tell. Multiple reciptients lead to multiple different envelopes, containing all the same mail message. 337 Apart from deciding where to sanitize the mail header, is the question where to generate the envelope. The envelope specifies the actual recipient of the mail, no matter what the \texttt{To:}, \texttt{Cc:}, and \texttt{Bcc:} headers tell. Multiple reciptients lead to multiple different envelopes, containing all the same mail message.
194
195
196
197 \subsubsection*{Choose route to use}
198
199 One key feature of \masqmail\ is its ability to send mail out in different ways. The decision is based on the current online state and whether a route may be used for a message or not. The online state can be retrieved in tree ways, explained in \ref{sec:fixme}. A route to send is found by checking every available route for being able to transfer the current message, until one matches.
200
201 This functionality should be implemented in the module that is responsible to invoke one of the outgoing channel modules (for example the one for \SMTP\ or the pipe module).
202
203 \masqmail\ can rewrite the envelope's from address and the \texttt{From:} header, dependent on the outgoing route to use. This rewrite must be done \emph{after} it is clear which route a mail will take, of course, so this may be not the module where other header editing is done.
204 %fixme: see hafiz05 page 57: maybe put the rewriting into the sending module (like smx, exim, courier) (problem with archiving of all outgoing mail?)
205 338
206 339
207 340
208 \subsubsection*{Aliasing} 341 \subsubsection*{Aliasing}
209 342
218 351
219 Aliasing is often handled in expanding the alias and reinjecting the mail into the system. Unfortunately, the mail is processed twice then; additionally does the system have to handle more mail this way. If it is wanted to check the new recipient address for acceptance and do all processing again, then reinjecting it is the best choice. 352 Aliasing is often handled in expanding the alias and reinjecting the mail into the system. Unfortunately, the mail is processed twice then; additionally does the system have to handle more mail this way. If it is wanted to check the new recipient address for acceptance and do all processing again, then reinjecting it is the best choice.
220 353
221 354
222 355
356 \subsubsection*{Choose route to use}
357
358 One key feature of \masqmail\ is its ability to send mail out in different ways. The decision is based on the current online state and whether a route may be used for a message or not. The online state can be retrieved in tree ways, explained in \ref{sec:fixme}. A route to send is found by checking every available route for being able to transfer the current message, until one matches.
359
360 This functionality should be implemented in the module that is responsible to invoke one of the outgoing channel modules (for example the one for \SMTP\ or the pipe module).
361
362 \masqmail\ can rewrite the envelope's from address and the \texttt{From:} header, dependent on the outgoing route to use. This rewrite must be done \emph{after} it is clear which route a mail will take, of course, so this may be not the module where other header editing is done.
363 %fixme: see hafiz05 page 57: maybe put the rewriting into the sending module (like smx, exim, courier) (problem with archiving of all outgoing mail?)
364
365
366
223 \subsubsection*{Authentication} 367 \subsubsection*{Authentication}
224 368
225 One thing to avoid is being an \name{open relay}. Open relays allow to relay mail from everywhere to everywhere. This is a major source of spam. The solution is restricting relay\footnote{Relaying is passing mail, that is not from and not for the own system, through it.} access. 369 One thing to avoid is being an \name{open relay}. Open relays allow to relay mail from everywhere to everywhere. This is a major source of spam. The solution is restricting relay\footnote{Relaying is passing mail, that is not from and not for the own system, through it.} access.
226 370
227 Several ways to restrict access are available. The most simple one is restrictiction by the \NAME{IP} address. No extra complexity is added this way, but static \NAME{IP} addresses are mandatory. This kind of restriction may be enabled using the operating system's \path{hosts.allow} and \path{hosts.deny} files. To allow only connections to port 25 from localhost or the local network \texttt{192.168.100.0/24} insert the line ``\texttt{25: ALL}'' into \path{hosts.deny} and ``\texttt{25: 127.0.0.1, 192.168.100.}'' into \path{hosts.allow}. 371 Several ways to restrict access are available. The most simple one is restrictiction by the \NAME{IP} address. No extra complexity is added this way, but static \NAME{IP} addresses are mandatory. This kind of restriction may be enabled using the operating system's \path{hosts.allow} and \path{hosts.deny} files. To allow only connections to port 25 from localhost or the local network \texttt{192.168.100.0/24} insert the line ``\texttt{25: ALL}'' into \path{hosts.deny} and ``\texttt{25: 127.0.0.1, 192.168.100.}'' into \path{hosts.allow}.
228 372
229 If static access restriction is not possible, for example if mail from locations with changing \NAME{IP} addresses wants to be accepted, some kind of authentication mechanism is required. Three common kinds exist: 373 If static access restriction is not possible, for example if mail from locations with changing \NAME{IP} addresses wants to be accepted, some kind of authentication mechanism is required. Three common kinds exist:
230 \begin{enumerate} 374 \begin{enumerate}
231 \item \SMTP-after-\NAME{POP}: uses authenication on the \NAME{POP} protocol to permit incoming \SMTP\ connections for a limited time afterwards. 375 \item \SMTP-after-\NAME{POP}: uses authenication on the \NAME{POP} protocol to permit incoming \SMTP\ connections for a limited time afterwards.
232 \item \SMTP authentication: is an extension to \SMTP. Authentication can be requested before mail is accepted. 376 \item \SMTP authentication: is an extension to \SMTP. Authentication can be requested before mail is accepted.
233 \item Certificates: confirm the identity of someone. 377 \item Certificates: confirm the identity of someone.
234 \end{enumerate} 378 \end{enumerate}
235 The first mechanism requires a \NAME{POP} (or \NAME{IMAP}) server running on the same host (or a trusted one), to enable the \SMTP\ server to use the login dates on the \NAME{POP} server. This is a common practice used by mail service providers, but is not adequate for the environments \masqmail\ is designed for.
236
237 Certificate based authentication, like provided by \NAME{TLS}, suffers from the overhead of certificate management. But \NAME{TLS} provides encryption too, so is useful anyway.
238
239 \SMTP\ authentication (also refered to as \NAME{SMTP-AUTH}) suppoert is easiest received by using a \name{Simple Authentication and Security Layer} implementation. \person{Dent} sees in \NAME{SASL} the best solution for authenticating dynamic users:
240 \begin{quote}
241 %None of these add-ons is an ideal solution. They require additional code compiled into your existing daemons that may then require special write accesss to system files. They also require additional work for busy system administrators. If you cannot use any of the nonauthenticating alternatives mentioned earlier, or your business requirements demand that all of your users' mail pass through your system no matter where they are on the Internet, SASL is probably the solution that offers the most reliable and scalable method to authenticate users.
242 None of these [authentication methods] is an ideal solution. They require additional code compiled into your existing daemons that may then require special write accesss to system files. They also require additional work for busy system administrators. If you cannot use any of the nonauthenticating alternatives mentioned earlier, or your business requirements demand that all of your users' mail pass through your system no matter where they are on the Internet, \NAME{SASL} is probably the solution that offers the most reliable and scalable method to authenticate users.
243 \cite[page 44]{dent04}
244 \end{quote}
245
246 %either by
247 %- network/ip address
248 % easiest: restricting by static IP addresses (Access control via hosts.allow/hosts.deny)
249 %or
250 %- some kind of auth (for dynamic remote hosts)
251 % adds complexity
252 % - SASL
253 % - POP/IMAP: pop-before-smtp, DRAC, WHOSON
254 % - TLS (certificates)
255 379
256 380
257 381
258 \subsubsection*{Encryption} 382 \subsubsection*{Encryption}
259 383
263 387
264 \TLS\ allows to create secure tunnels through which arbitrary programs can communicate. Hence one can add secure communication afterwards to programs without changing them. \name{OpenSSL} for example---a free implementation---allows traffic to be piped into a command; a secure tunnel is created and the traffic is forwarded through it. Or a secure tunnel can be set up between a local and a remote port; this tunnel can then be used by any application. 388 \TLS\ allows to create secure tunnels through which arbitrary programs can communicate. Hence one can add secure communication afterwards to programs without changing them. \name{OpenSSL} for example---a free implementation---allows traffic to be piped into a command; a secure tunnel is created and the traffic is forwarded through it. Or a secure tunnel can be set up between a local and a remote port; this tunnel can then be used by any application.
265 389
266 The \NAME{POP} protocol, for example, is good suited for such tunneling, but \SMTP\ is is not generally. Outgoing \SMTP\ client connections can be tunneled without problem---\masqmail\ already provides a configure option called \texttt{wrapper} to do so. Tunneling incomming connections to a server leads to problems with \SMTP. As data comes encrypted through the tunnel to the receiving host and gets then decrypted and forwarded on local to the port the application listens on. From the \MTA's view, this makes all connections appear to come from localhost, unfortunately. Figure \ref{fig:stunnel} depicts the data flow. 390 The \NAME{POP} protocol, for example, is good suited for such tunneling, but \SMTP\ is is not generally. Outgoing \SMTP\ client connections can be tunneled without problem---\masqmail\ already provides a configure option called \texttt{wrapper} to do so. Tunneling incomming connections to a server leads to problems with \SMTP. As data comes encrypted through the tunnel to the receiving host and gets then decrypted and forwarded on local to the port the application listens on. From the \MTA's view, this makes all connections appear to come from localhost, unfortunately. Figure \ref{fig:stunnel} depicts the data flow.
267 391
268 \begin{figure}
269 \begin{center}
270 \input{input/stunnel.tex}
271 \end{center}
272 \caption{Data flow using \name{stunnel}}
273 \label{fig:stunnel}
274 \end{figure}
275
276 For incoming connections, \NAME{STARTTLS}---defined in \RFC2487---is what \mta{}s implement. 392 For incoming connections, \NAME{STARTTLS}---defined in \RFC2487---is what \mta{}s implement.
277 393
278 \masqmail\ is already able to encrypt outgoing connections, but encryption of incoming connections, using \NAME{STARTTLS} should be implemented. This only affects the \SMTP\ server module. 394 \masqmail\ is already able to encrypt outgoing connections, but encryption of incoming connections, using \NAME{STARTTLS} should be implemented. This only affects the \SMTP\ server module.
279 395
280 %TLS/SSL prevents attackers to listen on the cable
281 %but it does not prevent man-in-the-middle attacks
282 %signed certificates help here
283 % or PGP encryption
284
285
286 %do not use stunnel wit SMTP:
287 %because all incoming mail would be from 127.0.0.1 !!
288 %use STARTTLS instead
289
290 %postfix: main.cf
291 %\begin{verbatim}
292 % smtpd_use_tls = yes
293 % smtpd_tls_received_header = no (does not log in received headers)
294 %
295 % smtpd_tls_key_file = /etc/postfix/key.pem
296 % smtpd_tls_cert_file = /etc/postfix/cert.pem
297 % smtpd_tls_CA_file = /etc/postfix/CAcert.pem
298 %
299 % smtp_use_tls = yes (use TLS for sending)
300 % smtp_tls_key_file = /etc/postfix/key.pem
301 % smtp_tls_cert_file = /etc/postfix/cert.pem
302 % smtp_tls_CA_file = /etc/postfix/CAcert.pem
303 %\end{verbatim}
304 396
305 397
306 398
307 399
308 \subsubsection*{Spam prevention} 400 \subsubsection*{Spam prevention}
380 472
381 \postfix\ for example has a \texttt{always\_bcc} feature, to send a copy of every mail to a definable reciptient. At least this funtionality should be given, although a more complete approach is preferable. 473 \postfix\ for example has a \texttt{always\_bcc} feature, to send a copy of every mail to a definable reciptient. At least this funtionality should be given, although a more complete approach is preferable.
382 474
383 475
384 476
385 \section{Merging the parts} 477
386 478
387 The last sections identified the jobs that need to be done by a modern \MTA; problems and prefered choices were mentioned too. Now the various jobs are assigned to modules, of which an architecture is created. It is inpired by existing ones and driven by the identified jobs and requirements. 479 \subsection{The resulting architecture}
388
389 One major design idea of the design were:
390 \begin{itemize}
391 \item free the internal system from in and out channels
392 \item arbitrary protocol handlers have to be addable afterwards
393 \item a single facility for scanning (all mail goes through it)
394 \item concentrate on mail transfer
395 \end{itemize}
396 480
397 The result is a symetric design, featuring the following parts: Any number of handlers for incoming connections to receive mail and pass it to the module that stores it into the incoming queue. A central scanning module take mail from the incoming queue, processes it in various ways and puts it afterwards into the outgoing queue. Another module takes it out there and passes it to a matching transport module that transfers it to the destination. In other words, three main modules (queue-in, scanning, queue-out) are connected by the two queues (incoming, outgoing); on each end are more modules to receive and send mail---for each protocol one. Figure \ref{fig:masqmail-arch-new} depicts the new designed architecture. 481 The result is a symetric design, featuring the following parts: Any number of handlers for incoming connections to receive mail and pass it to the module that stores it into the incoming queue. A central scanning module take mail from the incoming queue, processes it in various ways and puts it afterwards into the outgoing queue. Another module takes it out there and passes it to a matching transport module that transfers it to the destination. In other words, three main modules (queue-in, scanning, queue-out) are connected by the two queues (incoming, outgoing); on each end are more modules to receive and send mail---for each protocol one. Figure \ref{fig:masqmail-arch-new} depicts the new designed architecture.
398 482
399 \begin{figure} 483 \begin{figure}
400 \begin{center} 484 \begin{center}
408 492
409 Special regard was put on addable support for further mail transfer protocols. This appears to be most similar to \qmail, which was designed to handle multiple protocols. 493 Special regard was put on addable support for further mail transfer protocols. This appears to be most similar to \qmail, which was designed to handle multiple protocols.
410 %fixme: do i need all this ``quesses''?? 494 %fixme: do i need all this ``quesses''??
411 495
412 496
413 \subsection{Modules and queues} 497 \subsubsection*{Modules and queues}
414 498
415 The new architecture consists of several modules and two queues. They are defined in more detail now, and the jobs, identified above, are assigned to them. First the three main modules, then the queues, and afterwards the modules for incoming and outgoing transfer. 499 The new architecture consists of several modules and two queues. They are defined in more detail now, and the jobs, identified above, are assigned to them. First the three main modules, then the queues, and afterwards the modules for incoming and outgoing transfer.
416 500
417 501
418 The \name{queue-in} module creates new spool files in the \name{incoming} queue for incoming messages. It is a process running in background, waiting for connections from one of the receiver modules. When one of them requests for a new spool file, the \name{queue-in} module opens one and returns a positive result. The receiver module then sends the envelope and message, which is written into the spool file by \name{queue-in}. If all went well, another positive result is returend. 502 The \name{queue-in} module creates new spool files in the \name{incoming} queue for incoming messages. It is a process running in background, waiting for connections from one of the receiver modules. When one of them requests for a new spool file, the \name{queue-in} module opens one and returns a positive result. The receiver module then sends the envelope and message, which is written into the spool file by \name{queue-in}. If all went well, another positive result is returend.
435 \name{Transport modules}, on the oppersite side of the system, are the modules to send outgoing mail; they are the interface between \name{queue-out} and remote hosts or local commands for further processing. The most popular ones are the \name{smtp} module (which acts as the \SMTP\ client) and the \name{pipe} module (to interface gateways to other systems or networks, like fax or uucp). A module for local delivery is not included, as it is in most other \MTA{}s; the reasons are described in FIXME.%fixme 519 \name{Transport modules}, on the oppersite side of the system, are the modules to send outgoing mail; they are the interface between \name{queue-out} and remote hosts or local commands for further processing. The most popular ones are the \name{smtp} module (which acts as the \SMTP\ client) and the \name{pipe} module (to interface gateways to other systems or networks, like fax or uucp). A module for local delivery is not included, as it is in most other \MTA{}s; the reasons are described in FIXME.%fixme
436 Thus a \name{mail delivery agent} (like \name{procmail}) is to be used with the \name{pipe} module. 520 Thus a \name{mail delivery agent} (like \name{procmail}) is to be used with the \name{pipe} module.
437 521
438 522
439 523
440 \subsection{Inter-module communication} 524 \subsubsection*{Inter-module communication}
441 525
442 Communication between modules is required to exchange data and status information. It is also called ``Inter-process communication'' (short: \NAME{IPC}), as modules are programs being part of a larger system, and processes are generally seen as programs in execution. 526 Communication between modules is required to exchange data and status information. It is also called ``Inter-process communication'' (short: \NAME{IPC}), as modules are programs being part of a larger system, and processes are generally seen as programs in execution.
443 527
444 The connections between \name{queue-in} and \name{scanning}, aswell as between \name{scanning} and \name{queue-out} is provided by the queues, only sending signals to trigger instant runs may be useful. Communication between receiving and transport modules and the outside world are done using the specific protocol they do handle. 528 The connections between \name{queue-in} and \name{scanning}, aswell as between \name{scanning} and \name{queue-out} is provided by the queues, only sending signals to trigger instant runs may be useful. Communication between receiving and transport modules and the outside world are done using the specific protocol they do handle.
445 529
470 554
471 Figure \ref{fig:ipc-protocol} is a state diagram for the protocol. 555 Figure \ref{fig:ipc-protocol} is a state diagram for the protocol.
472 556
473 557
474 558
475 \subsection{Spool file format} 559 \subsubsection*{Spool file format}
476 560
477 The spool file format is basically the same as the one in current \masqmail: one file for the message body, the other for envelope and header information. The data file is stored in a separate data pool. It is written by \name{queue-in}, \name{scanning} can read it if necessary, \name{queue-out} reads it to generate the outgoing message, and deletes it after successful transfer. The header file (including the envelope) is written into the \name{incoming} queue. The \name{scanning} modules reads it, processes it, and writes a modified copy into the \name{outgoing} queue; the file in \name{incoming} is deleted then. \name{queue-out} finally takes the header file from \name{outgoing} to generate the resulting message. This data flow is shown in figure \ref{fig:queue-data-flow}. 561 The spool file format is basically the same as the one in current \masqmail: one file for the message body, the other for envelope and header information. The data file is stored in a separate data pool. It is written by \name{queue-in}, \name{scanning} can read it if necessary, \name{queue-out} reads it to generate the outgoing message, and deletes it after successful transfer. The header file (including the envelope) is written into the \name{incoming} queue. The \name{scanning} modules reads it, processes it, and writes a modified copy into the \name{outgoing} queue; the file in \name{incoming} is deleted then. \name{queue-out} finally takes the header file from \name{outgoing} to generate the resulting message. This data flow is shown in figure \ref{fig:queue-data-flow}.
478 562
479 \begin{figure} 563 \begin{figure}
480 \begin{center} 564 \begin{center}
491 No spool files are modified after they are written to disk. Modifications to header files can be made by the \name{scanning} module in the ``move'' from \name{incoming} to \name{outgoing}---it is a create and remove, actually. Further rewriting can happen in \name{queue-out}, as well without altering the file. 575 No spool files are modified after they are written to disk. Modifications to header files can be made by the \name{scanning} module in the ``move'' from \name{incoming} to \name{outgoing}---it is a create and remove, actually. Further rewriting can happen in \name{queue-out}, as well without altering the file.
492 576
493 Data files do not change at all within the system. They are written in default local plain text format. Required translation is done in the receiver and transport modules. 577 Data files do not change at all within the system. They are written in default local plain text format. Required translation is done in the receiver and transport modules.
494 578
495 579
496 %\begin{verbatim} 580 \begin{tabular}[hbt]{ l l }
497 %s f / envelope data 581
498 %p i | NL 582 \mbox{ queue-in:} & \mbox{
499 %o l | / header lines 583 \begin{tabular}[hbt]{| c | c | c |}
500 %o e | mail | NL 584 \hline
501 %l \ \ mail body 585 incoming & outgoing & pool \\
502 %\end{verbatim} 586 \hline
587 \hline
588 - & - & - \\
589 \hline
590 0600 & - & - \\
591 \hline
592 0600 & - & 0600 \\
593 \hline
594 0700 & - & 0600 \\
595 \hline
596 \end{tabular}
597 } \\
598
599 \quad & \\
600
601 \mbox{scanning:} & \mbox{
602 \begin{tabular}[hbt]{| c | c | c |}
603 \hline
604 incoming & outgoing & pool \\
605 \hline
606 \hline
607 0700 & - & 0600 \\
608 \hline
609 0700 & 0600 & 0600 \\
610 \hline
611 0700 & 0700 & 0600 \\
612 \hline
613 - & 0700 & 0600 \\
614 \hline
615 \end{tabular}
616 } \\
617
618 \quad & \\
619
620 \mbox{queue-out:} & \mbox{
621 \begin{tabular}[hbt]{| c | c | c |}
622 \hline
623 incoming & outgoing & pool \\
624 \hline
625 \hline
626 - & 0700 & 0600 \\
627 \hline
628 - & 0700 & - \\
629 \hline
630 - & - & - \\
631 \hline
632 \end{tabular}
633 } \\
634
635 \end{tabular}
503 636
504 A sample header file. 637 A sample header file.
505 \begin{verbatim} 638 \begin{verbatim}
506 1LGtYh-0ut-00 (backup copy of the file name) 639 1LGtYh-0ut-00 (backup copy of the file name)
507 MF:<meillo@dream> (envelope: sender) 640 MF:<meillo@dream> (envelope: sender)
521 \end{verbatim} 654 \end{verbatim}
522 655
523 656
524 657
525 658
526 \subsection{Rights and permission} 659 \subsubsection*{Rights and permission}
527 660
528 The user set required for \qmail\ seems to be too complex. One special user, like \postfix\ uses, is more appropriate. \name{root} privilege and \name{setuid} permission is avoided as much as possible. 661 The user set required for \qmail\ seems to be too complex. One special user, like \postfix\ uses, is more appropriate. \name{root} privilege and \name{setuid} permission is avoided as much as possible.
529 662
530 Table \ref{tab:new-masqmail-permissions} shows the suggested ownership and permissions of the modules. Figure \ref{fig:new-masqmail-queue} shows the permissions and ownership used for the queue. 663 Table \ref{tab:new-masqmail-permissions} shows the suggested ownership and permissions of the modules. Figure \ref{fig:new-masqmail-queue} shows the permissions and ownership used for the queue.
531 664
565 698
566 699
567 700
568 701
569 702
703 http://fanf.livejournal.com/50917.html %how not to design an mta - the sendmail command
704 http://fanf.livejournal.com/51349.html %how not to design an mta - partitioning for security
705 http://fanf.livejournal.com/61132.html %how not to design an mta - local delivery
706 http://fanf.livejournal.com/64941.html %how not to design an mta - spool file format
707 http://fanf.livejournal.com/65203.html %how not to design an mta - spool file logistics
708 http://fanf.livejournal.com/65911.html %how not to design an mta - more about log-structured MTA queues
709 http://fanf.livejournal.com/67297.html %how not to design an mta - more log-structured MTA queues
710 http://fanf.livejournal.com/70432.html %how not to design an mta - address verification
711 http://fanf.livejournal.com/72258.html %how not to design an mta - content scanning
712
713
714
715
716
717
718
719
570 720
571 721
572 722
573 \section{Directions to go} 723 \section{Directions to go}
574 724
725 Now how could \masqmail\ be like in, say, five years?
726
575 This section discusses about what shapes \masqmail\ could have---which directions the development could go to. 727 This section discusses about what shapes \masqmail\ could have---which directions the development could go to.
576 728
577 729
578 \subsubsection*{\masqmail\ in five years} 730
579 731
580 Now how could \masqmail\ be like in, say, five years? 732 1) fix the current version
581 733
582 --- 734
583 735 2) create a new one
584 A design from scratch?
585 << what would be needed (effort) >>
586 But how is the effort of this complete rewrite compared to what is gained afterwards? 736 But how is the effort of this complete rewrite compared to what is gained afterwards?
587
588 << would one create it at all? >> 737 << would one create it at all? >>
589 738
590 --- 739
591 740 pro---contra
592 741
593 742
594 \subsubsection*{Work to do} 743
595 744
596 << short term goals --- long term goals >> 745 << short term goals --- long term goals >>
597 746
598 do it like sendmail: first do the most needed stuff on the old design to make it still usable. Then design a new version from scratch, for the future. 747 do it like sendmail: first do the most needed stuff on the old design to make it still usable. Then design a new version from scratch, for the future.
599 748