1 (edited by stannicek 2015-01-12 19:55:56)

Topic: [SOLVED] Howto disable SMTP service for specific mailbox

==== Required information ====
- iRedMail version: 0.8.7
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): PGSQL
- Linux/BSD distribution name and version: CentOS 6
- Related log if you're reporting an issue:
====

Hello.

Is there a way how to disable SMTP service for specific user/mailbox using VMAIL database?

I allready tried to change mailbox.enablesmtp and mailbox.enablesmtpsecured to 0, but it doesn't help.
I belive disabling mailbox using mailbox.active=0 will do the job, but it will disable mailbox completely which is not the way i want to go...

Thanks in advance.

Best Regards,
Stanislav

----

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

2

Re: [SOLVED] Howto disable SMTP service for specific mailbox

changing mailbox.enablesmtp and mailbox.enablesmtpsecured to 0 is the right way. How did you test sending mail?

3 (edited by stannicek 2015-01-07 03:27:51)

Re: [SOLVED] Howto disable SMTP service for specific mailbox

Environment : 2 domains configured (one production + one testing) at the same server

Email sent over TLS from testing mailbox (with enablesmtp=0 and enablesmtpsecured=0) to different mailbox at production domain using Thunderbird an it worked sad.

Regards,
Stanislav

4

Re: [SOLVED] Howto disable SMTP service for specific mailbox

Could you please show me output of "postconf -n" command and file /etc/dovecot/dovecot-pgsql.conf? Note: remove password before pasting.

5 (edited by stannicek 2015-01-09 22:29:57)

Re: [SOLVED] Howto disable SMTP service for specific mailbox

postconf -n :

alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases
allow_min_user = no
biff = no
bounce_queue_lifetime = 1d
broken_sasl_auth_clients = yes
command_directory = /usr/sbin
config_directory = /etc/postfix
content_filter = smtp-amavis:[127.0.0.1]:10024
daemon_directory = /usr/libexec/postfix
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
delay_warning_time = 0h
disable_vrfy_command = yes
dovecot_destination_recipient_limit = 1
enable_original_recipient = no
home_mailbox = Maildir/
html_directory = no
inet_interfaces = all
inet_protocols = ipv4 ipv6
mail_owner = postfix
mailbox_command = /usr/libexec/dovecot/deliver
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
maximal_backoff_time = 4000s
maximal_queue_lifetime = 1d
message_size_limit = 15728640
minimal_backoff_time = 300s
mydestination = $myhostname, localhost, localhost.localdomain, localhost.$myhostname
mydomain = domain.cz
myhostname = host.domain.cz
mynetworks = 127.0.0.0/8, [removed for security]/25, [removed for security]/25, [removed for security]/25
mynetworks_style = subnet
myorigin = host.domain.cz
newaliases_path = /usr/bin/newaliases.postfix
proxy_read_maps = $canonical_maps $lmtp_generic_maps $local_recipient_maps $mydestination $mynetworks $recipient_bcc_maps $recipient_canonical_maps $relay_domains $relay_recipient_maps $relocated_maps $sender_bcc_maps $sender_canonical_maps $smtp_generic_maps $smtpd_sender_login_maps $transport_maps $virtual_alias_domains $virtual_alias_maps $virtual_mailbox_domains $virtual_mailbox_maps $smtpd_sender_restrictions
queue_directory = /var/spool/postfix
queue_run_delay = 300s
readme_directory = /usr/share/doc/postfix-2.11.0/README_FILES
recipient_bcc_maps = proxy:pgsql:/etc/postfix/pgsql/recipient_bcc_maps_user.cf, proxy:pgsql:/etc/postfix/pgsql/recipient_bcc_maps_domain.cf
recipient_delimiter = +
relay_domains = $mydestination, proxy:pgsql:/etc/postfix/pgsql/relay_domains.cf
sample_directory = /usr/share/doc/postfix-2.11.0/samples
sender_bcc_maps = proxy:pgsql:/etc/postfix/pgsql/sender_bcc_maps_user.cf, proxy:pgsql:/etc/postfix/pgsql/sender_bcc_maps_domain.cf
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtp-amavis_destination_recipient_limit = 1
smtp_data_init_timeout = 240s
smtp_data_xfer_timeout = 600s
smtp_tls_note_starttls_offer = yes
smtpd_data_restrictions = reject_unauth_pipelining
smtpd_end_of_data_restrictions = check_policy_service inet:127.0.0.1:10031
smtpd_helo_required = yes
smtpd_helo_restrictions = permit_mynetworks,permit_sasl_authenticated, check_helo_access pcre:/etc/postfix/helo_access.pcre
smtpd_recipient_limit = 50
smtpd_recipient_restrictions = reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unlisted_recipient, check_policy_service inet:127.0.0.1:7777, check_policy_service inet:127.0.0.1:10031, permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, reject_non_fqdn_helo_hostname, reject_invalid_helo_hostname
smtpd_reject_unlisted_recipient = yes
smtpd_reject_unlisted_sender = yes
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = no
smtpd_sasl_local_domain =
smtpd_sasl_path = ./dovecot-auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_sender_login_maps = proxy:pgsql:/etc/postfix/pgsql/sender_login_maps.cf
smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_sender_login_mismatch
smtpd_tls_CAfile = /etc/ssl/2012-10-17-mail/tcs-ca-bundle.pem
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/ssl/2012-10-17-mail/mail.pem
smtpd_tls_key_file = /etc/ssl/2012-10-17-mail/mail.pem
smtpd_tls_loglevel = 0
smtpd_tls_security_level = may
tls_random_source = dev:/dev/urandom
transport_maps = proxy:pgsql:/etc/postfix/pgsql/transport_maps_user.cf, proxy:pgsql:/etc/postfix/pgsql/transport_maps_domain.cf
unknown_local_recipient_reject_code = 550
virtual_alias_domains =
virtual_alias_maps = proxy:pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf, proxy:pgsql:/etc/postfix/pgsql/domain_alias_maps.cf, proxy:pgsql:/etc/postfix/pgsql/catchall_maps.cf, proxy:pgsql:/etc/postfix/pgsql/domain_alias_catchall_maps.cf
virtual_gid_maps = static:501
virtual_mailbox_base = /var/vmail
virtual_mailbox_domains = proxy:pgsql:/etc/postfix/pgsql/virtual_mailbox_domains.cf
virtual_mailbox_maps = proxy:pgsql:/etc/postfix/pgsql/virtual_mailbox_maps.cf
virtual_minimum_uid = 500
virtual_transport = dovecot
virtual_uid_maps = static:500

dovecot-pgsql.conf :

driver = pgsql
default_pass_scheme = CRYPT
connect = host=127.0.0.1 dbname=[removed for security] user=[removed for security] password=[removed for security]
password_query = SELECT password FROM mailbox WHERE username='%u' AND active='1'
user_query = SELECT \
    mailbox.storagebasedirectory || '/' || mailbox.storagenode || '/' || mailbox.maildir AS home, \
    '*:bytes=' || mailbox.quota*1048576 AS quota_rule \
FROM mailbox,domain \
WHERE mailbox.username='%u' \
    AND mailbox.domain='%d' \
    AND mailbox.enable%Ls%Lc=1 \
    AND mailbox.domain=domain.domain \
    AND domain.backupmx=0 \
    AND domain.active=1 \
    AND mailbox.active=1

I checked this twice, but i didn't found anything. :-\

I also checked /etc/postfix/pgsql/sender_login_maps.cf :

query       = SELECT mailbox.username FROM mailbox,domain WHERE mailbox.username='%s' AND mailbox.domain='%d' AND mailbox.domain=domain.domain AND mailbox.enablesmtp=1 AND mailbox.active=1 AND domain.backupmx=0 AND domain.active=1

Regards,
Stanislav

6

Re: [SOLVED] Howto disable SMTP service for specific mailbox

Maybe, the problem is somewhere in the order of permit_mynetworks in smtpd_sender_restrictions/smtpd_helo_restrictions, but my client PC with thunderbird is located outside defined mynetworks.

Regards,
Stanislav

7

Re: [SOLVED] Howto disable SMTP service for specific mailbox

I found the problem in your case.

With default iRedMail setting, Postfix parameter "smtpd_sender_restrictions" is set like below:

smtpd_sender_restrictions = permit_mynetworks, reject_sender_login_mismatch, permit_sasl_authenticated

You have wrong setting.
And if you have enablesmtp=1 and enablesmtpsecured=1 for user 'postmaster@a.cn', you will get below result:

# postmap -q 'postmaster@a.cn' mysql:/etc/postfix/mysql/sender_login_maps.cf
postmaster@a.cn

Now set enablesmtp=0 and enablesmtpsecured=0 for same user, you will get empty value with same command:

# postmap -q 'postmaster@a.cn' mysql:/etc/postfix/mysql/sender_login_maps.cf
[RETURN NOTHING]

And send from Thunderbird will get error message like this:

553, '5.7.1 <postmaster@a.cn>: Sender address rejected: not owned by user postmaster@a.cn'

8

Re: [SOLVED] Howto disable SMTP service for specific mailbox

But i found another issue on Ubuntu 14.04 with Dovecot-2.2.9: Dovecot always use 'enableimapsecure' when Postfix uses Dovecot as SASL auth server, it should be 'enablesmtpsecured' instead.
Obviously, this causes unexpected issues.

9

Re: [SOLVED] Howto disable SMTP service for specific mailbox

Hmm, this change (switch of permit_sasl_authenticated <-> reject_sender_login_mismatch) has been done to allow authenticated user to send as different "FROM:" to the username (wanted behaviour).

Something like this topic : http://www.iredmail.org/forum/topic4915 … iases.html

10 (edited by stannicek 2015-01-07 21:31:57)

Re: [SOLVED] Howto disable SMTP service for specific mailbox

It look like it would be better to use it this way :

smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauthenticated_sender_login_mismatch

11

Re: [SOLVED] Howto disable SMTP service for specific mailbox

Anyway, it will not fix our problem, since i'm an authenticated client. Any other suggestion?

12

Re: [SOLVED] Howto disable SMTP service for specific mailbox

I think about modifying of

/etc/postfix/main.cf :

smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated

/opt/iRedAPD-1.4.4/settings.py :

plugins = ['reject_null_sender', 'sql_alias_access_policy', 'reject_sender_login_mismatch']

and adaptation of /opt/iRedAPD-1.4.4/plugins/reject_sender_login_mismatch.py :

else:
            logging.debug('Not strict restriction (ALLOWED_LOGIN_MISMATCH_STRICTLY = False).')
            if sasl_username in ALLOWED_LOGIN_MISMATCH_SENDERS \
               or sasl_sender_domain in ALLOWED_LOGIN_MISMATCH_SENDERS:
                return SMTP_ACTIONS['default']

would be the right way.

13

Re: [SOLVED] Howto disable SMTP service for specific mailbox

ZhangHuangbin wrote:

But i found another issue on Ubuntu 14.04 with Dovecot-2.2.9: Dovecot always use 'enableimapsecure' when Postfix uses Dovecot as SASL auth server, it should be 'enablesmtpsecured' instead.
Obviously, this causes unexpected issues.

I did the same test on Debian 7 with Dovecot 2.1.17, it correctly uses 'enablesmtp' and 'enablesmtpsecured'. So it looks like a bug in Dovecot-2.2.9.

14 (edited by stannicek 2015-01-07 22:13:33)

Re: [SOLVED] Howto disable SMTP service for specific mailbox

It looks like, that smtpd_sender_login_maps is only used when reject_sender_login_mismatch is used in smtpd_sender_restrictions.
Thus, enabling of reject_sender_login_mismatch.py plugin and removing the "sender_login_mismatch" from Postfix's "smtpd_sender_restrictions" setting will not do the same thing as plugin comment states.

# How to use this plugin:
#
# *) You must remove "sender_login_mismatch" restriction rule in Postfix
#    setting "smtpd_sender_restrictions" (/etc/postfix/main.cf). this plugin
#    will do the same restriction for you.

sender_login_maps.cf check will not be called due to removed  reject_sender_login_mismatch in "smtpd_sender_restrictions" setting.

sender_login_maps.cf  :
SELECT mailbox.username FROM mailbox,domain WHERE mailbox.username='%s' AND mailbox.domain='%d' AND mailbox.domain=domain.domain AND mailbox.enablesmtp=1 AND mailbox.active=1 AND domain.backupmx=0 AND domain.active=1

I think the SQL check above should be implemented in reject_sender_login_mismatch.py to be consistent with reject_sender_login_mismatch option in "smtpd_sender_restrictions" setting.

15

Re: [SOLVED] Howto disable SMTP service for specific mailbox

I don't agree. I will test CentOS 6 later.

16

Re: [SOLVED] Howto disable SMTP service for specific mailbox

ZhangHuangbin wrote:

I don't agree. I will test CentOS 6 later.

Hmm, I just reading postfix doc of "smtpd_sender_restrictions" parameter and it's options :

reject_sender_login_mismatch
    Reject the request when $smtpd_sender_login_maps specifies an owner for the MAIL FROM address, but the client is not (SASL) logged in as that MAIL FROM address owner; or when the client is (SASL) logged in, but the client login name doesn't own the MAIL FROM address according to $smtpd_sender_login_maps.

No other parameter/option mentioned the smtpd_sender_login_maps.

Maybe i'm wrong.

17

Re: [SOLVED] Howto disable SMTP service for specific mailbox

Tested on CentOS 6 (MySQL) with Dovecot-2.1.17, setting enablesmtp=0 and enablesmtpsecured=0 to disable smtp service works.

18

Re: [SOLVED] Howto disable SMTP service for specific mailbox

Tested on Ubuntu 14.10 (PGSQL) with Dovecot-2.2.9, setting enablesmtp=0 and enablesmtpsecured=0 to disable smtp service works.

Looks like just Ubuntu 14.04 + Dovecot-2.2.9 has this issue. I'm not sure whether it's a Dovecot bug or a Ubuntu package bug.

19

Re: [SOLVED] Howto disable SMTP service for specific mailbox

ZhangHuangbin wrote:

Tested on CentOS 6 (MySQL) with Dovecot-2.1.17, setting enablesmtp=0 and enablesmtpsecured=0 to disable smtp service works.

We are on 2.1.17

Did you test with

"smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated" + iRedAPD(with enabled reject_sender_login_mismatch.py)

or

"smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_sender_login_mismatch"  + iRedAPD(without enabled reject_sender_login_mismatch.py)

or

"smtpd_sender_restrictions = permit_mynetworks, reject_sender_login_mismatch, permit_sasl_authenticated" ?

So, dovecot is also responsible for enabling/disabling smtp for mailbox (enablesmtp=0 / enablesmtpsecured=0) before postfix's sender_login_maps.cf?

I'm just asking to know about where to search for problem...

Regards,
Stanislav

20

Re: [SOLVED] Howto disable SMTP service for specific mailbox

*) Any restriction rules AFTER "permit_sasl_authenticated" will be IGNORED if user successfully performed SMTP auth. I hope we're clear here.
*) Dovecot is used as SASL server in Postfix (smtpd_sasl_type=dovecot), so when Dovecot queries SQL/LDAP database to get user account, it should use 'enablesmtp=1' (or enablesmtpsecured=1) in SQL command as defined in /etc/dovecot/dovecot-mysql.conf (or dovecot-pgsql.conf).

Now, we should be clear that there's nothing to do with Postfix in this case.

21

Re: [SOLVED] Howto disable SMTP service for specific mailbox

ZhangHuangbin wrote:

*) Any restriction rules AFTER "permit_sasl_authenticated" will be IGNORED if user successfully performed SMTP auth. I hope we're clear here.
*) Dovecot is used as SASL server in Postfix (smtpd_sasl_type=dovecot), so when Dovecot queries SQL/LDAP database to get user account, it should use 'enablesmtp=1' (or enablesmtpsecured=1) in SQL command as defined in /etc/dovecot/dovecot-mysql.conf (or dovecot-pgsql.conf).

Now, we should be clear that there's nothing to do with Postfix in this case.

Yeah, right. I'm going to debug/investigate why dovecot don't use 'enablesmtp=0 + enablesmtpsecured=0' in our case.

Regards,
Stanislav

22 (edited by stannicek 2015-01-08 21:52:44)

Re: [SOLVED] Howto disable SMTP service for specific mailbox

Dovecot log (auth_debug = yes) when smtp used :

Jan 08 14:36:55 auth: Debug: client in: AUTH    1       PLAIN   service=smtp    nologin lip=1.2.3.4     rip=1.1.1.1       secured resp=<hidden>
Jan 08 14:36:55 auth: Debug: sql(user@domain.ltd,1.1.1.1): query: SELECT password FROM mailbox WHERE username='user@domain.ltd' AND active='1'
Jan 08 14:36:55 auth: Debug: client passdb out: OK      1       user=user@domain.ltd

No check for enablesmtp / enablesecuresmtp. On the other hand imap is checked correctly :

Jan 08 14:36:56 auth: Debug: client in: AUTH    1       PLAIN   service=imap    secured session=NW0/IiQMGQCT5QWX        lip=1.2.3.4     rip=1.1.1.1       lport=143       rport=26137
Jan 08 14:36:56 auth: Debug: client passdb out: CONT    1
Jan 08 14:36:56 auth: Debug: client in: CONT<hidden>
Jan 08 14:36:56 auth: Debug: sql(user@domain.ltd,1.1.1.1,<NW0/IiQMGQCT5QWX>): query: SELECT password FROM mailbox WHERE username='user@domain.ltd' AND active='1'
Jan 08 14:36:56 auth: Debug: client passdb out: OK      1       user=user@domain.ltd
Jan 08 14:36:56 auth: Debug: master in: REQUEST 2382626817      21050   1       9ccab41e5c56ea160831c9e0854c45af
Jan 08 14:36:56 auth: Debug: sql(user@domain.ltd,1.1.1.1,<NW0/IiQMGQCT5QWX>): SELECT mailbox.storagebasedirectory || '/' || mailbox.storagenode || '/' || mailbox.maildir AS home, '*:bytes=' || mailbox.quota*1048576 AS quota_rule FROM mailbox,domain WHERE mailbox.username='user@domain.ltd' AND mailbox.domain='domain.ltd' AND mailbox.enableimapsecured=1 AND mailbox.domain=domain.domain AND domain.backupmx=0 AND domain.active=1 AND mailbox.active=1
Jan 08 14:36:56 auth: Debug: master userdb out: USER    2382626817      user@domain.ltd        home=/var/vmail/vmail1/domain.ltd/u/s/r/user-2015.01.06.08.57.47/      quota_rule=*:bytes=20971520

Regards,
Stanislav

23

Re: [SOLVED] Howto disable SMTP service for specific mailbox

It looks like, that "user_query" from dovecot-pgsql.conf is not called when "service=smtp" is used.

24

Re: [SOLVED] Howto disable SMTP service for specific mailbox

stannicek wrote:

It looks like, that "user_query" from dovecot-pgsql.conf is not called when "service=smtp" is used.

After hours of searching i wasn't able to determine the reason ...

So, the only solution i was able to do was to edit password_query as follows :

password_query = SELECT password FROM mailbox WHERE username='%u' AND active='1' AND mailbox.enable%Ls%Lc='1'

This will only log an unknown user to dovecot.log :

Jan 12 09:02:14 auth: Info: sql(user@domain.ltd,1.1.1.1): unknown user

Regards,
Stanislav

25

Re: [SOLVED] Howto disable SMTP service for specific mailbox

Your solution is better. I will merge it into next iRedMail release.