From: Jakub Czajka Date: Sat, 29 Oct 2022 22:22:28 +0000 (+0200) Subject: [dovecot] Enable virtual mailboxes. X-Git-Url: https://git.ekhem.eu.org/?a=commitdiff_plain;h=da9de6a2905598f5eab28a8b410c5133979c39e1;p=server.git [dovecot] Enable virtual mailboxes. 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. --- diff --git a/databases/mail/mail_db_create.sql b/databases/mail/mail_db_create.sql index d826faa..a1c1f50 100644 --- a/databases/mail/mail_db_create.sql +++ b/databases/mail/mail_db_create.sql @@ -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 ); diff --git a/dovecot/10-mail.conf b/dovecot/10-mail.conf index aa0925b..1c65e68 100644 --- a/dovecot/10-mail.conf +++ b/dovecot/10-mail.conf @@ -27,7 +27,7 @@ # # # -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. -#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. diff --git a/dovecot/README b/dovecot/README index 8d57ec8..de9de73 100644 --- a/dovecot/README +++ b/dovecot/README @@ -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= \ --command="INSERT INTO users \ - - VALUES ('user', 'domain.com', MD5(''), \ - '/home/debian', id -u, id -g)" + VALUES ('user', 'domain.com', MD5(''))" ``` diff --git a/dovecot/auth-sql.conf.ext b/dovecot/auth-sql.conf.ext index ccbea86..308c983 100644 --- a/dovecot/auth-sql.conf.ext +++ b/dovecot/auth-sql.conf.ext @@ -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: # -#userdb { - #driver = static - #args = uid=vmail gid=vmail home=/var/vmail/%u -#} +userdb { + driver = static + args = uid=vmail gid=vmail home=/var/vmail/%n +} diff --git a/dovecot/dovecot-sql.conf.ext b/dovecot/dovecot-sql.conf.ext index 3b8cd59..fd5566f 100644 --- a/dovecot/dovecot-sql.conf.ext +++ b/dovecot/dovecot-sql.conf.ext @@ -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