Browse Source

templates updated to use Dovecot::Conf#attribute function

Xabier de Zuazo 11 years ago
parent
commit
817da39d24

+ 20 - 96
templates/default/conf.d/10-auth.conf.erb

@@ -6,173 +6,97 @@
 # SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
 # matches the local IP (ie. you're connecting from the same computer), the
 # connection is considered secure and plaintext authentication is allowed.
-<% unless @conf['disable_plaintext_auth'].nil? -%>
-disable_plaintext_auth = <%= Dovecot::Conf.value(@conf['disable_plaintext_auth']) %>
-<% else -%>
-#disable_plaintext_auth = yes
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'disable_plaintext_auth', true) %>
 
 # Authentication cache size (e.g. 10M). 0 means it's disabled. Note that
 # bsdauth, PAM and vpopmail require cache_key to be set for caching to be used.
-<% unless @conf['auth_cache_size'].nil? -%>
-auth_cache_size = <%= Dovecot::Conf.value(@conf['auth_cache_size']) %>
-<% else -%>
-#auth_cache_size = 0
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_cache_size', 0) %>
 # Time to live for cached data. After TTL expires the cached record is no
 # longer used, *except* if the main database lookup returns internal failure.
 # We also try to handle password changes automatically: If user's previous
 # authentication was successful, but this one wasn't, the cache isn't used.
 # For now this works only with plaintext authentication.
-<% unless @conf['auth_cache_ttl'].nil? -%>
-auth_cache_ttl = <%= Dovecot::Conf.value(@conf['auth_cache_ttl']) %>
-<% else -%>
-#auth_cache_ttl = 1 hour
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_cache_ttl', '1 hour') %>
 # TTL for negative hits (user not found, password mismatch).
 # 0 disables caching them completely.
-<% unless @conf['auth_cache_negative_ttl'].nil? -%>
-auth_cache_negative_ttl = <%= Dovecot::Conf.value(@conf['auth_cache_negative_ttl']) %>
-<% else -%>
-#auth_cache_negative_ttl = 1 hour
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_cache_negative_ttl', '1 hour') %>
 
 # Space separated list of realms for SASL authentication mechanisms that need
 # them. You can leave it empty if you don't want to support multiple realms.
 # Many clients simply use the first one listed here, so keep the default realm
 # first.
-<% unless @conf['auth_realms'].nil? -%>
-auth_realms = <%= Dovecot::Conf.value(@conf['auth_realms']) %>
-<% else -%>
-#auth_realms =
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_realms') %>
 
 # Default realm/domain to use if none was specified. This is used for both
 # SASL realms and appending @domain to username in plaintext logins.
-<% unless @conf['auth_default_realm'].nil? -%>
-auth_default_realm = <%= Dovecot::Conf.value(@conf['auth_default_realm']) %>
-<% else -%>
-#auth_default_realm = 
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_default_realm') %>
 
 # List of allowed characters in username. If the user-given username contains
 # a character not listed in here, the login automatically fails. This is just
 # an extra check to make sure user can't exploit any potential quote escaping
 # vulnerabilities with SQL/LDAP databases. If you want to allow all characters,
 # set this value to empty.
-<% unless @conf['auth_username_chars'].nil? -%>
-auth_username_chars = <%= Dovecot::Conf.value(@conf['auth_username_chars']) %>
-<% else -%>
-#auth_username_chars = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_username_chars', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@') %>
 
 # Username character translations before it's looked up from databases. The
 # value contains series of from -> to characters. For example "#@/@" means
 # that '#' and '/' characters are translated to '@'.
-<% unless @conf['auth_username_translation'].nil? -%>
-auth_username_translation = <%= Dovecot::Conf.value(@conf['auth_username_translation']) %>
-<% else -%>
-#auth_username_translation =
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_username_translation') %>
 
 # Username formatting before it's looked up from databases. You can use
 # the standard variables here, eg. %Lu would lowercase the username, %n would
 # drop away the domain if it was given, or "%n-AT-%d" would change the '@' into
 # "-AT-". This translation is done after auth_username_translation changes.
-<% unless @conf['auth_username_format'].nil? -%>
-auth_username_format = <%= Dovecot::Conf.value(@conf['auth_username_format']) %>
-<% else -%>
-#auth_username_format =
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_username_format') %>
 
 # If you want to allow master users to log in by specifying the master
 # username within the normal username string (ie. not using SASL mechanism's
 # support for it), you can specify the separator character here. The format
 # is then <username><separator><master username>. UW-IMAP uses "*" as the
 # separator, so that could be a good choice.
-<% unless @conf['auth_master_user_separator'].nil? -%>
-auth_master_user_separator = <%= Dovecot::Conf.value(@conf['auth_master_user_separator']) %>
-<% else -%>
-#auth_master_user_separator =
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_master_user_separator') %>
 
 # Username to use for users logging in with ANONYMOUS SASL mechanism
-<% unless @conf['auth_anonymous_username'].nil? -%>
-auth_anonymous_username = <%= Dovecot::Conf.value(@conf['auth_anonymous_username']) %>
-<% else -%>
-#auth_anonymous_username = anonymous
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_anonymous_username', 'anonymous') %>
 
 # Maximum number of dovecot-auth worker processes. They're used to execute
 # blocking passdb and userdb queries (eg. MySQL and PAM). They're
 # automatically created and destroyed as needed.
-<% unless @conf['auth_worker_max_count'].nil? -%>
-auth_worker_max_count = <%= Dovecot::Conf.value(@conf['auth_worker_max_count']) %>
-<% else -%>
-#auth_worker_max_count = 30
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_worker_max_count', 30) %>
 
 # Host name to use in GSSAPI principal names. The default is to use the
 # name returned by gethostname(). Use "$ALL" (with quotes) to allow all keytab
 # entries.
-<% unless @conf['auth_gssapi_hostname'].nil? -%>
-auth_gssapi_hostname = <%= Dovecot::Conf.value(@conf['auth_gssapi_hostname']) %>
-<% else -%>
-#auth_gssapi_hostname =
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_gssapi_hostname') %>
 
 # Kerberos keytab to use for the GSSAPI mechanism. Will use the system
 # default (usually /etc/krb5.keytab) if not specified. You may need to change
 # the auth service to run as root to be able to read this file.
-<% unless @conf['auth_krb5_keytab'].nil? -%>
-auth_krb5_keytab = <%= Dovecot::Conf.value(@conf['auth_krb5_keytab']) %>
-<% else -%>
-#auth_krb5_keytab = 
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_krb5_keytab') %>
 
 # Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon and
 # ntlm_auth helper. <doc/wiki/Authentication/Mechanisms/Winbind.txt>
-<% unless @conf['auth_use_winbind'].nil? -%>
-auth_use_winbind = <%= Dovecot::Conf.value(@conf['auth_use_winbind']) %>
-<% else -%>
-#auth_use_winbind = no
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_use_winbind', false) %>
 
 # Path for Samba's ntlm_auth helper binary.
-<% unless @conf['auth_winbind_helper_path'].nil? -%>
-auth_winbind_helper_path = <%= Dovecot::Conf.value(@conf['auth_winbind_helper_path']) %>
-<% else -%>
-#auth_winbind_helper_path = /usr/bin/ntlm_auth
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_winbind_helper_path', '/usr/bin/ntlm_auth') %>
 
 # Time to delay before replying to failed authentications.
-<% unless @conf['auth_failure_delay'].nil? -%>
-auth_failure_delay = <%= Dovecot::Conf.value(@conf['auth_failure_delay']) %>
-<% else -%>
-#auth_failure_delay = 2 secs
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_failure_delay', '2 secs') %>
 
 # Require a valid SSL client certificate or the authentication fails.
-<% unless @conf['auth_ssl_require_client_cert'].nil? -%>
-auth_ssl_require_client_cert = <%= Dovecot::Conf.value(@conf['auth_ssl_require_client_cert']) %>
-<% else -%>
-#auth_ssl_require_client_cert = no
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_ssl_require_client_cert', false) %>
 
 # Take the username from client's SSL certificate, using 
 # X509_NAME_get_text_by_NID() which returns the subject's DN's
 # CommonName. 
-#auth_ssl_username_from_cert = no
+<%= Dovecot::Conf.attribute(@conf, 'auth_ssl_username_from_cert', false) %>
 
 # Space separated list of wanted authentication mechanisms:
 #   plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey
 #   gss-spnego
 # NOTE: See also disable_plaintext_auth setting.
