summaryrefslogtreecommitdiff
path: root/src/leap/util/fileutil.py
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-08-08 06:53:10 +0900
committerkali <kali@leap.se>2012-08-08 06:53:10 +0900
commit530e10214a6f018909714b288d997df13ab4f9df (patch)
tree995596699e26d27ddcbd442698646b32dd11ba6c /src/leap/util/fileutil.py
parent36b0dfacca794e9cb899b5dde2dae3b8bbc6cc43 (diff)
check for bad permissions on vpn key files
Diffstat (limited to 'src/leap/util/fileutil.py')
-rw-r--r--src/leap/util/fileutil.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/leap/util/fileutil.py b/src/leap/util/fileutil.py
index bb2c243b..cc3bf34b 100644
--- a/src/leap/util/fileutil.py
+++ b/src/leap/util/fileutil.py
@@ -1,10 +1,14 @@
import errno
from itertools import chain
+import logging
import os
import platform
import stat
+logger = logging.getLogger()
+
+
def is_user_executable(fpath):
st = os.stat(fpath)
return bool(st.st_mode & stat.S_IXUSR)
@@ -85,3 +89,23 @@ def mkdir_p(path):
pass
else:
raise
+
+
+def check_and_fix_urw_only(_file):
+ """
+ test for 600 mode and try
+ to set it if anything different found
+ """
+ mode = os.stat(_file).st_mode
+ if mode != int('600', 8):
+ try:
+ logger.warning(
+ 'bad permission on %s '
+ 'attempting to set 600',
+ _file)
+ os.chmod(_file, stat.S_IRUSR | stat.S_IWUSR)
+ except OSError:
+ logger.error(
+ 'error while trying to chmod 600 %s',
+ _file)
+ raise