VirtualMailManager/handler.py
branchv0.7.x
changeset 648 9cf2cf762e26
parent 643 df1e3b67882a
child 649 08837f3fbced
equal deleted inserted replaced
647:d91dd7bc8fce 648:9cf2cf762e26
    14 
    14 
    15 import os
    15 import os
    16 import re
    16 import re
    17 
    17 
    18 from shutil import rmtree
    18 from shutil import rmtree
       
    19 from stat import S_IRGRP, S_IROTH, S_IWGRP, S_IWOTH
    19 from subprocess import Popen, PIPE
    20 from subprocess import Popen, PIPE
    20 
    21 
    21 from VirtualMailManager.account import Account
    22 from VirtualMailManager.account import Account
    22 from VirtualMailManager.alias import Alias
    23 from VirtualMailManager.alias import Alias
    23 from VirtualMailManager.aliasdomain import AliasDomain
    24 from VirtualMailManager.aliasdomain import AliasDomain
   102                              "'%(cfg_path)s'") % {'cfg_file': CFG_FILE,
   103                              "'%(cfg_path)s'") % {'cfg_file': CFG_FILE,
   103                            'cfg_path': CFG_PATH}, CONF_NOFILE)
   104                            'cfg_path': CFG_PATH}, CONF_NOFILE)
   104 
   105 
   105     def _check_cfg_file(self):
   106     def _check_cfg_file(self):
   106         """Checks the configuration file, returns bool"""
   107         """Checks the configuration file, returns bool"""
       
   108         GRPRW = S_IRGRP | S_IWGRP
       
   109         OTHRW = S_IROTH | S_IWOTH
   107         self._find_cfg_file()
   110         self._find_cfg_file()
   108         fstat = os.stat(self._cfg_fname)
   111         fstat = os.stat(self._cfg_fname)
   109         fmode = int(oct(fstat.st_mode & 0o777))
   112         if (fstat.st_uid == fstat.st_gid and fstat.st_mode & OTHRW) or \
   110         if fmode % 100 and fstat.st_uid != fstat.st_gid or \
   113            (fstat.st_uid != fstat.st_gid and fstat.st_mode & (GRPRW | OTHRW)):
   111            fmode % 10 and fstat.st_uid == fstat.st_gid:
       
   112             # TP: Please keep the backticks around the command. `chmod 0600 …`
   114             # TP: Please keep the backticks around the command. `chmod 0600 …`
   113             raise PermissionError(_("wrong permissions for '%(file)s': "
   115             raise PermissionError(_("wrong permissions for '%(file)s': "
   114                                     "%(perms)s\n`chmod 0600 %(file)s` would "
   116                                     "%(perms)s\n`chmod 0600 %(file)s` would "
   115                                     "be great.") % {'file': self._cfg_fname,
   117                                     "be great.") % {'file': self._cfg_fname,
   116                                   'perms': fmode}, CONF_WRONGPERM)
   118                                   'perms': oct(fstat.st_mode)[-4:]},
       
   119                                   CONF_WRONGPERM)
   117         else:
   120         else:
   118             return True
   121             return True
   119 
   122 
   120     def _chkenv(self):
   123     def _chkenv(self):
   121         """Make sure our base_directory is a directory and that all
   124         """Make sure our base_directory is a directory and that all