完全禁用 postfix HELO 检查

完全禁用 postfix HELO 检查

我正在尝试为一个古怪的旧语音邮件系统设置邮件中继。我在虚拟机上设置了 postfix,启用了中继,验证了我可以从同一子网 telnet 到端口 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]

我对这个语音邮件系统的控制非常有限,所以让它正常运行可能不是一个选择。有没有办法让 postfix 接受任何 EHLO/HELO,即使根本没有主机名?

答案1

我查看了 的源代码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

它不漂亮,但很有效。

相关内容