Postfix
完全禁用 postfix HELO 檢查
我正在嘗試為古怪的舊語音郵件系統設置郵件中繼。我在 vm 上設置了 postfix,啟用了中繼,驗證了我可以從同一子網遠端登錄到埠 25 並在任何我想要的地方發送郵件。這是我的 main.cf:
# See /usr/share/postfix/main.cf.dist for a commented, more complete version # Debian specific: Specifying a file name will cause the first # line of that file to be used as the name. The Debian default # is /etc/mailname. #myorigin = /etc/mailname smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu) biff = no # appending .domain is the MUA's job. append_dot_mydomain = no # Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h readme_directory = no # TLS parameters smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls=yes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for # information on enabling SSL in the smtp client. smtpd_helo_required = no smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination myhostname = mailer alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = mailer, localhost.localdomain, localhost relayhost = mynetworks = 192.168.1.0/24 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_command = procmail -a "$EXTENSION" mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all
不幸的是,舊的語音郵件總是在發送郵件之前嘗試發送一個裸露的 EHLO。我為該主機打開了調試,這就是我所看到的:
Oct 13 11:48:57 mailer postfix/smtpd[2201]: connect from unknown[192.168.1.98] Oct 13 11:48:57 mailer postfix/smtpd[2201]: smtp_stream_setup: maxtime=300 enable_deadline=0 Oct 13 11:48:57 mailer postfix/smtpd[2201]: match_hostname: unknown ~? 192.168.1.0/24 Oct 13 11:48:57 mailer postfix/smtpd[2201]: match_hostaddr: 192.168.1.98 ~? 192.168.1.0/24 Oct 13 11:48:57 mailer postfix/smtpd[2201]: > unknown[192.168.1.98]: 220 mailer ESMTP Postfix (Ubuntu) Oct 13 11:48:57 mailer postfix/smtpd[2201]: watchdog_pat: 0x7f17a114afe0 Oct 13 11:48:57 mailer postfix/smtpd[2201]: < unknown[192.168.1.98]: EHLO Oct 13 11:48:57 mailer postfix/smtpd[2201]: > unknown[192.168.1.98]: 501 Syntax: EHLO hostname Oct 13 11:48:57 mailer postfix/smtpd[2201]: watchdog_pat: 0x7f17a114afe0 Oct 13 11:48:58 mailer postfix/smtpd[2201]: < unknown[192.168.1.98]: HELO Oct 13 11:48:58 mailer postfix/smtpd[2201]: > unknown[192.168.1.98]: 501 Syntax: HELO hostname Oct 13 11:48:58 mailer postfix/smtpd[2201]: watchdog_pat: 0x7f17a114afe0 Oct 13 11:48:58 mailer postfix/smtpd[2201]: < unknown[192.168.1.98]: QUIT Oct 13 11:48:58 mailer postfix/smtpd[2201]: > unknown[192.168.1.98]: 221 2.0.0 Bye Oct 13 11:48:58 mailer postfix/smtpd[2201]: match_hostname: unknown ~? 192.168.1.0/24 Oct 13 11:48:58 mailer postfix/smtpd[2201]: match_hostaddr: 192.168.1.98 ~? 192.168.1.0/24 Oct 13 11:48:58 mailer postfix/smtpd[2201]: disconnect from unknown[192.168.1.98]
我對這個語音郵件系統的控制非常有限,所以讓它正常執行可能不是一個選擇。有沒有辦法讓後綴接受任何 EHLO/HELO,即使根本沒有主機名?
我查看了 的來源
smtpd
,看來這目前是不可能的。helo_cmd()
並且ehlo_cmd()
都在 中檢查至少 2 個值argv
,其中第一個值(可能)是請求的命令(HELO
/EHLO
),第二個是主機名。任何額外的參數都與第二個參數連接在一起,以得出最終的主機名值。然後各種配置選項控制該值的驗證方式,但它必須存在。編輯:
將其放入 postfix-users 郵件列表後,有人指出可以在處理之前將正則表達式應用於命令參數。我必須
postfix-pcre
通過apt-get
. 然後我創建一個/etc/postfix/smtpd_cmd_filter
像這樣的文件:# smtpd_cmd_filter # Work around brain-dead empty EHLO /^EHLO\s$/ EHLO domain.invalid /^HELO\s$/ HELO domain.invalid
並將以下行添加到
main.cf
:smtpd_command_filter = pcre:/etc/postfix/smtpd_cmd_filter
它不漂亮,但它有效。