summaryrefslogtreecommitdiff
path: root/src/leap/util/privilege_policies.py
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2013-07-29 18:01:34 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2013-07-30 10:19:25 -0300
commit4a8b4afd158076d63aac75e1014071ee340da12b (patch)
tree5cdcfd59d8f72808d9b8228ce79355208097c08f /src/leap/util/privilege_policies.py
parentdf200f6379608b379c5fec47ddb030b6d72ce93a (diff)
Add check for outdated polkit file. Closes #3209.
Diffstat (limited to 'src/leap/util/privilege_policies.py')
-rw-r--r--src/leap/util/privilege_policies.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/leap/util/privilege_policies.py b/src/leap/util/privilege_policies.py
index 05ae60e0..72442553 100644
--- a/src/leap/util/privilege_policies.py
+++ b/src/leap/util/privilege_policies.py
@@ -87,6 +87,25 @@ def get_policy_contents(openvpn_path):
return POLICY_TEMPLATE.format(path=openvpn_path)
+def is_policy_outdated(path):
+ """
+ Returns if the existing polkit file is outdated, comparing if the path
+ is correct.
+
+ :param path: the path that should have the polkit file.
+ :type path: str.
+ :rtype: bool
+ """
+ _system = platform.system()
+ platform_checker = _system + "PolicyChecker"
+ policy_checker = globals().get(platform_checker, None)
+ if policy_checker is None:
+ logger.debug("we could not find a policy checker implementation "
+ "for %s" % (_system,))
+ return False
+ return policy_checker().is_outdated(path)
+
+
class PolicyChecker:
"""
Abstract PolicyChecker class
@@ -129,3 +148,22 @@ class LinuxPolicyChecker(PolicyChecker):
:rtype: bool
"""
return not os.path.isfile(self.LINUX_POLKIT_FILE)
+
+ def is_outdated(self, path):
+ """
+ Returns if the existing polkit file is outdated, comparing if the path
+ is correct.
+
+ :param path: the path that should have the polkit file.
+ :type path: str.
+ :rtype: bool
+ """
+ polkit = None
+ try:
+ with open(self.LINUX_POLKIT_FILE) as f:
+ polkit = f.read()
+ except IOError, e:
+ logger.error("Error reading polkit file(%s): %r" % (
+ self.LINUX_POLKIT_FILE, e))
+
+ return get_policy_contents(path) != polkit