Browse Source

selecting a driver by default in auth dabatases when not set

Xabier de Zuazo 11 years ago
parent
commit
ed0ea86ffd

+ 3 - 5
attributes/auth.rb

@@ -4,7 +4,7 @@ default['dovecot']['auth']['system'] = {}
 default['dovecot']['auth']['sql']['drivers'] = []
 
 default['dovecot']['auth']['checkpassword'] = nil
-# default['dovecot']['auth']['checkpassword'] = {
+# default['dovecot']['auth']['checkpassword'] = { # hash
 #   'passdb' => {
 #     'driver' => 'checkpassword',
 #     'args' => '/usr/bin/checkpassword',
@@ -15,10 +15,9 @@ default['dovecot']['auth']['checkpassword'] = nil
 # }
 
 default['dovecot']['auth']['system'] = {}
-# default['dovecot']['auth']['system'] = {
-#   'passdb' => [
+# default['dovecot']['auth']['system']['passdb'] = [ # array
 #   {
-#     'driver' => 'pam',
+#     # without driver
 #     'args' => 'dovecot',
 #   },
 #   {
@@ -34,5 +33,4 @@ default['dovecot']['auth']['system'] = {}
 #     'args' => '',
 #   },
 # ]
-# }
 

+ 5 - 1
libraries/conf.rb

@@ -31,12 +31,15 @@ module Dovecot
       Dovecot::Protocols.list(conf).join(' ')
     end
 
