1 (edited by zalsat 2017-12-09 19:45:31)

Topic: dovecot ldap: bad search filter

Hello all,
i am trying to integrate iRedMail with Windows AD users. I am following official instruction with a few changes. I am using Windows 2012R2 for AD and mail is installed in a debian 9. Before installing iRedmail i have joined debian server in domain.

- ad_sender_login_maps.cf
server_host = srv.domain.local
search_base = dc=domain,dc=local
version = 3
bind            = yes
start_tls       = no
bind_dn         = vmail@domain.local
bind_pw         = password
search_base     = cn=users,dc=domain,dc=local
scope           = sub
query_filter    = (&(userPrincipalName=%s)(objectClass=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))
result_attribute= samaccountname
debuglevel      = 0

postmap -q user1@domain.local ldap:/etc/postfix/ad_sender_login_maps.cf result is:  user1

ad_virtual_mailbox_maps.cf
server_host = srv.domain.local
search_base = dc=domain,dc=local
version = 3
search_base = dc=domain,dc=local
scope           = sub
query_filter = (&(objectclass=person)(mail=%s))
result_attribute = samaccountname
result_format = %s/Maildir/
bind = yes
start_tls       = no
bind_dn = vmail@domain.local
bind_pw = password
debuglevel      = 0

postmap -q user1@domain.local ldap:/etc/postfix/ad_virtual_mailbox_maps.cf result is : user1/Maildir

ad_virtual_group_maps.cf
server_host = srv.domain.local
search_base = dc=domain,dc=local
version = 3
bind            = yes
start_tls       = no
bind_dn         = vmail@domain.local
bind_pw         = password
scope           = sub
query_filter    = (&(objectClass=group)(mail=%s))
special_result_attribute = member
leaf_result_attribute = mail
result_attribute= samaccountname
debuglevel      = 0

postmap -q mail_group@domain.local ldap:/etc/postfix/ad_virtual_group_maps.cf show group members, user1, user2...

postconf - n output is:

alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases
allow_min_user = no
allow_percent_hack = no
biff = no
body_checks = pcre:/etc/postfix/body_checks.pcre
command_directory = /usr/sbin
compatibility_level = 2
content_filter = smtp-amavis:[127.0.0.1]:10024
daemon_directory = /usr/lib/postfix/sbin
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_                                                                                                                     directory/$process_name $process_id & sleep 5
disable_vrfy_command = yes
dovecot_destination_recipient_limit = 1
enable_original_recipient = no
header_checks = pcre:/etc/postfix/header_checks
inet_interfaces = all
inet_protocols = all
lmtp_tls_mandatory_protocols = !SSLv2 !SSLv3
lmtp_tls_protocols = !SSLv2 !SSLv3
mail_owner = postfix
mailq_path = /usr/bin/mailq
message_size_limit = 15728640
mydestination = $myhostname, localhost, localhost.localdomain
mydomain = domain.local
myhostname = mail
mynetworks = 127.0.0.1 [::1] 192.168.0.0/24
myorigin = mail.domain.local
newaliases_path = /usr/bin/newaliases
postscreen_access_list = permit_mynetworks cidr:/etc/postfix/postscreen_access.c                                                                                                                     idr
postscreen_blacklist_action = enforce
postscreen_dnsbl_action = enforce
postscreen_dnsbl_reply_map = texthash:/etc/postfix/postscreen_dnsbl_reply
postscreen_dnsbl_sites = zen.spamhaus.org=127.0.0.[2..11]*3 b.barracudacentral.o                                                                                                                     rg=127.0.0.[2..11]*2
postscreen_dnsbl_threshold = 2
postscreen_dnsbl_whitelist_threshold = -2
postscreen_greet_action = enforce
proxy_read_maps = $canonical_maps $lmtp_generic_maps $local_recipient_maps $myde                                                                                                                     stination $mynetworks $recipient_bcc_maps $recipient_canonical_maps $relay_domai                                                                                                                     ns $relay_recipient_maps $relocated_maps $sender_bcc_maps $sender_canonical_maps                                                                                                                      $smtp_generic_maps $smtpd_sender_login_maps $transport_maps $virtual_alias_doma                                                                                                                     ins $virtual_alias_maps $virtual_mailbox_domains $virtual_mailbox_maps $smtpd_se                                                                                                                     nder_restrictions $sender_dependent_relayhost_maps
queue_directory = /var/spool/postfix
recipient_bcc_maps =
recipient_delimiter = +
relay_domains =
relay_recipient_maps =
sender_bcc_maps =
sender_dependent_relayhost_maps =
sendmail_path = /usr/sbin/sendmail
setgid_group = postdrop
smtp-amavis_destination_recipient_limit = 1
smtp_tls_CAfile = $smtpd_tls_CAfile
smtp_tls_loglevel = 1
smtp_tls_mandatory_protocols = !SSLv2 !SSLv3
smtp_tls_note_starttls_offer = yes
smtp_tls_protocols = !SSLv2 !SSLv3
smtp_tls_security_level = may
smtpd_data_restrictions = reject_unauth_pipelining
smtpd_end_of_data_restrictions = check_policy_service inet:127.0.0.1:7777
smtpd_helo_required = yes
smtpd_helo_restrictions = permit_mynetworks permit_sasl_authenticated check_helo                                                                                                                     _access pcre:/etc/postfix/helo_access.pcre reject_non_fqdn_helo_hostname reject_                                                                                                                     unknown_helo_hostname
smtpd_recipient_restrictions = reject_unknown_recipient_domain reject_non_fqdn_r                                                                                                                     ecipient reject_unlisted_recipient permit_mynetworks permit_sasl_authenticated r                                                                                                                     eject_unauth_destination
smtpd_reject_unlisted_recipient = yes
smtpd_reject_unlisted_sender = yes
smtpd_sasl_local_domain = domain.local
smtpd_sasl_path = private/dovecot-auth
smtpd_sasl_type = dovecot
smtpd_sender_login_maps = proxy:ldap:/etc/postfix/ad_sender_login_maps.cf
smtpd_sender_restrictions = reject_unknown_sender_domain reject_non_fqdn_sender                                                                                                                      reject_unlisted_sender permit_mynetworks permit_sasl_authenticated check_sender_                                                                                                                     access pcre:/etc/postfix/sender_access.pcre
smtpd_tls_CAfile = /etc/ssl/certs/iRedMail.crt
smtpd_tls_cert_file = /etc/ssl/certs/iRedMail.crt
smtpd_tls_dh1024_param_file = /etc/ssl/dh2048_param.pem
smtpd_tls_dh512_param_file = /etc/ssl/dh512_param.pem
smtpd_tls_exclude_ciphers = aNULL, eNULL, EXPORT, DES, RC4, MD5, PSK, aECDH, EDH                                                                                                                     -DSS-DES-CBC3-SHA, EDH-RSA-DES-CDC3-SHA, KRB5-DE5, CBC3-SHA
smtpd_tls_key_file = /etc/ssl/private/iRedMail.key
smtpd_tls_loglevel = 1
smtpd_tls_mandatory_protocols = !SSLv2 !SSLv3
smtpd_tls_protocols = !SSLv2 !SSLv3
smtpd_tls_security_level = may
swap_bangpath = no
tls_random_source = dev:/dev/urandom
transport_maps = hash:/etc/postfix/transport
unknown_local_recipient_reject_code = 550
virtual_alias_domains =
virtual_alias_maps = proxy:ldap:/etc/postfix/ad_virtual_group_maps.cf
virtual_gid_maps = static:2000
virtual_mailbox_base = /var/vmail
virtual_mailbox_domains = domain.local
virtual_mailbox_maps = proxy:ldap:/etc/postfix/ad_virtual_mailbox_maps.cf
virtual_minimum_uid = 2000
virtual_transport = dovecot
virtual_uid_maps = static:2000

