Browse Source

auth-checkpassword.conf.ext.erb template using variables

Xabier de Zuazo 11 years ago
parent
commit
59dc9d3c80
3 changed files with 42 additions and 1 deletions
  1. 11 0
      attributes/auth.rb
  2. 21 1
      libraries/conf.rb
  3. 10 0
      templates/default/conf.d/auth-checkpassword.conf.ext.erb

+ 11 - 0
attributes/auth.rb

@@ -3,3 +3,14 @@ default['dovecot']['auth'] = {}
 default['dovecot']['auth']['system'] = {}
 default['dovecot']['auth']['sql']['drivers'] = []
 
+default['dovecot']['auth']['checkpassword'] = nil
+# default['dovecot']['auth']['checkpassword'] = {
+#   'passdb' => {
+#     'driver' => 'checkpassword',
+#     'args' => '/usr/bin/checkpassword',
+#   },
+#   'userdb' => {
+#     'driver' => 'prefetch',
+#   },
+# }
+

+ 21 - 1
libraries/conf.rb

@@ -31,6 +31,26 @@ module Dovecot
       Dovecot::Protocols.list(conf).join(' ')
     end
 
+    def self.authdb(type, conf)
+
+      template =
+'<%= @type %> {
+  <% @conf.each do |key, value|
+       unless value.nil?
+  -%>
+  <%=    key %> = <%= @Dovecot_Conf.value(value) %>
+  <%   end
+     end -%>
+}'
+
+      eruby = Erubis::Eruby.new(template)
+      eruby.evaluate(
+        :type => type,
+        :conf => conf,
+        :Dovecot_Conf => Dovecot::Conf
+      )
+    end
+
     def self.plugin(name, conf)
 
       template =
@@ -38,7 +58,7 @@ module Dovecot
   <% @conf.each do |key, value|
        unless value.nil?
   -%>
-  <%= key %> = <%= @Dovecot_Conf.value(value) %>
+  <%=    key %> = <%= @Dovecot_Conf.value(value) %>
   <%   end
      end -%>
 }'

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

@@ -2,15 +2,25 @@
 #
 # <doc/wiki/AuthDatabase.CheckPassword.txt>
 
+<% if @auth['checkpassword'].kind_of?(Hash) and @auth['checkpassword'].length > 0 and
+      @auth['checkpassword']['passdb'].kind_of?(Hash) -%>
+<%=  Dovecot::Conf.authdb('passdb', @auth['checkpassword']['passdb']) %>
+<% else -%>
 passdb {
   driver = checkpassword
   args = /usr/bin/checkpassword
 }
+<% end -%>
 
+<% if @auth['checkpassword'].kind_of?(Hash) and @auth['checkpassword'].length > 0 and
+      @auth['checkpassword']['userdb'].kind_of?(Hash) -%>
+<%=  Dovecot::Conf.authdb('userdb', @auth['checkpassword']['userdb']) %>
+<% else -%>
 # passdb lookup should return also userdb info
 userdb {
   driver = prefetch
 }
+<% end -%>
 
 # Standard checkpassword doesn't support direct userdb lookups.
 # If you need checkpassword userdb, the checkpassword must support