VirtualMailManager/Config.py
branchv0.6.x
changeset 287 1e77dd639fa3
parent 286 e2046d47688b
child 290 e2785e04f92e
equal deleted inserted replaced
286:e2046d47688b 287:1e77dd639fa3
    15      ParsingError, RawConfigParser
    15      ParsingError, RawConfigParser
    16 from cStringIO import StringIO# TODO: move interactive stff to cli
    16 from cStringIO import StringIO# TODO: move interactive stff to cli
    17 
    17 
    18 from VirtualMailManager.common import exec_ok, get_unicode, is_dir, version_hex
    18 from VirtualMailManager.common import exec_ok, get_unicode, is_dir, version_hex
    19 from VirtualMailManager.constants.ERROR import CONF_ERROR
    19 from VirtualMailManager.constants.ERROR import CONF_ERROR
    20 from VirtualMailManager.errors import ConfigError
    20 from VirtualMailManager.errors import ConfigError, VMMError
       
    21 from VirtualMailManager.password import verify_scheme as _verify_scheme
    21 
    22 
    22 
    23 
    23 _ = lambda msg: msg
    24 _ = lambda msg: msg
    24 
    25 
    25 
    26 
   347                 'crypt_sha256_rounds': LCO(int, 0, self.getint),
   348                 'crypt_sha256_rounds': LCO(int, 0, self.getint),
   348                 'crypt_sha512_rounds': LCO(int, 0, self.getint),
   349                 'crypt_sha512_rounds': LCO(int, 0, self.getint),
   349                 'dovecot_version': LCO(str, None, self.hexversion,
   350                 'dovecot_version': LCO(str, None, self.hexversion,
   350                                        check_version_format),
   351                                        check_version_format),
   351                 'password_scheme': LCO(str, 'CRAM-MD5', self.get,
   352                 'password_scheme': LCO(str, 'CRAM-MD5', self.get,
   352                                        self.known_scheme),
   353                                        verify_scheme),
   353                 'transport': LCO(str, 'dovecot:', self.get),
   354                 'transport': LCO(str, 'dovecot:', self.get),
   354             },
   355             },
   355         }
   356         }
   356 
   357 
   357     def load(self):
   358     def load(self):
   394     def hexversion(self, section, option):
   395     def hexversion(self, section, option):
   395         """Converts the version number (e.g.: 1.2.3) from the *option*'s
   396         """Converts the version number (e.g.: 1.2.3) from the *option*'s
   396         value to an int."""
   397         value to an int."""
   397         return version_hex(self.get(section, option))
   398         return version_hex(self.get(section, option))
   398 
   399 
   399     def known_scheme(self, scheme):
       
   400         """Converts `scheme` to upper case and checks if is known by
       
   401         Dovecot (listed in VirtualMailManager.SCHEMES).
       
   402 
       
   403         Throws a `ConfigValueError` if the scheme is not listed in
       
   404         VirtualMailManager.SCHEMES.
       
   405 
       
   406         """
       
   407         scheme = scheme.upper()
       
   408         # TODO: VMM.SCHEMES
       
   409 
       
   410     def unicode(self, section, option):
   400     def unicode(self, section, option):
   411         """Returns the value of the `option` from `section`, converted
   401         """Returns the value of the `option` from `section`, converted
   412         to Unicode.
   402         to Unicode."""
   413 
       
   414         """
       
   415         return get_unicode(self.get(section, option))
   403         return get_unicode(self.get(section, option))
   416 
   404 
   417     def __chk_cfg(self):
   405     def __chk_cfg(self):
   418         """Checks all section's options for settings w/o a default
   406         """Checks all section's options for settings w/o a default
   419         value.
   407         value.
   443     if not re.match(version_re, version_string):
   431     if not re.match(version_re, version_string):
   444         raise ConfigValueError(_(u"Not a valid Dovecot version: '%s'") %
   432         raise ConfigValueError(_(u"Not a valid Dovecot version: '%s'") %
   445                                get_unicode(version_string))
   433                                get_unicode(version_string))
   446     return version_string
   434     return version_string
   447 
   435 
       
   436 
       
   437 def verify_scheme(scheme):
       
   438     """Checks if the password scheme *scheme* can be accepted and returns
       
   439     the verified scheme.
       
   440     """
       
   441     try:
       
   442         scheme, encoding = _verify_scheme(scheme)
       
   443     except VMMError, err:  # 'cast' it
       
   444         raise ConfigValueError(err.msg)
       
   445     if not encoding:
       
   446         return scheme
       
   447     return '%s.%s' % (scheme, encoding)
       
   448 
   448 del _
   449 del _