[Dovecot] Please help with Quota dict mysql configuration
Hello So what i have: centos 5.6 postfix 2.3.3 dovecot 2.0.13 postfixadmin 2.3.3 roundcube 0.5.3
All general things are working right now i can send receive email with ssl connections etc... Now i'm trying to configure additional options like quota and some other plugins like sieve, trash, expire and deleted-to-trash. Configuration of quota is on first place. I have read wiki regarding quota config , dict config but can't make things running. Hope there are normal sample configs you can share with me. I'm total noob in sql, so it's very difficult for me to arrange stuff in a way i need.
My configs:
dict { quota = mysql:/etc/dovecot/conf.d/sql/dovecot-dict-sql.conf # expire = sqlite:/etc/dovecot/dovecot-dict-sql.conf }
dovecot-dict-sql.conf sample i took from postfixadmin docs provided with package, also changed table to quota2 as suggested for dovecot 2: driver = mysql connect = host=localhost dbname=postfix user=postfix password=postfixadmin default_pass_scheme = MD5-CRYPT table = quota2 select_field = current where_field = path username_field = username
my sql.conf i took it from tutorial on your wiki : LDA postfix postfixadmin:
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=postfixadmin
user_query = SELECT concat('/home/vmail/', maildir) as home, concat('maildir:/home/vmail/', maildir) as mail, 1001 AS uid, 12 AS gid, concat('maildir:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1' #user_query = SELECT maildir, 1001 AS uid, 1001 AS gid, CONCAT('dict:storage=',floor(quota/1000),' proxy::quota') as quota FROM mailbox WHERE username = '%u' AND active='1'
password_query = SELECT username as user, password, concat('/home/vmail/', maildir) as userdb_home, concat('maildir:/home/vmail/', maildir) as userdb_mail, 1001 as userdb_uid, 12 as userdb_gid FROM mailbox WHERE username = '%u' AND active = '1'
The second user_query string i took from postfixadmin docs. But i dont know how to aply it. If it is better to use with mysql/postfixadmin
and after this all i dont how to configure quota.conf (90-quota.conf):
plugin { #quota = dirsize:User quota #quota = maildir:User quota #quota = dict:User quota::proxy::quota #quota = fs:User quota }
# Multiple quota roots are also possible, for example this gives each user # their own 100MB quota and one shared 1GB quota within the domain: plugin { #quota = dict:user::proxy::quota #quota2 = dict:domain:%d:proxy::quota_domain #quota_rule = *:storage=102400 #quota2_rule = *:storage=1048576 }
Please help me with configuration. I really stuck with this thing. And yes i've tried to find solutions on mailing list, but no luck. I want per domain/user quota in mysql. Also space usage to be shown in roundcube. Hope to get proper help ... And sorry... Thanks in advance.
Denis Iskandarov schreef:
Hello So what i have: centos 5.6 postfix 2.3.3 dovecot 2.0.13 postfixadmin 2.3.3 roundcube 0.5.3
All general things are working right now i can send receive email with ssl connections etc... Now i'm trying to configure additional options like quota and some other plugins like sieve, trash, expire and deleted-to-trash. Configuration of quota is on first place. I have read wiki regarding quota config , dict config but can't make things running. Hope there are normal sample configs you can share with me. I'm total noob in sql, so it's very difficult for me to arrange stuff in a way i need.
My configs:
dict { quota = mysql:/etc/dovecot/conf.d/sql/dovecot-dict-sql.conf # expire = sqlite:/etc/dovecot/dovecot-dict-sql.conf }
dovecot-dict-sql.conf sample i took from postfixadmin docs provided with package, also changed table to quota2 as suggested for dovecot 2: driver = mysql connect = host=localhost dbname=postfix user=postfix password=postfixadmin default_pass_scheme = MD5-CRYPT table = quota2 select_field = current where_field = path username_field = username
my sql.conf i took it from tutorial on your wiki : LDA postfix postfixadmin:
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=postfixadmin
user_query = SELECT concat('/home/vmail/', maildir) as home, concat('maildir:/home/vmail/', maildir) as mail, 1001 AS uid, 12 AS gid, concat('maildir:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1' #user_query = SELECT maildir, 1001 AS uid, 1001 AS gid, CONCAT('dict:storage=',floor(quota/1000),' proxy::quota') as quota FROM mailbox WHERE username = '%u' AND active='1'
password_query = SELECT username as user, password, concat('/home/vmail/', maildir) as userdb_home, concat('maildir:/home/vmail/', maildir) as userdb_mail, 1001 as userdb_uid, 12 as userdb_gid FROM mailbox WHERE username = '%u' AND active = '1'
The second user_query string i took from postfixadmin docs. But i dont know how to aply it. If it is better to use with mysql/postfixadmin
and after this all i dont how to configure quota.conf (90-quota.conf):
plugin { #quota = dirsize:User quota #quota = maildir:User quota #quota = dict:User quota::proxy::quota #quota = fs:User quota }
# Multiple quota roots are also possible, for example this gives each user # their own 100MB quota and one shared 1GB quota within the domain: plugin { #quota = dict:user::proxy::quota #quota2 = dict:domain:%d:proxy::quota_domain #quota_rule = *:storage=102400 #quota2_rule = *:storage=1048576 }
Please help me with configuration. I really stuck with this thing. And yes i've tried to find solutions on mailing list, but no luck. I want per domain/user quota in mysql. Also space usage to be shown in roundcube. Hope to get proper help ... And sorry... Thanks in advance. Maybe stupid, but are these plugin examples really from your dovecot.conf file ? If so remove the # before the quota lines!
this is my part from dovecot.conf (only relavant quota parts.)
quotadict = mysql:/usr/local/etc/dovecot/dovecot-dict-quota.conf
plugin { # Quota config quota = dict:User quota::noenforcing:proxy::quotadict quota_rule = *:storage=1G quota_rule2 = Trash:storage=+100M quota_warning = storage=95%% quota-warning 95 %u quota_warning2 = storage=90%% quota-warning 90 %u quota_warning3 = storage=80%% quota-warning 80 %u #OTHER Plugins .... .... }
service quota-warning { executable = script /usr/local/bin/quota-warning.sh user = vmail unix_listener quota-warning { user = vmail } }
protocol imap { imap_client_workarounds = delay-newmail tb-extra-mailbox-sep imap_idle_notify_interval = 120 s imap_logout_format = bytes=%i/%o imap_max_line_length = 65536 mail_plugins = quota imap_quota autocreate acl imap_acl mail_log notify fts fts_squat }
protocol lmtp { auth_socket_path = /var/run/dovecot/auth-master mail_plugins = sieve quota acl mail_log notify postmaster_address = postmaster@yourdomain.com sendmail_path = /usr/local/sbin/sendmail }
Above protocol lmtp could be protocol lda in your case
This is my dovecot-dict-quota.conf file
# Dovecot 2.0.x connect = host=192.xxx.xxx.xxx dbname=postfix user=postfix password=mypostfixpasswd map { pattern = priv/quota/storage table = quota2 username_field = username value_field = bytes } map { pattern = priv/quota/messages table = quota2 username_field = username value_field = messages }
This is my /usr/local/bin/quota-warning.sh file
#!/usr/local/bin/bash PERCENT=$1 USER=$2 cat << EOF | /usr/local/libexec/dovecot/deliver -d $USER -o "plugin/quota=maildir:User quota:noenforcing" From: support@yourdomain.com Subject: quota warning
Uw mailbox is momenteel voor $PERCENT% gevult. Verwijder oude mail, of vraag een verruiming van uw quota aan.
Your mailbox is now $PERCENT% full. Please remove some old mail, or ask for a larger quota.
Skrzynka pocztowa jest w tym momencie w $PERCENT% zapelniona. Usun stare wiadomosci,albo przenies w inny folder.
EOF
Hope this helps.
Regards, Johan Hendriks Double L Automatisering
Thanks for your samples, they would help me so much! My config is commented because i didn't know how to properly configure it, didn't understand theory to start doing things on practice. can you show me your dovecot-mysql.conf as well ? it should be final peace of puzzle for me. i'm interested in this two almost different user_query lines:
user_query = SELECT concat('/home/vmail/', maildir) as home, concat('maildir:/home/vmail/', maildir) as mail, 1001 AS uid, 12 AS gid, concat('maildir:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1'
user_query = SELECT maildir, 1001 AS uid, 1001 AS gid, CONCAT('dict:storage=',floor(quota/1000),' proxy::quota') as quota FROM mailbox WHERE username = '%u' AND active='1'
first one provided from dovecot wiki and second one from postfixadmin docs regarding dovecot configuration. may i use user_query like this? :
user_query = SELECT concat('/home/vmail/', maildir) as home, concat('maildir:/home/vmail/', maildir) as mail, 1001 AS uid, 12 AS gid, CONCAT('dict:storage=',floor(quota/1000),' proxy::quota') AS quota FROM mailbox WHERE username = '%u' AND active = '1'
seems like this line doing some nice customization showing quota in kilobytes and not in bytes. or if someone could explain what does this string means. also what does this line means ?: concat('maildir:/home/vmail/', maildir) as mail string about home i understood dovecot reads users home dir from this line. And i dont understand if why should i indicate in 10-mail.conf next string: mail_location = maildir:/home/vmail/%d/%u If it is overided by user_query from mysql?
Also what is meaning of quota(2) table. does dovecot reading configuration from there or just stores usage information ? Also what does this string mean?: pattern = priv/quota/messages what privileges those who reads the, or where are they indicated ?
Thanks in advance. Denis.
Maybe stupid, but are these plugin examples really from your dovecot.conf file ? If so remove the # before the quota lines!
this is my part from dovecot.conf (only relavant quota parts.)
quotadict = mysql:/usr/local/etc/dovecot/dovecot-dict-quota.conf
plugin { # Quota config quota = dict:User quota::noenforcing:proxy::quotadict quota_rule = *:storage=1G quota_rule2 = Trash:storage=+100M quota_warning = storage=95%% quota-warning 95 %u quota_warning2 = storage=90%% quota-warning 90 %u quota_warning3 = storage=80%% quota-warning 80 %u #OTHER Plugins .... .... }
service quota-warning { executable = script /usr/local/bin/quota-warning.sh user = vmail unix_listener quota-warning { user = vmail } }
protocol imap { imap_client_workarounds = delay-newmail tb-extra-mailbox-sep imap_idle_notify_interval = 120 s imap_logout_format = bytes=%i/%o imap_max_line_length = 65536 mail_plugins = quota imap_quota autocreate acl imap_acl mail_log notify fts fts_squat }
protocol lmtp { auth_socket_path = /var/run/dovecot/auth-master mail_plugins = sieve quota acl mail_log notify postmaster_address = postmaster@yourdomain.com sendmail_path = /usr/local/sbin/sendmail }
Above protocol lmtp could be protocol lda in your case
This is my dovecot-dict-quota.conf file
# Dovecot 2.0.x connect = host=192.xxx.xxx.xxx dbname=postfix user=postfix password=mypostfixpasswd map { pattern = priv/quota/storage table = quota2 username_field = username value_field = bytes } map { pattern = priv/quota/messages table = quota2 username_field = username value_field = messages }
This is my /usr/local/bin/quota-warning.sh file
#!/usr/local/bin/bash PERCENT=$1 USER=$2 cat << EOF | /usr/local/libexec/dovecot/deliver -d $USER -o "plugin/quota=maildir:User quota:noenforcing" From: support@yourdomain.com Subject: quota warning
Uw mailbox is momenteel voor $PERCENT% gevult. Verwijder oude mail, of vraag een verruiming van uw quota aan.
Your mailbox is now $PERCENT% full. Please remove some old mail, or ask for a larger quota.
Skrzynka pocztowa jest w tym momencie w $PERCENT% zapelniona. Usun stare wiadomosci,albo przenies w inny folder.
EOF
Hope this helps.
Regards, Johan Hendriks Double L Automatisering
Denis Iskandarov schreef:
Thanks for your samples, they would help me so much! My config is commented because i didn't know how to properly configure it, didn't understand theory to start doing things on practice. can you show me your dovecot-mysql.conf as well ? it should be final peace of puzzle for me. i'm interested in this two almost different user_query lines:
user_query = SELECT concat('/home/vmail/', maildir) as home, concat('maildir:/home/vmail/', maildir) as mail, 1001 AS uid, 12 AS gid, concat('maildir:storage=', quota) AS quota FROM mailbox WHERE username = '%u' AND active = '1'
user_query = SELECT maildir, 1001 AS uid, 1001 AS gid, CONCAT('dict:storage=',floor(quota/1000),' proxy::quota') as quota FROM mailbox WHERE username = '%u' AND active='1'
first one provided from dovecot wiki and second one from postfixadmin docs regarding dovecot configuration. may i use user_query like this? :
user_query = SELECT concat('/home/vmail/', maildir) as home, concat('maildir:/home/vmail/', maildir) as mail, 1001 AS uid, 12 AS gid, CONCAT('dict:storage=',floor(quota/1000),' proxy::quota') AS quota FROM mailbox WHERE username = '%u' AND active = '1'
seems like this line doing some nice customization showing quota in kilobytes and not in bytes. or if someone could explain what does this string means. also what does this line means ?: concat('maildir:/home/vmail/', maildir) as mail string about home i understood dovecot reads users home dir from this line. And i dont understand if why should i indicate in 10-mail.conf next string: mail_location = maildir:/home/vmail/%d/%u If it is overided by user_query from mysql?
Also what is meaning of quota(2) table. does dovecot reading configuration from there or just stores usage information ? Also what does this string mean?: pattern = priv/quota/messages what privileges those who reads the, or where are they indicated ?
Thanks in advance. Denis.
Maybe stupid, but are these plugin examples really from your dovecot.conf file ? If so remove the # before the quota lines!
this is my part from dovecot.conf (only relavant quota parts.)
quotadict = mysql:/usr/local/etc/dovecot/dovecot-dict-quota.conf
plugin { # Quota config quota = dict:User quota::noenforcing:proxy::quotadict quota_rule = *:storage=1G quota_rule2 = Trash:storage=+100M quota_warning = storage=95%% quota-warning 95 %u quota_warning2 = storage=90%% quota-warning 90 %u quota_warning3 = storage=80%% quota-warning 80 %u #OTHER Plugins .... .... }
service quota-warning { executable = script /usr/local/bin/quota-warning.sh user = vmail unix_listener quota-warning { user = vmail } }
protocol imap { imap_client_workarounds = delay-newmail tb-extra-mailbox-sep imap_idle_notify_interval = 120 s imap_logout_format = bytes=%i/%o imap_max_line_length = 65536 mail_plugins = quota imap_quota autocreate acl imap_acl mail_log notify fts fts_squat }
protocol lmtp { auth_socket_path = /var/run/dovecot/auth-master mail_plugins = sieve quota acl mail_log notify postmaster_address = postmaster@yourdomain.com sendmail_path = /usr/local/sbin/sendmail }
Above protocol lmtp could be protocol lda in your case
This is my dovecot-dict-quota.conf file
# Dovecot 2.0.x connect = host=192.xxx.xxx.xxx dbname=postfix user=postfix password=mypostfixpasswd map { pattern = priv/quota/storage table = quota2 username_field = username value_field = bytes } map { pattern = priv/quota/messages table = quota2 username_field = username value_field = messages }
This is my /usr/local/bin/quota-warning.sh file
#!/usr/local/bin/bash PERCENT=$1 USER=$2 cat<< EOF | /usr/local/libexec/dovecot/deliver -d $USER -o "plugin/quota=maildir:User quota:noenforcing" From: support@yourdomain.com Subject: quota warning
Uw mailbox is momenteel voor $PERCENT% gevult. Verwijder oude mail, of vraag een verruiming van uw quota aan.
Your mailbox is now $PERCENT% full. Please remove some old mail, or ask for a larger quota.
Skrzynka pocztowa jest w tym momencie w $PERCENT% zapelniona. Usun stare wiadomosci,albo przenies w inny folder.
EOF
Hope this helps.
Regards, Johan Hendriks Double L Automatisering Here it is.
# Database driver: mysql, pgsql driver = mysql
# Currently supported schemes include PLAIN, PLAIN-MD5, DIGEST-MD5, and CRYPT. default_pass_scheme = CRYPT
# Database options connect = host=192.xxx.xxx.xxx dbname=postfix user=postfix password=mypostfixpassword
password_query = select password
from mailbox where username = '%u'
and active = '1'
user_query = select maildir,
concat('*:messages=50000:bytes=', quota) as quota_rule
from mailbox where username = '%u' and active = '1'
Gr Johan
Hm, it looks very straighforward and not so flexible. i want get this string get working. some missconfiguration of arguments and syntax. i dont wanna mannually insert amount of message or bytes, if it's possible i would like everything to be read from database quota.conf Hope developers would see this thread and help also i understood aalmost all strings in query concat('/home/vmail/', maildir) as home - virtual users home directory concat('maildir:/home/vmail/', maildir) as mail - virtualusers maildirectory floor(quota/1000) - seems to be minimal quota for user. users quota devided by 1000
so for now i've tried to do next query string changed quota to quota_rule user_query = SELECT concat('/home/vmail/', maildir) as home, concat('maildir:/home/vmail/', maildir) as mail, 1001 AS uid, 12 AS gid, concat('dict:storage=',floor(quota/1000),' proxy::quotadict') AS quota_rule FROM mailbox WHERE username = '%u' AND active = '1'
plugin { quota = dict:User quota::proxy::quotadict quota_rule = *:storage=1G quota_rule2 = Trash:storage=+100M }
dict { quotadict = mysql:/etc/dovecot/conf.d/sql/dovecot-dict-sql.conf # expire = sqlite:/etc/dovecot/dovecot-dict-sql.conf }
and now error
Jun 24 13:19:59 imap: Debug: Added userdb setting: mail=maildir:/home/vmail/office.dev/test/ Jun 24 13:19:59 imap: Debug: Added userdb setting: plugin/quota_rule=dict:storage=10240 proxy::quotadict Jun 24 13:19:59 imap(test@office.dev): Debug: Effective uid=1001, gid=12, home=/home/vmail/office.dev/test/ Jun 24 13:19:59 imap(test@office.dev): Debug: Quota root: name=User quota backend=dict args=:proxy::quotadict Jun 24 13:19:59 imap(test@office.dev): Warning: quota root User quota rule dict:storage=10240 proxy::quotadict: obsolete configuration for rule 'storage=10240 proxy' should be changed to 'storage=+10240 proxy' Jun 24 13:19:59 imap(test@office.dev): Debug: Quota rule: root=User quota mailbox=dict bytes=+10240 messages=0 Jun 24 13:19:59 imap(test@office.dev): Error: user test@office.dev: Initialization failed: Failed to initialize quota: Invalid quota root quota: Invalid rule dict:storage=10240 proxy::quotadict: Invalid rule limit value: storage=10240 proxy Jun 24 13:19:59 imap(test@office.dev): Error: Invalid user settings. Refer to server log for more information. Jun 24 13:19:59 imap-login: Info: Login: user=test@office.dev, method=PLAIN, rip=192.168.0.11, lip=192.168.0.31, mpid=5742, TLS Jun 24 13:19:59 imap-login: Warning: SSL alert: where=0x4008, ret=256: warning close notify [192.168.0.11]
Here it is.
# Database driver: mysql, pgsql driver = mysql
# Currently supported schemes include PLAIN, PLAIN-MD5, DIGEST-MD5, and CRYPT. default_pass_scheme = CRYPT
# Database options connect = host=192.xxx.xxx.xxx dbname=postfix user=postfix password=mypostfixpassword
password_query = select password
from mailbox where username = '%u'
and active = '1'user_query = select maildir,
concat('*:messages=50000:bytes=', quota) as quota_rule
from mailbox where username = '%u' and active = '1'Gr Johan
Finally i've figured out this thing. Thanks for your assistance. Suddenly i've found your old post regarding same problem: http://www.mail-archive.com/dovecot@dovecot.org/msg16388.html +searching user_query in dovecot wiki found same description there http://wiki2.dovecot.org/Quota/Configuration?highlight=%28user_query%29 i dont know why i have seen this before.
i can say one more thing. in quota.conf next string has no sense coz it's overided by sql query and quota is set by postfix admin. i had other headache for an hour while figured this out. no sense quota_rule = *:storage=1G:messages=10000 (maybe for system users and/or users which are not binded to sql) what ever other quota_rule numbers for global settings but not quota_rule.
so thanks again moving to next problems with other plugins like expire...there is no expire table in sql ))))
After doing some configrations i got errors with quota and my setup is brocken now: dict: dict { quotadict = mysql:/etc/dovecot/conf.d/sql/dovecot-dict-sql.conf # expire = sqlite:/etc/dovecot/dovecot-dict-sql.conf }
dovecot-dict-sql.conf: connect = host=localhost dbname=postfix user=postfix password=postfixadmin map { pattern = priv/quota/storage table = quota2 username_field = username value_field = bytes } map { pattern = priv/quota/messages table = quota2 username_field = username value_field = messages }
quota plugin config: plugin { quota = dict:User quota::proxy::quotadict quota_rule = *:storage=1G quota_rule2 = Trash:storage=+100M }
user_query field: user_query = SELECT concat('/home/vmail/', maildir) as home, concat('maildir:/home/vmail/', maildir) as mail, 1001 AS uid, 12 AS gid, concat('dict:storage=',floor(quota/1000),' proxy::quotadict') AS quota FROM mailbox WHERE username = '%u' AND active = '1'
Errors log: dovecot.log: Jun 24 11:41:24 imap: Debug: Loading modules from directory: /usr/lib/dovecot Jun 24 11:41:24 imap: Debug: Module loaded: /usr/lib/dovecot/lib10_quota_plugin.so Jun 24 11:41:24 imap: Debug: Module loaded: /usr/lib/dovecot/lib11_imap_quota_plugin.so Jun 24 11:41:24 imap: Debug: Module loaded: /usr/lib/dovecot/lib20_autocreate_plugin.so Jun 24 11:41:24 imap: Debug: Added userdb setting: mail=maildir:/home/vmail/office.dev/test/ Jun 24 11:41:24 imap: Debug: Added userdb setting: plugin/quota=dict:storage=10240 proxy::quotadict Jun 24 11:41:24 imap(test@office.dev): Debug: Effective uid=1001, gid=12, home=/home/vmail/office.dev/test/ Jun 24 11:41:24 imap(test@office.dev): Debug: Quota root: name=storage=10240 proxy backend=dict args=:quotadict Jun 24 11:41:24 imap(test@office.dev): Debug: Quota rule: root=storage=10240 proxy mailbox=* bytes=1073741824 messages=0 Jun 24 11:41:24 imap(test@office.dev): Debug: Quota rule: root=storage=10240 proxy mailbox=Trash bytes=+104857600 messages=0 Jun 24 11:41:24 imap(test@office.dev): Debug: dict quota: user=test@office.dev, uri=quotadict, noenforcing=0 Jun 24 11:41:24 imap(test@office.dev): Error: Dictionary URI is missing ':': quotadict Jun 24 11:41:24 imap(test@office.dev): Error: user test@office.dev: Initialization failed: Failed to initialize quota: Quota root storage=10240 proxy: init() failed Jun 24 11:41:24 imap(test@office.dev): Error: Invalid user settings. Refer to server log for more information. Jun 24 11:41:24 imap-login: Info: Login: user=test@office.dev, method=PLAIN, rip=192.168.0.11, lip=192.168.0.31, mpid=4611, TLS Jun 24 11:41:24 imap-login: Warning: SSL alert: where=0x4008, ret=256: warning close notify [192.168.0.11]
# doveadm quota recalc doveadm(root): Error: chdir(/root/) failed: Permission denied (euid=1001(vmail) egid=12(mail) missing +x perm: /root, euid is not dir owner) doveadm(root): Error: chdir(/root) failed: Permission denied doveadm(root): Error: net_connect_unix(/var/run/dovecot//dict) failed: Permission denied (euid=1001(vmail) egid=12(mail) missing +r perm: /var/run/dovecot//dict, euid is not dir owner)
why this command working in my home /root dir ? i have done next thing after: service dict { unix_listener dict { mode = 0660 user = vmail group = mail } } now i'm getting only next: ~]# doveadm quota recalc doveadm(root): Error: chdir(/root/) failed: Permission denied (euid=1001(vmail) egid=12(mail) missing +x perm: /root, euid is not dir owner) doveadm(root): Error: chdir(/root) failed: Permission denied
Whats wrong. Please help.
participants (2)
-
Denis Iskandarov
-
Johan Hendriks