中国青基会
RSS
热门关键字:  None  linux+moodle安装  mac  rhel5  199
当前位置 : Nixsky>BSD>OpenBSD>列表

OpenBSD Mail Server: Postfix+OpenLDAP+Courier+Clamav...

来源:互联网 作者: 时间:2007-12-21 点击:

  First of all

  About this Document

  如果您发现该文档有任何错误、笔误,请直接联系我(Mail),或者在 讨论页面留言,而不要直接编辑本页。

  This article is Under Development.

  Wrote for OpenBSD 4.2 -release/-stable.

  Contact the author:

  Author:

  MSN: michaelbibby#hotmail.com

  Mail/GTalk: michaelbibby#gmail.com

  Overview

  Author

  Contact me: Michael Bibby(张煌彬)

  From: http://www.OpenBSDonly.org/,不做普及者!做开路人!

  Copyright: 本文档欢迎自由转载,但是请务必保留作者及出处等信息。

  About OpenBSD

  OpenBSD: "Only two remote holes in the default install, in more than 10 years!"

  参考:OpenBSD简介

  购买 OpenBSD 光盘是支持 OpenBSD 持续发展的重要途径。

  用于实践、实验本文档的最佳方法是购买一套 OpenBSD 光盘,欢迎您通过 http://www.openbsd.org/orders.html#china页面的联系方式与 Bibby联系购买,或直接参与 OpenBSDonly.org论坛。价格:

  CD(4.x -release):¥180。

  T-Shirt: ¥150。

  OS &Packages

  本邮件服务器基于 OpenBSD 4.2 -release 平台搭建,主要使用到了以下软件:

  courier-authlib

  courier-authlib-ldap

  courier-imap

  courier-pop3

  cyrus-sasl-x.y.z-ldap

  db-4.x.y

  mhash

  openldap-client

  openldap-server-x.y.z-bdb

  pcre

  php5-core

  php5-imap

  php5-ldap

  php5-mhash

  phpldapadmin

  postfix-x.y.z-sasl2-ldap

  

  以上软件包都可以在 OpenBSD 官方站点下载到: ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/。

  

  

  只有 postfix 软件包是使用 ports 编译的。其馀软件包都使用 binary packages 直接安装。

  

  

  您可以从离自己较近的镜像站点下载。镜像站点的列表可以在 http://www.openbsd.org/ftp.html页面找到。

  

  

  中国的用户可以使用以下几个镜像站点:

  FreeBSDChina.org 提供:ftp://ftp.freebsdchina.org/pub/OpenBSD/4.2/packages/i386/

  Mirror(OpenBSD TaiWan):ftp://ftp.tw.openbsd.org/pub/OpenBSD/4.2/packages/i386/

  Features

  目前本文档中的内容所实现的功能有:

  Apache+PHP(with module(s): -imap,-ldap,-mhash):Done.

  OpenLDAP(+phpLDAPadmin)安装与配置, Access Control List:Done.

  虚拟域(Virtual Domains)+虚拟用户(Virtual Users)(via openldap, cyrus-sasl-ldap):Done.

  SMTP SASL 认证(via cyrus-sasl-ldap):Done.

  POP3/IMAP(via courierpop3,imap}):Done.

  Quota(via maildrop): Done.

  WebMail(via SquirrelMail(with plugin(s): change_ldappass)): Done.

  邮件备份(Archive,使用 bcc 功能实现):Done.

  提供脚本用于创建虚拟域和虚拟用户:create_mail_ldap_user.sh

  Clamav、amavisd-new,病毒防护

  SpamAssassin,垃圾邮件过滤

  The Big Picture

  

  

  

  整个邮件系统的架构图(图片来源)。针对本文档,只需要将 Dovecot 替换成 Courier-IMAP/Courier-POP3,去掉 Jamm 即可。

  

  针对内容过滤和病毒过滤方面三个组件(SpamAssassin, ClamAV, amavisd-new)的架构(图片来源)

  Credits

  在测试和编写文档的过程中得到了一些朋友的帮助和支持,在此要特别感谢:

  OpenBSD:我个人最喜欢的 OS。人不能没有个性,而如果你使用的 OS 也极富个性,则在除了使用之外更多了一层喜爱。

  Google:没有你,我无法完成这篇文档。在学习 Linux/*BSD 的路上,你帮的忙可算是最大。

  OpenBSD-wiki.org:本文档是基于该网站上的 HowTo Virtual Domain Guide for v4.0完成的。

  另外还要特别感谢 http://www.OpenBSDonly.org上的:

  congli:一直以来,在学习 FreeBSD/OpenBSD 的过程中都得到了 congli 大哥的许多帮助,真的非常感谢。

  atyu30:你的需求激励着我前进,是压力,也是动力。

  很高兴在学习 OpenBSD 的同时,有这么多的朋友一路同行。

  Todo

  为每个软件增加“简介”。

  PF rules?

  Failover(carp(4))?

  OpenLDAP TLS support?

  pflogsumm, postfix logfile analysis

  WebMail

  ExtMail(WebMail)?

  预备知识

  PKG_PATH

  PKG_PATH 是一个很特殊的变量,它所指定的是你存放 binary packages 的路径,设置好之后就可以在任意目录下直接用以下命令来安装软件:

  # pkg_add package_name

  

  这里的 package_name 可以是不带版本号的软件包名称,也可以是软件包的全名。比如:

  #

  # pkg_add zsh

  #

  # ---- or ----

  #

  # pkg_add zsh-4.2.6p2

  #

  # ---- or ----

  #

  # pkg_add zsh-4.2.6p2.tgz

  #

  

  PKG_PATH 所指定的路径既可以是网络地址,也可以是本地路径。比如:

  # export PKG_PATH='ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/'

  # export PKG_PATH='/mnt/4.2/packages/i386/'

  

  

  

  在这里,地址必须以斜线(/)结尾,否则会出错。

  

  

  这里的 4.2 表示的是 OpenBSD 的版本,而 i386 则是表示系统的平台架构。可以采用更通用的写法来表示这两个值得:

  # export PKG_PATH='ftp://ftp.openbsd.org/pub/OpenBSD/$(uname -r)/packages/$(machine -a)/'

  

  更详细内容请参考:

  uname(1)

  machine(1)

  

  

  文档里出现的所有类似于 uname(1)这样的写法,都表示是这个命令的手册页(Manual Page),请使用 man 命令进行查看或者使用 OpenBSD 网站的在线查看功能。比如:# man uname# man 1 uname

  在线浏览手册页的地址是:

  Manual Pages

  

  

  可以将设置 PKG_PATH 的语句放在 ~/.profile 文件中,这样每次登录系统都会自动设置(~/.profile 是 ksh(1) 的默认初始化脚本之一)。

  

  

  本文中所有使用 pkg_add 安装软件的地方,都假设你已经设置好了 PKG_PATH 变量。如果你没有设置 PKG_PATH 变量,请在执行 pkg_add 时使用绝对/相对路径来指定软件包的位置。

  See also:

  OpenBSD FAQ 15.2.2 - Making things easy: PKG_PATH

  Apache+PHP

  在本文中,将需要用到 phpLDAPadmin 来管理 OpenLDAP,而 phpLDAPadmin 是一个使用 PHP 编写的程序,所以需要搭建 Apache+PHP 来支持 phpLDAPadmin。

  Apache

  启用 Apache

  OpenBSD 的基本系统中已经带了 Apache-1.3.x(在 4.2 -release 中是 1.3.29),所以只需要将它启用即可。

  编辑 /etc/rc.conf.local 文件,加入以下内容:

  httpd_flags=""

  

  

  

  建议不要直接修改 rc.conf(8) 文件。以下是 rc.conf(8) DESCRIPTION 的第二段内容:

  It is advisable to leave the /etc/rc.conf file untouched, and instead

  create and edit a new /etc/rc.conf.local file. Variables set in this

  file will override variables previously set in /etc/rc.conf.

  

  Apahce 的所有文件都放在 /var/www/ 目录下,以下是几个主要的目录及其用途:

  /var/www/

  |- cgi-bin/ <-- 存放 CGI 程序的主要目录

  |- conf/ <-- 存放配置文件的目录

  |- htdocs/ <-- 存放 Web 文件的目录

  |- logs/ <-- 存放 apache 服务器的日志文件

  |- users/ <-- 用于提供给系统用户作个人主页的目录

  

  Apache 的启动与停止

  Apache 使用 apachectl 程序来启动和停止:

  # apachectl start

  # apachectl stop

  

  安装 PHP:php5-core# pkg_add php5-core

  --- php5-core-5.2.3 -------------------

  To finish the install, enable the php5 module with:

  /usr/local/sbin/phpxs -s

  To enable parsing of PHP scripts, add the following to

  /var/www/conf/httpd.conf:

  

  AddType application/x-httpd-php .php

  Copy the config file below into /var/www/conf/php.ini

  /usr/local/share/examples/php5/php.ini-recommended

  Don't forget that the default OpenBSD httpd is chrooted

  into /var/www by default, so you may need to create support

  directories such as /var/www/tmp for PHP to work correctly.

  

  根据提示,执行:

  # /usr/local/sbin/phpxs -s

  [activating module `php5' in /var/www/conf/httpd.conf]

  cp /usr/local/lib/php/libphp5.so /usr/lib/apache/modules/libphp5.so

  chmod 755 /usr/lib/apache/modules/libphp5.so

  cp /var/www/conf/httpd.conf /var/www/conf/httpd.conf.bak

  cp /var/www/conf/httpd.conf.new /var/www/conf/httpd.conf

  rm /var/www/conf/httpd.conf.new

  You should copy the sample configuration files from

  /usr/local/share/examples/php5 to /var/www/conf/php.ini

  #

  

  复制 PHP 的配置文件 php.ini:

  # cp /usr/local/share/examples/php5/php.ini-recommended /var/www/conf/php.ini

  

  编辑 Apache 的配置文件(/var/www/conf/httpd.conf),让它能够识别和解析 PHP 文件:

  # [..snip..]

  # 在 DirectoryIndex 参数中加上 PHP 的索引文件:index.php。

  # index.php 和 index.html 的先后顺序决定了 apache 在进入一个目录的时候先读取哪个文件。

  DirectoryIndex index.php index.html

  # 将以下一行内容的注释符号给去掉:

  AddType application/x-httpd-php .php

  

  重启 apache 之后,它就能够识别和解析 PHP 文件了:

  # apachectl stop

  # apachectl start

  

  

  

  安装并配置好 PHP 后的 phpinfo() 页面信息

  现在可以创建一个 PHP 文件,测试 PHP 是否已经可以正确识别:

  # vi /var/www/htdocs/index.php

  

phpinfo();

?>  phpinfo();

  >

  

  使用 Web 浏览器访问你的服务器首页的 index.php 文件: http://your_server_IP/index.php,如果能够看到和以下截图类似的 PHP 信息,则表示 apache 已经可以正确识别和解析 PHP 文件。

  PHP Extensions

  为了支持整个邮件服务器,我们还需要安装以下 PHP 扩展:

  php5-ldap:用于 phpLDAPadmin

  php5-imap:用于 WebMail

  php5-mhash:为 phpLDAPadmin 提供加密算法支持

  模块在安装完成后需要重启 apache 才能生效。

  php5-ldap#

  # 安装 php5-ldap

  #

  # pkg_add php5-ldap

  --- php5-ldap-5.1.6p1 -------------------

  Enable this module in php.ini using the following command:

  /usr/local/sbin/phpxs -a ldap

  #

  # 启用 ldap

  #

  # /usr/local/sbin/phpxs -a ldap

  Activating extension : ldap

  #

  

  

  

  注意:这里将 cyrus-sasl 作为依赖包给装上了,但是因为它不支持 LDAP,所以我们在后面需要将它替换掉。

  php5-imap#

  # 安装 php5-imap

  #

  # pkg_add php5-imap

  --- php5-imap-5.2.3 -------------------

  Enable this module in php.ini using the following command:

  /usr/local/sbin/phpxs -a imap

  #

  # 启用 imap

  #

  # /usr/local/sbin/phpxs -a imap

  Activating extension : imap

  

  php5-mhash

  

  

  安装好 php5-xyz 模块后的 phpinfo() 页面内容

  #

  # 安装 php5-mhash

  #

  # pkg_add php5-mhash

  --- php5-mhash-5.2.3 -------------------

  Enable this module in php.ini using the following command:

  /usr/local/sbin/phpxs -a mhash

  #

  # 启用 imap

  #

  # /usr/local/sbin/phpxs -a mhash

  Activating extension : mhash

  

  OpenLDAP

  安装 OpenLDAP

  packages 里的 openldap-server 只支持使用 ldbm 作为 backend。网上的言论都说 bdb 的性能会好一些。而从 OpenBSD 4.2 -release 开始,OpenLDAP 已经有了 -bdb 的 binary package 了。

  # pkg_add openldap-server-2.3.33p1-bdb

  openldap-server-2.3.33p1-bdb: complete

  #

  

  配置 OpenLDAP

  authldap.schema

  这里将使用 courier 提供的 authldap.schema 这个 schema,用于与 Postfix 的整合。

  # cd /root

  #

  # 下载最新的 authldap.schema 文件

  #

  # ftp "http://courier.cvs.sourceforge.net/*checkout*/courier/libs/authlib/authldap.schema"

  Trying 66.35.250.84...

  Requesting http://courier.cvs.sourceforge.net/*checkout*/courier/libs/authlib/authldap.schema

  Successfully retrieved file.

  #

  # 将 authldap.schema 复制到对应的目录

  #

  # cp authldap.schema /etc/openldap/schema/

  

  

  

  注:在 courier-authlib-ldap 这个包中也包含有 authldap.schema 文件,可以直接代替这里的版本。

  /etc/openldap/slapd.conf

  OpenLDAP 的主配置文件是 /etc/openldap/slapd.conf。在这里,我们需要添加和修改一些内容:

  include /etc/openldap/schema/core.schema

  # 添加以下这些 schema

  include /etc/openldap/schema/corba.schema

  include /etc/openldap/schema/cosine.schema

  include /etc/openldap/schema/inetorgperson.schema

  include /etc/openldap/schema/nis.schema

  # 这是为了与 Postfix 整合所需要的

  include /etc/openldap/schema/authldap.schema

  pidfile /var/run/openldap/slapd.pid

  argsfile /var/run/openldap/slapd.args

  # Version of LDAP Protocol.

  # OpenLDAP 默认只允许使用 LDAP 协议的第三版本(LDAPv3)。

  # 如果需要强制使用 LDAPv3,则可以使用以下参数:

  #require LDAPv3

  # 如果需要提供 LDAPv2 的支持,需要加入以下参数:

  allow bind_v2

  # 日志级别,用于调试。不建议在生产环境中使用调试模式,可能降低服务器性能。

  loglevel 256

  # ... skip many lines here ...

  database bdb

  suffix "dc=bibby,dc=org"

  rootdn "cn=Manager,dc=bibby,dc=org"

  rootpw {SSHA}mHzQL7t4YG/a6g5mt2YPLE/+ErmekI34

  directory /var/openldap-data/bibby.org/

  index objectClass eq

  index mail,mailbox,maildrop,quota,uid,cn,o eq

  

  默认的配置文件只使用(include)了一个 schema(core.schema),这里添加了其它个较常用的 schema:

  corba.schema

  cosine.schema

  inetorgperson.schema

  nis.schema

  authldap.schema

  

  

  schema 文件的先后顺序非常重要,因为后面定义的属性的值,会覆盖前面加载的 schema 中定义的。

  pidfile/argsfile:这里的 pidfileargsfile的路径都没有采用默认的 /var/run/,因为我们将以 _openldap:_openldap这个用户和用户组的身份来运行 openldap 服务,而 /var/run/目录的权限不允许 _openldap用户创建 pid 文件,所以这里采用新建 /var/run/openldap/目录,并将该目录的 owner 设置为 _openldap:_openldap的方式,使得 _openldap用户能够将 pid 文件存放在这个目录下。

  require LDAPv3, allow bind_v2:这是提供 LDAPv2 协议的支持。OpenLDAP 默认强制使用 LDAPv3。

  loglevel:这是定义 OpenLDAP 的日志级别。不建议在实际生产环境中使用调试模式,因为大量的日志,需要频繁地使用~I/O,对~LDAP~服务器的性能有一定影响。

  

  

  OpenLDAP 默认将所有日志信息发送到 syslogd 的 'local4' 这个日志级别。所以,为了便于调试,可以将所有日志单独存放在某个日志文件里,比如:/var/log/openldap。修改 /etc/syslog.conf,增加一行:

  # File: part of /etc/syslog.conf

  # Notice: run 'touch /var/log/openldap' first.

  local4.* /var/log/openldap

  

  再手动创建 /var/log/openldap 这个文件,并通知 syslog 程序重新读取配置文件:

  # touch /var/log/openldap

  # kill -HUP $(cat /var/run/syslog.pid)

  

  database:这是定义 OpenLDAP 使用哪种数据库作为 backend,用来存储数据。以下两个版本所使用的 backend 有所不同,请根据自己的需要进行选择:

  openldap-server-2.3.33p1.tgz:只能使用 ldbm 作为 backend

  openldap-server-2.3.33p1-bdb.tgz:可以使用 bdb 作为 backend

  suffix:这是定义 LDAP 树的前缀。

  

  

  OpenLDAP 支持多个 suffix,这可以通过定义多个 database 来指定。

  rootdn:这是定义用来管理整个 LDAP 的管理员账号。

  rootpw:这是设定 rootdn 的密码。

  

  

  这里的 rootpw 後面的是使用 slappasswd 生成的密码,默认是使用 SSHA 这个加密算法的:

  # slappasswd

  New password:

  Re-enter new password:

  {SSHA}mHzQL7t4YG/a6g5mt2YPLE/+ErmekI34

  

  可以用 -h参数指定 slappasswd使用其它的加密算法。比如:

  # slappasswd -h {MD5}

  

  directory:这是定义 OpenLDAP 的数据都存放在哪个目录下。

  创建目录并设置权限:

  # mkdir /var/run/openldap

  # chown -R _openldap:_openldap /var/run/openldap

  # mkdir /var/openldap-data/bibby.org/

  # chown -R _openldap:_openldap /var/openldap-data

  # chmod -R 700 /var/openldap-data

  

  index,是让 LDAP 维护这几个属性的索引(index),可以加快 LDAP 查询速度。

  启动 OpenLDAP

  都配置好了,现在可以启动 OpenLDAP 了:

  # /usr/local/libexec/slapd -u _openldap -g _openldap

  [1] 7558

  

  这时候在 /var/log/openldap 里应该已经有一些信息了,不妨现在查看一下:

  # tail /var/log/openldap

  Sep 20 22:07:00 mail slapd[5496]: @(#) $OpenLDAP: slapd 2.3.33 (Mar 6 2007 20:51:09) $

  @i386.ports.openbsd.org:/usr/obj/i386/openldap-2.3.33-bdb/build-i386-bdb/servers/slapd

  Sep 20 22:07:01 mail slapd[5496]: WARNING: No dynamic config support for database ldbm.

  Sep 20 22:07:01 mail slapd[5496]: slapd starting

  

  如果看到有类似的输出,则表示确实在跑着。

  /etc/rc.conf.local

  在 /etc/rc.conf.local中加入以下内容:

  openldap_flags="-u _openldap -g _openldap"

  

  /etc/rc.local

  在 /etc/rc.local中加入以下内容:

  # Start OpenLDAP daemon.

  if [ X"${openldap_flags}" != X"NO" ]; then

  echo -n ' OpenLDAP'

  mkdir /var/run/openldap

  chown -R _openldap:_openldap /var/run/openldap

  /usr/local/libexec/slapd ${openldap_flags}

  fi

  

  reboot

  到这里就已经配置好了 OpenLDAP 服务器,建议重启以检查一下是否正常运行。

  初始化 LDAP

  LDAP 树结构

  这是我们规划好的 LDAP 树结构,请根据自己的需要进行调整:

  dc=bibby,dc=org

  |- cn=Manager

  |- o=domains

  |- o=domain1.com

  |- cn=bibby(mail=bibby@domain1.com)

  |- o=domain2.com

  

  root entry: dc=bibby,dc=org

  将以下代码保存为一个文件,例如 root.ldif。

  dn: dc=bibby,dc=org

  objectclass: dcObject

  objectclass: organization

  dc: bibby

  o: bibby

  

  请先确认 OpenLDAP 已经正在运行,再使用 OpenLDAP 提供的 ldapadd 工具将这个 root dn 添加进去,之后在 phpLDAPadmin 里就能看到这个 dn 了:

  # ldapadd -x -D "cn=Manager,dc=bibby,dc=org" -W -f root.ldif

  Enter LDAP Password:

  adding new entry "dc=bibby,dc=org"

  #

  

  简单解释:

  -x:使用认证;

  -D:指定使用哪个 dn 来操作;

  -W:提示输入密码;

  -f:指定要添加的 entry 的内容从文件中读入;

  详细解释请参考以下命令的输出信息:

  # ldapadd -h

  # man ldapadd

  

  看看结果:

  # ldapsearch -x -D 'cn=Manager,dc=bibby,dc=org' -b 'dc=bibby,dc=org' -W

  Enter LDAP Password:

  # extended LDIF

  #

  # LDAPv3

  # base with scope subtree

  # filter: (objectclass=*)

  # requesting: ALL

  #

  # bibby.org

  dn: dc=bibby,dc=org

  objectClass: dcObject

  objectClass: organization

  dc: bibby

  o: bibby

  # search result

  search: 2

  result: 0 Success

  # numResponses: 2

  # numEntries: 1

  #

  

  看到刚才添加的 dn 了吧?

  简单解释:

  -b:要查找哪个 dn 下的内容(base dn for search);

  更详细信息请参考以下命令的输出信息:

  # ldapsearch -h

  # man ldapsearch

  

  cn=Manager,dc=bibby,dc=org

  将以下内容保存为 manager.ldif 文件后使用 ldapadd 添加:

  dn: cn=Manager,dc=bibby,dc=org

  objectClass: organizationalRole

  cn: Manager

  

  o=domains,dc=bibby,dc=org

  将以下内容保存为 base_ou.ldif 文件后使用 ldapadd 添加:

  dn: o=domains,dc=bibby,dc=org

  objectClass: Organization

  o: domains

  

  Postfix 查找用户将从 o=domains,dc=bibby,dc=org 开始查询。

  uid=vmail,o=domains,dc=bibby,dc=org

  这个帐号将用于 saslauthd/postfix 连接 LDAP 查询用户信息,它对 o=domains,dc=bibby,dc=org 下的所有内容都有管理权限。在添加之前请确认这里的 uidNumber/gidNumber:

  dn: uid=vmail,o=domains,dc=bibby,dc=org

  cn: vmail

  objectClass: organizationalRole

  objectClass: top

  objectClass: posixAccount

  gidNumber: 1002

  homeDirectory: /home/vmail/

  uid: vmail

  uidNumber: 1002

  userPassword: 123456

  

  在使用 ldapadd 添加好之后,打开 /etc/openldap/slapd.conf 文件,在 'database bdb' 这一行之前添加以下内容,用于作访问控制:

  access to dn.children="o=domains,dc=bibby,dc=org"

  by self write

  by dn="uid=vmail,o=domains,dc=bibby,dc=org" read

  by * auth

  access to *

  by * none

  

  o=domainX.com,o=domains,dc=bibby,dc=org

  下面则是针对每个不同的域设置的一个子结点。

  将以下内容复制保存后,使用 ldapadd 添加:

  dn: o=domain1.com,o=domains,dc=bibby,dc=org

  objectClass: Organization

  o: domain1.com

  dn: o=domain2.com,o=domains,dc=bibby,dc=org

  objectClass: Organization

  o: domain2.com

  

  这里的属性 o 指定的值将会被直接作为邮件地址的后缀,类似于 @domain1.com。

  uid=bibby,o=domain1.com,o=domains,dc=bibby,dc=org

  以下 LDIF 文件的内容是将一个用户添加到 domain1.com 中。在 Appendix章节中为 LDAP 管理员提供了用于手工批量创建用户的 Shell 脚本。

  dn: uid=bibby,o=domain1.com,o=domains,dc=bibby,dc=org

  objectClass: top

  objectClass: organizationalPerson

  objectClass: CourierMailAccount

  objectClass: CourierMailAlias

  homeDirectory: /home/vmail/domains

  mailbox: domain1.com/bibby/Maildir/

  mail: bibby@domain1.com

  maildrop: bibby@domain1.com

  quota: 10240000S

  userPassword: {MD5}e41hj20lJ7j0XSksFgCEuw==

  uid: bibby

  cn: bibby

  sn: bibby

  

  这里已经设置了邮箱的路径,即 homeDirectory + mailbox:

  /home/vmail/domains/domain1.com/bibby/Maildir/

  

  这里也设置了用户的初始密码:

  userPassword: {MD5}e41hj20lJ7j0XSksFgCEuw==

  

  这里的初始密码也是用 slappasswd 工具生成的。

  当然也可以直接用明文来保存密码:

  userPassword: 123456

  

  另外,这里的 maildrop 是为了设置邮箱容量限额(quota)用的。它由 CourierMailAlias 这个 objectClass 提供。

  quota 里的 10240000S 表示的是 10M(Size of 10240000 Bytes),你也可以写成是 100C 来表示总共 100 个文件/邮件(count (C) of 100 files)。

  phpLDAPadmin

  安装 phpLDAPadmin# pkg_add phpldapadmin

  phpldapadmin-1.0.1p0: complete

  --- phpldapadmin-1.0.1p1 -------------------

  phpLDAPAdmin has been installed into /var/www/phpldapadmin-1.0.1

  Edit /var/www/phpldapadmin-1.0.1/config/config.php to configure phpLDAPAdmin

  You should point this to the DocumentRoot of your web-server:

  # ln -s ../phpldapadmin-1.0.1 /var/www/htdocs/phpldapadmin

  (make sure you use a relative symlink since Apache is chrooted)

  For jpeg photos to work properly, you must do this:

  # mkdir /var/www/tmp

  # chown www:daemon /var/www/tmp

  # chmod 1755 /var/www/tmp

  Where tmp is the $jpeg_temp_dir configured in config.php

  You can ensure you have a working install by accessing:

  http:///phpldapadmin/index.php

  

  将 phpldapadmin 做一个符号链接到 /var/www/htdocs 目录:

  # cd /var/www/htdocs

  # ln -s ../phpldapadmin-1.0.1 phpldapadmin

  

  另外,由于 apache 默认是被 chroot 在 /var/www 目录下的,所以如果程序需要访问 /tmp 目录,则必须为它设置 /var/www/tmp 目录:

  # mkdir /var/www/tmp

  # chown www:daemon /var/www/tmp

  # chmod 1755 /var/www/tmp

  

  配置 phpLDAPadmin

  默认情况下,phpLDAPadmin 不需要任何修改就可以直接登录了。但是这里为了将它所能浏览的内容限制在一定范围,需要在配置文件 phpldapadmin/config/config.php 中修改以下一个参数:

  $ldapservers->SetValue($i,'server','base',array('o=domains,dc=bibby,dc=org'));

  

  这样修改之后,登录 phpLDAPadmin 就只能看到 o=domains,dc=bibby,dc=org 这个节点以下的内容了。

  登录 phpLDAPadmin

  

  phpLDAPadmin 登录界面

  现在可以访问: http://IP/phpldapadmin/作测试了。用户名为 /etc/openldap/slapd.conf 中设置的 dn 的值:

  cn=Manager,dc=bibby,dc=org

  

  密码就是在 /etc/openldap/slapd.conf 里的 rootpw,当然,输入的肯定不是 '{SSHA}XXXXXXXXX' 那一大串,而是用 slappasswd 生成加密字符串时的密码。如下图所示:

  Postfix

  Cyrus-SASL:smtpd 认证

  在安装 php5-ldap 组件时,cyrus-sasl2 已经作为依赖的包被安装上了。但是这里却需要 SASL2 能够支持 LDAP,所以这时候只好使用 cyrus-sasl2...-ldap 包来替换掉它:

  # pkg_add -r cyrus-sasl-2.1.22p1-ldap

  cyrus-sasl-2.1.22p1-ldap (extracting): complete

  cyrus-sasl-2.1.22p1 (deleting): complete

  cyrus-sasl-2.1.22p1-ldap (installing): complete

  Clean shared items: complete

  --- cyrus-sasl-2.1.22p1 -------------------

  You should also run rm -rf /var/sasl2/*

  #

  # rm -rf /var/sasl2/*

  

  /usr/local/lib/sasl2/smtpd.confpwcheck_method: saslauthd

  mech_list: plain login

  

  /etc/saslauthd.confldap_servers: ldap://127.0.0.1/

  ldap_search_base: o=domains,dc=bibby,dc=org

  ldap_timeout: 10

  ldap_bind_dn: uid=vmail,o=domains,dc=bibby,dc=org

  ldap_bind_pw: 123456

  ldap_filter: mail=%u@%r

  

  /etc/rc.conf.localsaslauthd_flags="-a ldap -O /etc/saslauthd.conf -m /var/spool/postfix/var/sasl2/"

  

  注意,这里是大写字母 -O,而不是数字0。

  如果需要调试 SASL 认证,请在命令行下使用 -d 参数执行 saslauthd:

  # /usr/local/sbin/saslauthd -a ldap -O /etc/saslauthd.conf -m /var/spool/postfix/var/sasl2/ -d &

  

  

  

  注意:-d 参数请不要用在 /etc/rc.conf.local 文件中,这个参数只适合在命令行下执行。

  

  

  添加的 -m 参数是参考了这个贴子:postfix-2.2.0-sasl2-ldap / cyrus-sasl-2.1.20p3-ldap on OpenBSD 3.7

  /etc/rc.local# Start the SASL2 auth daemon

  if [ X"${saslauthd_flags}" != X"NO" ] ; then

  echo -n ' saslauthd'

  mkdir -p /var/spool/postfix/var/sasl2 2>/dev/null

  /usr/local/sbin/saslauthd ${saslauthd_flags}

  fi

  

  测试 SASL 认证

  将 /etc/saslauthd.conf 中的 ldap_filter 的值修改为:

  ldap_filter: mail=%u

  

  之后可以使用 testsaslauthd 进行测试:

  # mkdir -p /var/spool/postfix/var/sasl2

  # /usr/local/sbin/saslauthd -a ldap -O /etc/saslauthd.conf -m /var/spool/postfix/var/sasl2 -d &

  #

  # testsaslauthd -f /var/spool/postfix/var/sasl2/mux -u bibby@domain1.com -p password

  0: OK "Success."

  #

  

  

  

  因为 OpenBSD 下的 Postfix 被 chroot 在 /var/spool/postfix 底下,所以不能用默认的 /var/sasl2/ 目录,而应该用 /var/spool/postfix/var/sasl2/。

  /var/log/authlog

  SASL 的日志都会记录在该日志文件中:/var/log/authlog

  安装 Postfix

  为了让 Postfix 支持 OpenLDAP 作为后台存储用户信息,也支持 SASL 认证,只好通过 ports 编译来加入我们需要的功能。

  先用 packages 安装依赖包:

  # pkg_add pcre

  pcre-7.1: complete

  #

  

  再编译 postfix:

  # cd /usr/ports/mail/postfix/stable/

  # FLAVOR="sasl2 ldap" make package

  ===> Checking files for postfix-2.3.7-sasl2-ldap

  `/usr/ports/distfiles/postfix/postfix-2.3.7.tar.gz' is up to date.

  >> Checksum OK for postfix/postfix-2.3.7.tar.gz. (sha1)

  ===> postfix-2.3.7-sasl2-ldap depends on: pcre-* - found

  ===> postfix-2.3.7-sasl2-ldap depends on: cyrus-sasl-* - found

  ===> postfix-2.3.7-sasl2-ldap depends on: openldap-client-2.* - found

  ===> Verifying specs: pcre sasl2 ldap.>=2 lber pcre sasl2 ldap.>=2 lber c crypto ssl c crypto ssl

  ===> found pcre.1.0 sasl2.2.21 ldap.9.1 lber.9.1 c.40.3 crypto.13.0 ssl.11.0

  ===> Extracting for postfix-2.3.7-sasl2-ldap

  ===> Patching for postfix-2.3.7-sasl2-ldap

  ===> Configuring for postfix-2.3.7-sasl2-ldap

  [...snip...]

  ===> Building package for postfix-2.3.7-sasl2-ldap

  Create /usr/ports/packages/i386/all/postfix-2.3.7-sasl2-ldap.tgz

  Link to /usr/ports/packages/i386/ftp/postfix-2.3.7-sasl2-ldap.tgz

  #

  

  安装 postfix:

  # pkg_add /usr/ports/packages/i386/all/postfix-2.3.7-sasl2-ldap.tgz

  postfix-2.3.7-sasl2-ldap: complete

  --- postfix-2.3.7-sasl2-ldap -------------------

  -> Creating /etc/mailer.conf.postfix

  -> Creating Postfix spool directory and chroot area under /var/spool/postfix

  Warning: you still need to edit myorigin/mydestination/mynetworks

  parameter settings in /etc/postfix/main.cf.

  See also http://www.postfix.org/STANDARD_CONFIGURATION_README.html

  for information about dialup sites or about sites inside a

  firewalled network.

  BTW: Check your /etc/mail/aliases file and be sure to set up

  aliases that send mail for root and postmaster to a real person,

  then run /usr/local/sbin/newaliases.

  +---------------

  | Configuration files has been installed in /etc/postfix.

  | Please update these files to meet your needs.

  +---------------

  +---------------

  | Postfix can be set up to replace sendmail entirely. Please read the

  | documentation at file:/usr/local/share/doc/postfix/html/index.html or

  | http://www.postfix.org/ carefully before you decide to do this!

  |

  | To replace sendmail with postfix you have to install a new mailer.conf

  | using the following command:

  |

  | /usr/local/sbin/postfix-enable

  |

  | If you want to restore sendmail, this is done using the following command:

  |

  | /usr/local/sbin/postfix-disable

  +---------------

  #

  

  安装后的初步配置

  根据提示,执行命令替换掉系统里的 sendmail:

  # /usr/local/sbin/postfix-enable

  

  修改参数让 postfix 在系统启动时自动启动:

  # echo 'sendmail_flags="-bd"' >>/etc/rc.conf.local

  

  为 postfix 添加 syslogd 参数:

  # echo 'syslogd_flags="-a /var/spool/postfix/dev/log"' >>/etc/rc.conf.local

  

  将 crontab 里的定时任务也去掉(在行首加上注释符号'#' 即可): # crontab -e

  #*/30 * * * * /usr/sbin/sendmail -L sm-msp-queue -Ac -q

  

  配置 Postfix

  /etc/postfix/main.cf

  Generic

  根据自己的需要,配置以下参数:

  # File: /etc/postfix/main.cf

  # myhostname,表示邮件服务器都主机名,通常和系统的 hostname 一致。

  myhostname = mail.bibby.org

  # 邮件服务器所在的域。

  mydomain = bibby.org

  myorigin = $myhostname

  # inet_interfaces,指定邮件服务器将监听从哪些网络接口进来的服务请求

  inet_interfaces = all

  mynetworks = 127.0.0.0/8

  # 这里指定别名(alias)文件的位置。

  # 如果使用 /etc/postfix/aliases 文件,还需要执行这个命令:

  # # postalias hash:/etc/postfix/aliases

  # 也可以直接指定为 sendmail 所使用的 aliases 文件:

  # alias_maps = hash:/etc/aliases

  # 如果使用 /etc/aliases,还需要执行这个命令:

  # # /usr/local/sbin/newaliases

  alias_maps = hash:/etc/postfix/aliases

  # 邮箱格式将使用 Maildir 格式,而不是 mbox。

  home_mailbox = Maildir/

  

  

  

  这里的 /etc/postfix/aliases 文件已由 postfix 提供了,但是还需要多执行一个 postalias 命令来生成 postfix 需要的数据库:

  # postalias hash:/etc/postfix/aliases

  

  

  

  如果需要使用 Sendmail 的 aliases 文件(/etc/aliases),则还需要执行 /usr/local/sbin/newaliases 命令:

  # /usr/local/sbin/newaliases

  

  虚拟域/虚拟用户

  以下内容是通过 LDAP 获取虚拟域和虚拟用户的部分,需要添加在 Postfix 的 main.cf 配置文件中:

  #

  # mydestination and Virtual Domains.

  #

  # mydestination,非常重要的一个参数。告诉邮件服务器,需要将哪些邮件接收下来。

  # 在这里表示所有邮件接收人的地址为以下域名结尾的都会被本邮件服务器给收下来:

  # - @localhost

  # - @mail.bibby.org

  # - @domain1.com

  # - @domain2.com

  # 其中,domain1.com, domain2.com 都是我们做的虚拟域。这些虚拟域都是存放

  # LDAP 里的。

  mydestination = $myhostname, localhost, ldap:virtualdomains

  virtualdomains_server_host = 127.0.0.1

  virtualdomains_server_port = 389

  virtualdomains_bind = yes

  virtualdomains_version = 3

  virtualdomains_bind_dn = uid=vmail,o=domains,dc=bibby,dc=org

  virtualdomains_bind_pw = 123456

  virtualdomains_search_base = o=domains,dc=bibby,dc=org

  virtualdomains_query_filter = (o=%s)

  virtualdomains_result_attribute = o

  #

  # LDAP configuration for Virtual Users.

  #

  transport_maps = hash:/etc/postfix/transport

  virtual_minimum_uid = 1002

  virtual_uid_maps = static:1002

  virtual_gid_maps = static:1002

  virtual_mailbox_base = /home/vmail/domains

  virtual_mailbox_maps = ldap:accounts

  accounts_server_host = 127.0.0.1

  accounts_server_port = 389

  accounts_version = 3

  accounts_search_base = o=domains,dc=bibby,dc=org

  accounts_query_filter = (&(mail=%s)(objectClass=CourierMailAccount))

  accounts_result_attribute = mailbox

  accounts_bind = yes

  accounts_bind_dn = uid=vmail,o=domains,dc=bibby,dc=org

  accounts_bind_pw = 123456

  accountsmap_server_host = 127.0.0.1

  accountsmap_server_port = 389

  accountsmap_version = 3

  accountsmap_bind = yes

  accountsmap_bind_dn = uid=vmail,o=domains,dc=bibby,dc=org

  accountsmap_bind_pw = 123456

  accountsmap_search_base = o=domains,dc=bibby,dc=org

  accountsmap_query_filter = (&(mail=%s)(objectClass=CourierMailAccount))

  accountsmap_result_attribute = mail

  virtual_maps = ldap:aliases

  aliases_server_host = 127.0.0.1

  aliases_server_port = 389

  aliases_version = 3

  aliases_bind = yes

  aliases_bind_dn = uid=vmail,o=domains,dc=bibby,dc=org

  aliases_bind_pw = 123456

  aliases_search_base = o=domains,dc=bibby,dc=org

  aliases_query_filter = (&(mail=%s)(objectClass=CourierMailAlias))

  aliases_result_attribute = maildrop

  local_recipient_maps = $alias_maps $virtual_mailbox_maps

  

  

  

  请将这里的 o=domains,dc=bibby,dc=org 替换成你自己设置好的 LDAP 结构。

  

  

  请留意这里的这几个参数和值:

  transport_maps = hash:/etc/postfix/transport

  virtual_mailbox_base = /home/vmail/domains

  virtual_minimum_uid = 1002

  virtual_uid_maps = static:1002

  virtual_gid_maps = static:1002

  /etc/postfix/transport

  transport_maps = hash:/etc/postfix/transport

  Postfix 会从 transport_maps 参数指定的文件中查找虚拟域,所以我们需要在 /etc/postfix/transport 文件中加入我们的虚拟域的信息:

  domain1.com virtual:

  domain2.com virtual:

  

  编辑完后还需要执行以下命令,否则 Postfix 会报错:

  # /usr/local/sbin/postmap /etc/postfix/transport

  

  另外,为了 Postfix 能够解析 domainX.com 的域名,这里将使用 /etc/hosts 文件来负责解析:

  127.0.0.1 domain1.com www.domain1.com mail.domain1.com

  127.0.0.1 domain2.com www.domain2.com mail.domain2.com

  

  

  

  域名解析属于 DNS 服务器的工作,如果您需要让互联网上的其它服务器能够解析你的域名,请设置您的 DNS 服务器。

  virtual mailbox/uid/gid

  virtual_mailbox_base = /home/vmail/domains

  virtual_minimum_uid = 1002

  virtual_uid_maps = static:1002

  virtual_gid_maps = static:1002

  这里我们将创建一个新的用户 vmail,用它的 HOME 目录来存放所有域、所有用户的邮件。这里的 UID/GID 都是指 vmail 这个用户的 UID/GID。

  创建 vmail 用户和组:

  # useradd -m -d /home/vmail -s /sbin/nologin -u 1002 -g=uid vmail

  

  接下来创建用于存放虚拟域所有用户邮件的目录,并设置权限:

  # mkdir -p /home/vmail/domains/

  # chown -R vmail:vmail /home/vmail/domains

  # rm -f /home/vmail/.*

  

  这里的 /home/vmail/domains 下存放所有以虚拟域的域名命名的目录,用于存放各个域内用户的邮件:

  /home/vmail/domains/domain1.com

  /home/vmail/domains/domain2.com

  所以在 /etc/postfix/main.cf 中设置:

  virtual_mailbox_base = /home/vmail/domains

  

  

  

  注意这里的 HOME 目录:/home/vmail。这个目录将用于存放所有域用户的邮件,所以可能需要较大空间,请根据自己的实际情况进行规划。

  

  

  如果需要修改 vmail 用户的 HOME 目录,请使用 vipw 命令修改 /etc/passwd 文件:

  # vipw

  

  

  

  你可能注意到了,我们并没有创建这样的目录:

  /home/vmail/domains/domain1.com

  /home/vmail/domains/domain2.com

  

  因为 Postfix 会自动创建它,所以这里我们不需要创建。

  SASL 用户认证

  以下内容是通过 SASL 进行用户认证的部分,将它加到 /etc/postfix/main.cf 中:

  # For SASL auth

  smtpd_sasl_auth_enable = yes

  smtpd_sasl_local_domain =

  smtpd_sasl_security_options = noanonymous

  broken_sasl_auth_clients = yes

  smtpd_recipient_restrictions = permit_mynetworks,

  permit_sasl_authenticated,

  reject_unauth_destination

  # reject_non_fqdn_hostname,

  # reject_non_fqdn_sender,

  # reject_non_fqdn_recipient,

  # reject_unauth_pipelining,

  # reject_invalid_hostname,

  

  

  

  关于如何在 OpenBSD 的 postfix 中配置 sasl 认证,可以在 /usr/local/share/doc/postfix/readme/SASL_README文件中找到配置的详细信息。

  到此,Postfix 的配置就已经完成了,建议您重启系统以进行 Postfix 的 SMTP 测试。

  # reboot

  

  测试 Postfix 的 SMTP 功能

  默认情况下,SMTP 服务使用 25 端口监听服务请求。

  # telnet localhost 25

  Trying ::1...

  Connected to localhost.

  Escape character is '^]'.

  220 mail.bibby.org ESMTP Postfix #<-- 看到这个就表示 Postfix 在监听 25 端口

  helo localhost #<-- 执行

  250 mail.bibby.org

  mail from: bibby@domain1.com #<-- 执行,from 表示发件人

  250 2.1.0 Ok

  rcpt to: bibby@domain1.com #<-- 执行,to 表示收件人

  250 2.1.5 Ok

  data #<-- 执行,data 表示邮件正文

  354 End data with .

  hello. #<-- 从这里开始输入邮件正文

  Contact me: michaelbibby#gmail.com

  . #<-- 一个点加回车,表示邮件正文编写完毕

  250 2.0.0 Ok: queued as A47D0197B4 #<-- 这里是这封邮件在队列中的编号,您看到的可能和这里的不一样

  quit #<-- 执行,退出 telnet

  221 2.0.0 Bye

  Connection closed by foreign host.

  #

  

  

  

  在输入以下两句命令时,Postfix 会查询 LDAP,所以可能会比较慢:

  mail from: bibby@domain1.com

  rcpt to: bibby@domain1.com

  

  如果这里出现问题,请查看 Postfix 的日志文件以查找问题所在:/var/log/maillog,主要问题应该是在 /etc/postfix/main.cf 文件中 LDAP 的设置上。

  这是在 Postfix 的邮件日志(/var/log/maillog)里的内容:

  Sep 21 21:15:02 mail postfix/smtpd[2536]: connect from localhost[::1]

  Sep 21 21:15:21 mail postfix/smtpd[2536]: 4486F197B4: client=localhost[::1]

  Sep 21 21:15:28 mail postfix/cleanup[25905]: 4486F197B4: message-id=<20070921131521.4486F197B4@mail.bibby.org>

  Sep 21 21:15:28 mail postfix/qmgr[27062]: 4486F197B4: from=, size=333, nrcpt=1 (queue active

  )

  Sep 21 21:15:28 mail postfix/virtual[26736]: 4486F197B4: to=, relay=virtual, delay=14, delay

  s=14/0.05/0/0.01, dsn=2.0.0, status=sent (delivered to maildir)

  Sep 21 21:15:28 mail postfix/qmgr[27062]: 4486F197B4: removed

  Sep 21 21:15:30 mail postfix/smtpd[2536]: disconnect from localhost[::1]

  

  看起来邮件是顺利投递出去了。看看文件系统上是否有邮件文件:

  # ls /home/vmail/domains/domain1.com/bibby/Maildir/new/

  1190380785.V0If18bM813706.mail.bibby.org

  

  呵,看来邮件已经正确投递了,看看邮件里的内容是否和刚才发出去的一样:

  # cat /home/vmail/domains/domain1.com/bibby/Maildir/new/1190380785.V0If18bM813706.mail.bibby.org

  Return-Path:

  X-Original-To: bibby@domain1.com

  Delivered-To: bibby@domain1.com

  Received: from localhost (localhost [IPv6:::1])

  by mail.bibby.org (Postfix) with SMTP id 83AC8197B4

  for ; Fri, 21 Sep 2007 21:21:18 +0800 (HKT)

  Message-Id: <20070921132123.83AC8197B4@mail.bibby.org>

  Date: Fri, 21 Sep 2007 21:21:18 +0800 (HKT)

  From: bibby@domain1.com

  To: undisclosed-recipients:;

  hello.

  Contact me: michaelbibby#gmail.com

  #

  

  呵,这下放心了。

  到此为止,SMTP 服务正常工作。接下来的任务是 POP3/IMAP。

  Debug

  如果在这里出现了错误,建议给 /etc/postfix/master.cf (第九行)中的 smtpd 加上 -v 参数:

  smtp inet n - - - - smtpd -v

  

  Courier

  安装 courier-*

  安装以下软件包:

  courier-authlib

  courier-authlib-ldap

  courier-imap

  courier-pop3

  courier-authlib-ldap# pkg_add courier-authlib-ldap

  libltdl-1.5.22p2: complete

  expect-5.43.0p0-no_tk:tcl-8.4.7p5: complete

  expect-5.43.0p0-no_tk: complete

  courier-authlib-0.58p3: complete

  courier-authlib-ldap-0.58p3: complete

  --- courier-authlib-0.58p3 -------------------

  Sample configuration files are installed in /etc/courier/.

  --- tcl-8.4.7p5 -------------------

  You may wish to add /usr/local/lib/tcl8.4/man to /etc/man.conf

  #

  

  courier-authlib-ldap 的配置文件都在 /etc/courier/ 目录下,主要是这两个文件:

  authdaemonrc

  authldaprc

  courier-imap# pkg_add courier-imap

  gdbm-1.8.3p0: complete

  courier-imap-4.1.1p2: complete

  --- courier-imap-4.1.1p2 -------------------

  You now need to edit appropriately the Courier-IMAP configuration files

  installed in /etc/courier/courier/.

  Pay particular attention to the details in imapd.cnf, and read ssl(8) if

  necessary. You MUST set the CN in imapd.cnf to the hostname by which

  your IMAP server is accessed, or else clients will complain. When this

  is done, you can use the 'mkimapdcert' script to automatically generate

  a server certificate, which is installed into /etc/ssl/private/imapd.pem

  To control the daemon use /usr/local/libexec/imapd.rc and

  /usr/local/libexec/imapd-ssl.rc, and to run the authdaemon, place the

  following in /etc/rc.local:

  mkdir -p /var/run/courier{,-auth}/

  /usr/local/sbin/authdaemond start

  

  courier-pop3# pkg_add courier-pop3

  courier-pop3-4.1.1p0: complete

  --- courier-pop3-4.1.1p0 -------------------

  You now need to edit appropriately the Courier-POP3 configuration files

  installed in /etc/courier/courier/.

  To use POP3-SSL, be sure to read ssl(8) and run the mkpop3dcert script

  if you require a self-signed certificate.

  To control the daemon use /usr/local/libexec/pop3.rc and

  /usr/local/libexec/pop3-ssl.rc.

  

  配置 Courier-IMAP/POP3

  /etc/courier/authdaemonrc

  告诉 Courier,使用 LDAP 进行认证:

  authmodulelist="authldap"

  authmodulelistorig="authldap"

  

  /etc/courier/authldaprc# 指定 LDAP 服务器

  LDAP_URI ldap://127.0.0.1:389

  # 指定从 LDAP 树的哪个子树开始查找

  LDAP_BASEDN o=domains,dc=bibby,dc=org

  LDAP_BINDDN uid=vmail,o=domains,dc=bibby,dc=org

  LDAP_BINDPW 123456

  LDAP_AUTHBIND 1

  LDAP_FILTER (objectClass=CourierMailAccount)

  LDAP_GLOB_UID vmail

  LDAP_GLOB_GID vmail

  LDAP_MAILDIRQUOTA quota

  LDAP_FULLNAME cn

  

  这里因为没有为 LDAP 提供 SSL 支持,所以 LDAP_URI 里应该写 'ldap://x.x.x.x:389',如果是使用 TLS/SSL 支持的 LDAP,则应该写成是 'ldaps://x.x.x.x:389'。

  /etc/rc.conf.local# For courier imap/pop3 daemon.

  imapd_flags=""

  pop3d_flags=""

  authdaemond_flags=""

  

  /etc/rc.local# Start the Courier IMAP daemon

  if [ X"${imapd_flags}" != X"NO" ]; then

  echo -n ' imap'

  mkdir /var/run/courier 2>/dev/null

  /usr/local/libexec/imapd.rc start

  fi

  # Start the Courier POP3 daemon

  if [ X"${pop3d_flags}" != X"NO" ]; then

  echo -n ' pop3'

  mkdir /var/run/courier 2>/dev/null

  /usr/local/libexec/pop3d.rc start

  fi

  # Start SASL authdaemond.

  if [ X"${authdaemond_flags}" != X"NO" ]; then

  echo -n ' authdaemond'

  mkdir /var/run/courier-auth 2>/dev/null

  /usr/local/sbin/authdaemond start

  fi

  

  到此,建议重启系统以测试配置。

  # reboot

  

  测试 POP3/IMAP

  重启之后建议使用 Thunderbird 等邮件客户端进行 SMTP/POP3/IMAP 功能的测试。

  收发邮件的用户名,填的应该是邮件地址。比如:bibby@domain1.com,而不是:bibby。

  Debug

  pop3

  简单的 POP3 验证测试:

  # telnet localhost 110

  Trying ::1...

  Connected to localhost.

  Escape character is '^]'.

  +OK Hello there.

  user bibby@domain1.com # <-- 输入用户名

  +OK Password required.

  pass 123456 # <-- 输入密码

  +OK logged in. # <-- 验证成功

  

  如果在测试时碰到以下这种的情况,可以先用 SMTP 功能发送一封邮件给用户,然后再测试:

  # telnet localhost 110

  Trying ::1...

  Connected to localhost.

  Escape character is '^]'.

  +OK Hello there.

  user bibby@domain1.com # <-- 输入用户名

  +OK Password required.

  pass 123456 # <-- 输入密码

  -ERR chdir domain1.com/bibby/Maildir/ failed # <-- Maildir/ 不存在

  

  authdaemon

  在 /etc/courier/authdaemonrc 中有一个关于调试的参数:

  ##NAME: DEBUG_LOGIN:0

  #

  # Dump additional diagnostics to syslog

  #

  # DEBUG_LOGIN=0 - turn off debugging

  # DEBUG_LOGIN=1 - turn on debugging

  # DEBUG_LOGIN=2 - turn on debugging + log passwords too

  DEBUG_LOGIN=0

  

  如果需要调试,可以将 DEBUG_LOGIN 的值设置为 1 或者 2。

  WebMail

  SquerrilMail

  安装 SquirrelMail

  从 SquerrilMail 官方网站的 下载页面下载最新版本。

  解压到服务器的 /var/www/htdocs/ 目录(注:这里用 -VERSION 来代替具体的版本号): # bzip2 -d squirrelmail-VERSION.tar.bz2

  # tar xf squirrelmail-VERSION.tar

  # mv squirrelmail-VERSION /var/www/

  # cd /var/www/htdocs/

  # ln -s ../squirrelmail-VERSION mail

  

  修改权限: # chown -R www:www /var/www/squirrelmail-VERSION/

  

  创建目录,用于存放邮件附件等数据: # cd /var/www/squirrelmail-VERSION/

  # mkdir data attach

  # chown www:www data attach

  # chmod 730 attach

  

  配置 SquirrelMail

  

  SquirrelMail 登录界面

  # /var/www/htdocs/mail/config/conf.pl

  

  这里有几个参数需要修改:

  Organization Preferences

  Organization Name

  Server Settings

  Domain

  Update IMAP Settings

  IMAP Server(将 localhost 改成 '127.0.0.1')

  Update SMTP Settings

  SMTP Server(将 localhost 改成 '127.0.0.1')

  General Options

  Data Directory (/squirrelmail-VERSION/data/)

  Attachment Directory (/squirrelmail-VERSION/attach/)

  Languages(其它编码请参考 squirrelmail-VERSION/functions/i18n.php 文件)

  Default Language(改成 zh_CN)

  Default Charset(改成 gb2312,否则会导致邮件乱码)

  Set pre-defined settings for specific IMAP servers

  courier

  因为 Apache 默认是被 chroot 在 /var/www/ 目录下,所以这里的 Data Directory 和 Attachment Directory 目录必须这么写。

  配置完成之后,可以使用 configtest.php 页面帮助检查设置是否正确: http://your_server_ip/mail/src/configtest.php

  OK,如果没有什么问题的话,现在就可以登录 WebMail 了: http://your_server_ip/mail/

  Plugins

  change_ldappass

  从 'change_ldappass'插件的主页下载最新版本。

  解压缩,并复制到正确的位置: # tar zxf change_ldappass-VERSION.tar.gz

  # cp -rf change_ldappass /var/www/squirrelmail-VERSION/plugins/

  #

  # cd /var/www/squirrelmail-VERSION/plugins/

  # chown -R www:www change_ldappass

  # chmod -R 755 change_ldappass

  #

  

  启用插件: # /var/www/squirrelmail-VERSION/config/conf.pl

  

  选择:

  Plugins

  change_ldappass

  保存退出。

  配置 change_ldappass:

  将配置文件模板复制一份:

  # cd /var/www/squirrelmail-VERSION/plugins/change_ldappass

  # cp config_sample.php config.php

  

  在 config.php 文件中需要修改以下内容:

  $ldap_server = '127.0.0.1';

  $ldap_protocol_version = 3;

  $ldap_password_field = 'userPassword';

  $ldap_user_field = 'mail';

  $ldap_base_dn = 'o=domains,dc=bibby,dc=org';

  $ldap_filter = '(objectClass=CourierMailAccount)';

  $query_dn = 'uid=vmail,o=domains,dc=bibby,dc=org';

  $query_pw = '123456';

  

  修改完成之后,用户就可以登录到 SquirrelMail 里,通过菜单 'Options --> Change Password' 来修改 LDAP 里的密码了。

  SpamAssassin

  What SpamAssassin Is

  以下内容引自官方网站:

  SpamAssassin is a mail filter which attempts to identify spam using a variety of mechanisms including text analysis, Bayesian filtering, DNS blocklists, and collaborative filtering databases. SpamAssassin is a project of the Apache Software Foundation (ASF).

  Installation

  使用以下命令安装 SpamAssassin:

  # pkg_add p5-Mail-SpamAssassin

  

  装好以后,可以通过配置文件 /etc/mail/spamassassin/local.cf 文件配置 SpamAssassin。

  /etc/mail/spamassassin/local.cf

  这里 SpamAssassin 的主配置文件。我主要修改了以下几个参数:

  rewrite_header Subject ***** SPAM *****

  report_safe 1

  lock_method flock

  required_score 5.0

  

  配置文件里只有几个基本的参数,并且都带有详细的解释。

  需要更多说明可以参考 man 文档或阅读 官方文档:

  # man Mail::SpamAssassin::Conf

  

  ClamAV

  简介

  以下简介内容来自 ClamAV 官方网站:

  Clam Antivirus是一个UNIX下开源(GPL)杀毒软件包,这个软件最主要目的是集成在邮件服务器里,查杀邮件附件中的病毒。软件中包含主要一个灵活可升级的多线程后台程序,一个命令行扫描程序,一个自动升级程序,软件运行基于随Clam Antivirus软件包同时发布的共享库文件。你也可以在你的软件中使用这些共享库文件,最重要的是,病毒库升级的很快很及时。

  主要特征:

  命令行扫描程序

  高效,多线程后台程序

  支持sendmail的milter接口

  支持数字签名的病毒库升级程序

  支持病毒扫描C语言库

  支持按访问扫描(Linux? and FreeBSD?)

  病毒库每天多次升级(可以查杀的总病毒数量见主页)

  内置支持RAR(2.0),Zip,Gzip,Bzip2,Tar,MS OLE2,MS Cabinet files,MS CHM(压缩的HTML),MS SZDD压缩格式

  内置支持mbox,Maildir和原始邮件文件格式

  内置支持UPX,FSG,和Petite压缩的PE可执行文件

  Installation

  使用 binary package 安装 ClamAV:

  # pkg_add clamav

  --- clamav-0.90.3p1 -------------------

  Edit /etc/clamd.conf and /etc/freshclam.conf

  to use ClamAV.

  Use freshclam to install an up-to-date virus signature database.

  If you want to scan RAR(2.0) and/or ARJ archives, you have to manually

  build and install the archivers/unarj and archivers/unrar ports.

  #

  

  如果需要 ClamAV 能够扫描 RAR/ARJ 格式的压缩文件,需要手动安装以下两个 Ports:

  archivers/unrar

  archivers/unarj

  按照提示,编辑 /etc/clamd.conf 和 /etc/freshclam.conf。

  配置 freshclam/clamd

  /etc/freshclam.conf

  请根据自己的需要去修改配置文件,我这里只修改了这几个参数:

  # Part of file: /etc/freshclam.conf

  #Example # 这一行一定要注释掉

  DatabaseDirectory /var/db/clamav

  UpdateLogFile /var/log/freshclam.log

  LogVerbose yes

  PidFile /var/run/clamav/freshclam.pid

  DatabaseOwner _clamav

  DatabaseMirror db.cn.clamav.net

  

  这里指定了日志文件为:/var/log/freshclam.log,并且属于 _clamav 用户,所以需要创建它:

  # touch /var/log/freshclam.log

  # chown _clamav:_clamav /var/log/freshclam.log

  

  Pid 文件的路径这里没有使用默认的 '/var/run/freshclam.pid',而是使用 '/var/run/clamav' 这个目录来存放,所以还需要额外创建:

  # mkdir /var/run/clamav

  # chown -R _clamav:_clamav /var/run/clamav

  

  现在可以更新病毒库了:

  # freshclam

  

  /etc/clamd.conf

  这是 clamd 程序的配置文件。请根据自己的实际需要修改,我主要修改了以下几个参数:

  # Part of file: /etc/clamd.conf

  #Example # 这一行一定要注释掉

  LogFile /var/log/clamd.log

  LogVerbose yes

  PidFile /var/run/clamav/clamd.pid

  TemporaryDirectory /var/tmp

  DatabaseDirectory /var/db/clamav

  LocalSocket /tmp/clamd

  User _clamav

  

  这里指定了日志文件为:/var/log/clamd.log,并且属于 _clamav 用户,所以需要创建它:

  # touch /var/log/clamd.log

  # chown _clamav:_clamav /var/log/clamd.log

  

  

  

  这里使用的 Pid 文件的存放路径也是使用 '/var/run/clamav/'。

  现在可以直接启动 clamd 了:

  # clamd

  Running as user _clamav (UID 539, GID 539)

  #

  

  先留意一下 clamd 的日志文件:

  # cat /var/log/clamd.log

  +++ Started at Wed Dec 5 09:31:50 2007

  clamd daemon 0.90.3 (OS: openbsd4.2, ARCH: i386, CPU: i386)

  Log file size limited to 1048576 bytes.

  Reading databases from /var/db/clamav

  Loaded 171942 signatures.

  Unix socket file /tmp/clamd

  Setting connection queue length to 15

  ERROR: Can't save PID in file /var/run/clamd.pid

  Listening daemon: PID: 4168

  Archive: Archived file size limit set to 10485760 bytes.

  Archive: Recursion level limit set to 8.

  Archive: Files limit set to 1000.

  Archive: Compression ratio limit set to 250.

  Archive support enabled.

  Algorithmic detection enabled.

  Portable Executable support enabled.

  ELF support enabled.

  Mail files support enabled.

  Mail: Recursion level limit set to 64.

  OLE2 support enabled.

  PDF support disabled.

  HTML support enabled.

  Self checking every 1800 seconds.

  Set stacksize to 1048576

  

  看到类似的信息就表示 clamd 已经开始工作了,现在可以尝试用 clamdscan 去扫描文件:

  # clamdscan /var/log/*

  /var/log/authlog: Access denied. ERROR

  /var/log/authlog.0.gz: Access denied. ERROR

  /var/log/clamd.log: OK

  /var/log/daemon: Access denied. ERROR

  /var/log/failedlogin: Access denied. ERROR

  /var/log/freshclam.log: OK

  /var/log/ftpd: Access denied. ERROR

  /var/log/lastlog: OK

  /var/log/lpd-errs: Access denied. ERROR

  /var/log/maillog: Access denied. ERROR

  /var/log/maillog.0.gz: Access denied. ERROR

  /var/log/messages: OK

  /var/log/messages.0.gz: OK

  /var/log/messages.1.gz: OK

  /var/log/openldap: OK

  /var/log/rdist: OK

  /var/log/secure: Access denied. ERROR

  /var/log/sendmail.st: OK

  /var/log/wtmp: OK

  /var/log/xferlog: Access denied. ERROR

  ----------- SCAN SUMMARY -----------

  Infected files: 0

  Time: 0.212 sec (0 m 0 s)

  

  OK,It works.

  /etc/rc.conf.local

  在 /etc/rc.conf.local 中添加以下内容,用于控制 ClamAV 在开机时启动:

  freshclam_flags="-d -c 2"

  clamd_flags=""

  

  /etc/rc.local

  在 /etc/rc.local 中添加以下内容,用于启动 ClamAV 的组件:

  # Start freshclam.

  if [ X"${freshclam_flags}" != X"NO" ]; then

  echo -n ' freshclam'

  mkdir /var/run/clamav 2>/dev/null

  chown -R _clamav:_clamav /var/run/clamav

  /usr/local/bin/freshclam ${freshclam_flags}

  fi

  # Start clamd.

  if [ X"${clamd_flags}" != X"NO" ]; then

  echo -n ' clamd'

  mkdir /var/run/clamav 2>/dev/null

  chown -R _clamav:_clamav /var/run/clamav

  /usr/local/sbin/clamd ${clamd_flags} >/dev/null 2>&1

  fi

  

  

  

  由于 clamd 需要读取病毒库里的病毒指纹,所以在之行 clamd 之后需要较长的一段时间来生成 socket 文件:/tmp/clamd。

  Usage

  ClamAV 提供了两个用于扫描病毒的命令:

  clamscan

  clamdscan

  这两个命令使用方法类似,在这里简单介绍一下 clamscan

  扫描指定的文件: # clamscan file

  

  扫描当前目录: # clamscan

  

  扫描 /home 目录中所有文件 (包括子目录): # clamscan -r /home

  

  扫描数据流: # cat testfile | clamscan -

  

  amavisd-new

  Introduction

  以下介绍内容来自 amavsid-new 官方网站:

  amavisd-new is a high-performance interface between mailer (MTA) and content checkers: virus scanners, and/or SpamAssassin. It is written in Perl for maintainability, without paying a significant price for speed. It talks to MTA via (E)SMTP or LMTP, or by using helper programs. Best with Postfix, fine with dual-sendmail setup and Exim v4, works with sendmail/milter, or with any MTA as a SMTP relay. For Courier and qmail MTA integration there is a patch in the distributed package.

  amavisd-new 是一个介于 MTA 和内容过滤软件之间的桥梁,其角色就像是两者之间的沟通者。 amavisd-new 本身也是个简单的 MTA,也可以用来架设一个独立的 Mail Gateway,提供多台 Mail Server 做邮件过滤。除此之外,amavisd-new 还可以结合十多种杀毒软件来做病毒防护。

  Installation

  amavisd-new 依赖 freeze,但是 freeze 不允许以二进制的形式发布,所以必须使用 ports 来安装:

  # cd /usr/ports/archivers/freeze

  # make install clean

  

  这里建议同时安装 unrar/unarj 支持,ports 路径分别为:

  /usr/ports/archivers/unrar

  /usr/ports/archivers/unarj

  装好 freeze/unrar/unarj 之后再安装 amavisd-new:

  # pkg_add amavisd-new

  --- amavisd-new-2.3.2p0 -------------------

  Enable amavisd-new in /etc/rc.local with the following lines:

  if [ -x /usr/local/sbin/amavisd ]; then

  echo -n ' amavisd'; /usr/local/sbin/amavisd

  fi

  

  Configuration

  amavisd-new

  amavisd-new 的配置文件为:/etc/amavisd.conf。还需要额外创建几个目录:

  # mkdir /var/amavisd/{tmp,var,db}

  # chown -R _clamav:_clamav /var/amavisd/

  

  由于计划以 _clamav 这个用户的身份去运行 amavisd,所以这里将目录的权限给了 _clamav 用户和组。

  我修改了以下几个参数:

  #

  # Part of file: /etc/amavisd.conf

  #

  $max_servers = 15;

  $daemon_user = '_clamav';

  $daemon_group = '_clamav';

  $mydomain = 'mail.bibby.org';

  $pid_file = "/var/run/amavisd.pid";

  # 在 @av_scanners 部分中,只保留 ClamAV 相关的内容,其它的都注释掉。

  @av_scanners = (

  # ### http://www.clamav.net/

  ['ClamAV-clamd',

  # 注意:以下一行必须进行修改,因为 clamd 的 socket 文件路径并不是 /var/run/clamav/clamd。

  #\&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamav/clamd"],

  \&ask_daemon, ["CONTSCAN {}\n", "/tmp/clamd"],

  qr/\bOK$/, qr/\bFOUND$/,

  qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],

  );

  # 在 @av_scanners_backup 部分,只保留 ClamAV 相关的内容,其它的都注释掉。

  @av_scanners_backup = (

  ### http://www.clamav.net/ - backs up clamd or Mail::ClamAV

  ['ClamAV-clamscan', 'clamscan',

  "--stdout --disable-summary -r --tempdir=$TEMPBASE {}", [0], [1],

  qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],

  );

  

  编辑完后,可以执行以下命令以检查 amavisd 是否配置正确:

  # /usr/local/sbin/amavisd debug

  

  /etc/rc.conf.local

  在 /etc/rc.conf.local 中添加以下内容,用于控制 amavisd-new 在系统开机时是否自动启动:

  amavisd_flags=""

  

  /etc/rc.local

  在 /etc/rc.local 中添加以下内容:

  # Start amavisd-new.

  if [ X"${amavisd_flags}" != X"NO" ]; then

  echo -n ' amavisd'

  /usr/local/sbin/amavisd ${amavisd_flags}

  fi

  

  测试 amavisd-new# echo "hello" | mail -s "subject" www@openbsdonly.org

  

  在 /var/log/maillog 里应该会有类似这样的内容:

  Dec 5 11:04:01 mail amavis[18411]: (18411-02) Passed CLEAN, -> , Message-ID: <20071205030359.EECB067D30@mail.bibby.org>, mail_id: 3agVrt7nAgxM, Hits: 1.406, 899 ms

  

  这就表示 clamav, amavisd-new 正常工作。

  /etc/postfix/master.conf

  添加以下内容:

  smtp-amavis unix - - - - 2 smtp

  -o smtp_data_done_timeout=1200

  -o smtp_send_xforward_command=yes

  -o disable_dns_lookups=yes

  -o max_use=20

  127.0.0.1:10025 inet n - - - - smtpd

  -o content_filter=

  -o local_recipient_maps=

  -o relay_recipient_maps=

  -o smtpd_restriction_classes=

  -o smtpd_delay_reject=no

  -o smtpd_client_restrictions=permit_mynetworks,reject

  -o smtpd_helo_restrictions=

  -o smtpd_sender_restrictions=

  -o smtpd_recipient_restrictions=permit_mynetworks,reject

  -o mynetworks_style=host

  -o mynetworks=127.0.0.0/8

  -o strict_rfc821_envelopes=yes

  -o smtpd_error_sleep_time=0

  -o smtpd_soft_error_limit=1001

  -o smtpd_hard_error_limit=1000

  -o smtpd_client_connection_count_limit=0

  -o smtpd_client_connection_rate_limit=0

  -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks

  

  还需要通知 Postfix:

  # postconf -e 'content_filter=smtp-amavis:[127.0.0.1]:10024'

  

  重新 reload:

  # postfix reload

  

  Appendix

  PF Rules

  Script: openbsd_mail_server-0.1

  这是由三个脚本组成的 Shell 脚本

  openbsd_mail_server-0.1.sh,主程序,由它完成所有的软件安装与配置工作。可以不需要其它脚本进行辅助。

  config_via_dialog.sh 是作为辅助的。如果你不想自己编辑 openbsd_mail_server-0.1.sh 设置变量,可以通过 config_via_dialog 来设置。

  create_maiil_ldap_user.sh 是为了在搭建好邮件服务器之后批量添加用户而写的一个脚本。在添加完用户之后会自动给新用户发送一封欢迎邮件(为了让 postfix 创建用户的 Maildir/,欢迎邮件的标题和内容需要自行修改)。

  使用说明:

  Global Setting 区域中的几个变量需要根据实际情况进行修改。使用方法: # chmod +x create_mail_ldap_user.sh

  # ./create_mail_ldap_user.sh DOMAIN_NAME New_Username

  # ./create_mail_ldap_user.sh DOMAIN_NAME User1 User2 User3...

  

  

  

  该脚本包含在 openbsd_mail_server-0.1 的自动安装脚本中。下载地址: 脚本,Ver: 0.1。自动搭建基于 OpenBSD 的邮件服务器

  Maildrop "a

  courier-imap 自带了 deliverquota(8) 这个工具可以实现 quota。这里采用的是单独的 maildrop 程序。

  安装 maildrop# pkg_add maildrop

  maildrop-2.0.2p2: complete

  --- maildrop-2.0.2p2 -------------------

  The documentation for maildrop has been installed in

  /usr/local/share/doc/maildrop.

  You should also read /usr/local/share/doc/maildrop/SECURITY

  file now, as it has

  some important information regarding the setuid/setgid

  bits that some of the binaries that have been installed

  may need for correct operation.

  There are currently NO setuid/gid bits enabled, but if you

  use maildrop in certain capacities, these will need to be

  set to allow maildrop to function correctly.

  

  配置 maildrop

  /etc/courier/maildroprc

  从 maildrop(1) 里可以看到,/etc/courier/maildroprc 是 maildrop 默认的配置文件,但是这个文件默认是没有的,可以自行创建:

  #

  # File: /etc/courier/maildroprc

  #

  SHELL="/bin/sh"

  HOME = '/home/vmail/domains'

  MAILDIR='Maildir/'

  LOGNAME=tolower("$LOGNAME")

  EXTENSION="$1"

  RECIPIENT=tolower("$2")

  USER="$3"

  HOST="$4"

  SENDER="$5"

  USERHOME="$HOME/$HOST/$USER"

  DEFAULT="$HOME/$HOST/$USER/$MAILDIR"

  `test -e $DEFAULT`

  if ( $RETURNCODE != 0 )

  {

  `mkdir -p $USERHOME`

  `maildirmake $DEFAULT`

  `chown vmail:vmail -R $DEFAULT`

  `chmod 0700 $DEFAULT`

  }

  to "$DEFAULT"

  logfile "/var/log/maildrop"

  VERBOSE="5"

  log "---"

  

  logfile: 指定 maildrop 的日志文件;

  默认情况下,如果用户的 Maildir/ 目录还未创建,邮件会延迟投递,直到它被手工创建为止。这里则通过 maildrop 自动创建。

  还需要执行以下步骤:

  # touch /var/log/maildrop

  # chown root:wheel /var/log/maildrop

  # chmod 642 /var/log/maildrop

  

  VERBOSE:指定日志级别。也可以在 /etc/postfix/master.cf 文件中直接用 -V 参数指定。

  log:每条日志信息都会以指定的字符串作为分隔。

  为 /var/log/maildrop 文件添加 logrotate 功能:

  # echo '/var/log/maildrop root:wheel 640 5 30 * Z' >>/etc/newsyslog.conf

  

  具体的含义请参考:newsyslog(8)。

  /etc/quotawarnmsg

  这是当用户的邮箱容量达到指定的限额时,邮件服务器自动给用户发送的警告邮件。可以直接复制 maildrop 提供的模板:

  # cp /usr/local/share/doc/maildrop/quotawarnmsg /etc/

  

  

  

  复制之后,还需要将 quotawarnmsg 里的邮件地址改为你实际需要的地址。

  /etc/postfix/master.cf

  修改 /etc/postfix/master.cf文件,将 maildrop 的注释符号去掉,并加上参数 '-w 80':

  maildrop unix - n n - - pipe

  flags=DRhu user=vmail argv=/usr/local/bin/maildrop -w 80 -d ${user}@${nexthop} ${extension} ${recipient} ${user} ${nexthop} ${sender}

  

  -w 80:表示在邮箱容量达到 80% 的时候发送一封警告邮件给用户。

  更多的参数请参考:maildrop(1)。

  /etc/postfix/main.cf

  修改 /etc/postfix/main.cf文件,添加一行:

  maildrop_destination_recipient_limit = 1

  

  /etc/postfix/transport

  修改已经编辑过的 /etc/postfix/transport 文件,原来的内容为:

  domain1.com virtual:

  domain2.com virtual:

  

  现在需要修改为:

  domain1.com maildrop

  domain2.com maildrop

  

  这是为了告诉 Postfix,这几个域的邮件都需要经过 maildrop 程序来投递。

  修改完后需要执行:

  # postmap /etc/postfix/transport

  # postfix reload

  

  测试 maildrop

  配置好了以上步骤之后就可以使用邮件客户端来发送你邮件,以测试 maildrop 是否生效。

  这是我的 /var/log/maillog 里的部分内容:

  Nov 20 11:02:46 mail postfix/pipe[23181]: 5AC7C65D1B: to=,

  relay=maildrop, delay=0.94, delays=0.25/0.07/0/0.62, dsn=2.0.0, status=sent

  (delivered via maildrop service)

  

  注意这里的 relay=maildrop,以及最后一个括号里的内容 (delivered via maildrop service),这就表示 maildrop 已经生效了。

  这是另外一段 maillog 里的日志信息:

  Nov 20 11:06:25 mail postfix/pipe[10906]: 0D6B765D1B: to=,

  relay=maildrop, delay=1.1, delays=0.79/0.12/0/0.23, dsn=5.7.0, status=bounced

  (permission denied. Command output: maildrop: maildir over quota. )

  

  最后一个括号里的内容 (permission denied. Command output: maildrop: maildir over quota. )表示已经超过邮箱容量了。

  邮件备份(Archive)

  这里主要用 postfix 自身的 bcc(密送)功能来做简单的邮件备份。

  /etc/postfix/main.cf

  首先,在 /etc/postfix/main.cf 里加上以下参数:

  sender_bcc_maps = hash:/etc/postfix/sender_bcc_maps

  recipient_bcc_maps = hash:/etc/postfix/recipient_bcc_maps

  always_bcc = root@mail.bibby.org

  

  简单解释这里的几个参数:

  sender_bcc_maps:通过 postfix 发送出去的邮件。

  recipient_bcc_maps:通过 postfix 接收到的邮件。

  always_bcc:通过 postfix 发送和接收的任何邮件。参数是一个邮件地址。

  /etc/postfix/{sender_bcc_maps,recipient_bcc_maps}

  在 /etc/postfix/sender_bcc_maps 和 /etc/postfix/recipient_bcc_maps 中添加以下内容:

  # Single User.

  #bibby@domain1.com root@mail.bibby.org

  #bibby@domain1.com root@mail.bibby.org

  # Whole domain.

  @domain1.com out@domain1.com

  @domain2.com out@domain1.com

  

  

  

  这两个个文件里既可以设置单个用户,也可以设置整个域的 bcc 地址。

  

  

  别忘了将 out@domain1.com 的邮箱 quota 值给设置得大一些,或者直接设置为 0。

  编辑完后需要执行 postmap:

  # postmap /etc/postfix/sender_bcc_maps

  # postmap /etc/postfix/recipient_bcc_maps

  

  Postfix reload:

  # postfix reload

  

  mod_auth_ldap:为 Apache 设置 LDAP 用户验证

  安装 mod_auth_ldap# pkg_add mod_auth_ldap

  mod_auth_ldap-1.6.0p5: complete

  --- mod_auth_ldap-1.6.0p5 -------------------

  To finish the install of mod_auth_ldap, you need

  to enable the module using the following command

  /usr/local/sbin/mod_auth_ldap-enable

  If you already have Apache running on your machine,

  you should not use "apachectl restart" - instead,

  you should fully stop and then restart the server.

  #

  

  按照提示,启用 mod_auth_ldap 模块:

  # /usr/local/sbin/mod_auth_ldap-enable

  Enabling module...

  [activating module `auth_ldap' in /var/www/conf/httpd.conf]

  cp /usr/local/lib/mod_auth_ldap.so /usr/lib/apache/modules/mod_auth_ldap.so

  chmod 755 /usr/lib/apache/modules/mod_auth_ldap.so

  cp /var/www/conf/httpd.conf /var/www/conf/httpd.conf.bak

  cp /var/www/conf/httpd.conf.new /var/www/conf/httpd.conf

  rm /var/www/conf/httpd.conf.new

  

  执行完之后看 httpd.conf 文件,会发现多了一行:

  LoadModule auth_ldap_module /usr/lib/apache/modules/mod_auth_ldap.so

  

  slapd.conf:LDAPv2 支持

  

  

  由于 mod_auth_ldap 使用的是 LDAPv2 协议,所以请确认你的 LDAP 服务器支持使用 LDAPv2 进行连接。OpenLDAP 可以在配置文件中添加以下参数让它支持 LDAPv2 协议:

  # Part of file: /etc/openldap/slapd.conf

  allow bind_v2

  

  httpd.conf:配置 Apache

  这是一个示例配置,添加在 httpd.conf 文件中:

  

  AuthName "LDAP AUTH ENABLED"

  AuthType Basic

  AuthLDAPEnabled on

  AuthLDAPAuthoritative on

  AuthLDAPUrl ldap://127.0.0.1:389/o=domains,dc=bibby,dc=org?mail?children?(objectClass=CourierMailAccount)

  AuthLDAPBindDN uid=vmail,o=domains,dc=bibby,dc=org

  AuthLDAPBindPassword 123456

  require valid-user

  

  

  这里使用用户的 mail 属性的值作为登录的用户名。

  更多的参数请参考 mod_auth_ldap 自带的文档:/usr/local/share/doc/mod_auth_ldap/auth_ldap.html

  Resource Links

  LDAP

  Documentation

  OpenLDAP

  Documentation,官方文档

  OpenLDAP Software 2.4 Administrator's Guide

  Access Control,OpenLDAP 里的访问控制

  Other Publications,资源丰富,强烈推荐

  The SLAPD and SLURPD Administrator's Guide: PDF, PS

  RedHat Directory Server

  Deployment Guide for Red Hat Directory Server,强烈推荐。此文档适用于任何一种 LADP 软件。

  LDAP Howto, LDAP Links, LDAP Whitepapers

  什么是 LDAP

  Admin Tools

  LDAP Admin, Windows LDAP manager.

  Postfix/Courier

  Postfix

  Postfix Add-on Software

  Manual Pages:

  LDAP_TABLE(5)

  Courier

  Courier Patch for automatic maildir creation

  Postfix 配置文件 main.cf 中常用参数介绍

  ldap, postfix and courier-imap howto

  Mail server on Debian GNU/Linux Sarge, maildrop "a

  Setting up maildrop

  Maildrop configuration

  OpenBSD as a Mail Server

  ClamAV

  ClamAV

  Clam AntiVirus 0.90 User Manual

  Submit your virus sample here(提交新的病毒样本文件)

  Amavisd-new

  Fairly-Secure Anti-SPAM Gateway Using OpenBSD, Postfix, Greylisting, Amavisd-new, SpamAssassin, Razor and DCC

  SpamAssassin

  openbsd+postfix + spamassassin + greylist + xbl spam gateway

  OpenBSD 3.4 email server, procmail+SpamAssassin

  用 SpamAssassin 消灭垃圾邮件

  SquirrelMail

  SquirrelMail

  SquirrelOutlook,经过修改的 SquirrelMail,界面类似于 OutLook 程序。

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册