验证用户时出现 dovecot 错误(未为用户设置主目录)

验证用户时出现 dovecot 错误(未为用户设置主目录)

我正在尝试设置一个相对基本的带有 MySQL 后端的 postfix/dovecot IMAP/SMTP 服务器。身份验证似乎成功了,但我似乎收到了以下错误:

Initialization failed: Namespace '': Home directory not set for user. Can't expand ~/ for mail root dir in: ~/myserver.io/mail/

我得到的错误是这样的,以及 DEBUG:

Feb  8 04:27:13 localhost dovecot: auth: Debug: Loading modules from directory: /usr/lib64/dovecot/auth
Feb  8 04:27:13 localhost dovecot: auth: Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_mysql.so
Feb  8 04:27:13 localhost dovecot: auth: Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_sqlite.so
Feb  8 04:27:13 localhost dovecot: auth: Debug: Read auth token secret from /var/run/dovecot/auth-token-secret.dat
Feb  8 04:27:13 localhost dovecot: auth: Debug: auth client connected (pid=9974)
Feb  8 04:27:13 localhost dovecot: auth: Debug: client in: AUTH#0111#011PLAIN#011service=imap#011secured#011session=IeV306tkgAB/AAAB#011lip=127.0.0.1#011rip=127.0.0.1#011lport=143#011rport=50816#011resp=AG1haWxAdmVuZ2VhbmNlLmlvAENyM2F0MXZlLS0= (previous base64 data may contain sensitive data)
Feb  8 04:27:13 localhost dovecot: auth-worker(9977): Debug: Loading modules from directory: /usr/lib64/dovecot/auth
Feb  8 04:27:13 localhost dovecot: auth-worker(9977): Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_mysql.so
Feb  8 04:27:13 localhost dovecot: auth-worker(9977): Debug: Module loaded: /usr/lib64/dovecot/auth/libdriver_sqlite.so
Feb  8 04:27:13 localhost dovecot: auth-worker(9977): Debug: sql([email protected],127.0.0.1): query: SELECT username, domain, password, CONCAT('maildir:~/', maildir) AS userdb_home, '1000' AS userdb_uid, '1000' AS userdb_gid FROM mailbox WHERE username = 'mail' AND domain = 'myserver.io'
Feb  8 04:27:13 localhost dovecot: auth: Debug: client passdb out: OK#0111#[email protected]
Feb  8 04:27:13 localhost dovecot: auth: Debug: master in: REQUEST#0112229403649#0119974#0111#011aaa130ec6f6296678ec1e9e7866efbaf#011session_pid=9980#011request_auth_token
Feb  8 04:27:13 localhost dovecot: auth-worker(9977): Debug: sql([email protected],127.0.0.1): SELECT CONCAT('maildir:~/', maildir) as mail, '1000' AS uid, '1000' as gid FROM mailbox WHERE username = 'mail' AND domain = 'myserver.io'
Feb  8 04:27:13 localhost dovecot: auth: Debug: master userdb out: USER#0112229403649#[email protected]#011mail=maildir:~/myserver.io/mail/#011uid=1000#011gid=1000#011auth_token=d72ede03452694f33b4b1c759539f7ec613cab95
Feb  8 04:27:13 localhost dovecot: imap-login: Login: user=<[email protected]>, method=PLAIN, rip=127.0.0.1, lip=127.0.0.1, mpid=9980, secured, session=<IeV306tkgAB/AAAB>
Feb  8 04:27:13 localhost dovecot: imap: Debug: Added userdb setting: mail=maildir:~/myserver.io/mail/
Feb  8 04:27:13 localhost dovecot: imap([email protected]): Debug: Effective uid=1000, gid=1000, home=
Feb  8 04:27:13 localhost dovecot: imap([email protected]): Debug: Namespace inbox: type=private, prefix=, sep=/, inbox=yes, hidden=no, list=yes, subscriptions=yes location=maildir:~/myserver.io/mail/
Feb  8 04:27:13 localhost dovecot: imap([email protected]): Error: user [email protected]: Initialization failed: Namespace '': Home directory not set for user. Can't expand ~/ for mail root dir in: ~/myserver.io/mail/
Feb  8 04:27:13 localhost dovecot: imap([email protected]): Error: Invalid user settings. Refer to server log for more information.
p=/, inbox=yes, hidden=no, list=yes, subscriptions=yes location=maildir:~/myserver.io/mail/

我的 dovecot 配置是:

[root@postfix webmail]# dovecot -n
# 2.2.10: /etc/dovecot/dovecot.conf
# OS: Linux 4.14.14-x86_64-linode94 x86_64 CentOS Linux release 7.4.1708 (Core)
auth_debug_passwords = yes
disable_plaintext_auth = no
mail_debug = yes
mail_gid = vmail
mail_privileged_group = mail
mail_uid = vmail
namespace inbox {
  inbox = yes
  location =
  mailbox Drafts {
    auto = subscribe
    special_use = \Drafts
  }
  mailbox Junk {
    auto = subscribe
    special_use = \Junk
  }
  mailbox Sent {
    auto = subscribe
    special_use = \Sent
  }
  mailbox Trash {
    auto = subscribe
    special_use = \Trash
  }
  prefix =
  separator = /
  type = private
}
passdb {
  args = /etc/dovecot/dovecot-sql.conf
  driver = sql
}
protocols = imap
service auth {
  unix_listener /var/spool/postfix/private/auth {
    group = postfix
    mode = 0660
    user = postfix
  }
  unix_listener auth-master {
    group = vmail
    mode = 0660
    user = vmail
  }
  user = $default_internal_user
}
ssl = no
userdb {
  args = /etc/dovecot/dovecot-sql.conf
  driver = sql
}

最后,我的 MySQL conf

driver = mysql
# The mysqld.sock socket may be in different locations in different systems.
# Use "host= ... pass=foo#bar" with double-quotes if your password has '#' character.
connect = host=localhost dbname=postfix user=root password=supersecretpass
default_pass_scheme = MD5-CRYPT

# Alternatively you can connect to localhost as well:
#connect = host=localhost dbname=mails user=admin password=pass # port=3306

password_query = SELECT username, domain, password, \
                 CONCAT('maildir:~/', maildir) AS userdb_home, \
                 '1000' AS userdb_uid, '1000' AS userdb_gid \
                 FROM mailbox WHERE username = '%n' AND domain = '%d'

user_query = SELECT CONCAT('maildir:~/', maildir) as mail, '1000' AS uid, '1000' as gid FROM mailbox WHERE username = '%n' AND domain = '%d'

# For using doveadm -A:
iterate_query = SELECT username, domain FROM mailbox

我彻底不知所措了!

答案1

错误非常明显:

Error: user [email protected]: Initialization failed: Namespace '': Home directory not set for user. Can't expand ~/ for mail root dir in: ~/myserver.io/mail/

Dovecot 不知道将邮件放在哪里,因为您已将 maildir 设置为~/myserver.io/mail/,但尚未告诉它用户的主目录。尝试以下操作,它设置homeuserdb_mail

password_query = SELECT username, domain, password, \
             FROM mailbox WHERE username = '%n' AND domain = '%d' 
user_query     = SELECT CONCAT('maildir:~/', maildir) as userdb_mail,\
             CONCAT('/home/', username) as home,\
             '1000' AS uid, '1000' as gid \
             FROM mailbox WHERE username = '%n' AND domain = '%d'

相关内容