2

postfix+courier-authlib+sasl实现虚拟用户/虚拟域的种种陷阱

 1 year ago
source link: https://blogread.cn/it/article/4971?f=hot1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

postfix+courier-authlib+sasl实现虚拟用户/虚拟域的种种陷阱

浏览:1258次  出处信息

    [具体的安装过程,请参考这篇文章:http://man.chinaunix.net/tech/Postfix_I.html#a.6 ]

    这几天研究了一下EDM,装上postfix玩了玩虚拟用户,发现安装过程中好多陷阱,网上的教程文章误人子弟的太多,所以忍不住吐槽一下,一般过程就不写了,就写常见的几个陷阱:

    1.网上都说sasl的配置文件在/usr/lib/sasl2/smtpd.conf ,个别文档说在/etc/sasl2/smtpd.conf.我浏览/usr/lib/sasl2/目录的时候就疯了,这下面全是so文件,怎么能把etc配置文件和一堆so文件搁一块?也没任何地方可以明确指明这个文件放哪儿,最后翻postfix的文档,人家说了,一般是放这两个地方,不过有个别linux发行版把它指定在/etc/postfix/sasl/下面…好吧,我中标了  我用的这个版本的ubuntu就是这么放在/etc/postfix/sasl/下的

    2.在/etc/postfix/main.cf里:

    #smtpd_sasl_application_name = smtpd 语法已经废弃,改为:

    smtpd_sasl_path = smtpd 了

    3.很多兄弟估计也是smtp连接的时候授权都没成功呢,就在那儿刷postfix的日志呢….记住调试的时候,一定要把/etc/courier/authdaemonrc里的DEBUG_LOGIN=0 改为DEBUG_LOGIN=1 .不过调试完成记得改回去, 不然泄露用户smtp密码.

    4.类似错误:SASL authentication failure: cannot connect to Courier authdaemond: No such file or directory SASL LOGIN authentication failed: generic failure这种错误,碰到的兄弟有很多吧.这是说,postfix无法通过sasl连接到认证服务器,这里就是无法连接到courier-authdaemon.出这个错误的原因是,postfix的进程默认是在chroot环境里运行的,相信在你的操作系统里,courier-authdaemon进程产生的socket文件/var/run/courier/authdaemon/socket 一定是存在的.网上有些伪专家就指导你说,这个文件的授权不对,你要chmod 755啥的.扯蛋,能用chmod 755解决的问题,绝对是超低级的问题了.postfix在chroot环境,根本读不到chroot环境以外的文件.于是又有一堆伪专家出谋划策,说,我们做个符号链接一下就行了.我最开始在google上搜到这个答案的时候高兴坏了,以为真的一下子就解决了呢.ln -s /var/run/courier/authdaemon/socket /var/spool/postfix/var/run/courier/authdaemon/socket 这样,可以了吧.抱歉,也不行的,我特地重复了一下这个过程,就为了看postfix是怎么提示的:

    SASL authentication failure: cannot connect to Courier authdaemond: Too many levels of symbolic links

    不好意思,又掉陷阱了.而且,在有的兄弟那里,courier-authdaemon的socket文件和postfix的spool不在一个卷上,linux根本就没法跨卷创建符号链接的.

    我的解决办法:

    #试着在/etc/postfix/master.cf 中smtp inet n - - - - smtpd

    smtp inet n - n - - smtpd(这里修改掉的n,这一列表示是否在chroot中运行)后面还会遇到类似的问题;

    5.说一下这个错误:

    日志类似:

    类似postfix/trivial-rewrite[23299]: warning: connect to mysql server localhost: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) postfix/trivial-rewrite[23299]: fatal: mysql:/etc/postfix/mysql_virtual_domains_maps.cf(0,lock|fold_fix): table lookup problempostfix/master[13544]: warning: process /usr/lib/postfix/trivial-rewrite pid 23299 exit status 1

    我的解决办法很简单,在postfix的相关写Mysql用户名密码的配置文件里,将localhost改成127.0.0.1,同时保证mysql server对127.0.0.1这个IP做了授权就Ok了. 这个原因是,postfix使用了一种多进程的架构,不同的进程可以各自配置是否以chroot方式运行.(以chroot方式运行为postfix提升了安全性,但是为配置的兄弟们带来了不少麻烦).postfix在chroot环境里,所以,它是读不到/var/run/mysqld/mysqld.sock文件的.当然也可以关掉chroot.

    6 出现authentication error: Input/output error错误的时候估计是查询mysql时,authdaemond出错了。具体要打开authdaemonrc里的:

     DEBUG_LOGIN=2    原来默认是0

     然后看看/var/log/message或/var/log/mail.log 在认证失败时有什么提示。根据提示去检查问题到底出在哪儿

    7.类似错误:Feb 14 18:21:06 hostname postfix/smtpd[15254]: warning: SASL authentication failure: cannot connect to Courier authdaemond: Permission deniedFeb 14 18:21:06 hostname postfix/smtpd[15254]: warning: localhost[127.0.0.1]: SASL LOGIN authentication failed: generic failure这种一般是因为权限的问题,假设你的authdaemond的socket路径是/var/run/courier/authdaemon/socket  像下面这样一级级目录地修复权限就没问题:

    sudo chmod a+x /var/

     sudo chmod a+x /var/run/

     sudo chmod a+x /var/run/courier/

     sudo chmod a+x /var/run/courier/authdaemon/

     这也是一个容易让人困惑的地方.sasl不仅需要能读那个socket文件,还要能读它的各级父目录;

建议继续学习:

QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK