将postfix与LDAP集成到电子邮件用户可以访问特定的主机

我在Ubuntu 14.04( slapd 2.4.31-1 )下安装了phpldapadminsudo-ldap和其他软件包,可以安装openLDAP v3。 我正在尝试将postfix与LDAP集成,因此我可以将电子邮件发送到[email protected][email protected]

当前设置

作为此设置的一部分,我拥有允许用户访问的每个主机的host属性(或者仅仅是允许访问所有主机的* )。 我在我的LDAP客户端上使用这个来授予或拒绝对特定主机的访问。 还与每个用户相关联的是他们在mail属性中的公司电子邮件地址。 下面给出用户的LDIF示例:

 dn: uid=auser,ou=People,dc=example,dc=com cn: A User displayname: A User gecos: A User gidnumber: 1011 givenname: A homedirectory: /home/auser host: host1 host: host2 host: host3 host: host4 mailacceptinggeneralid: root loginshell: /bin/bash mail: [email protected] objectclass: inetOrgPerson objectclass: posixAccount objectclass: shadowAccount objectclass: hostObject objectclass: postfixUser objectclass: top sn: User uid: auser uidnumber: 1001 

LDAP中用户邮件地址的Postfix查找

我有一个/etc/postfix/ldap-aliases.cf文件,其内容如下:

 server_host = ldap.example.com search_base = dc=example, dc=com # look for entries with this query_filter = (|(uid=%s)(mailacceptinggeneralid=%s)(mail=%[email protected])) # what attribute from the search result is returned result_attribute = mail # the format in which the result is returned result_format = %s 

这个configuration工作到目前为止,并通过下面的postmap命令得到确认,返回我期望的地址:

 # A query using the uid of the user postmap -q auser ldap:/etc/postfix/ldap-mail.cf [email protected] # A query using the corporate username postmap -q a.user ldap:/etc/postfix/ldap-mail.cf [email protected] # A query for a user specified in mailacceptinggeneralid postmap -q root ldap:/etc/postfix/ldap-mail.cf [email protected] 

有权访问主机的用户的Postfix查找

我希望能够发送电子邮件到[email protected]例如,并从LDAP获取所有有权访问host2用户的地址(即host属性设置为host2* 。这是我需要的地方一些帮助。

到目前为止,我有一个文件/etc/postfix/ldap-host-users.cf其中包含:

 server_host = ldap.example.com search_base = dc=example, dc=com query_filter = (|(host=%3)(host=\*)) result_attribute = mail result_format = %s 

它假设查询包含FQDN,但我认为postfix只使用username (可能是由于我在/etc/postfix/main.cf使用alias_maps ?)。 无论如何,testing以上:

 postmap -q [email protected] ldap:/etc/postfix/ldap-host-users.cf [email protected] # The following also returns a list of email addresses, but shouldn't: postmap -q [email protected] ldap:/etc/postfix/ldap-host-users.cf [email protected] 

postconf -n输出

 alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases, ldap:/etc/postfix/ldap-mail.cf, ldap:/etc/postfix/ldap-host-users.cf append_dot_mydomain = no biff = no config_directory = /etc/postfix inet_interfaces = all inet_protocols = all mailbox_size_limit = 0 mydestination = $myhostname, localhost.example.com, , localhost myhostname = host2.example.com mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 readme_directory = no recipient_delimiter = + relayhost = smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu) smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtpd_use_tls = yes 

问题

  • postfix只使用本地username查询,并且不包含查询中的FQDN?
    • 这是因为我在/etc/postfix/main.cf使用alias_maps
  • 我可以以某种方式检查查询的username部分是users ,如果是别的东西,则不返回任何内容? 例如在query_filter我可以做一些像%u="users"
  • 有没有更好/不同的方式来实现这一目标?

一些部分答案:

1. Postfix只使用本地用户名进行查询,并且不包含查询中的FQDN? 这是因为我在/etc/postfix/main.cf使用alias_maps

是的 ,根据alias_maps文档,我们需要引用man 5别名来了解语法细节。

该名称是本地地址(无域名部分) 。 当名称包含任何特殊字符(如空格, #', ,:'或'@')时,请使用双引号。 该名称被折叠为小写,以便使数据库查找不区分大小写。

所以,这是来自postfix的预期行为。


3.有没有更好的/不同的方式来实现这一目标?

使用virtual_alias_maps 。 根据这个关于alias_maps和virtual_alias_maps的疑惑 , virtual_alias_maps将“user @ domain”作为input。