]> git.ekhem.eu.org Git - server.git/commitdiff
[dovecot] Enable virtual mailboxes.
authorJakub Czajka <jakub@ekhem.eu.org>
Sat, 29 Oct 2022 22:22:28 +0000 (00:22 +0200)
committerJakub Czajka <jakub@ekhem.eu.org>
Sun, 3 Dec 2023 17:00:57 +0000 (18:00 +0100)
Virtual mailboxes are mailboxes created for new users automatically
based on their credentials. Userdb lookups aren't necessary.
Directories for virtual mailboxes are owned by a single system
user (`vmail`). This commit enables virtual mailboxes in `dovecot`:
- Static userdb instead of SQL query.
- Username column as the primary key of the address book. It has to be
unique to prevent virtual mailboxes overlapping.

databases/mail/mail_db_create.sql
dovecot/10-mail.conf
dovecot/README
dovecot/auth-sql.conf.ext
dovecot/dovecot-sql.conf.ext

index d826faa1ce7ef16b183ec9c370e7db3bd51cf97b..a1c1f50201d95e7fd5bd63b34651bc0f8021913f 100644 (file)
@@ -2,12 +2,9 @@
 -- License: 0BSD.
 
 CREATE TABLE IF NOT EXISTS users (
-    username VARCHAR(128) NOT NULL,
+    username VARCHAR(128) PRIMARY KEY,
     domain VARCHAR(128) NOT NULL,
     password VARCHAR(64) NOT NULL,
-    home VARCHAR(255) NOT NULL,
-    uid INTEGER NOT NULL,
-    gid INTEGER NOT NULL,
     active CHAR(1) DEFAULT 'Y' NOT NULL
 );
 
index aa0925b1395ee2e8d929dc823533bf2a1bc70054..1c65e682dcf6cb7959ad31907cac9bde7967110f 100644 (file)
@@ -27,7 +27,7 @@
 #
 # <doc/wiki/MailLocation.txt>
 #
-mail_location = mbox:~/mail:INBOX=/var/mail/%u
+mail_location = maildir:/var/vmail/%n
 
 # If you need to set multiple mailbox locations or want to change default
 # namespace settings, you can do it by defining namespace sections.
@@ -105,8 +105,8 @@ namespace inbox {
 # System user and group used to access mails. If you use multiple, userdb
 # can override these by returning uid or gid fields. You can use either numbers
 # or names. <doc/wiki/UserIds.txt>
-#mail_uid =
-#mail_gid =
+mail_uid = vmail
+mail_gid = vmail
 
 # Group to enable temporarily for privileged operations. Currently this is
 # used only with INBOX when either its initial creation or dotlocking fails.
index 8d57ec890ab4d33373d913088324052155950861..de9de734766a6845f97bfbfb28d7a3fd323282eb 100644 (file)
@@ -92,6 +92,18 @@ Execute `mail_db_create.sql`.
 psql --dbname=mail_db --file=databases/mail/mail_db_create.sql
 ```
 
+Mailbox
+-------
+
+Use `vmail` user for virtual mailboxes.
+
+```
+$ useradd --home-dir /var/vmail --shell /usr/sbin/nologin --lock \
+    --create-home vmail
+$ touch /var/log/dovecot.log /var/log/dovecot-info.log
+$ chown vmail:vmail /var/log/{dovecot.log,dovecot-info.log}
+```
+
 Administration
 --------------
 
@@ -100,7 +112,5 @@ Add a user.
 ```
 psql --username=postgres --dbname=<database> \
   --command="INSERT INTO users \
-
-             VALUES ('user', 'domain.com', MD5('<password>'), \
-                    '/home/debian', id -u, id -g)"
+             VALUES ('user', 'domain.com', MD5('<password>'))"
 ```
index ccbea864165b7f516fd3e38a6546bfea669cd6e7..308c9833f977f90beffcbaf967ea5ab81cdfe49e 100644 (file)
@@ -16,15 +16,15 @@ passdb {
 #  driver = prefetch
 #}
 
-userdb {
-  driver = sql
-  args = /etc/dovecot/dovecot-sql.conf.ext
-}
+#userdb {
+#  driver = sql
+#  args = /etc/dovecot/dovecot-sql.conf.ext
+#}
 
 # If you don't have any user-specific settings, you can avoid the user_query
 # by using userdb static instead of userdb sql, for example:
 # <doc/wiki/UserDatabase.Static.txt>
-#userdb {
-  #driver = static
-  #args = uid=vmail gid=vmail home=/var/vmail/%u
-#}
+userdb {
+  driver = static
+  args = uid=vmail gid=vmail home=/var/vmail/%n
+}
index 3b8cd59fab0428b89547066b3a60684d7a429e0e..fd5566fa202c27fb2219bf5f47f1bdd5a7daa943 100644 (file)
@@ -127,9 +127,9 @@ password_query = \
 #   user_query = SELECT dir AS home, user AS uid, group AS gid FROM users where userid = '%u'
 #   user_query = SELECT home, 501 AS uid, 501 AS gid FROM users WHERE userid = '%u'
 #
-user_query = \
-  SELECT home, uid, gid \
-  FROM users WHERE username = '%n' AND domain = '%d' AND active = 'Y'
+#user_query = \
+#  SELECT home, uid, gid \
+#  FROM users WHERE username = '%n' AND domain = '%d' AND active = 'Y'
 
 # If you wish to avoid two SQL lookups (passdb + userdb), you can use
 # userdb prefetch instead of userdb sql in dovecot.conf. In that case you'll