# HG changeset patch
# User Pascal Volk <user@localhost.localdomain.org>
# Date 1353537442 0
# Node ID 9cf2cf762e261eac62a2f0ba6be123c4ebff40a3
# Parent  d91dd7bc8fceae75e185418a84f64dc8a6aa4a59
VMM/handler: Reworked config file permission check.

diff -r d91dd7bc8fce -r 9cf2cf762e26 VirtualMailManager/handler.py
--- a/VirtualMailManager/handler.py	Wed Nov 21 13:13:31 2012 +0000
+++ b/VirtualMailManager/handler.py	Wed Nov 21 22:37:22 2012 +0000
@@ -16,6 +16,7 @@
 import re
 
 from shutil import rmtree
+from stat import S_IRGRP, S_IROTH, S_IWGRP, S_IWOTH
 from subprocess import Popen, PIPE
 
 from VirtualMailManager.account import Account
@@ -104,16 +105,18 @@
 
     def _check_cfg_file(self):
         """Checks the configuration file, returns bool"""
+        GRPRW = S_IRGRP | S_IWGRP
+        OTHRW = S_IROTH | S_IWOTH
         self._find_cfg_file()
         fstat = os.stat(self._cfg_fname)
-        fmode = int(oct(fstat.st_mode & 0o777))
-        if fmode % 100 and fstat.st_uid != fstat.st_gid or \
-           fmode % 10 and fstat.st_uid == fstat.st_gid:
+        if (fstat.st_uid == fstat.st_gid and fstat.st_mode & OTHRW) or \
+           (fstat.st_uid != fstat.st_gid and fstat.st_mode & (GRPRW | OTHRW)):
             # TP: Please keep the backticks around the command. `chmod 0600 …`
             raise PermissionError(_("wrong permissions for '%(file)s': "
                                     "%(perms)s\n`chmod 0600 %(file)s` would "
                                     "be great.") % {'file': self._cfg_fname,
-                                  'perms': fmode}, CONF_WRONGPERM)
+                                  'perms': oct(fstat.st_mode)[-4:]},
+                                  CONF_WRONGPERM)
         else:
             return True