30_exim4-config_check_rcpt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. ### acl/30_exim4-config_check_rcpt
  2. #################################
  3. # This access control list is used for every RCPT command in an incoming
  4. # SMTP message. The tests are run in order until the address is either
  5. # accepted or denied.
  6. #
  7. acl_check_rcpt:
  8. # Accept if the source is local SMTP (i.e. not over TCP/IP). We do this by
  9. # testing for an empty sending host field.
  10. accept
  11. hosts = :
  12. control = dkim_disable_verify
  13. # Do not try to verify DKIM signatures of incoming mail if DC_minimaldns
  14. # or DISABLE_DKIM_VERIFY are set.
  15. .ifdef DC_minimaldns
  16. warn
  17. control = dkim_disable_verify
  18. .else
  19. .ifdef DISABLE_DKIM_VERIFY
  20. warn
  21. control = dkim_disable_verify
  22. .endif
  23. .endif
  24. # The following section of the ACL is concerned with local parts that contain
  25. # certain non-alphanumeric characters. Dots in unusual places are
  26. # handled by this ACL as well.
  27. #
  28. # Non-alphanumeric characters other than dots are rarely found in genuine
  29. # local parts, but are often tried by people looking to circumvent
  30. # relaying restrictions. Therefore, although they are valid in local
  31. # parts, these rules disallow certain non-alphanumeric characters, as
  32. # a precaution.
  33. #
  34. # Empty components (two dots in a row) are not valid in RFC 2822, but Exim
  35. # allows them because they have been encountered. (Consider local parts
  36. # constructed as "firstinitial.secondinitial.familyname" when applied to
  37. # a name without a second initial.) However, a local part starting
  38. # with a dot or containing /../ can cause trouble if it is used as part of a
  39. # file name (e.g. for a mailing list). This is also true for local parts that
  40. # contain slashes. A pipe symbol can also be troublesome if the local part is
  41. # incorporated unthinkingly into a shell command line.
  42. #
  43. # These ACL components will block recipient addresses that are valid
  44. # from an RFC2822 point of view. We chose to have them blocked by
  45. # default for security reasons.
  46. #
  47. # If you feel that your site should have less strict recipient
  48. # checking, please feel free to change the default values of the macros
  49. # defined in main/01_exim4-config_listmacrosdefs or override them from a
  50. # local configuration file.
  51. #
  52. # Two different rules are used. The first one has a quite strict
  53. # default, and is applied to messages that are addressed to one of the
  54. # local domains handled by this host.
  55. # The default value of CHECK_RCPT_LOCAL_LOCALPARTS is defined in
  56. # main/01_exim4-config_listmacrosdefs:
  57. # CHECK_RCPT_LOCAL_LOCALPARTS = ^[.] : ^.*[@%!/|`#&?]
  58. # This blocks local parts that begin with a dot or contain a quite
  59. # broad range of non-alphanumeric characters.
  60. .ifdef CHECK_RCPT_LOCAL_LOCALPARTS
  61. deny
  62. domains = +local_domains
  63. local_parts = CHECK_RCPT_LOCAL_LOCALPARTS
  64. message = restricted characters in address
  65. .endif
  66. # The second rule applies to all other domains, and its default is
  67. # considerably less strict.
  68. # The default value of CHECK_RCPT_REMOTE_LOCALPARTS is defined in
  69. # main/01_exim4-config_listmacrosdefs:
  70. # CHECK_RCPT_REMOTE_LOCALPARTS = ^[./|] : ^.*[@%!`#&?] : ^.*/\\.\\./
  71. # It allows local users to send outgoing messages to sites
  72. # that use slashes and vertical bars in their local parts. It blocks
  73. # local parts that begin with a dot, slash, or vertical bar, but allows
  74. # these characters within the local part. However, the sequence /../ is
  75. # barred. The use of some other non-alphanumeric characters is blocked.
  76. # Single quotes might probably be dangerous as well, but they're
  77. # allowed by the default regexps to avoid rejecting mails to Ireland.
  78. # The motivation here is to prevent local users (or local users' malware)
  79. # from mounting certain kinds of attack on remote sites.
  80. .ifdef CHECK_RCPT_REMOTE_LOCALPARTS
  81. deny
  82. domains = !+local_domains
  83. local_parts = CHECK_RCPT_REMOTE_LOCALPARTS
  84. message = restricted characters in address
  85. .endif
  86. # Accept mail to postmaster in any local domain, regardless of the source,
  87. # and without verifying the sender.
  88. #
  89. accept
  90. .ifndef CHECK_RCPT_POSTMASTER
  91. local_parts = postmaster
  92. .else
  93. local_parts = CHECK_RCPT_POSTMASTER
  94. .endif
  95. domains = +local_domains : +relay_to_domains
  96. # Deny unless the sender address can be verified.
  97. #
  98. # This is disabled by default so that DNSless systems don't break. If
  99. # your system can do DNS lookups without delay or cost, you might want
  100. # to enable this feature.
  101. #
  102. # This feature does not work in smarthost and satellite setups as
  103. # with these setups all domains pass verification. See spec.txt chapter
  104. # 39.31 with the added information that a smarthost/satellite setup
  105. # routes all non-local e-mail to the smarthost.
  106. .ifdef CHECK_RCPT_VERIFY_SENDER
  107. deny
  108. message = Sender verification failed
  109. !acl = acl_local_deny_exceptions
  110. !verify = sender
  111. .endif
  112. # Verify senders listed in local_sender_callout with a callout.
  113. #
  114. # In smarthost and satellite setups, this causes the callout to be
  115. # done to the smarthost. Verification will thus only be reliable if the
  116. # smarthost does reject illegal addresses in the SMTP dialog.
  117. deny
  118. !acl = acl_local_deny_exceptions
  119. senders = ${if exists{CONFDIR/local_sender_callout}\
  120. {CONFDIR/local_sender_callout}\
  121. {}}
  122. !verify = sender/callout
  123. # Accept if the message comes from one of the hosts for which we are an
  124. # outgoing relay. It is assumed that such hosts are most likely to be MUAs,
  125. # so we set control=submission to make Exim treat the message as a
  126. # submission. It will fix up various errors in the message, for example, the
  127. # lack of a Date: header line. If you are actually relaying out out from
  128. # MTAs, you may want to disable this. If you are handling both relaying from
  129. # MTAs and submissions from MUAs you should probably split them into two
  130. # lists, and handle them differently.
  131. # Recipient verification is omitted here, because in many cases the clients
  132. # are dumb MUAs that don't cope well with SMTP error responses. If you are
  133. # actually relaying out from MTAs, you should probably add recipient
  134. # verification here.
  135. # Note that, by putting this test before any DNS black list checks, you will
  136. # always accept from these hosts, even if they end up on a black list. The
  137. # assumption is that they are your friends, and if they get onto black
  138. # list, it is a mistake.
  139. accept
  140. hosts = +relay_from_hosts
  141. control = submission/sender_retain
  142. control = dkim_disable_verify
  143. # Accept if the message arrived over an authenticated connection, from
  144. # any host. Again, these messages are usually from MUAs, so recipient
  145. # verification is omitted, and submission mode is set. And again, we do this
  146. # check before any black list tests.
  147. accept
  148. authenticated = *
  149. control = submission/sender_retain
  150. control = dkim_disable_verify
  151. # Insist that any other recipient address that we accept is either in one of
  152. # our local domains, or is in a domain for which we explicitly allow
  153. # relaying. Any other domain is rejected as being unacceptable for relaying.
  154. require
  155. message = relay not permitted
  156. domains = +local_domains : +relay_to_domains
  157. # We also require all accepted addresses to be verifiable. This check will
  158. # do local part verification for local domains, but only check the domain
  159. # for remote domains.
  160. require
  161. verify = recipient
  162. # Verify recipients listed in local_rcpt_callout with a callout.
  163. # This is especially handy for forwarding MX hosts (secondary MX or
  164. # mail hubs) of domains that receive a lot of spam to non-existent
  165. # addresses. The only way to check local parts for remote relay
  166. # domains is to use a callout (add /callout), but please read the
  167. # documentation about callouts before doing this.
  168. deny
  169. !acl = acl_local_deny_exceptions
  170. recipients = ${if exists{CONFDIR/local_rcpt_callout}\
  171. {CONFDIR/local_rcpt_callout}\
  172. {}}
  173. !verify = recipient/callout
  174. # CONFDIR/local_sender_blacklist holds a list of envelope senders that
  175. # should have their access denied to the local host. Incoming messages
  176. # with one of these senders are rejected at RCPT time.
  177. #
  178. # The explicit white lists are honored as well as negative items in
  179. # the black list. See exim4-config_files(5) for details.
  180. deny
  181. message = sender envelope address $sender_address is locally blacklisted here. If you think this is wrong, get in touch with postmaster
  182. !acl = acl_local_deny_exceptions
  183. senders = ${if exists{CONFDIR/local_sender_blacklist}\
  184. {CONFDIR/local_sender_blacklist}\
  185. {}}
  186. # deny bad sites (IP address)
  187. # CONFDIR/local_host_blacklist holds a list of host names, IP addresses
  188. # and networks (CIDR notation) that should have their access denied to
  189. # The local host. Messages coming in from a listed host will have all
  190. # RCPT statements rejected.
  191. #
  192. # The explicit white lists are honored as well as negative items in
  193. # the black list. See exim4-config_files(5) for details.
  194. deny
  195. message = sender IP address $sender_host_address is locally blacklisted here. If you think this is wrong, get in touch with postmaster
  196. !acl = acl_local_deny_exceptions
  197. hosts = ${if exists{CONFDIR/local_host_blacklist}\
  198. {CONFDIR/local_host_blacklist}\
  199. {}}
  200. # Warn if the sender host does not have valid reverse DNS.
  201. #
  202. # If your system can do DNS lookups without delay or cost, you might want
  203. # to enable this.
  204. # If sender_host_address is defined, it's a remote call. If
  205. # sender_host_name is not defined, then reverse lookup failed. Use
  206. # this instead of !verify = reverse_host_lookup to catch deferrals
  207. # as well as outright failures.
  208. .ifdef CHECK_RCPT_REVERSE_DNS
  209. warn
  210. condition = ${if and{{def:sender_host_address}{!def:sender_host_name}}\
  211. {yes}{no}}
  212. add_header = X-Host-Lookup-Failed: Reverse DNS lookup failed for $sender_host_address (${if eq{$host_lookup_failed}{1}{failed}{deferred}})
  213. .endif
  214. # Use spfquery to perform a pair of SPF checks (for details, see
  215. # http://www.openspf.org/)
  216. #
  217. # This is quite costly in terms of DNS lookups (~6 lookups per mail). Do not
  218. # enable if that's an issue. Also note that if you enable this, you must
  219. # install "spf-tools-perl" which provides the spfquery command.
  220. # Missing spf-tools-perl will trigger the "Unexpected error in
  221. # SPF check" warning.
  222. .ifdef CHECK_RCPT_SPF
  223. deny
  224. message = [SPF] $sender_host_address is not allowed to send mail from \
  225. ${if def:sender_address_domain {$sender_address_domain}{$sender_helo_name}}. \
  226. Please see \
  227. http://www.openspf.org/Why?scope=${if def:sender_address_domain \
  228. {mfrom}{helo}};identity=${if def:sender_address_domain \
  229. {$sender_address}{$sender_helo_name}};ip=$sender_host_address
  230. log_message = SPF check failed.
  231. !acl = acl_local_deny_exceptions
  232. condition = ${run{/usr/bin/spfquery.mail-spf-perl --ip \
  233. ${quote:$sender_host_address} --identity \
  234. ${if def:sender_address_domain \
  235. {--scope mfrom --identity ${quote:$sender_address}}\
  236. {--scope helo --identity ${quote:$sender_helo_name}}}}\
  237. {no}{${if eq {$runrc}{1}{yes}{no}}}}
  238. defer
  239. message = Temporary DNS error while checking SPF record. Try again later.
  240. !acl = acl_local_deny_exceptions
  241. condition = ${if eq {$runrc}{5}{yes}{no}}
  242. warn
  243. condition = ${if <={$runrc}{6}{yes}{no}}
  244. add_header = Received-SPF: ${if eq {$runrc}{0}{pass}\
  245. {${if eq {$runrc}{2}{softfail}\
  246. {${if eq {$runrc}{3}{neutral}\
  247. {${if eq {$runrc}{4}{permerror}\
  248. {${if eq {$runrc}{6}{none}{error}}}}}}}}}\
  249. } client-ip=$sender_host_address; \
  250. ${if def:sender_address_domain \
  251. {envelope-from=${sender_address}; }{}}\
  252. helo=$sender_helo_name
  253. warn
  254. log_message = Unexpected error in SPF check.
  255. condition = ${if >{$runrc}{6}{yes}{no}}
  256. .endif
  257. # Check against classic DNS "black" lists (DNSBLs) which list
  258. # sender IP addresses
  259. .ifdef CHECK_RCPT_IP_DNSBLS
  260. warn
  261. dnslists = CHECK_RCPT_IP_DNSBLS
  262. add_header = X-Warning: $sender_host_address is listed at $dnslist_domain ($dnslist_value: $dnslist_text)
  263. log_message = $sender_host_address is listed at $dnslist_domain ($dnslist_value: $dnslist_text)
  264. .endif
  265. # Check against DNSBLs which list sender domains, with an option to locally
  266. # whitelist certain domains that might be blacklisted.
  267. #
  268. # Note: If you define CHECK_RCPT_DOMAIN_DNSBLS, you must append
  269. # "/$sender_address_domain" after each domain. For example:
  270. # CHECK_RCPT_DOMAIN_DNSBLS = rhsbl.foo.org/$sender_address_domain \
  271. # : rhsbl.bar.org/$sender_address_domain
  272. .ifdef CHECK_RCPT_DOMAIN_DNSBLS
  273. warn
  274. !senders = ${if exists{CONFDIR/local_domain_dnsbl_whitelist}\
  275. {CONFDIR/local_domain_dnsbl_whitelist}\
  276. {}}
  277. dnslists = CHECK_RCPT_DOMAIN_DNSBLS
  278. add_header = X-Warning: $sender_address_domain is listed at $dnslist_domain ($dnslist_value: $dnslist_text)
  279. log_message = $sender_address_domain is listed at $dnslist_domain ($dnslist_value: $dnslist_text)
  280. .endif
  281. # This hook allows you to hook in your own ACLs without having to
  282. # modify this file. If you do it like we suggest, you'll end up with
  283. # a small performance penalty since there is an additional file being
  284. # accessed. This doesn't happen if you leave the macro unset.
  285. .ifdef CHECK_RCPT_LOCAL_ACL_FILE
  286. .include CHECK_RCPT_LOCAL_ACL_FILE
  287. .endif
  288. #############################################################################
  289. # This check is commented out because it is recognized that not every
  290. # sysadmin will want to do it. If you enable it, the check performs
  291. # Client SMTP Authorization (csa) checks on the sending host. These checks
  292. # do DNS lookups for SRV records. The CSA proposal is currently (May 2005)
  293. # an Internet draft. You can, of course, add additional conditions to this
  294. # ACL statement to restrict the CSA checks to certain hosts only.
  295. #
  296. # require verify = csa
  297. #############################################################################
  298. # Accept if the address is in a domain for which we are an incoming relay,
  299. # but again, only if the recipient can be verified.
  300. accept
  301. domains = +relay_to_domains
  302. endpass
  303. verify = recipient
  304. # At this point, the address has passed all the checks that have been
  305. # configured, so we accept it unconditionally.
  306. accept