vkill'blog

archlinux SBS--mail server(2):postfix SMTP server with cyrus SASL2(上)

12:59 , vkill
最后修改20081006 --by:vkill

postfix SMTP server with cyrus SASL2 (上)

环境:
2.6.25-ARCH  postfix-2.5.3  cyrus-sasl 2.1.22  mysql 5.0.60  pam_mysql-0.7RC1

知识点:
cyrus SASL支持的验证机制:PLAIN LOGIN OTP DIGEST-MD5 KERBEROS ANONYMOUS
cyrus SASL支持的验证架构:UNIX系统密码、SASL专用密码、外部数据库 等等
对于每个使用cyrus SASL函数库的应运系统,cyrus SASL各提供一个独立的配置文件,影响postfix的SASL配置文件是smtpd.conf,文件位置我习惯位于 /etc/sasl2/smtpd.conf,smtpd.conf文件至少要指出使用的验证架构等等。

设置 postfix 使用cyrus-sasl

[root@myhost ~]# vi /etc/postfix/main.cf
smtpd_sasl_auth_enable = yes  //启用SASL验证
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination  //核准授权用户
smtpd_sasl_security_options = noanonymous  //设定验证机制
smtpd_sasl_type = cyrus
smtpd_sasl_path = smtpd
##base  //供后面的测试使用
myhostname = mail.test.net
myorigin = $myhostname
mydestination = localhost, $myhostname


验证架构一:UNIX系统密码

1、修改smtpd配置文件

[root@myhost ~]# vi /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd
saslauthd_path:/var/run/saslauthd/mux  //这里的路径和saslauthd启动参数-m中指定的路径对应

2、启动saslauthd,archlinux的启动脚本是#/etc/rc.d/saslauthd start,启动参数在/etc/conf.d/saslauthd中

[root@myhost ~]# /usr/sbin/saslauthd -m /var/run/saslauthd -a shadow

3、测试saslauthd是否开启成功,假设已有一系统帐户 admin,密码123456

[root@myhost ~]# testsaslauthd -u admin -p 123456
0: OK "Success."

4、测试admin用户是否可以smtp发信

[root@myhost ~]# /etc/rc.d/postfix restart
[root@myhost ~]# ktelnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
220 mail.test.net ESMTP Postfix
ehlo aaa
250-mail.test.net
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH GSSAPI DIGEST-MD5 CRAM-MD5 OTP PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login
334 VXNlcm5hbWU6
YWRtaW5AbWFpbC50ZXN0Lm5ldA==    //用户名admin@mail.test.net base64编码后
334 UGFzc3dvcmQ6
MTIzNDU2    //密码123456 base64编码后
235 2.7.0 Authentication successful
quit
221 2.0.0 Bye
Connection closed by foreign host.

附:linux下获得字符串的base64编码,可以使用类似下面的命令来获得

[root@myhost ~]# echo -n "admin@mail.test.net" | base64


验证架构二:SASL专用密码
注:此方法不建议用,这样做后用户是不能用来接受邮件的
1、修改smtpd配置文件

[root@myhost ~]# vi /etc/sasl2/smtpd.conf
pwcheck_method: auxprop
auxprop_plugin: sasldb

2、增加帐户abc,密码123456,-u选项指出该帐户所属的网域

[root@myhost ~]# saslpasswd2 -c -u `postconf -h myhostname` abc

注:这里也可以不使用`postconf -h myhostname`,主要是因为默认smtpd_sasl_local_domain参数的值是$myhostname,所以常见的都是用这个来做测试
3、查看帐户列表

[root@myhost ~]# sasldblistusers2
abc@mail.test.net: userPassword
abc@mail.test.net: cmusaslsecretOTP

4、修改密码文件权限

[root@myhost ~]# chmod 644 /etc/sasldb2

5、测试abc用户是否可以smtp发信

[root@myhost ~]# /etc/rc.d/postfix restart
[root@myhost ~]# ktelnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
220 mail.test.net ESMTP Postfix
ehlo aaa
250-mail.test.net
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH GSSAPI DIGEST-MD5 CRAM-MD5 OTP PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login
334 VXNlcm5hbWU6
YWJjQG1haWwudGVzdC5uZXQ=    //用户名abc@mail.test.net base64编码后
334 UGFzc3dvcmQ6
MTIzNDU2    //密码123456 base64编码后
235 2.7.0 Authentication successful
quit
221 2.0.0 Bye
Connection closed by foreign host.


Last modified by vkill on2008/10/07 09:58
类别:linux system | Tags: , , , , , , , , , , | 0 条评论, 479 次阅读
网友评论(0):
发表评论:

Nickname: 
Email:
Site URI: