0

Issue

Dovecot does not use mail_location as I expect.

I want to provide email service for users in LDAP directory. User accounts are virtual accounts stored in an LDAP and they ARE NOT mapped to local users.

Details

Package versions

OS              Debian GNU/Linux 8.2 (jessie)
dovecot-core    1:2.2.13-12~deb8u1
dovecot-imapd   1:2.2.13-12~deb8u1
dovecot-ldap    1:2.2.13-12~deb8u1
squirrelmail    2:1.4.23~svn20120406-2
postfix         2.11.3-1
apache2         2.4.10-10+deb8u3

Configuration details

I set in /etc/dovecot/conf.d/10-mail.conf:

mail_location = maildir:/var/mail/vhosts/%d/%n

so I expect to mail location be at /var/mail/vhosts/mydomain.com/myuser for myuser@mydomain.com.

Some dovecot settings, thrown by dovecot -n command, are:

mail_location = maildir:/var/mail/vhosts/%d/%n
mail_privileged_group = mail
namespace inbox {
  inbox = yes
  location =
  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox Junk {
    special_use = \Junk
  }
  mailbox Sent {
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    special_use = \Sent
  }
  mailbox Trash {
    special_use = \Trash
  }
  prefix =
}
protocols = " imap lmtp sieve"
service auth-worker {
  user = vmail
}
service imap-login {
  inet_listener imap {
    port = 143
  }
}
service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    group = postfix
    mode = 0600
    user = postfix
  }
}
userdb {
  args = /etc/dovecot/dovecot-ldap.conf.ext
  driver = ldap
}

Looking in /var/log/mail.log using tail -f command, it throws:

Sep 27 19:10:48 balam dovecot: imap-login: Login: user=<myuser>, method=PLAIN, rip=::1, lip=::1, mpid=24907, secured, session=<7/umVr8gvwAAAAAAAAAAAAAAAAAAAAAB>
Sep 27 19:10:48 balam dovecot: imap(myuser): Error: user myuser: Initialization failed: Namespace '': mkdir(/var/mail/vhosts//myuser) failed: Permission denied (euid=30000(myuser) egid=30002(IT) missing +w perm: /var/mail/vhosts/, dir owned by 5000:5000 mode=0755)
Sep 27 19:10:48 balam dovecot: imap(myuser): Error: Invalid user settings. Refer to server log for more information.

which is attempting to create mail directory at /var/mail/vhosts//myuser, instead of /var/mail/vhosts/mydomain.com/myuser as I want and expect.

If you need more details, please ask me!

Tests

In order to test login I have mounted a SquirrelMail client, which trigger previous events logged in /var/log/mail.log.

Israel
  • 3,252
  • 4
  • 36
  • 54
  • Maybe [this tutorial will help](http://www.rosehosting.com/blog/mailserver-with-virtual-users-and-domains-using-postfix-and-dovecot-on-a-centos-6-vps/) I used it to build my own multi-domain capable email server with no problems. I think you can find where you it went wrong for you, since the configuration describe in the site is similar to yours – samayo Sep 27 '15 at 21:15
  • @samayo, This tutorial is quite different, because config files are different from CentOS 6 to Debian 8 (jessie). – Israel Sep 27 '15 at 22:37

1 Answers1

0

You have to set two parameters - mail_uid and mail_gid in the config. Until they are not set deliver perform database lookup to get adressee's UID and GID. If any - they'll be used for filesystem access. While mail storage hierarcy belong to 5000:5000 LDA have no access to write inside /var/mail/vhosts

Just add an explicit declaration of user who can access mail storage:

mail_location = maildir:/var/mail/vhosts/%d/%n
mail_uid = 5000 # or his login name
mail_gid = 5000 # or his group name

and restart dovecot. Then deliver will be invoked with UID/GID=5000. Even more, now you can set mail storage permissions to 700 to prevent anyone except 5000:5000 to access mail storage.

Kondybas
  • 686
  • 6
  • 15
  • What about if user info for email accounts are not mapped with local users? I take email user accounts from LDAP directory. – Israel Sep 27 '15 at 22:32
  • 1
    Virtual users that haven't corresponding local ones are the general practice nowadays. Not only for mail but for almost every other service that need an authentication. System and services **should** have separate users. – Kondybas Sep 27 '15 at 23:15
  • I have added `mail_uid = vmail` and `mail_gid = vmail` to `/etc/dovecot/conf.d/10-mail.conf` file and restarted dovecot (`service dovecot restart`), finally tried to login again but, it still throwing same messages `Initialization failed: Namespace '': mkdir(/var/mail/vhosts//myuser) failed`. I expect some mkdir on `/var/mail/vhosts/mydomain.com/myuser`. – Israel Sep 27 '15 at 23:29