![dovecot userdb passwd-file default_fields uid 没有扩展 %variable](https://linux22.com/image/652990/dovecot%20userdb%20passwd-file%20default_fields%20uid%20%E6%B2%A1%E6%9C%89%E6%89%A9%E5%B1%95%20%25variable.png)
我正在尝试建立一个非常简单的共享邮件服务器,其中每个“域”都是一个系统用户,即“example.com”是一个真实用户,其 /home/example.com/、uid 为 5001 且 gid“example.com”为 5001。
每个域\用户在其主目录中都有自己的 maildir,以及一个包含与该域关联的虚拟邮件用户的普通密码文件。
Dovecot 版本和配置信息:
# 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
}
每次尝试连接到 pop3\imap 端口时,服务器都会出现以下错误
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>
客户端看到:
$ 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.
查看 wiki (http://wiki2.dovecot.org/UserDatabase#Userdb_settings) 明确指出 default_fields 值支持 %variables,所以我不确定我是否缺少实现此功能所需的其他配置。
由于在客户端发出 USER\LOGIN 命令之前发生这种情况,我理解没有用户名可以从中提取 %d 域部分,因此失败。我不明白的是为什么在客户端发出身份验证尝试之前会进行 Dovecot 身份验证尝试。
如果我将配置更改为固定的 uid\gid
default_fields = uid=example.com gid=example.com home=/home/%d/mail/%n mail=maildir:/home/%d/mail/%n
允许连接并发出正确的身份验证命令。但随后,任何非 example.com 域的用户访问邮箱都会失败。