VirtualMailManager/VirtualMailManager.py
changeset 155 eb866ebb9f2e
parent 143 16542519a5a8
child 156 a849843115e9
equal deleted inserted replaced
154:6e6488722807 155:eb866ebb9f2e
    93             raise VMMException(_(u'“%s” is not a directory.\n\
    93             raise VMMException(_(u'“%s” is not a directory.\n\
    94 (vmm.cfg: section "domdir", option "base")') %
    94 (vmm.cfg: section "domdir", option "base")') %
    95                 self.__Cfg.get('domdir', 'base'), ERR.NO_SUCH_DIRECTORY)
    95                 self.__Cfg.get('domdir', 'base'), ERR.NO_SUCH_DIRECTORY)
    96         for opt, val in self.__Cfg.items('bin'):
    96         for opt, val in self.__Cfg.items('bin'):
    97             if not os.path.exists(val):
    97             if not os.path.exists(val):
    98                 raise VMMException(_(u'“%(binary)s” doesn\'t exists.\n\
    98                 raise VMMException(_(u'“%(binary)s” doesn\'t exist.\n\
    99 (vmm.cfg: section "bin", option "%(option)s")') %{'binary': val,'option': opt},
    99 (vmm.cfg: section "bin", option "%(option)s")') %{'binary': val,'option': opt},
   100                     ERR.NO_SUCH_BINARY)
   100                     ERR.NO_SUCH_BINARY)
   101             elif not os.access(val, os.X_OK):
   101             elif not os.access(val, os.X_OK):
   102                 raise VMMException(_(u'“%(binary)s” is not executable.\n\
   102                 raise VMMException(_(u'“%(binary)s” is not executable.\n\
   103 (vmm.cfg: section "bin", option "%(option)s")') %{'binary': val,'option': opt},
   103 (vmm.cfg: section "bin", option "%(option)s")') %{'binary': val,'option': opt},
   327                 os.chdir(domdir)
   327                 os.chdir(domdir)
   328                 if os.path.isdir(userdir):
   328                 if os.path.isdir(userdir):
   329                     mdstat = os.stat(userdir)
   329                     mdstat = os.stat(userdir)
   330                     if (mdstat.st_uid, mdstat.st_gid) != (uid, gid):
   330                     if (mdstat.st_uid, mdstat.st_gid) != (uid, gid):
   331                         raise VMMException(
   331                         raise VMMException(
   332                          _(u'Owner/group mismatch in home directory detected.'),
   332                          _(u'Detected owner/group mismatch in home directory.'),
   333                          ERR.MAILDIR_PERM_MISMATCH)
   333                          ERR.MAILDIR_PERM_MISMATCH)
   334                     rmtree(userdir, ignore_errors=True)
   334                     rmtree(userdir, ignore_errors=True)
   335                 else:
   335                 else:
   336                     raise VMMException(_(u"No such directory: %s") %
   336                     raise VMMException(_(u"No such directory: %s") %
   337                         os.path.join(domdir, userdir), ERR.NO_SUCH_DIRECTORY)
   337                         os.path.join(domdir, userdir), ERR.NO_SUCH_DIRECTORY)
   342                 return
   342                 return
   343             basedir = self.__Cfg.get('domdir', 'base')
   343             basedir = self.__Cfg.get('domdir', 'base')
   344             domdirdirs = domdir.replace(basedir+'/', '').split('/')
   344             domdirdirs = domdir.replace(basedir+'/', '').split('/')
   345             domdirparent = os.path.join(basedir, domdirdirs[0])
   345             domdirparent = os.path.join(basedir, domdirdirs[0])
   346             if basedir.count('..') or domdir.count('..'):
   346             if basedir.count('..') or domdir.count('..'):
   347                 raise VMMException(
   347                 raise VMMException(_(u'Found ".." in domain directory path.'),
   348                         _(u'FATAL: ".." in domain directory path detected.'),
   348                         ERR.FOUND_DOTS_IN_PATH)
   349                             ERR.FOUND_DOTS_IN_PATH)
       
   350             if os.path.isdir(domdirparent):
   349             if os.path.isdir(domdirparent):
   351                 os.chdir(domdirparent)
   350                 os.chdir(domdirparent)
   352                 if os.lstat(domdirdirs[1]).st_gid != gid:
   351                 if os.lstat(domdirdirs[1]).st_gid != gid:
   353                     raise VMMException(
   352                     raise VMMException(_(
   354                     _(u'FATAL: group mismatch in domain directory detected'),
   353                         u'Detected group mismatch in domain directory.'),
   355                         ERR.DOMAINDIR_GROUP_MISMATCH)
   354                         ERR.DOMAINDIR_GROUP_MISMATCH)
   356                 rmtree(domdirdirs[1], ignore_errors=True)
   355                 rmtree(domdirdirs[1], ignore_errors=True)
   357 
   356 
   358     def __getSalt(self):
   357     def __getSalt(self):
   359         from random import choice
   358         from random import choice
   433     def setupIsDone(self):
   432     def setupIsDone(self):
   434         """Checks if vmm is configured, returns bool"""
   433         """Checks if vmm is configured, returns bool"""
   435         try:
   434         try:
   436             return self.__Cfg.getboolean('config', 'done')
   435             return self.__Cfg.getboolean('config', 'done')
   437         except ValueError, e:
   436         except ValueError, e:
   438             raise VMMConfigException(_(u"""Configurtion error: "%s"
   437             raise VMMConfigException(_(u"""Configuration error: "%s"
   439 (in section "connfig", option "done") see also: vmm.cfg(5)\n""") % str(e),
   438 (in section "config", option "done") see also: vmm.cfg(5)\n""") % str(e),
   440                   ERR.CONF_ERROR)
   439                   ERR.CONF_ERROR)
   441 
   440 
   442     def configure(self, section=None):
   441     def configure(self, section=None):
   443         """Starts interactive configuration.
   442         """Starts interactive configuration.
   444 
   443 
   595         gid = self.__getDomain(alias._dest._domainname).getID()
   594         gid = self.__getDomain(alias._dest._domainname).getID()
   596         if gid > 0 and not VirtualMailManager.accountExists(self.__dbh,
   595         if gid > 0 and not VirtualMailManager.accountExists(self.__dbh,
   597         alias._dest) and not VirtualMailManager.aliasExists(self.__dbh,
   596         alias._dest) and not VirtualMailManager.aliasExists(self.__dbh,
   598         alias._dest):
   597         alias._dest):
   599             self.__warnings.append(
   598             self.__warnings.append(
   600                 _(u"The destination account/alias “%s” doesn't exists yet.")%\
   599                 _(u"The destination account/alias “%s” doesn't exist.")%\
   601                         alias._dest)
   600                         alias._dest)
   602 
   601 
   603     def userDelete(self, emailaddress, force=None):
   602     def userDelete(self, emailaddress, force=None):
   604         if force not in [None, 'delalias']:
   603         if force not in [None, 'delalias']:
   605             raise VMMException(_(u"Invalid argument: “%s”") % force,
   604             raise VMMException(_(u"Invalid argument: “%s”") % force,
   616                         ERR.MAILDIR_PERM_MISMATCH, ERR.NO_SUCH_DIRECTORY]:
   615                         ERR.MAILDIR_PERM_MISMATCH, ERR.NO_SUCH_DIRECTORY]:
   617                     warning = _(u"""\
   616                     warning = _(u"""\
   618 The account has been successfully deleted from the database.
   617 The account has been successfully deleted from the database.
   619     But an error occurred while deleting the following directory:
   618     But an error occurred while deleting the following directory:
   620     “%(directory)s”
   619     “%(directory)s”
   621     Reason: %(raeson)s""") % {'directory': acc.getDir('home'),'raeson': e.msg()}
   620     Reason: %(reason)s""") % {'directory': acc.getDir('home'),'reason': e.msg()}
   622                     self.__warnings.append(warning)
   621                     self.__warnings.append(warning)
   623                 else:
   622                 else:
   624                     raise e
   623                     raise e
   625 
   624 
   626     def aliasInfo(self, aliasaddress):
   625     def aliasInfo(self, aliasaddress):
   652         return getAccountByID(uid, self.__dbh)
   651         return getAccountByID(uid, self.__dbh)
   653 
   652 
   654     def userPassword(self, emailaddress, password):
   653     def userPassword(self, emailaddress, password):
   655         acc = self.__getAccount(emailaddress)
   654         acc = self.__getAccount(emailaddress)
   656         if acc.getUID() == 0:
   655         if acc.getUID() == 0:
   657            raise VMMException(_(u"Account doesn't exists"), ERR.NO_SUCH_ACCOUNT)
   656            raise VMMException(_(u"Account doesn't exist"), ERR.NO_SUCH_ACCOUNT)
   658         if password is None:
   657         if password is None:
   659             password = self._readpass()
   658             password = self._readpass()
   660         acc.modify('password', self.__pwhash(password, user=emailaddress))
   659         acc.modify('password', self.__pwhash(password, user=emailaddress))
   661 
   660 
   662     def userName(self, emailaddress, name):
   661     def userName(self, emailaddress, name):