详述在OpenBSD下打开sendmail的SMTP AUTH
发表于 : 2011-12-12 9:56
关于openbsd环境中sendmail的AUTH问题,网上的资料很有限,有些内容已经过时。参考相关资料,经过实践,大体分以下几个步骤
一.pkg_add sasl2
二.重新编译sendmail以支持AUTH
三.设置sendmail.mc和sasl
telnet 验证
一,需要安装sasl
1.export PKG_PATH=ftp://ftp.jaist.ac.jp//pub/OpenBSD/4.4/packages/i386/
2.pkg_add cyrus-sasl-2.1.22p4
sasl会默认全部安装到/usr/local/lib/sasl2/和/usr/local/sbin/
二,重新编译sendmail
方法:
1.下载src.tar.gz
2.tar -C /usr/src -xvzf src.tar.gz
3.cd /usr/src/gnu/usr.sbin/sendmail/sendmail
4.编辑makefile,在Makefile中已经对编译相关参数设置好了,只用在开头加上WANT_SMTPAUTH=1即可,相比以前版本更加简洁
5.cd /usr/src/gnu/usr.sbin/sendmail
6.make; make install; make clean
相对openbsd以前的老版本,现在的编译显得更简单些。
完成后,
三,设置sendmail和sasl
1.cd /usr/share/sendmail/cf
2.cp openbsd-proto.mc sendmail.mc (openbsd-proto.mc就是sendmail的sendmail.mc)
3.vi sendmail.mc 在相关位置,大概93行加入以下两行
define(`confAUTH_MECHANISMS', `LOGIN PLAIN DIGEST-MD5 CRAM-MD5')dnl
TRUST_AUTH_MECH(`LOGIN PLAIN DIGEST-MD5 CRAM-MD5')dnl
4.make sendmail.cf
5.cp sendmail.cf /etc/mail/
6.vi /etc/rc.local
把 sendmail_flags="-L sm-mta -C/etc/mail/localhost.cf -bd -q30m"
改为 sendmail_flags="-L sm-mta -C/etc/mail/sendmail.cf -bd -q30m"
这样,sendmail就可以既发邮件又收邮件。
7.改为hosts解析,创建/etc/mail/service.switch文件,填写
hosts files
8.vi /etc/hosts
例如:
sasl的设置:
sasl的设置有两种方法,第一种用login验证,即用系统的用户名和密码验证。
需要在/usr/local/lib/sasl2/下创建Sendmail.conf文件,写以下内容:
第二种方法将上面的改为
pwcheck_method:saslauth
cd 到 /usr/local/sbin
./saslpasswd2 jsjer
password:....
./testsaslauthd -u jsjer -p 123
重启saslauthd (ps -ax |grep saslauthd, kill pid, saslauth -a sasldb)
重启sendmail
一.pkg_add sasl2
二.重新编译sendmail以支持AUTH
三.设置sendmail.mc和sasl
telnet 验证
一,需要安装sasl
可以看出openbsd的默认sendmail是不支持AUTH的,所以只有重新编译了,编译前要安装sasl的支持库。# sendmail -d0.1
Version 8.14.3
Compiled with: DNSMAP LOG MAP_REGEX MATCHGECOS MILTER MIME7TO8 MIME8TO7 NAMED_BIND NETINET NETINET6 NETUNIX NEWDB NIS PIPELINING SCANF STARTTLS TCPWRAPPERS USERDB XDEBUG
1.export PKG_PATH=ftp://ftp.jaist.ac.jp//pub/OpenBSD/4.4/packages/i386/
2.pkg_add cyrus-sasl-2.1.22p4
sasl会默认全部安装到/usr/local/lib/sasl2/和/usr/local/sbin/
二,重新编译sendmail
方法:
1.下载src.tar.gz
2.tar -C /usr/src -xvzf src.tar.gz
3.cd /usr/src/gnu/usr.sbin/sendmail/sendmail
4.编辑makefile,在Makefile中已经对编译相关参数设置好了,只用在开头加上WANT_SMTPAUTH=1即可,相比以前版本更加简洁
5.cd /usr/src/gnu/usr.sbin/sendmail
6.make; make install; make clean
相对openbsd以前的老版本,现在的编译显得更简单些。
完成后,
如果有上面的SASLv2即表示编译成功。# sendmail -d0.1
Version 8.14.3
Compiled with: DNSMAP LOG MAP_REGEX MATCHGECOS MILTER MIME7TO8 MIME8TO7 NAMED_BIND NETINET NETINET6 NETUNIX NEWDB NIS PIPELINING SASLv2 SCANF STARTTLS TCPWRAPPERS USERDB XDEBUG
三,设置sendmail和sasl
1.cd /usr/share/sendmail/cf
2.cp openbsd-proto.mc sendmail.mc (openbsd-proto.mc就是sendmail的sendmail.mc)
3.vi sendmail.mc 在相关位置,大概93行加入以下两行
define(`confAUTH_MECHANISMS', `LOGIN PLAIN DIGEST-MD5 CRAM-MD5')dnl
TRUST_AUTH_MECH(`LOGIN PLAIN DIGEST-MD5 CRAM-MD5')dnl
4.make sendmail.cf
5.cp sendmail.cf /etc/mail/
6.vi /etc/rc.local
把 sendmail_flags="-L sm-mta -C/etc/mail/localhost.cf -bd -q30m"
改为 sendmail_flags="-L sm-mta -C/etc/mail/sendmail.cf -bd -q30m"
这样,sendmail就可以既发邮件又收邮件。
7.改为hosts解析,创建/etc/mail/service.switch文件,填写
hosts files
8.vi /etc/hosts
例如:
到此,sendmail得设置几乎完了,就等sasl设置好后重新启动。127.0.0.1 localhost.jsjer.com localhost
192.168.11.104 openbsd4.jsjer.com openbsd4
192.168.11.144 openbsd5.jsjer.com openbsd5
sasl的设置:
sasl的设置有两种方法,第一种用login验证,即用系统的用户名和密码验证。
需要在/usr/local/lib/sasl2/下创建Sendmail.conf文件,写以下内容:
然后到/usr/local/sbin/下pwcheck_method: saslauthd
验证:#./saslauthd -a getpwent
#head /var/run/sendmail.pid
#kill -HUP pid
出现上面的AUTH LOGIN PLAIN,并能用用户的登录名和密码验证,但安全性不高。# telnet openbsd4 25
Trying 192.168.11.104...
Connected to openbsd4.
Escape character is '^]'.
220 openbsd4.lvteacher.com ESMTP Sendmail 8.14.3/8.14.3; Mon, 12 Dec 2011 06:39:01 +0800 (CST)
ehlo openbsd4
250-openbsd4.lvteacher.com Hello [email protected] [192.168.11.104], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH LOGIN PLAIN
250-DELIVERBY
250 HELP
第二种方法将上面的改为
pwcheck_method:saslauth
cd 到 /usr/local/sbin
./saslpasswd2 jsjer
password:....
./testsaslauthd -u jsjer -p 123
重启saslauthd (ps -ax |grep saslauthd, kill pid, saslauth -a sasldb)
重启sendmail
# telnet openbsd4 25
Trying 192.168.11.104...
Connected to openbsd4.
Escape character is '^]'.
220 openbsd4.lvteacher.com ESMTP Sendmail 8.14.3/8.14.3; Mon, 12 Dec 2011 08:12:53 +0800 (CST)
ehlo root
250-openbsd4.lvteacher.com Hello [email protected] [192.168.11.104], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH LOGIN PLAIN DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
auth login
334 VXNlcm5hbWU6
dGVzdA== //test的base64编码
334 UGFzc3dvcmQ6
MTIz //123的base64编码
235 2.0.0 OK Authenticated