Browse Source

added support for both arrays and hashes in auth userdb/passdb values

Xabier de Zuazo 11 years ago
parent
commit
b09e3284d0

+ 22 - 0
attributes/auth.rb

@@ -14,3 +14,25 @@ default['dovecot']['auth']['checkpassword'] = nil
 #   },
 # }
 
+default['dovecot']['auth']['system'] = {}
+default['dovecot']['auth']['system'] = {
+  'passdb' => [
+  {
+    'driver' => 'pam',
+    'args' => 'dovecot',
+  },
+  {
+    'driver' => 'passwd',
+    'args' => '',
+  },
+  {
+    'driver' => 'shadow',
+    'args' => '',
+  },
+  {
+    'driver' => 'bsdauth',
+    'args' => '',
+  },
+]
+}
+

+ 17 - 0
libraries/auth.rb

@@ -0,0 +1,17 @@
+
+module Dovecot
+  module Auth
+
+    def self.has_passdb?(auth)
+      auth.kind_of?(Hash) and auth.length > 0 and
+       ( auth['passdb'].kind_of?(Hash) or auth['passdb'].kind_of?(Array) )
+    end
+
+    def self.has_userdb?(auth)
+      auth.kind_of?(Hash) and auth.length > 0 and
+       ( auth['userdb'].kind_of?(Hash) or auth['userdb'].kind_of?(Array) )
+    end
+
+  end
+end
+

+ 9 - 6
libraries/conf.rb

@@ -34,13 +34,16 @@ module Dovecot
     def self.authdb(type, conf)
 
       template =
-'<%= @type %> {
-  <% @conf.each do |key, value|
-       unless value.nil?
+'<% confs = [ @conf ].flatten
+    confs.each do |conf| -%>
+<%=   @type %> {
+  <%  conf.each do |key, value|
+        unless value.nil?
   -%>
-  <%=    key %> = <%= @Dovecot_Conf.value(value) %>
-  <%   end
-     end -%>
+  <%=     key %> = <%= @Dovecot_Conf.value(value) %>
+  <%    end
+      end
+    end -%>
 }'
 
       eruby = Erubis::Eruby.new(template)

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

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