-<% unless @conf['auth_mechanisms'].nil? -%>
-auth_mechanisms = <%= Dovecot::Conf.value(@conf['auth_mechanisms']) %>
-<% else -%>
-#auth_mechanisms = plain
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_mechanisms', 'plain') %>
 
 ##
 ## Password and user databases

+ 4 - 20
templates/default/conf.d/10-director.conf.erb

@@ -11,35 +11,19 @@
 # List of IPs or hostnames to all director servers, including ourself.
 # Ports can be specified as ip:port. The default port is the same as
 # what director service's inet_listener is using.
-<% unless @conf['director_servers'].nil? -%>
-director_servers = <%= Dovecot::Conf.value(@conf['director_servers']) %>
-<% else -%>
-#director_servers = 
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'director_servers') %>
 
 # List of IPs or hostnames to all backend mail servers. Ranges are allowed
 # too, like 10.0.0.10-10.0.0.30.
-<% unless @conf['director_mail_servers'].nil? -%>
-director_mail_servers = <%= Dovecot::Conf.value(@conf['director_mail_servers']) %>
-<% else -%>
-#director_mail_servers = 
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'director_mail_servers') %>
 
 # How long to redirect users to a specific server after it no longer has
 # any connections.
-<% unless @conf['director_user_expire'].nil? -%>
-director_user_expire = <%= Dovecot::Conf.value(@conf['director_user_expire']) %>
-<% else -%>
-#director_user_expire = 15 min
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'director_user_expire', '15 min') %>
 
 # TCP/IP port that accepts doveadm connections (instead of director connections)
 # If you enable this, you'll also need to add inet_listener for the port.
-<% unless @conf['director_doveadm_port'].nil? -%>
-director_doveadm_port = <%= Dovecot::Conf.value(@conf['director_doveadm_port']) %>
-<% else -%>
-#director_doveadm_port = 0
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'director_doveadm_port', 0) %>
 
 <% if @services['director'].kind_of?(Hash) and @services['director'].length > 0 -%>
 <%= Dovecot::Conf.service('director', @services['director']) %>

+ 15 - 75
templates/default/conf.d/10-logging.conf.erb

@@ -4,84 +4,44 @@
 
 # Log file to use for error messages. "syslog" logs to syslog,
 # /dev/stderr logs to stderr.
-<% unless @conf['log_path'].nil? -%>
-log_path = <%= Dovecot::Conf.value(@conf['log_path']) %>
-<% else -%>
-#log_path = syslog
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'log_path', 'syslog') %>
 
 # Log file to use for informational messages. Defaults to log_path.
-<% unless @conf['info_log_path'].nil? -%>
-info_log_path = <%= Dovecot::Conf.value(@conf['info_log_path']) %>
-<% else -%>
-#info_log_path = 
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'info_log_path') %>
 # Log file to use for debug messages. Defaults to info_log_path.
-<% unless @conf['debug_log_path'].nil? -%>
-debug_log_path = <%= Dovecot::Conf.value(@conf['debug_log_path']) %>
-<% else -%>
-#debug_log_path = 
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'debug_log_path') %>
 
 # Syslog facility to use if you're logging to syslog. Usually if you don't
 # want to use "mail", you'll use local0..local7. Also other standard
 # facilities are supported.
-<% unless @conf['syslog_facility'].nil? -%>
-syslog_facility = <%= Dovecot::Conf.value(@conf['syslog_facility']) %>
-<% else -%>
-#syslog_facility = mail
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'syslog_facility', 'mail') %>
 
 ##
 ## Logging verbosity and debugging.
 ##
 
 # Log unsuccessful authentication attempts and the reasons why they failed.
-<% unless @conf['auth_verbose'].nil? -%>
-auth_verbose = <%= Dovecot::Conf.value(@conf['auth_verbose']) %>
-<% else -%>
-#auth_verbose = no
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_verbose', false) %>
 
 # In case of password mismatches, log the attempted password. Valid values are
 # no, plain and sha1. sha1 can be useful for detecting brute force password
 # attempts vs. user simply trying the same password over and over again.
-<% unless @conf['auth_verbose_passwords'].nil? -%>
-auth_verbose_passwords = <%= Dovecot::Conf.value(@conf['auth_verbose_passwords']) %>
-<% else -%>
-#auth_verbose_passwords = no
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_verbose_passwords', false) %>
 
 # Even more verbose logging for debugging purposes. Shows for example SQL
 # queries.
-<% unless @conf['auth_debug'].nil? -%>
-auth_debug = <%= Dovecot::Conf.value(@conf['auth_debug']) %>
-<% else -%>
-#auth_debug = no
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_debug', false) %>
 
 # In case of password mismatches, log the passwords and used scheme so the
 # problem can be debugged. Enabling this also enables auth_debug.
-<% unless @conf['auth_debug_passwords'].nil? -%>
-auth_debug_passwords = <%= Dovecot::Conf.value(@conf['auth_debug_passwords']) %>
-<% else -%>
-#auth_debug_passwords = no
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'auth_debug_passwords', false) %>
 
 # Enable mail process debugging. This can help you figure out why Dovecot
 # isn't finding your mails.
-<% unless @conf['mail_debug'].nil? -%>
-mail_debug = <%= Dovecot::Conf.value(@conf['mail_debug']) %>
-<% else -%>
-#mail_debug = no
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'mail_debug', false) %>
 
 # Show protocol level SSL errors.
-<% unless @conf['verbose_ssl'].nil? -%>
-verbose_ssl = <%= Dovecot::Conf.value(@conf['verbose_ssl']) %>
-<% else -%>
-#verbose_ssl = no
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'verbose_ssl', false) %>
 
 <% if @plugins.has_key?('mail_log') and @plugins['mail_log'].kind_of?(Hash) -%>
 <%= Dovecot::Conf.plugin('mail_log', @plugins['mail_log']) %>
@@ -102,36 +62,20 @@ plugin {
 
 # Prefix for each line written to log file. % codes are in strftime(3)
 # format.
-<% unless @conf['log_timestamp'].nil? -%>
-log_timestamp = <%= Dovecot::Conf.value(@conf['log_timestamp']) %>
-<% else -%>
-#log_timestamp = "%b %d %H:%M:%S "
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'log_timestamp', '"%b %d %H:%M:%S "') %>
 
 # Space-separated list of elements we want to log. The elements which have
 # a non-empty variable value are joined together to form a comma-separated
 # string.
-<% unless @conf['login_log_format_elements'].nil? -%>
-login_log_format_elements = <%= Dovecot::Conf.value(@conf['login_log_format_elements']) %>
-<% else -%>
-#login_log_format_elements = user=<%= '<%' %>u> method=%m rip=%r lip=%l mpid=%e %c
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'login_log_format_elements', 'user=<%u> method=%m rip=%r lip=%l mpid=%e %c') %>
 
 # Login log format. %$ contains login_log_format_elements string, %s contains
 # the data we want to log.
-<% unless @conf['login_log_format'].nil? -%>
-login_log_format = <%= Dovecot::Conf.value(@conf['login_log_format']) %>
-<% else -%>
-#login_log_format = %$: %s
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'login_log_format', '%$: %s') %>
  
 # Log prefix for mail processes. See doc/wiki/Variables.txt for list of
 # possible variables you can use.
-<% unless @conf['mail_log_prefix'].nil? -%>
-mail_log_prefix = <%= Dovecot::Conf.value(@conf['mail_log_prefix']) %>
-<% else -%>
-#mail_log_prefix = "%s(%u): "
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'mail_log_prefix', '"%s(%u): "') %>
 
 # Format to use for logging mail deliveries. You can use variables:
 #  %$ - Delivery status message (e.g. "saved to INBOX")
@@ -140,8 +84,4 @@ mail_log_prefix = <%= Dovecot::Conf.value(@conf['mail_log_prefix']) %>
 #  %f - From address
 #  %p - Physical size
 #  %w - Virtual size
-<% unless @conf['deliver_log_format'].nil? -%>
-deliver_log_format = <%= Dovecot::Conf.value(@conf['deliver_log_format']) %>
-<% else -%>
-#deliver_log_format = msgid=%m: %$
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'deliver_log_format', 'msgid=%m: %$') %>

+ 11 - 55
templates/default/dovecot.conf.erb

@@ -27,91 +27,47 @@ protocols = <%= Dovecot::Conf.protocols(@protocols) %>
 # "*" listens in all IPv4 interfaces, "::" listens in all IPv6 interfaces.
 # If you want to specify non-default ports or anything more complex,
 # edit conf.d/master.conf.
