20 from VirtualMailManager.constants import CONF_ERROR |
20 from VirtualMailManager.constants import CONF_ERROR |
21 from VirtualMailManager.errors import ConfigError, VMMError |
21 from VirtualMailManager.errors import ConfigError, VMMError |
22 from VirtualMailManager.maillocation import known_format |
22 from VirtualMailManager.maillocation import known_format |
23 from VirtualMailManager.password import verify_scheme as _verify_scheme |
23 from VirtualMailManager.password import verify_scheme as _verify_scheme |
24 |
24 |
25 DB_MODULES = ('psycopg2', 'pypgsql') |
|
26 DB_SSL_MODES = ('allow', 'disabled', 'prefer', 'require', 'verify-ca', |
25 DB_SSL_MODES = ('allow', 'disabled', 'prefer', 'require', 'verify-ca', |
27 'verify-full') |
26 'verify-full') |
28 |
27 |
29 _ = lambda msg: msg |
28 _ = lambda msg: msg |
30 |
29 |
311 'du': LCO(str, '/usr/bin/du', self.get, exec_ok), |
310 'du': LCO(str, '/usr/bin/du', self.get, exec_ok), |
312 'postconf': LCO(str, '/usr/sbin/postconf', self.get, exec_ok), |
311 'postconf': LCO(str, '/usr/sbin/postconf', self.get, exec_ok), |
313 }, |
312 }, |
314 'database': { |
313 'database': { |
315 'host': LCO(str, 'localhost', self.get), |
314 'host': LCO(str, 'localhost', self.get), |
316 'module': LCO(str, 'psycopg2', self.get, check_db_module), |
|
317 'name': LCO(str, 'mailsys', self.get), |
315 'name': LCO(str, 'mailsys', self.get), |
318 'pass': LCO(str, None, self.get), |
316 'pass': LCO(str, None, self.get), |
319 'port': LCO(int, 5432, self.getint), |
317 'port': LCO(int, 5432, self.getint), |
320 'sslmode': LCO(str, 'prefer', self.get, check_db_ssl_mode), |
318 'sslmode': LCO(str, 'prefer', self.get, check_db_ssl_mode), |
321 'user': LCO(str, None, self.get), |
319 'user': LCO(str, None, self.get), |
435 if not VERSION_RE.match(value): |
433 if not VERSION_RE.match(value): |
436 self._missing['misc'] = ['version: ' + |
434 self._missing['misc'] = ['version: ' + |
437 _("Not a valid Dovecot version: '%s'") % value] |
435 _("Not a valid Dovecot version: '%s'") % value] |
438 # section database |
436 # section database |
439 db_err = [] |
437 db_err = [] |
440 value = self.dget('database.module').lower() |
438 value = self.dget('database.sslmode') |
441 if value not in DB_MODULES: |
439 if value not in DB_SSL_MODES: |
442 db_err.append('module: ' + |
440 db_err.append('sslmode: ' + |
443 _("Unsupported database module: '%s'") % value) |
441 _("Unknown pgsql SSL mode: '%s'") % value) |
444 if value == 'psycopg2': |
|
445 value = self.dget('database.sslmode') |
|
446 if value not in DB_SSL_MODES: |
|
447 db_err.append('sslmode: ' + |
|
448 _("Unknown pgsql SSL mode: '%s'") % value) |
|
449 if db_err: |
442 if db_err: |
450 self._missing['database'] = db_err |
443 self._missing['database'] = db_err |
451 # section mailbox |
444 # section mailbox |
452 value = self.dget('mailbox.format') |
445 value = self.dget('mailbox.format') |
453 if not known_format(value): |
446 if not known_format(value): |
469 if lisdir(path): |
462 if lisdir(path): |
470 return path |
463 return path |
471 raise ConfigValueError(_("No such directory: %s") % get_unicode(path)) |
464 raise ConfigValueError(_("No such directory: %s") % get_unicode(path)) |
472 |
465 |
473 |
466 |
474 def check_db_module(module): |
|
475 """Check if the *module* is a supported pgsql module.""" |
|
476 if module.lower() in DB_MODULES: |
|
477 return module |
|
478 raise ConfigValueError(_("Unsupported database module: '%s'") % |
|
479 get_unicode(module)) |
|
480 |
|
481 |
|
482 def check_db_ssl_mode(ssl_mode): |
467 def check_db_ssl_mode(ssl_mode): |
483 """Check if the *ssl_mode* is one of the SSL modes, known by pgsql.""" |
468 """Check if the *ssl_mode* is one of the SSL modes, known by pgsql.""" |
484 if ssl_mode in DB_SSL_MODES: |
469 if ssl_mode in DB_SSL_MODES: |
485 return ssl_mode |
470 return ssl_mode |
486 raise ConfigValueError(_("Unknown pgsql SSL mode: '%s'") % |
471 raise ConfigValueError(_("Unknown pgsql SSL mode: '%s'") % |