VirtualMailManager/password.py
branchv0.6.x
changeset 417 8209da83e256
parent 366 d6573da35b5f
child 461 cabdf94ec580
equal deleted inserted replaced
416:f32b323fd347 417:8209da83e256
   369     if scheme not in _scheme_info:
   369     if scheme not in _scheme_info:
   370         raise VMMError(_(u"Unsupported password scheme: '%s'") % scheme,
   370         raise VMMError(_(u"Unsupported password scheme: '%s'") % scheme,
   371                        VMM_ERROR)
   371                        VMM_ERROR)
   372     if cfg_dget('misc.dovecot_version') < _scheme_info[scheme][1]:
   372     if cfg_dget('misc.dovecot_version') < _scheme_info[scheme][1]:
   373         raise VMMError(_(u"The password scheme '%(scheme)s' requires Dovecot "
   373         raise VMMError(_(u"The password scheme '%(scheme)s' requires Dovecot "
   374                          u">= v%(version)s") % {'scheme': scheme,
   374                          u">= v%(version)s.") % {'scheme': scheme,
   375                        'version': version_str(_scheme_info[scheme][1])},
   375                        'version': version_str(_scheme_info[scheme][1])},
   376                        VMM_ERROR)
   376                        VMM_ERROR)
   377     if len(scheme_encoding) > 1:
   377     if len(scheme_encoding) > 1:
   378         if cfg_dget('misc.dovecot_version') < 0x10100a01:
   378         if cfg_dget('misc.dovecot_version') < 0x10100a01:
   379             raise VMMError(_(u'Encoding suffixes for password schemes require '
   379             raise VMMError(_(u'Encoding suffixes for password schemes require '
   380                              u'Dovecot >= v1.1.alpha1'), VMM_ERROR)
   380                              u'Dovecot >= v1.1.alpha1.'), VMM_ERROR)
   381         if scheme_encoding[1] not in ('B64', 'BASE64', 'HEX'):
   381         if scheme_encoding[1] not in ('B64', 'BASE64', 'HEX'):
   382             raise VMMError(_(u"Unsupported password encoding: '%s'") %
   382             raise VMMError(_(u"Unsupported password encoding: '%s'") %
   383                            scheme_encoding[1], VMM_ERROR)
   383                            scheme_encoding[1], VMM_ERROR)
   384         encoding = scheme_encoding[1]
   384         encoding = scheme_encoding[1]
   385     else:
   385     else:
   398         raise TypeError('Password is not a string: %r' % password)
   398         raise TypeError('Password is not a string: %r' % password)
   399     if isinstance(password, unicode):
   399     if isinstance(password, unicode):
   400         password = password.encode(ENCODING)
   400         password = password.encode(ENCODING)
   401     password = password.strip()
   401     password = password.strip()
   402     if not password:
   402     if not password:
   403         raise ValueError("Couldn't accept empty password.")
   403         raise ValueError("Could not accept empty password.")
   404     if scheme is None:
   404     if scheme is None:
   405         scheme = cfg_dget('misc.password_scheme')
   405         scheme = cfg_dget('misc.password_scheme')
   406     scheme, encoding = verify_scheme(scheme)
   406     scheme, encoding = verify_scheme(scheme)
   407     if scheme == 'DIGEST-MD5':
   407     if scheme == 'DIGEST-MD5':
   408         assert isinstance(user, EmailAddress)
   408         assert isinstance(user, EmailAddress)