-<% if @conf['listen'] -%>
-listen = <%= @conf['listen'] %>
-<% else -%>
-#listen = *, ::
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'listen', '*, ::') %>
 
 # Base directory where to store runtime data.
-<% unless @conf['base_dir'].nil? -%>
-base_dir = <%= Dovecot::Conf.value(@conf['base_dir']) %>
-<% else -%>
-#base_dir = /var/run/dovecot/
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'base_dir', '/var/run/dovecot/') %>
 
 # Name of this instance. Used to prefix all Dovecot processes in ps output.
-<% unless @conf['instance_name'].nil? -%>
-instance_name = <%= Dovecot::Conf.value(@conf['instance_name']) %>
-<% else -%>
-#instance_name = dovecot
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'instance_name', 'dovecot') %>
 
 # Greeting message for clients.
-<% unless @conf['login_greeting'].nil? -%>
-login_greeting = <%= Dovecot::Conf.value(@conf['login_greeting']) %>
-<% else -%>
-#login_greeting = Dovecot ready.
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'login_greeting', 'Dovecot ready.') %>
 
 # Space separated list of trusted network ranges. Connections from these
 # IPs are allowed to override their IP addresses and ports (for logging and
 # for authentication checks). disable_plaintext_auth is also ignored for
 # these networks. Typically you'd specify your IMAP proxy servers here.
-<% unless @conf['login_trusted_networks'].nil? -%>
-login_trusted_networks = <%= Dovecot::Conf.value(@conf['login_trusted_networks']) %>
-<% else -%>
-#login_trusted_networks =
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'login_trusted_networks') %>
 
 # Space separated list of login access check sockets (e.g. tcpwrap)
-<% unless @conf['login_access_sockets'].nil? -%>
-login_access_sockets = <%= Dovecot::Conf.value(@conf['login_access_sockets']) %>
-<% else -%>
-#login_access_sockets = 
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'login_access_sockets') %>
 
 # Show more verbose process titles (in ps). Currently shows user name and
 # IP address. Useful for seeing who are actually using the IMAP processes
 # (eg. shared mailboxes or if same uid is used for multiple accounts).
-<% unless @conf['verbose_proctitle'].nil? -%>
-verbose_proctitle = <%= Dovecot::Conf.value(@conf['verbose_proctitle']) %>
-<% else -%>
-#verbose_proctitle = no
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'verbose_proctitle', false) %>
 
 # Should all processes be killed when Dovecot master process shuts down.
 # Setting this to "no" means that Dovecot can be upgraded without
 # forcing existing client connections to close (although that could also be
 # a problem if the upgrade is e.g. because of a security fix).
-<% unless @conf['shutdown_clients'].nil? -%>
-shutdown_clients = <%= Dovecot::Conf.value(@conf['shutdown_clients']) %>
-<% else -%>
-#shutdown_clients = yes
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'shutdown_clients', true) %>
 
 # If non-zero, run mail commands via this many connections to doveadm server,
 # instead of running them directly in the same process.
-<% unless @conf['doveadm_worker_count'].nil? -%>
-doveadm_worker_count = <%= Dovecot::Conf.value(@conf['doveadm_worker_count']) %>
-<% else -%>
-#doveadm_worker_count = 0
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'doveadm_worker_count', 0) %>
 # UNIX socket or host:port used for connecting to doveadm server
-<% unless @conf['doveadm_socket_path'].nil? -%>
-doveadm_socket_path = <%= Dovecot::Conf.value(@conf['doveadm_socket_path']) %>
-<% else -%>
-#doveadm_socket_path = doveadm-server
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'doveadm_socket_path', 'doveadm-server') %>
 
 # Space separated list of environment variables that are preserved on Dovecot
 # startup and passed down to all of its child processes. You can also give
 # key=value pairs to always set specific settings.
-<% unless @conf['import_environment'].nil? -%>
-import_environment = <%= Dovecot::Conf.value(@conf['import_environment']) %>
-<% else -%>
-#import_environment = TZ
-<% end -%>
+<%= Dovecot::Conf.attribute(@conf, 'import_environment', 'TZ') %>
 
 ##
 ## Dictionary server settings