Postfix3.3.1
postscreen.c
[詳解]
1 /*++
2 /* NAME
3 /* postscreen 8
4 /* SUMMARY
5 /* Postfix zombie blocker
6 /* SYNOPSIS
7 /* \fBpostscreen\fR [generic Postfix daemon options]
8 /* DESCRIPTION
9 /* The Postfix \fBpostscreen\fR(8) server provides additional
10 /* protection against mail server overload. One \fBpostscreen\fR(8)
11 /* process handles multiple inbound SMTP connections, and decides
12 /* which clients may talk to a Postfix SMTP server process.
13 /* By keeping spambots away, \fBpostscreen\fR(8) leaves more
14 /* SMTP server processes available for legitimate clients, and
15 /* delays the onset of server overload conditions.
16 /*
17 /* This program should not be used on SMTP ports that receive
18 /* mail from end-user clients (MUAs). In a typical deployment,
19 /* \fBpostscreen\fR(8) handles the MX service on TCP port 25, and
20 /* \fBsmtpd\fR(8) receives mail from MUAs on the \fBsubmission\fR
21 /* service (TCP port 587) which requires client authentication.
22 /* Alternatively, a site could set up a dedicated, non-postscreen,
23 /* "port 25" server that provides \fBsubmission\fR service and
24 /* client authentication, but no MX service.
25 /*
26 /* \fBpostscreen\fR(8) maintains a temporary whitelist for
27 /* clients that have passed a number of tests. When an SMTP
28 /* client IP address is whitelisted, \fBpostscreen\fR(8) hands
29 /* off the connection immediately to a Postfix SMTP server
30 /* process. This minimizes the overhead for legitimate mail.
31 /*
32 /* By default, \fBpostscreen\fR(8) logs statistics and hands
33 /* off each connection to a Postfix SMTP server process, while
34 /* excluding clients in mynetworks from all tests (primarily,
35 /* to avoid problems with non-standard SMTP implementations
36 /* in network appliances). This default mode blocks no clients,
37 /* and is useful for non-destructive testing.
38 /*
39 /* In a typical production setting, \fBpostscreen\fR(8) is
40 /* configured to reject mail from clients that fail one or
41 /* more tests. \fBpostscreen\fR(8) logs rejected mail with the
42 /* client address, helo, sender and recipient information.
43 /*
44 /* \fBpostscreen\fR(8) is not an SMTP proxy; this is intentional.
45 /* The purpose is to keep spambots away from Postfix SMTP
46 /* server processes, while minimizing overhead for legitimate
47 /* traffic.
48 /* SECURITY
49 /* .ad
50 /* .fi
51 /* The \fBpostscreen\fR(8) server is moderately security-sensitive.
52 /* It talks to untrusted clients on the network. The process
53 /* can be run chrooted at fixed low privilege.
54 /* STANDARDS
55 /* RFC 821 (SMTP protocol)
56 /* RFC 1123 (Host requirements)
57 /* RFC 1652 (8bit-MIME transport)
58 /* RFC 1869 (SMTP service extensions)
59 /* RFC 1870 (Message Size Declaration)
60 /* RFC 1985 (ETRN command)
61 /* RFC 2034 (SMTP Enhanced Status Codes)
62 /* RFC 2821 (SMTP protocol)
63 /* Not: RFC 2920 (SMTP Pipelining)
64 /* RFC 3207 (STARTTLS command)
65 /* RFC 3461 (SMTP DSN Extension)
66 /* RFC 3463 (Enhanced Status Codes)
67 /* RFC 5321 (SMTP protocol, including multi-line 220 banners)
68 /* DIAGNOSTICS
69 /* Problems and transactions are logged to \fBsyslogd\fR(8).
70 /* BUGS
71 /* The \fBpostscreen\fR(8) built-in SMTP protocol engine
72 /* currently does not announce support for AUTH, XCLIENT or
73 /* XFORWARD.
74 /* If you need to make these services available
75 /* on port 25, then do not enable the optional "after 220
76 /* server greeting" tests.
77 /*
78 /* The optional "after 220 server greeting" tests may result in
79 /* unexpected delivery delays from senders that retry email delivery
80 /* from a different IP address. Reason: after passing these tests a
81 /* new client must disconnect, and reconnect from the same IP
82 /* address before it can deliver mail. See POSTSCREEN_README, section
83 /* "Tests after the 220 SMTP server greeting", for a discussion.
84 /* CONFIGURATION PARAMETERS
85 /* .ad
86 /* .fi
87 /* Changes to main.cf are not picked up automatically, as
88 /* \fBpostscreen\fR(8) processes may run for several hours.
89 /* Use the command "postfix reload" after a configuration
90 /* change.
91 /*
92 /* The text below provides only a parameter summary. See
93 /* \fBpostconf\fR(5) for more details including examples.
94 /*
95 /* NOTE: Some \fBpostscreen\fR(8) parameters implement
96 /* stress-dependent behavior. This is supported only when the
97 /* default parameter value is stress-dependent (that is, it
98 /* looks like ${stress?{X}:{Y}}, or it is the $\fIname\fR
99 /* of an smtpd parameter with a stress-dependent default).
100 /* Other parameters always evaluate as if the \fBstress\fR
101 /* parameter value is the empty string.
102 /* COMPATIBILITY CONTROLS
103 /* .ad
104 /* .fi
105 /* .IP "\fBpostscreen_command_filter ($smtpd_command_filter)\fR"
106 /* A mechanism to transform commands from remote SMTP clients.
107 /* .IP "\fBpostscreen_discard_ehlo_keyword_address_maps ($smtpd_discard_ehlo_keyword_address_maps)\fR"
108 /* Lookup tables, indexed by the remote SMTP client address, with
109 /* case insensitive lists of EHLO keywords (pipelining, starttls, auth,
110 /* etc.) that the \fBpostscreen\fR(8) server will not send in the EHLO response
111 /* to a remote SMTP client.
112 /* .IP "\fBpostscreen_discard_ehlo_keywords ($smtpd_discard_ehlo_keywords)\fR"
113 /* A case insensitive list of EHLO keywords (pipelining, starttls,
114 /* auth, etc.) that the \fBpostscreen\fR(8) server will not send in the EHLO
115 /* response to a remote SMTP client.
116 /* .PP
117 /* Available in Postfix version 3.1 and later:
118 /* .IP "\fBdns_ncache_ttl_fix_enable (no)\fR"
119 /* Enable a workaround for future libc incompatibility.
120 /* TROUBLE SHOOTING CONTROLS
121 /* .ad
122 /* .fi
123 /* .IP "\fBpostscreen_expansion_filter (see 'postconf -d' output)\fR"
124 /* List of characters that are permitted in postscreen_reject_footer
125 /* attribute expansions.
126 /* .IP "\fBpostscreen_reject_footer ($smtpd_reject_footer)\fR"
127 /* Optional information that is appended after a 4XX or 5XX
128 /* \fBpostscreen\fR(8) server
129 /* response.
130 /* .IP "\fBsoft_bounce (no)\fR"
131 /* Safety net to keep mail queued that would otherwise be returned to
132 /* the sender.
133 /* BEFORE-POSTSCREEN PROXY AGENT
134 /* .ad
135 /* .fi
136 /* Available in Postfix version 2.10 and later:
137 /* .IP "\fBpostscreen_upstream_proxy_protocol (empty)\fR"
138 /* The name of the proxy protocol used by an optional before-postscreen
139 /* proxy agent.
140 /* .IP "\fBpostscreen_upstream_proxy_timeout (5s)\fR"
141 /* The time limit for the proxy protocol specified with the
142 /* postscreen_upstream_proxy_protocol parameter.
143 /* PERMANENT WHITE/BLACKLIST TEST
144 /* .ad
145 /* .fi
146 /* This test is executed immediately after a remote SMTP client
147 /* connects. If a client is permanently whitelisted, the client
148 /* will be handed off immediately to a Postfix SMTP server
149 /* process.
150 /* .IP "\fBpostscreen_access_list (permit_mynetworks)\fR"
151 /* Permanent white/blacklist for remote SMTP client IP addresses.
152 /* .IP "\fBpostscreen_blacklist_action (ignore)\fR"
153 /* The action that \fBpostscreen\fR(8) takes when a remote SMTP client is
154 /* permanently blacklisted with the postscreen_access_list parameter.
155 /* MAIL EXCHANGER POLICY TESTS
156 /* .ad
157 /* .fi
158 /* When \fBpostscreen\fR(8) is configured to monitor all primary
159 /* and backup MX addresses, it can refuse to whitelist clients
160 /* that connect to a backup MX address only. For small sites,
161 /* this requires configuring primary and backup MX addresses
162 /* on the same MTA. Larger sites would have to share the
163 /* \fBpostscreen\fR(8) cache between primary and backup MTAs,
164 /* which would introduce a common point of failure.
165 /* .IP "\fBpostscreen_whitelist_interfaces (static:all)\fR"
166 /* A list of local \fBpostscreen\fR(8) server IP addresses where a
167 /* non-whitelisted remote SMTP client can obtain \fBpostscreen\fR(8)'s temporary
168 /* whitelist status.
169 /* BEFORE 220 GREETING TESTS
170 /* .ad
171 /* .fi
172 /* These tests are executed before the remote SMTP client
173 /* receives the "220 servername" greeting. If no tests remain
174 /* after the successful completion of this phase, the client
175 /* will be handed off immediately to a Postfix SMTP server
176 /* process.
177 /* .IP "\fBdnsblog_service_name (dnsblog)\fR"
178 /* The name of the \fBdnsblog\fR(8) service entry in master.cf.
179 /* .IP "\fBpostscreen_dnsbl_action (ignore)\fR"
180 /* The action that \fBpostscreen\fR(8) takes when a remote SMTP client's combined
181 /* DNSBL score is equal to or greater than a threshold (as defined
182 /* with the postscreen_dnsbl_sites and postscreen_dnsbl_threshold
183 /* parameters).
184 /* .IP "\fBpostscreen_dnsbl_reply_map (empty)\fR"
185 /* A mapping from actual DNSBL domain name which includes a secret
186 /* password, to the DNSBL domain name that postscreen will reply with
187 /* when it rejects mail.
188 /* .IP "\fBpostscreen_dnsbl_sites (empty)\fR"
189 /* Optional list of DNS white/blacklist domains, filters and weight
190 /* factors.
191 /* .IP "\fBpostscreen_dnsbl_threshold (1)\fR"
192 /* The inclusive lower bound for blocking a remote SMTP client, based on
193 /* its combined DNSBL score as defined with the postscreen_dnsbl_sites
194 /* parameter.
195 /* .IP "\fBpostscreen_greet_action (ignore)\fR"
196 /* The action that \fBpostscreen\fR(8) takes when a remote SMTP client speaks
197 /* before its turn within the time specified with the postscreen_greet_wait
198 /* parameter.
199 /* .IP "\fBpostscreen_greet_banner ($smtpd_banner)\fR"
200 /* The \fItext\fR in the optional "220-\fItext\fR..." server
201 /* response that
202 /* \fBpostscreen\fR(8) sends ahead of the real Postfix SMTP server's "220
203 /* text..." response, in an attempt to confuse bad SMTP clients so
204 /* that they speak before their turn (pre-greet).
205 /* .IP "\fBpostscreen_greet_wait (normal: 6s, overload: 2s)\fR"
206 /* The amount of time that \fBpostscreen\fR(8) will wait for an SMTP
207 /* client to send a command before its turn, and for DNS blocklist
208 /* lookup results to arrive (default: up to 2 seconds under stress,
209 /* up to 6 seconds otherwise).
210 /* .IP "\fBsmtpd_service_name (smtpd)\fR"
211 /* The internal service that \fBpostscreen\fR(8) hands off allowed
212 /* connections to.
213 /* .PP
214 /* Available in Postfix version 2.11 and later:
215 /* .IP "\fBpostscreen_dnsbl_whitelist_threshold (0)\fR"
216 /* Allow a remote SMTP client to skip "before" and "after 220
217 /* greeting" protocol tests, based on its combined DNSBL score as
218 /* defined with the postscreen_dnsbl_sites parameter.
219 /* .PP
220 /* Available in Postfix version 3.0 and later:
221 /* .IP "\fBpostscreen_dnsbl_timeout (10s)\fR"
222 /* The time limit for DNSBL or DNSWL lookups.
223 /* AFTER 220 GREETING TESTS
224 /* .ad
225 /* .fi
226 /* These tests are executed after the remote SMTP client
227 /* receives the "220 servername" greeting. If a client passes
228 /* all tests during this phase, it will receive a 4XX response
229 /* to all RCPT TO commands. After the client reconnects, it
230 /* will be allowed to talk directly to a Postfix SMTP server
231 /* process.
232 /* .IP "\fBpostscreen_bare_newline_action (ignore)\fR"
233 /* The action that \fBpostscreen\fR(8) takes when a remote SMTP client sends
234 /* a bare newline character, that is, a newline not preceded by carriage
235 /* return.
236 /* .IP "\fBpostscreen_bare_newline_enable (no)\fR"
237 /* Enable "bare newline" SMTP protocol tests in the \fBpostscreen\fR(8)
238 /* server.
239 /* .IP "\fBpostscreen_disable_vrfy_command ($disable_vrfy_command)\fR"
240 /* Disable the SMTP VRFY command in the \fBpostscreen\fR(8) daemon.
241 /* .IP "\fBpostscreen_forbidden_commands ($smtpd_forbidden_commands)\fR"
242 /* List of commands that the \fBpostscreen\fR(8) server considers in
243 /* violation of the SMTP protocol.
244 /* .IP "\fBpostscreen_helo_required ($smtpd_helo_required)\fR"
245 /* Require that a remote SMTP client sends HELO or EHLO before
246 /* commencing a MAIL transaction.
247 /* .IP "\fBpostscreen_non_smtp_command_action (drop)\fR"
248 /* The action that \fBpostscreen\fR(8) takes when a remote SMTP client sends
249 /* non-SMTP commands as specified with the postscreen_forbidden_commands
250 /* parameter.
251 /* .IP "\fBpostscreen_non_smtp_command_enable (no)\fR"
252 /* Enable "non-SMTP command" tests in the \fBpostscreen\fR(8) server.
253 /* .IP "\fBpostscreen_pipelining_action (enforce)\fR"
254 /* The action that \fBpostscreen\fR(8) takes when a remote SMTP client
255 /* sends
256 /* multiple commands instead of sending one command and waiting for
257 /* the server to respond.
258 /* .IP "\fBpostscreen_pipelining_enable (no)\fR"
259 /* Enable "pipelining" SMTP protocol tests in the \fBpostscreen\fR(8)
260 /* server.
261 /* CACHE CONTROLS
262 /* .ad
263 /* .fi
264 /* .IP "\fBpostscreen_cache_cleanup_interval (12h)\fR"
265 /* The amount of time between \fBpostscreen\fR(8) cache cleanup runs.
266 /* .IP "\fBpostscreen_cache_map (btree:$data_directory/postscreen_cache)\fR"
267 /* Persistent storage for the \fBpostscreen\fR(8) server decisions.
268 /* .IP "\fBpostscreen_cache_retention_time (7d)\fR"
269 /* The amount of time that \fBpostscreen\fR(8) will cache an expired
270 /* temporary whitelist entry before it is removed.
271 /* .IP "\fBpostscreen_bare_newline_ttl (30d)\fR"
272 /* The amount of time that \fBpostscreen\fR(8) will use the result from
273 /* a successful "bare newline" SMTP protocol test.
274 /* .IP "\fBpostscreen_dnsbl_max_ttl (${postscreen_dnsbl_ttl?{$postscreen_dnsbl_ttl}:{1}}h)\fR"
275 /* The maximum amount of time that \fBpostscreen\fR(8) will use the
276 /* result from a successful DNS-based reputation test before a
277 /* client IP address is required to pass that test again.
278 /* .IP "\fBpostscreen_dnsbl_min_ttl (60s)\fR"
279 /* The minimum amount of time that \fBpostscreen\fR(8) will use the
280 /* result from a successful DNS-based reputation test before a
281 /* client IP address is required to pass that test again.
282 /* .IP "\fBpostscreen_greet_ttl (1d)\fR"
283 /* The amount of time that \fBpostscreen\fR(8) will use the result from
284 /* a successful PREGREET test.
285 /* .IP "\fBpostscreen_non_smtp_command_ttl (30d)\fR"
286 /* The amount of time that \fBpostscreen\fR(8) will use the result from
287 /* a successful "non_smtp_command" SMTP protocol test.
288 /* .IP "\fBpostscreen_pipelining_ttl (30d)\fR"
289 /* The amount of time that \fBpostscreen\fR(8) will use the result from
290 /* a successful "pipelining" SMTP protocol test.
291 /* RESOURCE CONTROLS
292 /* .ad
293 /* .fi
294 /* .IP "\fBline_length_limit (2048)\fR"
295 /* Upon input, long lines are chopped up into pieces of at most
296 /* this length; upon delivery, long lines are reconstructed.
297 /* .IP "\fBpostscreen_client_connection_count_limit ($smtpd_client_connection_count_limit)\fR"
298 /* How many simultaneous connections any remote SMTP client is
299 /* allowed to have
300 /* with the \fBpostscreen\fR(8) daemon.
301 /* .IP "\fBpostscreen_command_count_limit (20)\fR"
302 /* The limit on the total number of commands per SMTP session for
303 /* \fBpostscreen\fR(8)'s built-in SMTP protocol engine.
304 /* .IP "\fBpostscreen_command_time_limit (normal: 300s, overload: 10s)\fR"
305 /* The time limit to read an entire command line with \fBpostscreen\fR(8)'s
306 /* built-in SMTP protocol engine.
307 /* .IP "\fBpostscreen_post_queue_limit ($default_process_limit)\fR"
308 /* The number of clients that can be waiting for service from a
309 /* real Postfix SMTP server process.
310 /* .IP "\fBpostscreen_pre_queue_limit ($default_process_limit)\fR"
311 /* The number of non-whitelisted clients that can be waiting for
312 /* a decision whether they will receive service from a real Postfix
313 /* SMTP server
314 /* process.
315 /* .IP "\fBpostscreen_watchdog_timeout (10s)\fR"
316 /* How much time a \fBpostscreen\fR(8) process may take to respond to
317 /* a remote SMTP client command or to perform a cache operation before it
318 /* is terminated by a built-in watchdog timer.
319 /* STARTTLS CONTROLS
320 /* .ad
321 /* .fi
322 /* .IP "\fBpostscreen_tls_security_level ($smtpd_tls_security_level)\fR"
323 /* The SMTP TLS security level for the \fBpostscreen\fR(8) server; when
324 /* a non-empty value is specified, this overrides the obsolete parameters
325 /* postscreen_use_tls and postscreen_enforce_tls.
326 /* .IP "\fBtlsproxy_service_name (tlsproxy)\fR"
327 /* The name of the \fBtlsproxy\fR(8) service entry in master.cf.
328 /* OBSOLETE STARTTLS SUPPORT CONTROLS
329 /* .ad
330 /* .fi
331 /* These parameters are supported for compatibility with
332 /* \fBsmtpd\fR(8) legacy parameters.
333 /* .IP "\fBpostscreen_use_tls ($smtpd_use_tls)\fR"
334 /* Opportunistic TLS: announce STARTTLS support to remote SMTP clients,
335 /* but do not require that clients use TLS encryption.
336 /* .IP "\fBpostscreen_enforce_tls ($smtpd_enforce_tls)\fR"
337 /* Mandatory TLS: announce STARTTLS support to remote SMTP clients, and
338 /* require that clients use TLS encryption.
339 /* MISCELLANEOUS CONTROLS
340 /* .ad
341 /* .fi
342 /* .IP "\fBconfig_directory (see 'postconf -d' output)\fR"
343 /* The default location of the Postfix main.cf and master.cf
344 /* configuration files.
345 /* .IP "\fBdelay_logging_resolution_limit (2)\fR"
346 /* The maximal number of digits after the decimal point when logging
347 /* sub-second delay values.
348 /* .IP "\fBcommand_directory (see 'postconf -d' output)\fR"
349 /* The location of all postfix administrative commands.
350 /* .IP "\fBmax_idle (100s)\fR"
351 /* The maximum amount of time that an idle Postfix daemon process waits
352 /* for an incoming connection before terminating voluntarily.
353 /* .IP "\fBprocess_id (read-only)\fR"
354 /* The process ID of a Postfix command or daemon process.
355 /* .IP "\fBprocess_name (read-only)\fR"
356 /* The process name of a Postfix command or daemon process.
357 /* .IP "\fBsyslog_facility (mail)\fR"
358 /* The syslog facility of Postfix logging.
359 /* .IP "\fBsyslog_name (see 'postconf -d' output)\fR"
360 /* A prefix that is prepended to the process name in syslog
361 /* records, so that, for example, "smtpd" becomes "prefix/smtpd".
362 /* .PP
363 /* Available in Postfix 3.3 and later:
364 /* .IP "\fBservice_name (read-only)\fR"
365 /* The master.cf service name of a Postfix daemon process.
366 /* SEE ALSO
367 /* smtpd(8), Postfix SMTP server
368 /* tlsproxy(8), Postfix TLS proxy server
369 /* dnsblog(8), DNS black/whitelist logger
370 /* syslogd(8), system logging
371 /* README FILES
372 /* .ad
373 /* .fi
374 /* Use "\fBpostconf readme_directory\fR" or "\fBpostconf
375 /* html_directory\fR" to locate this information.
376 /* .nf
377 /* .na
378 /* POSTSCREEN_README, Postfix Postscreen Howto
379 /* LICENSE
380 /* .ad
381 /* .fi
382 /* The Secure Mailer license must be distributed with this software.
383 /* HISTORY
384 /* .ad
385 /* .fi
386 /* This service was introduced with Postfix version 2.8.
387 /*
388 /* Many ideas in \fBpostscreen\fR(8) were explored in earlier
389 /* work by Michael Tokarev, in OpenBSD spamd, and in MailChannels
390 /* Traffic Control.
391 /* AUTHOR(S)
392 /* Wietse Venema
393 /* IBM T.J. Watson Research
394 /* P.O. Box 704
395 /* Yorktown Heights, NY 10598, USA
396 /*
397 /* Wietse Venema
398 /* Google, Inc.
399 /* 111 8th Avenue
400 /* New York, NY 10011, USA
401 /*--*/
402 
403 /* System library. */
404 
405 #include <sys_defs.h>
406 #include <sys/stat.h>
407 #include <stdlib.h>
408 
409 /* Utility library. */
410 
411 #include <msg.h>
412 #include <mymalloc.h>
413 #include <events.h>
414 #include <myaddrinfo.h>
415 #include <dict_cache.h>
416 #include <set_eugid.h>
417 #include <vstream.h>
418 #include <name_code.h>
419 #include <inet_proto.h>
420 
421 /* Global library. */
422 
423 #include <mail_conf.h>
424 #include <mail_params.h>
425 #include <mail_version.h>
426 #include <mail_proto.h>
427 #include <data_redirect.h>
428 #include <string_list.h>
429 
430 /* Master server protocols. */
431 
432 #include <mail_server.h>
433 
434 /* Application-specific. */
435 
436 #include <postscreen.h>
437 
438  /*
439  * Configuration parameters.
440  */
445 
448 
451 
456 
463 
466 
473 
476 
479 
483 
492 
496 
500 
504 
507 
510 
513 
516 
519 
523 
524  /*
525  * Global variables.
526  */
527 int psc_check_queue_length; /* connections being checked */
528 int psc_post_queue_length; /* being sent to real SMTPD */
529 DICT_CACHE *psc_cache_map; /* cache table handle */
530 VSTRING *psc_temp; /* scratchpad */
531 char *psc_smtpd_service_name; /* path to real SMTPD */
532 int psc_pregr_action; /* PSC_ACT_DROP/ENFORCE/etc */
533 int psc_dnsbl_action; /* PSC_ACT_DROP/ENFORCE/etc */
534 int psc_pipel_action; /* PSC_ACT_DROP/ENFORCE/etc */
535 int psc_nsmtp_action; /* PSC_ACT_DROP/ENFORCE/etc */
536 int psc_barlf_action; /* PSC_ACT_DROP/ENFORCE/etc */
537 int psc_min_ttl; /* Update with new tests! */
538 STRING_LIST *psc_forbid_cmds; /* CONNECT GET POST */
539 int psc_stress_greet_wait; /* stressed greet wait */
540 int psc_normal_greet_wait; /* stressed greet wait */
541 int psc_stress_cmd_time_limit; /* stressed command limit */
542 int psc_normal_cmd_time_limit; /* normal command time limit */
543 int psc_stress; /* stress level */
544 int psc_lowat_check_queue_length; /* stress low-water mark */
545 int psc_hiwat_check_queue_length; /* stress high-water mark */
546 DICT *psc_dnsbl_reply; /* DNSBL name mapper */
547 HTABLE *psc_client_concurrency; /* per-client concurrency */
548 
549  /*
550  * Local variables and functions.
551  */
552 static ARGV *psc_acl; /* permanent white/backlist */
553 static int psc_blist_action; /* PSC_ACT_DROP/ENFORCE/etc */
554 static ADDR_MATCH_LIST *psc_wlist_if; /* whitelist interfaces */
555 
556 static void psc_endpt_lookup_done(int, VSTREAM *,
559 
560 /* psc_dump - dump some statistics before exit */
561 
562 static void psc_dump(char *unused_service, char **unused_argv)
563 {
564 
565  /*
566  * Dump preliminary cache cleanup statistics when the process commits
567  * suicide while a cache cleanup run is in progress. We can't currently
568  * distinguish between "postfix reload" (we should restart) or "maximal
569  * idle time reached" (we could finish the cache cleanup first).
570  */
571  if (psc_cache_map) {
572  dict_cache_close(psc_cache_map);
573  psc_cache_map = 0;
574  }
575 }
576 
577 /* psc_drain - delayed exit after "postfix reload" */
578 
579 static void psc_drain(char *unused_service, char **unused_argv)
580 {
581  int count;
582 
583  /*
584  * After "postfix reload", complete work-in-progress in the background,
585  * instead of dropping already-accepted connections on the floor.
586  *
587  * Unfortunately we must close all writable tables, so we can't store or
588  * look up reputation information. The reason is that we don't have any
589  * multi-writer safety guarantees. We also can't use the single-writer
590  * proxywrite service, because its latency guarantees are too weak.
591  *
592  * All error retry counts shall be limited. Instead of blocking here, we
593  * could retry failed fork() operations in the event call-back routines,
594  * but we don't need perfection. The host system is severely overloaded
595  * and service levels are already way down.
596  *
597  * XXX Some Berkeley DB versions break with close-after-fork. Every new
598  * version is an improvement over its predecessor.
599  *
600  * XXX Don't assume that it is OK to share the same LMDB lockfile descriptor
601  * between different processes.
602  */
603  if (psc_cache_map != 0 /* XXX && psc_cache_map
604  requires locking */ ) {
605  dict_cache_close(psc_cache_map);
606  psc_cache_map = 0;
607  }
608  for (count = 0; /* see below */ ; count++) {
609  if (count >= 5) {
610  msg_fatal("fork: %m");
611  } else if (event_server_drain() != 0) {
612  msg_warn("fork: %m");
613  sleep(1);
614  continue;
615  } else {
616  return;
617  }
618  }
619 }
620 
621 /* psc_service - handle new client connection */
622 
623 static void psc_service(VSTREAM *smtp_client_stream,
624  char *unused_service,
625  char **unused_argv)
626 {
627 
628  /*
629  * For sanity, require that at least one of INET or INET6 is enabled.
630  * Otherwise, we can't look up interface information, and we can't
631  * convert names or addresses.
632  */
633  if (inet_proto_info()->ai_family_list[0] == 0)
634  msg_fatal("all network protocols are disabled (%s = %s)",
636 
637  /*
638  * This program handles all incoming connections, so it must not block.
639  * We use event-driven code for all operations that introduce latency.
640  *
641  * Note: instead of using VSTREAM-level timeouts, we enforce limits on the
642  * total amount of time to receive a complete SMTP command line.
643  */
644  non_blocking(vstream_fileno(smtp_client_stream), NON_BLOCKING);
645 
646  /*
647  * Look up the remote SMTP client address and port.
648  */
649  psc_endpt_lookup(smtp_client_stream, psc_endpt_lookup_done);
650 }
651 
652 /* psc_endpt_lookup_done - endpoint lookup completed */
653 
654 static void psc_endpt_lookup_done(int endpt_status,
655  VSTREAM *smtp_client_stream,
656  MAI_HOSTADDR_STR *smtp_client_addr,
657  MAI_SERVPORT_STR *smtp_client_port,
658  MAI_HOSTADDR_STR *smtp_server_addr,
659  MAI_SERVPORT_STR *smtp_server_port)
660 {
661  const char *myname = "psc_endpt_lookup_done";
662  PSC_STATE *state;
663  const char *stamp_str;
664  int saved_flags;
665 
666  /*
667  * Best effort - if this non-blocking write(2) fails, so be it.
668  */
669  if (endpt_status < 0) {
670  (void) write(vstream_fileno(smtp_client_stream),
671  "421 4.3.2 No system resources\r\n",
672  sizeof("421 4.3.2 No system resources\r\n") - 1);
673  event_server_disconnect(smtp_client_stream);
674  return;
675  }
676  if (msg_verbose > 1)
677  msg_info("%s: sq=%d cq=%d connect from [%s]:%s",
679  smtp_client_addr->buf, smtp_client_port->buf);
680 
681  msg_info("CONNECT from [%s]:%s to [%s]:%s",
682  smtp_client_addr->buf, smtp_client_port->buf,
683  smtp_server_addr->buf, smtp_server_port->buf);
684 
685  /*
686  * Bundle up all the loose session pieces. This zeroes all flags and time
687  * stamps.
688  */
689  state = psc_new_session_state(smtp_client_stream, smtp_client_addr->buf,
690  smtp_client_port->buf,
691  smtp_server_addr->buf,
692  smtp_server_port->buf);
693 
694  /*
695  * Reply with 421 when the client has too many open connections.
696  */
697  if (var_psc_cconn_limit > 0
699  msg_info("NOQUEUE: reject: CONNECT from [%s]:%s: too many connections",
700  state->smtp_client_addr, state->smtp_client_port);
702  "421 4.7.0 Error: too many connections\r\n");
703  return;
704  }
705 
706  /*
707  * Reply with 421 when we can't forward more connections.
708  */
711  msg_info("NOQUEUE: reject: CONNECT from [%s]:%s: all server ports busy",
712  state->smtp_client_addr, state->smtp_client_port);
714  "421 4.3.2 All server ports are busy\r\n");
715  return;
716  }
717 
718  /*
719  * The permanent white/blacklist has highest precedence.
720  */
721  if (psc_acl != 0) {
722  switch (psc_acl_eval(state, psc_acl, VAR_PSC_ACL)) {
723 
724  /*
725  * Permanently blacklisted.
726  */
728  msg_info("BLACKLISTED [%s]:%s", PSC_CLIENT_ADDR_PORT(state));
730  switch (psc_blist_action) {
731  case PSC_ACT_DROP:
733  "521 5.3.2 Service currently unavailable\r\n");
734  return;
735  case PSC_ACT_ENFORCE:
737  "550 5.3.2 Service currently unavailable\r\n");
738  break;
739  case PSC_ACT_IGNORE:
741 
742  /*
743  * Not: PSC_PASS_SESSION_STATE. Repeat this test the next
744  * time.
745  */
746  break;
747  default:
748  msg_panic("%s: unknown blacklist action value %d",
749  myname, psc_blist_action);
750  }
751  break;
752 
753  /*
754  * Permanently whitelisted.
755  */
757  msg_info("WHITELISTED [%s]:%s", PSC_CLIENT_ADDR_PORT(state));
758  psc_conclude(state);
759  return;
760 
761  /*
762  * Other: dunno (don't know) or error.
763  */
764  default:
765  break;
766  }
767  }
768 
769  /*
770  * The temporary whitelist (i.e. the postscreen cache) has the lowest
771  * precedence. This cache contains information about the results of prior
772  * tests. Whitelist the client when all enabled test results are still
773  * valid.
774  */
775  if ((state->flags & PSC_STATE_MASK_ANY_FAIL) == 0
776  && state->client_info->concurrency == 1
777  && psc_cache_map != 0
778  && (stamp_str = psc_cache_lookup(psc_cache_map, state->smtp_client_addr)) != 0) {
779  saved_flags = state->flags;
780  psc_parse_tests(state, stamp_str, event_time());
781  state->flags |= saved_flags;
782  if (msg_verbose)
783  msg_info("%s: cached + recent flags: %s",
784  myname, psc_print_state_flags(state->flags, myname));
785  if ((state->flags & PSC_STATE_MASK_ANY_TODO_FAIL) == 0) {
786  msg_info("PASS OLD [%s]:%s", PSC_CLIENT_ADDR_PORT(state));
787  psc_conclude(state);
788  return;
789  }
790  } else if (state->client_info->concurrency > 1) {
791  saved_flags = state->flags;
792  psc_todo_tests(state, event_time());
793  state->flags |= saved_flags;
794  if (msg_verbose)
795  msg_info("%s: new + recent flags: %s",
796  myname, psc_print_state_flags(state->flags, myname));
797  } else {
798  saved_flags = state->flags;
799  psc_new_tests(state);
800  state->flags |= saved_flags;
801  if (msg_verbose)
802  msg_info("%s: new + recent flags: %s",
803  myname, psc_print_state_flags(state->flags, myname));
804  }
805 
806  /*
807  * Don't whitelist clients that connect to backup MX addresses. Fail
808  * "closed" on error.
809  */
810  if (addr_match_list_match(psc_wlist_if, smtp_server_addr->buf) == 0) {
812  msg_info("WHITELIST VETO [%s]:%s", PSC_CLIENT_ADDR_PORT(state));
813  }
814 
815  /*
816  * Reply with 421 when we can't analyze more connections. That also means
817  * no deep protocol tests when the noforward flag is raised.
818  */
822  msg_info("reject: connect from [%s]:%s: all screening ports busy",
823  state->smtp_client_addr, state->smtp_client_port);
825  "421 4.3.2 All screening ports are busy\r\n");
826  return;
827  }
828 
829  /*
830  * If the client has no up-to-date results for some tests, do those tests
831  * first. Otherwise, skip the tests and hand off the connection.
832  */
833  if (state->flags & PSC_STATE_MASK_EARLY_TODO)
834  psc_early_tests(state);
836  psc_smtpd_tests(state);
837  else
838  psc_conclude(state);
839 }
840 
841 /* psc_cache_validator - validate one cache entry */
842 
843 static int psc_cache_validator(const char *client_addr,
844  const char *stamp_str,
845  void *unused_context)
846 {
847  PSC_STATE dummy_state;
848  PSC_CLIENT_INFO dummy_client_info;
849 
850  /*
851  * This function is called by the cache cleanup pseudo thread.
852  *
853  * When an entry is removed from the cache, the client will be reported as
854  * "NEW" in the next session where it passes all tests again. To avoid
855  * silly logging we remove the cache entry only after all tests have
856  * expired longer ago than the cache retention time.
857  */
858  dummy_state.client_info = &dummy_client_info;
859  psc_parse_tests(&dummy_state, stamp_str, event_time() - var_psc_cache_ret);
860  return ((dummy_state.flags & PSC_STATE_MASK_ANY_TODO) == 0);
861 }
862 
863 /* pre_jail_init - pre-jail initialization */
864 
865 static void pre_jail_init(char *unused_name, char **unused_argv)
866 {
867  VSTRING *redirect;
868 
869  /*
870  * Open read-only maps before dropping privilege, for consistency with
871  * other Postfix daemons.
872  */
874  if (*var_psc_acl)
876  /* Ignore smtpd_forbid_cmds lookup errors. Non-critical feature. */
877  if (*var_psc_forbid_cmds)
881  if (*var_psc_dnsbl_reply)
882  psc_dnsbl_reply = dict_open(var_psc_dnsbl_reply, O_RDONLY,
884 
885  /*
886  * Never, ever, get killed by a master signal, as that would corrupt the
887  * database when we're in the middle of an update.
888  */
889  if (setsid() < 0)
890  msg_warn("setsid: %m");
891 
892  /*
893  * Security: don't create root-owned files that contain untrusted data.
894  * And don't create Postfix-owned files in root-owned directories,
895  * either. We want a correct relationship between (file or directory)
896  * ownership and (file or directory) content. To open files before going
897  * to jail, temporarily drop root privileges.
898  */
900  redirect = vstring_alloc(100);
901 
902  /*
903  * Keep state in persistent external map. As a safety measure we sync the
904  * database on each update. This hurts on LINUX file systems that sync
905  * all dirty disk blocks whenever any application invokes fsync().
906  *
907  * Start the cache maintenance pseudo thread after dropping privileges.
908  */
909 #define PSC_DICT_OPEN_FLAGS (DICT_FLAG_DUP_REPLACE | DICT_FLAG_SYNC_UPDATE | \
910  DICT_FLAG_OPEN_LOCK)
911 
912  if (*var_psc_cache_map)
913  psc_cache_map =
915  O_CREAT | O_RDWR, PSC_DICT_OPEN_FLAGS);
916 
917  /*
918  * Clean up and restore privilege.
919  */
920  vstring_free(redirect);
922 
923  /*
924  * Initialize the dummy SMTP engine.
925  */
927 }
928 
929 /* pre_accept - see if tables have changed */
930 
931 static void pre_accept(char *unused_name, char **unused_argv)
932 {
933  static time_t last_event_time;
934  time_t new_event_time;
935  const char *name;
936 
937  /*
938  * If some table has changed then stop accepting new connections. Don't
939  * check the tables more than once a second.
940  */
941  new_event_time = event_time();
942  if (new_event_time >= last_event_time + 1
943  && (name = dict_changed_name()) != 0) {
944  msg_info("table %s has changed - finishing in the background", name);
946  } else {
947  last_event_time = new_event_time;
948  }
949 }
950 
951 /* post_jail_init - post-jail initialization */
952 
953 static void post_jail_init(char *unused_name, char **unused_argv)
954 {
955  const NAME_CODE actions[] = {
959  PSC_NAME_ACT_CONT, PSC_ACT_IGNORE, /* compatibility */
960  0, -1,
961  };
962  int cache_flags;
963  const char *tmp;
964 
965  /*
966  * This routine runs after the skeleton code has entered the chroot jail.
967  * Prevent automatic process suicide after a limited number of client
968  * requests. It is OK to terminate after a limited amount of idle time.
969  */
970  var_use_limit = 0;
971 
972  /*
973  * Workaround for parameters whose values may contain "$", and that have
974  * a default of "$parametername". Not sure if it would be a good idea to
975  * always to this in the mail_conf_raw(3) module.
976  */
977  if (*var_psc_rej_footer == '$'
982  }
983  if (*var_psc_exp_filter == '$'
988  }
989 
990  /*
991  * Other one-time initialization.
992  */
993  psc_temp = vstring_alloc(10);
995  psc_smtpd_service_name = mystrdup(STR(psc_temp));
996  psc_dnsbl_init();
997  psc_early_init();
998  psc_smtpd_init();
999 
1000  if ((psc_blist_action = name_code(actions, NAME_CODE_FLAG_NONE,
1001  var_psc_blist_action)) < 0)
1002  msg_fatal("bad %s value: %s", VAR_PSC_BLIST_ACTION,
1005  var_psc_dnsbl_action)) < 0)
1006  msg_fatal("bad %s value: %s", VAR_PSC_DNSBL_ACTION,
1009  var_psc_pregr_action)) < 0)
1010  msg_fatal("bad %s value: %s", VAR_PSC_PREGR_ACTION,
1013  var_psc_pipel_action)) < 0)
1014  msg_fatal("bad %s value: %s", VAR_PSC_PIPEL_ACTION,
1017  var_psc_nsmtp_action)) < 0)
1018  msg_fatal("bad %s value: %s", VAR_PSC_NSMTP_ACTION,
1021  var_psc_barlf_action)) < 0)
1022  msg_fatal("bad %s value: %s", VAR_PSC_BARLF_ACTION,
1024  /* Fail "closed" on error. */
1027 
1028  /*
1029  * Start the cache maintenance pseudo thread last. Early cleanup makes
1030  * verbose logging more informative (we get positive confirmation that
1031  * the cleanup thread runs).
1032  */
1033  cache_flags = DICT_CACHE_FLAG_STATISTICS;
1034  if (msg_verbose > 1)
1035  cache_flags |= DICT_CACHE_FLAG_VERBOSE;
1036  if (psc_cache_map != 0 && var_psc_cache_scan > 0)
1037  dict_cache_control(psc_cache_map,
1038  CA_DICT_CACHE_CTL_FLAGS(cache_flags),
1040  CA_DICT_CACHE_CTL_VALIDATOR(psc_cache_validator),
1041  CA_DICT_CACHE_CTL_CONTEXT((void *) 0),
1043 
1044  /*
1045  * Pre-compute the minimal and maximal TTL.
1046  */
1047  psc_min_ttl =
1051 
1052  /*
1053  * Pre-compute the stress and normal command time limits.
1054  */
1055  mail_conf_update(VAR_STRESS, "yes");
1060 
1066 
1069  if (msg_verbose)
1070  msg_info(VAR_PSC_CMD_TIME ": stress=%d normal=%d lowat=%d hiwat=%d",
1073 
1075  msg_panic("compiler error: 0.7 * %d = %d", var_psc_pre_queue_limit,
1078  msg_panic("compiler error: 0.9 * %d = %d", var_psc_pre_queue_limit,
1080 
1081  /*
1082  * Per-client concurrency.
1083  */
1084  psc_client_concurrency = htable_create(var_psc_pre_queue_limit);
1085 }
1086 
1088 
1089 /* main - pass control to the multi-threaded skeleton */
1090 
1091 int main(int argc, char **argv)
1092 {
1093 
1094  /*
1095  * List smtpd(8) parameters before any postscreen(8) parameters that have
1096  * defaults dependencies on them.
1097  */
1098  static const CONFIG_STR_TABLE str_table[] = {
1126  0,
1127  };
1128  static const CONFIG_INT_TABLE int_table[] = {
1133  0,
1134  };
1135  static const CONFIG_NINT_TABLE nint_table[] = {
1139  0,
1140  };
1141  static const CONFIG_TIME_TABLE time_table[] = {
1154 
1155  0,
1156  };
1157  static const CONFIG_BOOL_TABLE bool_table[] = {
1165  0,
1166  };
1167  static const CONFIG_RAW_TABLE raw_table[] = {
1173  0,
1174  };
1175  static const CONFIG_NBOOL_TABLE nbool_table[] = {
1180  0,
1181  };
1182 
1183  /*
1184  * Fingerprint executables and core dumps.
1185  */
1187 
1188  event_server_main(argc, argv, psc_service,
1189  CA_MAIL_SERVER_STR_TABLE(str_table),
1190  CA_MAIL_SERVER_INT_TABLE(int_table),
1191  CA_MAIL_SERVER_NINT_TABLE(nint_table),
1192  CA_MAIL_SERVER_TIME_TABLE(time_table),
1193  CA_MAIL_SERVER_BOOL_TABLE(bool_table),
1194  CA_MAIL_SERVER_RAW_TABLE(raw_table),
1195  CA_MAIL_SERVER_NBOOL_TABLE(nbool_table),
1196  CA_MAIL_SERVER_PRE_INIT(pre_jail_init),
1197  CA_MAIL_SERVER_POST_INIT(post_jail_init),
1198  CA_MAIL_SERVER_PRE_ACCEPT(pre_accept),
1200  CA_MAIL_SERVER_SLOW_EXIT(psc_drain),
1201  CA_MAIL_SERVER_EXIT(psc_dump),
1203  0);
1204 }
int var_psc_pregr_ttl
Definition: postscreen.c:482
#define DEF_SMTPD_ENFORCE_TLS
Definition: mail_params.h:1276
int msg_verbose
Definition: msg.c:177
PSC_CLIENT_INFO * client_info
Definition: postscreen.h:83
int var_psc_uproxy_tmout
Definition: postscreen.c:522
#define DEF_PSC_DNSBL_REPLY
Definition: mail_params.h:3665
char * var_psc_forbid_cmds
Definition: postscreen.c:450
#define DEF_PSC_UPROXY_TMOUT
Definition: mail_params.h:3787
#define RESTORE_SAVED_EUGID()
Definition: set_eugid.h:28
#define CA_MAIL_SERVER_WATCHDOG(v)
Definition: mail_server.h:73
#define DEF_PSC_GREET_WAIT
Definition: mail_params.h:3617
void myfree(void *ptr)
Definition: mymalloc.c:207
#define MATCH_FLAG_RETURN
Definition: match_list.h:40
#define PSC_ACL_ACT_WHITELIST
Definition: postscreen.h:569
#define VAR_PSC_NSMTP_ACTION
Definition: mail_params.h:3688
#define CA_MAIL_SERVER_BOOL_TABLE(v)
Definition: mail_server.h:58
char * var_psc_cache_map
Definition: postscreen.c:467
#define addr_match_list_match(l, a)
char * var_smtpd_service
Definition: postscreen.c:441
#define CA_MAIL_SERVER_RAW_TABLE(v)
Definition: mail_server.h:60
char * mystrdup(const char *str)
Definition: mymalloc.c:225
char * var_smtpd_exp_filter
Definition: postscreen.c:517
#define DEF_PSC_DNSBL_TMOUT
Definition: mail_params.h:3669
#define VAR_SMTPD_CMD_FILTER
Definition: mail_params.h:1259
#define VAR_PSC_BARLF_ACTION
Definition: mail_params.h:3700
int psc_pipel_action
Definition: postscreen.c:534
bool var_psc_disable_vrfy
Definition: postscreen.c:464
#define VAR_PSC_DNSBL_SITES
Definition: mail_params.h:3636
#define PSC_STATE_MASK_ANY_FAIL
Definition: postscreen.h:269
#define PSC_FAIL_SESSION_STATE(state, bits)
Definition: postscreen.h:422
#define VAR_SMTPD_FORBID_CMDS
Definition: mail_params.h:1255
Definition: argv.h:17
#define VAR_PSC_DISABLE_VRFY
Definition: mail_params.h:3752
NORETURN msg_panic(const char *fmt,...)
Definition: msg.c:295
char * var_smtpd_ehlo_dis_maps
Definition: postscreen.c:453
#define CA_MAIL_SERVER_STR_TABLE(v)
Definition: mail_server.h:57
#define DEF_PSC_NSMTP_ENABLE
Definition: mail_params.h:3685
#define DEF_PSC_PIPEL_ACTION
Definition: mail_params.h:3677
#define inet_proto_info()
Definition: inet_proto.h:29
#define STRING_LIST
Definition: string_list.h:22
char * data_redirect_map(VSTRING *result, const char *map)
#define psc_acl_parse
Definition: postscreen.h:575
char * smtp_client_port
Definition: postscreen.h:75
#define DEF_PSC_CMD_COUNT
Definition: mail_params.h:3713
#define VAR_STRESS
Definition: mail_params.h:3532
#define VAR_PSC_POST_QLIMIT
Definition: mail_params.h:3600
#define psc_acl_pre_jail_init
Definition: postscreen.h:574
STRING_LIST * psc_forbid_cmds
Definition: postscreen.c:538
int var_psc_dnsbl_thresh
Definition: postscreen.c:486
#define DEF_PSC_PREGR_BANNER
Definition: mail_params.h:3621
char * var_psc_uproxy_proto
Definition: postscreen.c:521
#define SAVE_AND_SET_EUGID(uid, gid)
Definition: set_eugid.h:23
#define DEF_SMTPD_REJ_FOOTER
Definition: mail_params.h:3921
char * var_psc_cmd_time
Definition: postscreen.c:506
#define VAR_SMTPD_CCONN_LIMIT
Definition: mail_params.h:3061
#define VAR_SMTPD_BANNER
Definition: mail_params.h:1211
#define CA_MAIL_SERVER_SLOW_EXIT(v)
Definition: mail_server.h:75
bool var_helo_required
Definition: postscreen.c:444
#define VAR_PSC_CMD_TIME
Definition: mail_params.h:3716
#define CA_MAIL_SERVER_EXIT(v)
Definition: mail_server.h:67
#define DEF_PSC_ACL
Definition: mail_params.h:3773
#define DEF_PSC_BARLF_TTL
Definition: mail_params.h:3705
int var_psc_dnsbl_tmout
Definition: postscreen.c:491
#define PSC_DICT_OPEN_FLAGS
#define DEF_SMTPD_USE_TLS
Definition: mail_params.h:1272
#define DEF_SMTPD_TLS_LEVEL
Definition: mail_params.h:1268
DICT * dict_open(const char *, int, int)
Definition: dict_open.c:421
#define DEF_PSC_PREGR_ACTION
Definition: mail_params.h:3629
char * var_psc_rej_footer
Definition: postscreen.c:512
const char * mail_conf_lookup(const char *name)
Definition: mail_conf.c:255
int psc_check_queue_length
Definition: postscreen.c:527
#define PSC_UNFAIL_SESSION_STATE(state, bits)
Definition: postscreen.h:450
#define CA_DICT_CACHE_CTL_INTERVAL(v)
Definition: dict_cache.h:48
#define VAR_PSC_BLIST_ACTION
Definition: mail_params.h:3708
int flags
Definition: postscreen.h:70
#define DEF_PSC_CMD_TIME
Definition: mail_params.h:3717
int var_psc_dnsbl_max_ttl
Definition: postscreen.c:490
Definition: htable.h:25
#define DEF_PSC_EXP_FILTER
Definition: mail_params.h:3765
int var_psc_cache_scan
Definition: postscreen.c:468
#define VAR_DNSBLOG_SERVICE
Definition: mail_params.h:3790
char * var_psc_pregr_banner
Definition: postscreen.c:480
#define DEF_PSC_CACHE_RET
Definition: mail_params.h:3609
#define DEF_SMTPD_EHLO_DIS_MAPS
Definition: mail_params.h:3126
char * var_smtpd_ehlo_dis_words
Definition: postscreen.c:452
#define DEF_PSC_PREGR_TTL
Definition: mail_params.h:3633
int psc_barlf_action
Definition: postscreen.c:536
int var_psc_watchdog
Definition: postscreen.c:472
#define VAR_SMTPD_SERVICE
Definition: mail_params.h:3596
#define DEF_DISABLE_VRFY_CMD
Definition: mail_params.h:424
bool var_psc_pipel_enable
Definition: postscreen.c:493
#define DEF_PSC_TLS_LEVEL
Definition: mail_params.h:3733
#define DEF_SMTPD_SERVICE
Definition: mail_params.h:3597
#define PSC_STATE_FLAG_WLIST_FAIL
Definition: postscreen.h:119
#define DEF_PSC_DNSBL_WTHRESH
Definition: mail_params.h:3645
int var_psc_dnsbl_wthresh
Definition: postscreen.c:487
#define DEF_PSC_BARLF_ACTION
Definition: mail_params.h:3701
#define DEF_PSC_PIPEL_TTL
Definition: mail_params.h:3681
void psc_smtpd_init(void)
#define string_list_init(o, f, p)
Definition: string_list.h:24
#define DEF_PSC_USE_TLS
Definition: mail_params.h:3737
#define DEF_HELO_REQUIRED
Definition: mail_params.h:2074
#define VAR_PSC_ENFORCE_TLS
Definition: mail_params.h:3740
int var_psc_pipel_ttl
Definition: postscreen.c:495
char * var_tlsproxy_service
Definition: postscreen.c:509
HTABLE * htable_create(ssize_t size)
Definition: htable.c:179
Definition: dict.h:78
#define CA_DICT_CACHE_CTL_FLAGS(v)
Definition: dict_cache.h:47
void psc_early_tests(PSC_STATE *)
int event_server_drain(void)
Definition: event_server.c:305
#define DEF_PSC_ENFORCE_TLS
Definition: mail_params.h:3741
#define VAR_PSC_BARLF_ENABLE
Definition: mail_params.h:3696
#define CA_MAIL_SERVER_POST_INIT(v)
Definition: mail_server.h:65
void psc_smtpd_pre_jail_init(void)
const char * psc_cache_lookup(DICT_CACHE *, const char *)
#define CA_MAIL_SERVER_INT_TABLE(v)
Definition: mail_server.h:56
char * var_psc_pregr_action
Definition: postscreen.c:481
#define PSC_NAME_ACT_CONT
Definition: postscreen.h:354
#define PSC_NAME_ACT_IGNORE
Definition: postscreen.h:353
char * var_psc_tls_level
Definition: postscreen.c:460
int var_psc_cconn_limit
Definition: postscreen.c:515
char buf[MAI_HOSTADDR_STRSIZE]
Definition: myaddrinfo.h:146
#define VAR_PSC_DNSBL_REPLY
Definition: mail_params.h:3664
bool var_psc_barlf_enable
Definition: postscreen.c:501
void psc_early_init(void)
#define VAR_PSC_DNSBL_WTHRESH
Definition: mail_params.h:3644
#define VAR_SMTPD_REJ_FOOTER
Definition: mail_params.h:3920
char * var_psc_ehlo_dis_maps
Definition: postscreen.c:455
#define ADDR_MATCH_LIST
#define VAR_PSC_DNSBL_MIN_TTL
Definition: mail_params.h:3656
#define PSC_STATE_MASK_ANY_TODO
Definition: postscreen.h:277
#define DICT_CACHE_FLAG_VERBOSE
Definition: dict_cache.h:35
#define DEF_PSC_PRE_QLIMIT
Definition: mail_params.h:3605
#define DEF_SMTPD_EHLO_DIS_WORDS
Definition: mail_params.h:3122
#define PSC_CLIENT_ADDR_PORT(state)
Definition: postscreen.h:414
#define DEF_PSC_BLIST_ACTION
Definition: mail_params.h:3709
#define PSC_STATE_FLAG_BLIST_FAIL
Definition: postscreen.h:116
char * var_dnsblog_service
Definition: postscreen.c:508
gid_t var_owner_gid
Definition: mail_params.c:235
uid_t var_owner_uid
Definition: mail_params.c:234
#define VAR_SMTPD_USE_TLS
Definition: mail_params.h:1271
#define DEF_DNSBLOG_SERVICE
Definition: mail_params.h:3791
PSC_STATE * psc_new_session_state(VSTREAM *, const char *, const char *, const char *, const char *)
#define PSC_STATE_MASK_SMTPD_TODO
Definition: postscreen.h:256
char * smtp_client_addr
Definition: postscreen.h:74
#define VAR_PSC_EHLO_DIS_WORDS
Definition: mail_params.h:3724
const char * dict_changed_name(void)
Definition: dict.c:583
#define PSC_ENFORCE_SESSION_STATE(state, reply)
Definition: postscreen.h:439
int var_psc_cache_ret
Definition: postscreen.c:469
void psc_conclude(PSC_STATE *)
char * var_psc_wlist_if
Definition: postscreen.c:520
char * var_psc_dnsbl_sites
Definition: postscreen.c:484
bool var_psc_nsmtp_enable
Definition: postscreen.c:497
#define DEF_SMTPD_FORBID_CMDS
Definition: mail_params.h:1256
#define VAR_PSC_DNSBL_ACTION
Definition: mail_params.h:3652
#define VAR_PSC_CMD_COUNT
Definition: mail_params.h:3712
int psc_stress_cmd_time_limit
Definition: postscreen.c:541
#define VAR_PSC_PREGR_BANNER
Definition: mail_params.h:3620
#define PSC_MIN(x, y)
Definition: postscreen.h:510
#define VAR_SMTPD_EHLO_DIS_MAPS
Definition: mail_params.h:3125
#define VAR_PSC_CMD_FILTER
Definition: mail_params.h:3768
#define VAR_SMTPD_EHLO_DIS_WORDS
Definition: mail_params.h:3121
#define VAR_PSC_PIPEL_ACTION
Definition: mail_params.h:3676
#define STR(x)
Definition: anvil.c:518
#define VAR_PSC_WLIST_IF
Definition: mail_params.h:3776
void msg_warn(const char *fmt,...)
Definition: msg.c:215
char * var_psc_ehlo_dis_words
Definition: postscreen.c:454
#define DEF_PSC_BARLF_ENABLE
Definition: mail_params.h:3697
VSTRING * vstring_alloc(ssize_t len)
Definition: vstring.c:353
#define CA_DICT_CACHE_CTL_END
Definition: dict_cache.h:46
#define NAME_CODE_FLAG_NONE
Definition: name_code.h:22
#define CA_DICT_CACHE_CTL_VALIDATOR(v)
Definition: dict_cache.h:49
#define VAR_PSC_PREGR_TTL
Definition: mail_params.h:3632
#define VAR_PSC_FORBID_CMDS
Definition: mail_params.h:3744
#define VAR_PSC_USE_TLS
Definition: mail_params.h:3736
int var_use_limit
Definition: mail_params.c:248
#define CA_MAIL_SERVER_NBOOL_TABLE(v)
Definition: mail_server.h:62
char * var_mynetworks
Definition: mail_params.c:261
void psc_new_tests(PSC_STATE *)
void psc_todo_tests(PSC_STATE *, time_t)
#define VAR_PSC_DNSBL_THRESH
Definition: mail_params.h:3640
#define MAIL_VERSION_STAMP_ALLOCATE
Definition: mail_version.h:67
NORETURN event_server_main(int argc, char **argv, MULTI_SERVER_FN service,...)
Definition: event_server.c:534
#define DEF_PSC_DNSBL_MAX_TTL
Definition: mail_params.h:3661
#define VAR_INET_PROTOCOLS
Definition: mail_params.h:994
char * var_smtpd_tls_level
Definition: postscreen.c:457
#define DEF_PSC_NSMTP_TTL
Definition: mail_params.h:3693
#define PSC_ACT_ENFORCE
Definition: postscreen.h:357
void dict_cache_close(DICT_CACHE *cp)
Definition: dict_cache.c:656
VSTRING * vstring_sprintf(VSTRING *vp, const char *format,...)
Definition: vstring.c:602
#define DEF_SMTPD_CCONN_LIMIT
Definition: mail_params.h:3062
int psc_stress_greet_wait
Definition: postscreen.c:539
#define PSC_ACT_IGNORE
Definition: postscreen.h:358
#define DEF_PSC_CACHE_MAP
Definition: mail_params.h:3593
#define VAR_PSC_REJ_FOOTER
Definition: mail_params.h:3760
#define CA_DICT_CACHE_CTL_CONTEXT(v)
Definition: dict_cache.h:50
#define CA_MAIL_SERVER_TIME_TABLE(v)
Definition: mail_server.h:59
void event_server_disconnect(VSTREAM *stream)
Definition: event_server.c:335
int psc_normal_greet_wait
Definition: postscreen.c:540
#define DEF_TLSPROXY_SERVICE
Definition: mail_params.h:3799
int var_psc_nsmtp_ttl
Definition: postscreen.c:499
#define PSC_DROP_SESSION_STATE(state, reply)
Definition: postscreen.h:432
#define PSC_STATE_FLAG_NOFORWARD
Definition: postscreen.h:112
#define VAR_PSC_NSMTP_ENABLE
Definition: mail_params.h:3684
int psc_nsmtp_action
Definition: postscreen.c:535
#define DICT_FLAG_DUP_WARN
Definition: dict.h:110
int var_psc_cmd_count
Definition: postscreen.c:505
int name_code(const NAME_CODE *table, int flags, const char *name)
Definition: name_code.c:65
#define DEF_PSC_DISABLE_VRFY
Definition: mail_params.h:3753
#define VAR_PSC_PIPEL_TTL
Definition: mail_params.h:3680
NORETURN msg_fatal(const char *fmt,...)
Definition: msg.c:249
bool var_psc_use_tls
Definition: postscreen.c:461
int var_psc_post_queue_limit
Definition: postscreen.c:470
#define VAR_PSC_UPROXY_PROTO
Definition: mail_params.h:3782
DICT * psc_dnsbl_reply
Definition: postscreen.c:546
VSTRING * psc_temp
Definition: postscreen.c:530
int psc_stress
Definition: postscreen.c:543
#define VAR_TLSPROXY_SERVICE
Definition: mail_params.h:3798
bool var_psc_enforce_tls
Definition: postscreen.c:462
char * var_psc_barlf_action
Definition: postscreen.c:502
bool var_smtpd_enforce_tls
Definition: postscreen.c:459
time_t event_time(void)
Definition: events.c:647
#define VAR_PSC_HELO_REQUIRED
Definition: mail_params.h:3748
#define VAR_PSC_NSMTP_TTL
Definition: mail_params.h:3692
char * var_smtpd_rej_footer
Definition: postscreen.c:511
int var_psc_greet_wait
Definition: postscreen.c:478
#define CA_MAIL_SERVER_NINT_TABLE(v)
Definition: mail_server.h:61
char * var_smtpd_cmd_filter
Definition: postscreen.c:446
void psc_smtpd_tests(PSC_STATE *)
#define DEF_PSC_DNSBL_MIN_TTL
Definition: mail_params.h:3657
#define VAR_PSC_TLS_LEVEL
Definition: mail_params.h:3732
#define VAR_PSC_DNSBL_TMOUT
Definition: mail_params.h:3668
#define VAR_PSC_CACHE_SCAN
Definition: mail_params.h:3612
int var_smtpd_cconn_limit
Definition: postscreen.c:514
#define NON_BLOCKING
Definition: iostuff.h:49
#define DEF_PSC_EHLO_DIS_WORDS
Definition: mail_params.h:3725
#define VAR_SMTPD_EXP_FILTER
Definition: mail_params.h:2343
char * var_psc_greet_ttl
Definition: postscreen.c:477
#define DEF_PSC_NSMTP_ACTION
Definition: mail_params.h:3689
#define DEF_PSC_DNSBL_SITES
Definition: mail_params.h:3637
#define DEF_PSC_PIPEL_ENABLE
Definition: mail_params.h:3673
#define VAR_SMTPD_TLS_LEVEL
Definition: mail_params.h:1267
#define DEF_PSC_POST_QLIMIT
Definition: mail_params.h:3601
int psc_hiwat_check_queue_length
Definition: postscreen.c:545
#define PSC_STATE_MASK_EARLY_TODO
Definition: postscreen.h:249
#define VAR_HELO_REQUIRED
Definition: mail_params.h:2073
#define VAR_PSC_PRE_QLIMIT
Definition: mail_params.h:3604
#define DEF_SMTPD_CMD_FILTER
Definition: mail_params.h:1260
void psc_endpt_lookup(VSTREAM *, PSC_ENDPT_LOOKUP_FN)
#define VAR_PSC_PREGR_ACTION
Definition: mail_params.h:3628
int non_blocking(int, int)
Definition: non_blocking.c:55
#define DICT_CACHE_FLAG_STATISTICS
Definition: dict_cache.h:36
char * var_psc_acl
Definition: postscreen.c:474
#define DEF_PSC_CMD_FILTER
Definition: mail_params.h:3769
#define DEF_PSC_WATCHDOG
Definition: mail_params.h:3721
#define VAR_DISABLE_VRFY_CMD
Definition: mail_params.h:423
#define VAR_PSC_UPROXY_TMOUT
Definition: mail_params.h:3786
VSTRING * vstring_free(VSTRING *vp)
Definition: vstring.c:380
#define DEF_PSC_CCONN_LIMIT
Definition: mail_params.h:3757
#define VAR_PSC_BARLF_TTL
Definition: mail_params.h:3704
#define VAR_PSC_EHLO_DIS_MAPS
Definition: mail_params.h:3728
char * var_psc_blist_action
Definition: postscreen.c:475
char * var_smtpd_forbid_cmds
Definition: postscreen.c:449
DICT_CACHE * psc_cache_map
Definition: postscreen.c:529
#define DEF_SMTPD_BANNER
Definition: mail_params.h:1212
#define DEF_PSC_WLIST_IF
Definition: mail_params.h:3777
#define CA_MAIL_SERVER_SOLITARY
Definition: mail_server.h:69
char * var_psc_exp_filter
Definition: postscreen.c:518
#define vstream_fileno(vp)
Definition: vstream.h:115
bool var_psc_helo_required
Definition: postscreen.c:465
#define psc_acl_eval(s, a, p)
Definition: postscreen.h:576
#define PSC_STATE_MASK_ANY_TODO_FAIL
Definition: postscreen.h:280
#define PSC_NAME_ACT_ENFORCE
Definition: postscreen.h:352
#define VAR_PSC_ACL
Definition: mail_params.h:3772
char * var_inet_protocols
Definition: mail_params.c:260
int var_psc_pre_queue_limit
Definition: postscreen.c:471
#define VAR_PSC_CCONN_LIMIT
Definition: mail_params.h:3756
#define VAR_PSC_CACHE_RET
Definition: mail_params.h:3608
int get_mail_conf_time(const char *, const char *, int, int)
#define addr_match_list_init(o, f, p)
#define VAR_PSC_CACHE_MAP
Definition: mail_params.h:3592
DICT_CACHE * dict_cache_open(const char *dbname, int open_flags, int dict_flags)
Definition: dict_cache.c:621
bool var_disable_vrfy_cmd
Definition: postscreen.c:443
char * var_psc_nsmtp_action
Definition: postscreen.c:498
HTABLE * psc_client_concurrency
Definition: postscreen.c:547
int psc_min_ttl
Definition: postscreen.c:537
int psc_pregr_action
Definition: postscreen.c:532
char buf[MAI_SERVPORT_STRSIZE]
Definition: myaddrinfo.h:154
char * var_psc_cmd_filter
Definition: postscreen.c:447
#define VAR_PSC_GREET_WAIT
Definition: mail_params.h:3616
void psc_dnsbl_init(void)
#define CA_MAIL_SERVER_PRE_ACCEPT(v)
Definition: mail_server.h:68
#define VAR_PSC_PIPEL_ENABLE
Definition: mail_params.h:3672
#define VAR_PSC_EXP_FILTER
Definition: mail_params.h:3764
#define DEF_SMTPD_EXP_FILTER
Definition: mail_params.h:2344
char * var_smtpd_banner
Definition: postscreen.c:442
int psc_lowat_check_queue_length
Definition: postscreen.c:544
int psc_dnsbl_action
Definition: postscreen.c:533
int main(int argc, char **argv)
Definition: postscreen.c:1091
int psc_normal_cmd_time_limit
Definition: postscreen.c:542
int psc_post_queue_length
Definition: postscreen.c:528
void mail_conf_update(const char *key, const char *value)
Definition: mail_conf.c:275
#define VAR_SMTPD_ENFORCE_TLS
Definition: mail_params.h:1275
#define DEF_PSC_DNSBL_THRESH
Definition: mail_params.h:3641
#define DEF_PSC_UPROXY_PROTO
Definition: mail_params.h:3783
#define DEF_PSC_EHLO_DIS_MAPS
Definition: mail_params.h:3729
char * var_psc_pipel_action
Definition: postscreen.c:494
#define DEF_PSC_HELO_REQUIRED
Definition: mail_params.h:3749
#define DEF_PSC_CACHE_SCAN
Definition: mail_params.h:3613
#define DEF_PSC_REJ_FOOTER
Definition: mail_params.h:3761
char * var_psc_dnsbl_action
Definition: postscreen.c:488
#define VAR_PSC_WATCHDOG
Definition: mail_params.h:3720
#define PSC_NAME_ACT_DROP
Definition: postscreen.h:351
const char * psc_print_state_flags(int, const char *)
char * var_psc_dnsbl_reply
Definition: postscreen.c:485
#define DEF_PSC_DNSBL_ACTION
Definition: mail_params.h:3653
#define MAIL_CLASS_PRIVATE
Definition: mail_proto.h:96
bool var_smtpd_use_tls
Definition: postscreen.c:458
#define PSC_ACT_DROP
Definition: postscreen.h:356
MAIL_VERSION_STAMP_DECLARE
Definition: postscreen.c:1087
#define VAR_PSC_DNSBL_MAX_TTL
Definition: mail_params.h:3660
#define PSC_ACL_ACT_BLACKLIST
Definition: postscreen.h:571
int var_psc_barlf_ttl
Definition: postscreen.c:503
int var_psc_dnsbl_min_ttl
Definition: postscreen.c:489
const char * mail_conf_eval_once(const char *string)
Definition: mail_conf.c:246
#define CA_MAIL_SERVER_PRE_INIT(v)
Definition: mail_server.h:64
void psc_parse_tests(PSC_STATE *, const char *, time_t)
char * psc_smtpd_service_name
Definition: postscreen.c:531
void msg_info(const char *fmt,...)
Definition: msg.c:199
void dict_cache_control(DICT_CACHE *cp,...)
Definition: dict_cache.c:538
#define DEF_PSC_FORBID_CMDS
Definition: mail_params.h:3745