我需要有关 ldap 搜索过滤器的帮助,以便从 ldap 检索用户电子邮件信息。我正在运行 Ubuntu 服务器 12.04 的 postfix_ldap。除了获取搜索返回的值外,一切似乎都运行正常。
版本 1
server_host = ldap://samba.example.com
search_base = dc=company, dc=example, dc=com
query_filter = mail=%s
bind = no
domain = example.com
版本 2
server_host = ldap://samba.example.com
search_base = dc=company, dc=example, dc=com
query_filter = mail=%s
bind_dn = cn=Users,dc=company,dc=example,dc=com
domain = example.com
邮件日志
Nov 26 11:13:26 mail postfix/smtpd[19662]: match_string: example.com ~? example.com
Nov 26 11:13:26 mail postfix/smtpd[19662]: dict_ldap_lookup: No existing connection for LDAP source /etc/postfix/ldap-aliases.cf, reopening
Nov 26 11:13:26 mail postfix/smtpd[19662]: dict_ldap_connect: Connecting to server ldap://samba.example.com
Nov 26 11:13:26 mail postfix/smtpd[19662]: dict_ldap_connect: Actual Protocol version used is 3.
Nov 26 11:13:26 mail postfix/smtpd[19662]: dict_ldap_connect: Binding to server ldap://samba.example.com with dn cn=Users,dc=company,dc=example,dc=com
Nov 26 11:13:26 mail postfix/smtpd[19662]: warning: dict_ldap_connect: Unable to bind to server ldap://samba.example.com with dn cn=Users,dc=company,dc=example,dc=com: 49 (Invalid credentials)
Nov 26 11:13:26 mail postfix/smtpd[19662]: warning: ldap:/etc/postfix/ldap-aliases.cf lookup error for "[email protected]"
Nov 26 11:13:26 mail postfix/smtpd[19662]: maps_find: virtual_alias_maps: [email protected]: search aborted
Nov 26 11:13:26 mail postfix/smtpd[19662]: mail_addr_find: [email protected] -> (try again)
Nov 26 11:13:26 mail postfix/smtpd[19662]: NOQUEUE: reject: RCPT from col0-omc3-s2.col0.hotmail.com[65.55.34.140]: 451 4.3.0 <[email protected]>: Temporary lookup failure; from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<col0-omc3-s2.col0.hotmail.com>
Nov 26 11:13:26 mail postfix/smtpd[19662]: > col0-omc3-s2.col0.hotmail.com[65.55.34.140]: 451 4.3.0 <[email protected]>: Temporary lookup failure
这是另一个搜索结果成功的日志,但无法获取结果的值
Nov 26 12:04:56 mail postfix/smtpd[20463]: dict_ldap_lookup: Using existing connection for LDAP source /etc/postfix/ldap-aliases.cf
Nov 26 12:04:56 mail postfix/smtpd[20463]: dict_ldap_lookup: /etc/postfix/ldap-aliases.cf: Searching with filter [email protected]
Nov 26 12:04:56 mail postfix/smtpd[20463]: dict_ldap_get_values[1]: Search found 1 match(es)
Nov 26 12:04:56 mail postfix/smtpd[20463]: dict_ldap_get_values[1]: Leaving dict_ldap_get_values
Nov 26 12:04:56 mail postfix/smtpd[20463]: dict_ldap_lookup: Search returned nothing
Nov 26 12:04:56 mail postfix/smtpd[20463]: maps_find: virtual_alias_maps: [email protected]: not found
Nov 26 12:04:56 mail postfix/smtpd[20463]: dict_ldap_lookup: In dict_ldap_lookup
Nov 26 12:04:56 mail postfix/smtpd[20463]: dict_ldap_lookup: /etc/postfix/ldap-aliases.cf: Skipping lookup of key 'tola.akintola': domain mismatch
Nov 26 12:04:56 mail postfix/smtpd[20463]: maps_find: virtual_alias_maps: tola.akintola: not found
Nov 26 12:04:56 mail postfix/smtpd[20463]: dict_ldap_lookup: In dict_ldap_lookup
Nov 26 12:04:56 mail postfix/smtpd[20463]: dict_ldap_lookup: /etc/postfix/ldap-aliases.cf: Skipping lookup of key '@example.com': domain mismatch
Nov 26 12:04:56 mail postfix/smtpd[20463]: maps_find: virtual_alias_maps: @example.com: not found
Nov 26 12:04:56 mail postfix/smtpd[20463]: mail_addr_find: [email protected] -> (not found)
我改进的 ldap-aliases.cf 如下所示:
server_host = ldap://samba.example.com
server_port = 3268
search_base = dc=company, dc=example, dc=com
query_filter = mail=%s
result_attribute = uid
bind_dn = cn=Administrator,cn=Users,dc=company,dc=example,dc=com
bind_pw = pass
domain = example.com
因此我想知道哪种 ldap 过滤器适合使其工作。
谢谢你的帮助。
答案1
经过一些调整后,下面的 postfix 配置可以正常工作:
server_host = ldap://samba.example.com
server_port = 3268
search_base = dc=company, dc=example, dc=com
query_filter = (&(mail=%s))
result_attribute =
leaf_result_attribute = mail
bind_dn = cn=Administrator,cn=Users,dc=company,dc=example,dc=com
bind_pw = passwd
domain = example.com