VirtualMailManager/VirtualMailManager.py
changeset 94 0d303d15549e
parent 90 1734eb5101c6
child 96 e903c8baa72d
equal deleted inserted replaced
93:bc41dfcef0ad 94:0d303d15549e
    44     """The main class for vmm"""
    44     """The main class for vmm"""
    45     def __init__(self):
    45     def __init__(self):
    46         """Creates a new VirtualMailManager instance.
    46         """Creates a new VirtualMailManager instance.
    47         Throws a VMMNotRootException if your uid is greater 0.
    47         Throws a VMMNotRootException if your uid is greater 0.
    48         """
    48         """
    49         self.__cfgFileName = '/usr/local/etc/vmm.cfg'
    49         self.__cfgFileName = ''
    50         self.__permWarnMsg = _(u"fix permissions for »%(cfgFileName)s«\n\
    50         self.__permWarnMsg = _(u"fix permissions for »%(cfgFileName)s«\n\
    51 `chmod 0600 %(cfgFileName)s` would be great.") % {'cfgFileName':
    51 `chmod 0600 %(cfgFileName)s` would be great.") % {'cfgFileName':
    52             self.__cfgFileName}
    52             self.__cfgFileName}
    53         self.__warnings = []
    53         self.__warnings = []
    54         self.__Cfg = None
    54         self.__Cfg = None
    65             self.__scheme = self.__Cfg.get('misc', 'passwdscheme')
    65             self.__scheme = self.__Cfg.get('misc', 'passwdscheme')
    66             self._postconf = Postconf(self.__Cfg.get('bin', 'postconf'))
    66             self._postconf = Postconf(self.__Cfg.get('bin', 'postconf'))
    67         if not sys.argv[1] in ['cf', 'configure']:
    67         if not sys.argv[1] in ['cf', 'configure']:
    68             self.__chkenv()
    68             self.__chkenv()
    69 
    69 
       
    70     def __findCfgFile(self):
       
    71         for path in ['/root', '/usr/local/etc', '/etc']:
       
    72             if os.path.isfile(path+'/vmm.cfg'):
       
    73                 self.__cfgFileName = path+'/vmm.cfg'
       
    74                 break
       
    75         if not len(self.__cfgFileName):
       
    76             raise VMMException(
       
    77                 _(u"No »vmm.cfg« found in: /root:/usr/local/etc:/etc"),
       
    78                 ERR.CONF_NOFILE)
       
    79 
    70     def __chkCfgFile(self):
    80     def __chkCfgFile(self):
    71         """Checks the configuration file, returns bool"""
    81         """Checks the configuration file, returns bool"""
    72         if not os.path.isfile(self.__cfgFileName):
    82         self.__findCfgFile()
    73             raise VMMException(_(u"The file »%s« does not exists.") %
       
    74                 self.__cfgFileName, ERR.CONF_NOFILE)
       
    75         fstat = os.stat(self.__cfgFileName)
    83         fstat = os.stat(self.__cfgFileName)
    76         fmode = int(oct(fstat.st_mode & 0777))
    84         fmode = int(oct(fstat.st_mode & 0777))
    77         if fmode % 100 and fstat.st_uid != fstat.st_gid \
    85         if fmode % 100 and fstat.st_uid != fstat.st_gid \
    78         or fmode % 10 and fstat.st_uid == fstat.st_gid:
    86         or fmode % 10 and fstat.st_uid == fstat.st_gid:
    79             raise VMMPermException(self.__permWarnMsg, ERR.CONF_ERROR)
    87             raise VMMPermException(self.__permWarnMsg, ERR.CONF_ERROR)