Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions manifests/mysql.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 10-auth.conf
# dovecot-sql.conf.ext
class dovecot::mysql (
$dbname = 'mails',
$dbpassword = 'admin',
$dbusername = 'pass',
$dbhost = 'localhost',
$dbport = 5432,
$dbdriver = 'mysql',
$pass_scheme = 'MD5-CRYPT',
$sqlconftemplate = 'dovecot/dovecot-sql.conf.ext',
$user_query = "SELECT maildir, 5000 AS uid, 5000 AS gid FROM mailbox WHERE username = '%u'",
$pass_query = "SELECT password FROM mailbox WHERE username = '%u'"
) {
file { "/etc/dovecot/dovecot-sql.conf.ext":
ensure => present,
content => template($sqlconftemplate),
mode => '0600',
owner => root,
group => dovecot,
require => Package['dovecot-mysql'],
before => Exec['dovecot'],
notify => Service['dovecot'],
}

package {'dovecot-mysql':
ensure => installed,
before => Exec['dovecot'],
notify => Service['dovecot']
}

dovecot::config::dovecotcfmulti { 'sqlauth':
config_file => 'conf.d/10-auth.conf',
changes => [
"set include 'auth-sql.conf.ext'",
"rm include[ . = 'auth-system.conf.ext']",
],
require => File["/etc/dovecot/dovecot-sql.conf.ext"]
}
}
4 changes: 4 additions & 0 deletions manifests/postgres.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
$dbusername = 'pass',
$dbhost = 'localhost',
$dbport = 5432,
$dbdriver = 'pgsql',
$mailstorepath = '/srv/vmail/',
$pass_scheme = 'CRYPT',
$sqlconftemplate = 'dovecot/dovecot-sql.conf.ext',
$user_query = "SELECT '<%= @mailstorepath %>'||SUBSTRING(email from (position('@' in email)+1) for (char_length(email)-position('@' in email)+1)) || '/' || SUBSTRING(email from 0 for position('@' in email)) AS home, '*:bytes='||quota AS quota_rule FROM users WHERE email = '%u'",
$pass_query = "SELECT '<%= @mailstorepath %>'||SUBSTRING(email from (position('@' in email)+1) for (char_length(email)-position('@' in email)+1)) || '/' || SUBSTRING(email from 0 for position('@' in email)) AS userdb_home, email AS user, password, '*:bytes='||quota AS userdb_quota_rule FROM users WHERE email = '%u'"
) {
file { "/etc/dovecot/dovecot-sql.conf.ext":
ensure => present,
Expand Down
13 changes: 4 additions & 9 deletions templates/dovecot-sql.conf.ext
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
driver = pgsql
driver = <%= @dbdriver %>
connect = host=<%= @dbhost %> port=<%= @dbport %> dbname=<%= @dbname %> user=<%= @dbusername %> password=<%= @dbpassword %>
default_pass_scheme = CRYPT
user_query = \
SELECT '<%= @mailstorepath %>'||SUBSTRING(email from (position('@' in email)+1) for (char_length(email)-position('@' in email)+1)) || '/' || SUBSTRING(email from 0 for position('@' in email)) AS home, '*:bytes='||quota AS quota_rule \
FROM users WHERE email = '%u'
password_query = \
SELECT '<%= @mailstorepath %>'||SUBSTRING(email from (position('@' in email)+1) for (char_length(email)-position('@' in email)+1)) || '/' || SUBSTRING(email from 0 for position('@' in email)) AS userdb_home, \
email AS user, password, '*:bytes='||quota AS userdb_quota_rule \
FROM users WHERE email = '%u'
default_pass_scheme = <%= @pass_scheme %>
user_query = <%= @user_query %>
password_query = <%= @pass_query %>