-    def self.authdb(type, conf)
+    def self.authdb(driver, type, conf)
 
       template =
 '<% confs = [ @conf ].flatten
     confs.each do |conf| -%>
 <%=   @type %> {
+  <%  unless conf.has_key?("driver") -%>
+  driver = <%=   @driver %>
+  <%  end -%>
   <%  conf.each do |key, value|
         unless value.nil?
   -%>
@@ -48,6 +51,7 @@ module Dovecot
 
       eruby = Erubis::Eruby.new(template)
       eruby.evaluate(
+        :driver => driver,
         :type => type,
         :conf => conf,
         :Dovecot_Conf => Dovecot::Conf

+ 2 - 2
templates/default/conf.d/auth-checkpassword.conf.ext.erb

@@ -3,7 +3,7 @@
 # <doc/wiki/AuthDatabase.CheckPassword.txt>
 
 <% if Dovecot::Auth.has_passdb?(@auth['checkpassword']) -%>
-<%=  Dovecot::Conf.authdb('passdb', @auth['checkpassword']['passdb']) %>
+<%=  Dovecot::Conf.authdb('checkpassword', 'passdb', @auth['checkpassword']['passdb']) %>
 <% else -%>
 passdb {
   driver = checkpassword
@@ -12,7 +12,7 @@ passdb {
 <% end -%>
 
 <% if Dovecot::Auth.has_userdb?(@auth['checkpassword']) -%>
-<%=  Dovecot::Conf.authdb('userdb', @auth['checkpassword']['userdb']) %>
+<%=  Dovecot::Conf.authdb('checkpassword', 'userdb', @auth['checkpassword']['userdb']) %>
 <% else -%>
 # passdb lookup should return also userdb info
 userdb {

+ 1 - 1
templates/default/conf.d/auth-deny.conf.ext.erb

@@ -6,7 +6,7 @@
 # checked first.
 
 <% if Dovecot::Auth.has_passdb?(@auth['deny']) -%>
-<%=  Dovecot::Conf.authdb('passdb', @auth['deny']['passdb']) %>
+<%=  Dovecot::Conf.authdb('passwd-file', 'passdb', @auth['deny']['passdb']) %>
 <% else -%>
 # Example deny passdb using passwd-file. You can use any passdb though.
 passdb {

+ 2 - 2
templates/default/conf.d/auth-ldap.conf.ext.erb

@@ -3,7 +3,7 @@
 # <doc/wiki/AuthDatabase.LDAP.txt>
 
 <% if Dovecot::Auth.has_passdb?(@auth['ldap']) -%>
-<%=  Dovecot::Conf.authdb('passdb', @auth['ldap']['passdb']) %>
+<%=  Dovecot::Conf.authdb('ldap', 'passdb', @auth['ldap']['passdb']) %>
 <% else -%>
 passdb {
   driver = ldap
@@ -14,7 +14,7 @@ passdb {
 <% end -%>
 
 <% if Dovecot::Auth.has_userdb?(@auth['ldap']) -%>
-<%=  Dovecot::Conf.authdb('userdb', @auth['ldap']['userdb']) %>
+<%=  Dovecot::Conf.authdb('ldap', 'userdb', @auth['ldap']['userdb']) %>
 <% else -%>
 # "prefetch" user database means that the passdb already provided the
 # needed information and there's no need to do a separate userdb lookup.

+ 1 - 1
templates/default/conf.d/auth-master.conf.ext.erb

@@ -5,7 +5,7 @@
 # <doc/wiki/Authentication.MasterUsers.txt>
 
 <% if Dovecot::Auth.has_passdb?(@auth['master']) -%>
-<%=  Dovecot::Conf.authdb('passdb', @auth['master']['passdb']) %>
+<%=  Dovecot::Conf.authdb('passwd-file', 'passdb', @auth['master']['passdb']) %>
 <% else -%>
 # Example master user passdb using passwd-file. You can use any passdb though.
 passdb {

+ 2 - 2
templates/default/conf.d/auth-passwdfile.conf.ext.erb

@@ -4,7 +4,7 @@
 # <doc/wiki/AuthDatabase.PasswdFile.txt>
 
 <% if Dovecot::Auth.has_passdb?(@auth['passwdfile']) -%>
-<%=  Dovecot::Conf.authdb('passdb', @auth['passwdfile']['passdb']) %>
+<%=  Dovecot::Conf.authdb('passwd-file', 'passdb', @auth['passwdfile']['passdb']) %>
 <% else -%>
 passdb {
   driver = passwd-file
@@ -13,7 +13,7 @@ passdb {
 <% end -%>
 
 <% if Dovecot::Auth.has_userdb?(@auth['userwdfile']) -%>
-<%=  Dovecot::Conf.authdb('userdb', @auth['passwdfile']['userdb']) %>
+<%=  Dovecot::Conf.authdb('passwd-file', 'userdb', @auth['passwdfile']['userdb']) %>
 <% else -%>
 userdb {
   driver = passwd-file

+ 2 - 2
templates/default/conf.d/auth-sql.conf.ext.erb

@@ -3,7 +3,7 @@
 # <doc/wiki/AuthDatabase.SQL.txt>
 
 <% if Dovecot::Auth.has_passdb?(@auth['sql']) -%>
-<%=  Dovecot::Conf.authdb('passdb', @auth['sql']['passdb']) %>
+<%=  Dovecot::Conf.authdb('sql', 'passdb', @auth['sql']['passdb']) %>
 <% else -%>
 passdb {
   driver = sql
@@ -14,7 +14,7 @@ passdb {
 <% end -%>
 
 <% if Dovecot::Auth.has_userdb?(@auth['sql']) -%>
-<%=  Dovecot::Conf.authdb('userdb', @auth['sql']['userdb']) %>
+<%=  Dovecot::Conf.authdb('sql', 'userdb', @auth['sql']['userdb']) %>
 <% else -%>
 # "prefetch" user database means that the passdb already provided the
 # needed information and there's no need to do a separate userdb lookup.

+ 2 - 2
templates/default/conf.d/auth-static.conf.ext.erb

@@ -9,7 +9,7 @@
 #  - simple testing
 
 <% if Dovecot::Auth.has_passdb?(@auth['static']) -%>
-<%=  Dovecot::Conf.authdb('passdb', @auth['static']['passdb']) %>
+<%=  Dovecot::Conf.authdb('static', 'passdb', @auth['static']['passdb']) %>
 <% else -%>
 #passdb {
 #  driver = static
@@ -23,7 +23,7 @@
 <% end -%>
 
 <% if Dovecot::Auth.has_userdb?(@auth['static']) -%>
-<%=  Dovecot::Conf.authdb('userdb', @auth['static']['userdb']) %>
+<%=  Dovecot::Conf.authdb('static', 'userdb', @auth['static']['userdb']) %>
 <% else -%>
 #userdb {
 #  driver = static

+ 2 - 2
templates/default/conf.d/auth-system.conf.ext.erb

@@ -8,7 +8,7 @@
 # REMEMBER: You'll need /etc/pam.d/dovecot file created for PAM
 # authentication to actually work. <doc/wiki/PasswordDatabase.PAM.txt>
 <% if Dovecot::Auth.has_passdb?(@auth['system']) -%>
-<%=  Dovecot::Conf.authdb('passdb', @auth['system']['passdb']) %>
+<%=  Dovecot::Conf.authdb('pam', 'passdb', @auth['system']['passdb']) %>
 <% else -%>
 passdb {
   driver = pam
@@ -51,7 +51,7 @@ passdb {
 # System users (NSS, /etc/passwd, or similiar). In many systems nowadays this
 # uses Name Service Switch, which is configured in /etc/nsswitch.conf.
 <% if Dovecot::Auth.has_userdb?(@auth['system']) -%>
-<%=  Dovecot::Conf.authdb('userdb', @auth['system']['userdb']) %>
+<%=  Dovecot::Conf.authdb('passwd', 'userdb', @auth['system']['userdb']) %>
 <% else -%>
 userdb {
   # <doc/wiki/AuthDatabase.Passwd.txt>

+ 2 - 2
templates/default/conf.d/auth-vpopmail.conf.ext.erb

@@ -3,7 +3,7 @@
 # <doc/wiki/AuthDatabase.VPopMail.txt>
 
 <% if Dovecot::Auth.has_passdb?(@auth['vpopmail']) -%>
-<%=  Dovecot::Conf.authdb('passdb', @auth['vpopmail']['passdb']) %>
+<%=  Dovecot::Conf.authdb('vpopmail', 'passdb', @auth['vpopmail']['passdb']) %>
 <% else -%>
 passdb {
   driver = vpopmail
@@ -14,7 +14,7 @@ passdb {
 <% end -%>
 
 <% if Dovecot::Auth.has_userdb?(@auth['vpopmail']) -%>
-<%=  Dovecot::Conf.authdb('userdb', @auth['vpopmail']['userdb']) %>
+<%=  Dovecot::Conf.authdb('vpopmail', 'userdb', @auth['vpopmail']['userdb']) %>
 <% else -%>
 userdb {
   driver = vpopmail