From cbe145f164fd39876c051772aefa7366d596dead Mon Sep 17 00:00:00 2001 From: Ben Speakman Date: Mon, 22 Feb 2016 11:48:58 +0000 Subject: [PATCH] Add mysql config --- manifests/mysql.pp | 40 ++++++++++++++++++++++++++++++++++ manifests/postgres.pp | 4 ++++ templates/dovecot-sql.conf.ext | 13 ++++------- 3 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 manifests/mysql.pp diff --git a/manifests/mysql.pp b/manifests/mysql.pp new file mode 100644 index 0000000..a8e6c99 --- /dev/null +++ b/manifests/mysql.pp @@ -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"] + } +} diff --git a/manifests/postgres.pp b/manifests/postgres.pp index dcb35dd..1567b44 100644 --- a/manifests/postgres.pp +++ b/manifests/postgres.pp @@ -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, diff --git a/templates/dovecot-sql.conf.ext b/templates/dovecot-sql.conf.ext index 8b38d1e..120a68e 100644 --- a/templates/dovecot-sql.conf.ext +++ b/templates/dovecot-sql.conf.ext @@ -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 %>