VirtualMailManager/VirtualMailManager.py
changeset 24 48ea255e8a85
parent 20 55146c78b3fb
child 28 87da30d30fde
equal deleted inserted replaced
23:d5ad5432e9eb 24:48ea255e8a85
    81         else:
    81         else:
    82             return True
    82             return True
    83 
    83 
    84     def __chkenv(self):
    84     def __chkenv(self):
    85         """"""
    85         """"""
    86         if not os.path.exists(self.__Cfg.get('maildir', 'base')):
    86         if not os.path.exists(self.__Cfg.get('domdir', 'base')):
    87             old_umask = os.umask(0007)
    87             old_umask = os.umask(0007)
    88             os.makedirs(self.__Cfg.get('maildir', 'base'), 0770)
    88             os.makedirs(self.__Cfg.get('domdir', 'base'), 0770)
    89             os.umask(old_umask)
    89             os.umask(old_umask)
    90         elif not os.path.isdir(self.__Cfg.get('maildir', 'base')):
    90         elif not os.path.isdir(self.__Cfg.get('domdir', 'base')):
    91             raise VMMException(('%s is not a directory' %
    91             raise VMMException(('%s is not a directory' %
    92                 self.__Cfg.get('maildir', 'base'), ERR.NO_SUCH_DIRECTORY))
    92                 self.__Cfg.get('domdir', 'base'), ERR.NO_SUCH_DIRECTORY))
    93         for opt, val in self.__Cfg.items('bin'):
    93         for opt, val in self.__Cfg.items('bin'):
    94             if not os.path.exists(val):
    94             if not os.path.exists(val):
    95                 raise VMMException(("%s doesn't exists." % val,
    95                 raise VMMException(("%s doesn't exists." % val,
    96                     ERR.NO_SUCH_BINARY))
    96                     ERR.NO_SUCH_BINARY))
    97             elif not os.access(val, os.X_OK):
    97             elif not os.access(val, os.X_OK):
   213         domainname = self.__chkDomainname(domainname)
   213         domainname = self.__chkDomainname(domainname)
   214         if transport is None:
   214         if transport is None:
   215             transport = self.__Cfg.get('misc', 'transport')
   215             transport = self.__Cfg.get('misc', 'transport')
   216         self.__dbConnect()
   216         self.__dbConnect()
   217         return Domain(self.__dbh, domainname,
   217         return Domain(self.__dbh, domainname,
   218                 self.__Cfg.get('maildir', 'base'), transport)
   218                 self.__Cfg.get('domdir', 'base'), transport)
   219 
   219 
   220     def __getDiskUsage(self, directory):
   220     def __getDiskUsage(self, directory):
   221         """Estimate file space usage for the given directory.
   221         """Estimate file space usage for the given directory.
   222         
   222         
   223         Keyword arguments:
   223         Keyword arguments:
   237         os.chown(directory, uid, gid)
   237         os.chown(directory, uid, gid)
   238 
   238 
   239     def __domdirmake(self, domdir, gid):
   239     def __domdirmake(self, domdir, gid):
   240         os.umask(0006)
   240         os.umask(0006)
   241         oldpwd = os.getcwd()
   241         oldpwd = os.getcwd()
   242         basedir = self.__Cfg.get('maildir', 'base')
   242         basedir = self.__Cfg.get('domdir', 'base')
   243         domdirdirs = domdir.replace(basedir+'/', '').split('/')
   243         domdirdirs = domdir.replace(basedir+'/', '').split('/')
   244 
   244 
   245         os.chdir(basedir)
   245         os.chdir(basedir)
   246         if not os.path.isdir(domdirdirs[0]):
   246         if not os.path.isdir(domdirdirs[0]):
   247             self.__makedir(domdirdirs[0], 489, 0,
   247             self.__makedir(domdirdirs[0], 489, 0,
   293                                 ERR.MAILDIR_PERM_MISMATCH))
   293                                 ERR.MAILDIR_PERM_MISMATCH))
   294                     rmtree(maildir, ignore_errors=True)
   294                     rmtree(maildir, ignore_errors=True)
   295 
   295 
   296     def __domdirdelete(self, domdir, gid):
   296     def __domdirdelete(self, domdir, gid):
   297         if gid > 0:
   297         if gid > 0:
   298             basedir = '%s' % self.__Cfg.get('maildir', 'base')
   298             basedir = '%s' % self.__Cfg.get('domdir', 'base')
   299             domdirdirs = domdir.replace(basedir+'/', '').split('/')
   299             domdirdirs = domdir.replace(basedir+'/', '').split('/')
   300             if basedir.count('..') or domdir.count('..'):
   300             if basedir.count('..') or domdir.count('..'):
   301                 raise VMMException(
   301                 raise VMMException(
   302                         ('FATAL: ".." in domain directory path detected.',
   302                         ('FATAL: ".." in domain directory path detected.',
   303                             ERR.FOUND_DOTS_IN_PATH))
   303                             ERR.FOUND_DOTS_IN_PATH))