VirtualMailManager/config.py
branchv0.7.x
changeset 716 915c14b21db3
parent 711 2a75058fc064
child 719 19486a140ef5
equal deleted inserted replaced
715:c6a33da1aa93 716:915c14b21db3
    14      Error, MissingSectionHeaderError, NoOptionError, NoSectionError, \
    14      Error, MissingSectionHeaderError, NoOptionError, NoSectionError, \
    15      ParsingError, RawConfigParser
    15      ParsingError, RawConfigParser
    16 from io import StringIO
    16 from io import StringIO
    17 
    17 
    18 from VirtualMailManager.common import VERSION_RE, \
    18 from VirtualMailManager.common import VERSION_RE, \
    19      exec_ok, expand_path, get_unicode, lisdir, size_in_bytes, version_hex
    19      exec_ok, expand_path, get_unicode, lisdir, size_in_bytes, version_hex, \
    20 from VirtualMailManager.constants import CONF_ERROR
    20      version_str
       
    21 from VirtualMailManager.constants import CONF_ERROR, MIN_DOVECOT_VERSION
    21 from VirtualMailManager.errors import ConfigError, VMMError
    22 from VirtualMailManager.errors import ConfigError, VMMError
    22 from VirtualMailManager.maillocation import known_format
    23 from VirtualMailManager.maillocation import known_format
    23 from VirtualMailManager.password import verify_scheme as _verify_scheme
    24 from VirtualMailManager.password import verify_scheme as _verify_scheme
    24 
    25 
    25 DB_SSL_MODES = ('allow', 'disabled', 'prefer', 'require', 'verify-ca',
    26 DB_SSL_MODES = ('allow', 'disabled', 'prefer', 'require', 'verify-ca',
   343                 'base_directory': LCO(str, '/srv/mail', self.get, is_dir),
   344                 'base_directory': LCO(str, '/srv/mail', self.get, is_dir),
   344                 'crypt_blowfish_rounds': LCO(int, 5, self.getint),
   345                 'crypt_blowfish_rounds': LCO(int, 5, self.getint),
   345                 'crypt_sha256_rounds': LCO(int, 5000, self.getint),
   346                 'crypt_sha256_rounds': LCO(int, 5000, self.getint),
   346                 'crypt_sha512_rounds': LCO(int, 5000, self.getint),
   347                 'crypt_sha512_rounds': LCO(int, 5000, self.getint),
   347                 'dovecot_version': LCO(str, None, self.hexversion,
   348                 'dovecot_version': LCO(str, None, self.hexversion,
   348                                        check_version_format),
   349                                        check_dovecot_version),
   349                 'password_scheme': LCO(str, 'CRAM-MD5', self.get,
   350                 'password_scheme': LCO(str, 'CRAM-MD5', self.get,
   350                                        verify_scheme),
   351                                        verify_scheme),
   351             },
   352             },
   352         }
   353         }
   353 
   354 
   428 
   429 
   429     def _chk_possible_values(self, miss_vers):
   430     def _chk_possible_values(self, miss_vers):
   430         """Check settings for which the possible values are known."""
   431         """Check settings for which the possible values are known."""
   431         if not miss_vers:
   432         if not miss_vers:
   432             value = self.get('misc', 'dovecot_version')
   433             value = self.get('misc', 'dovecot_version')
   433             if not VERSION_RE.match(value):
   434             try:
   434                 self._missing['misc'] = ['version: ' +
   435                 checked = check_dovecot_version(value)
   435                         _("Not a valid Dovecot version: '%s'") % value]
   436             except ConfigValueError as err:
       
   437                 self._missing['misc'] = ['dovecot_version: %s' % str(err)]
   436         # section database
   438         # section database
   437         db_err = []
   439         db_err = []
   438         value = self.dget('database.sslmode')
   440         value = self.dget('database.sslmode')
   439         if value not in DB_SSL_MODES:
   441         if value not in DB_SSL_MODES:
   440             db_err.append('sslmode: ' +
   442             db_err.append('sslmode: ' +
   495         raise ConfigValueError(_("Not a valid size value: '%s'") %
   497         raise ConfigValueError(_("Not a valid size value: '%s'") %
   496                                get_unicode(value))
   498                                get_unicode(value))
   497     return value
   499     return value
   498 
   500 
   499 
   501 
   500 def check_version_format(version_string):
   502 def check_dovecot_version(version_string):
   501     """Check if the *version_string* has the proper format, e.g.: '1.2.3'.
   503     """Check if the *version_string* has the proper format, e.g.: '2.0.0',
       
   504     and if the configured version is >= MIN_DOVECOT_VERSION.
   502     Returns the validated version string if it has the expected format.
   505     Returns the validated version string if it has the expected format.
   503     Otherwise a `ConfigValueError` will be raised.
   506     Otherwise a `ConfigValueError` will be raised.
   504     """
   507     """
   505     if not VERSION_RE.match(version_string):
   508     if not VERSION_RE.match(version_string):
   506         raise ConfigValueError(_("Not a valid Dovecot version: '%s'") %
   509         raise ConfigValueError(_("Not a valid Dovecot version: '%s'") %
   507                                get_unicode(version_string))
   510                                get_unicode(version_string))
       
   511     if version_hex(version_string) < MIN_DOVECOT_VERSION:
       
   512         raise ConfigValueError(_("vmm requires Dovecot >= %s") %
       
   513                                version_str(MIN_DOVECOT_VERSION))
   508     return version_string
   514     return version_string
   509 
   515 
   510 
   516 
   511 def verify_scheme(scheme):
   517 def verify_scheme(scheme):
   512     """Checks if the password scheme *scheme* can be accepted and returns
   518     """Checks if the password scheme *scheme* can be accepted and returns