I am following the guide for dovecot and dovecot-ldap.conf looks:
hosts           = srv.domain.local:389
ldap_version    = 3
auth_bind       = yes
dn              = vmail@domain.local
dnpass          = password
base            = cn=users,dc=domain,dc=local
scope           = subtree
deref           = never
user_filter     = (&(userPrincipalName=%u)(objectClass=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))
pass_filter     = (&(userPrincipalName=%u)(objectClass=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))
pass_attrs      = userPassword=password
default_pass_scheme = CRYPT
user_attrs      = =home=/var/vmail/vmail1/%Ln/Maildir/,=mail=maildir:/var/vmail/vmail1/%Ln/Maildir/

but when i try telnet pop3 output is:
telnet localhost pop3
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
useruser1@domain.local
+OK
pass password
-ERR [AUTH] Authentication failed.

and in /var/log/dovecot/dovecot.log i have:

mail dovecot: auth: Error: ldap(user1@domain.local,127.0.0.1,<yXNj8dhfXMl/AAAB>): ldap_search((& ( mail =u ) ( objectClass = person ) (! ( userAccountControl :   1.2 . 840.113556 . 1.4 . 803 : = 2 )))) parsing failed: Bad search filter.

Any suggestion.

thanks in advance

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: dovecot ldap: bad search filter

zalsat wrote:

mail dovecot: auth: Error: ldap(user1@domain.local,127.0.0.1,<yXNj8dhfXMl/AAAB>): ldap_search((& ( mail =u ) ( objectClass = person ) (! ( userAccountControl :   1.2 . 840.113556 . 1.4 . 803 : = 2 )))) parsing failed: Bad search filter.

it's more like a copy/paste issue to me.

3 (edited by zalsat 2017-12-09 19:44:38)

Re: dovecot ldap: bad search filter

Sorry i am new to linux.
What do you mean copy/paste error. In manual say just follow the instruction.

When posting log i replaced only username and domain name.

Thnx in advance

4

Re: dovecot ldap: bad search filter

Why are there many white spaces of the filter in pasted log?

5 (edited by zalsat 2017-12-11 18:42:09)

Re: dovecot ldap: bad search filter

normaly i did just copy paste. Anyway solved by using following config :

uris = ldap://ad.automaton.uk
ldap_version    = 3
auth_bind       = yes
base            = cn=users,dc=ad,dc=automaton,dc=uk
scope           = subtree
deref           = never
user_filter    = (&(uid=%n)(objectClass=*))
pass_filter    = (&(uid=%n)(objectClass=*))
auth_bind_userdn = CN=%n,CN=users,DC=ad,DC=automaton,DC=uk
# user_filter     = (&(userPrincipalName=%u)(objectClass=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))
# pass_filter     = (&(userPrincipalName=%u)(objectClass=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))
user_attrs    = homeDirectory=/var/vmail/%u,uidNumber=uid,gidNumber=gid
pass_attrs      = userPassword=password
default_pass_scheme = CRYPT

by this post https://dovecot.org/list/dovecot/2014-N … 98994.html