I'm trying to set up a very simple shared mail server, where each 'domain' is a system user, i.e. 'example.com' is a real user with /home/example.com/, a uid of 5001 and gid 'example.com' of 5001.
Each domain\user has their own maildir inside their home, and a plain passwd-file with the virtual mail users associated with that domain.
Dovecot version & config info:
# dovecot -n
# 2.2.13: /etc/dovecot/dovecot.conf
# OS: Linux 3.2.0-4-amd64 x86_64 Debian 7.8
auth_mechanisms = plain login
auth_verbose = yes
disable_plaintext_auth = no
mail_location = mbox:~/mail:INBOX=/var/mail/%u
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 =
}
passdb {
args = username_format=%n /home/%d/mail_users
driver = passwd-file
}
protocols = " imap lmtp pop3"
ssl = no
userdb {
args = username_format=%n /home/%d/mail_users
default_fields = uid=%d gid=%d home=/home/%d/mail/%n mail=maildir:/home/%d/mail/%n
driver = passwd-file
}
Every time I try to make a connection to the pop3\imap port, I get the following errors in the server
dovecot: auth: Fatal: passwd-file userdb: Invalid uid: %d
dovecot: master: Error: service(auth): command startup failed, throttling for 2 secs
dovecot: imap-login: Disconnected: Auth process broken (disconnected before auth was ready, waited 0 secs): user=<>, rip=192.168.30.10, lip=192.168.20.201, session=<2rgGLBkQ/wDAqB4K>
and the client sees:
$ telnet 192.168.20.201 imap
Trying 192.168.20.201...
Connected to 192.168.20.201.
Escape character is '^]'.
* BYE Disconnected: Auth process broken
Connection closed by foreign host.
Checking the wiki (http://wiki2.dovecot.org/UserDatabase#Userdb_settings) clearly states that the default_fields values support %variables, so I'm not sure if I'm missing some other config required for this to work.
As it happens before the client can issue a USER\LOGIN command, I understand that there is no user name from which to extract the %d domain part, hence the failure. What I don't understand is why there is a Dovecot authentication attempt before the client issues an authentication attempt.
If I alter the config to a fixed uid\gid
default_fields = uid=example.com gid=example.com home=/home/%d/mail/%n mail=maildir:/home/%d/mail/%n
The connection is allowed an a proper authentication command can be issued. But then of course accessing the mailbox for any user not of the example.com domain fails.