diff options
author | Kali Kaneko (leap communications) <kali@leap.se> | 2017-05-31 17:45:53 +0200 |
---|---|---|
committer | Kali Kaneko (leap communications) <kali@leap.se> | 2017-05-31 18:51:24 +0200 |
commit | 59807917612e301ac37d59f0d4d832979316896c (patch) | |
tree | b2fb3fe513ee1ec6f002b660b842c2321c1469a2 /src/leap/bitmask/vpn | |
parent | 419828838991e3dfa447f3b29b37e5277052abb4 (diff) |
[feat] install installers directly if we are root
Diffstat (limited to 'src/leap/bitmask/vpn')
-rw-r--r-- | src/leap/bitmask/vpn/privilege.py | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/src/leap/bitmask/vpn/privilege.py b/src/leap/bitmask/vpn/privilege.py index 4617aedf..d918a30d 100644 --- a/src/leap/bitmask/vpn/privilege.py +++ b/src/leap/bitmask/vpn/privilege.py @@ -33,29 +33,43 @@ from twisted.python.procutils import which from leap.bitmask.util import STANDALONE, here +from .constants import IS_LINUX + log = Logger() -def install_helpers(): - cmd = 'bitmask_helpers install' - if STANDALONE: - binary_path = os.path.join(here(), "bitmask") - cmd = "%s %s" % (binary_path, cmd) +# TODO wrap the install/uninstall helper functions around the policychecker +# classes below. - # TODO check if the command has succeeded, and display error - # if failed - commands.getoutput('pkexec ' + cmd) +def install_helpers(): + if IS_LINUX: + cmd = 'bitmask_helpers install' + if STANDALONE: + binary_path = os.path.join(here(), "bitmask") + cmd = "%s %s" % (binary_path, cmd) + if os.getuid() != 0: + cmd = 'pkexec ' + cmd + retcode, _ = commands.getstatusoutput(cmd) + if retcode != 0: + raise Exception('Could not install helpers') + else: + raise Exception('No install mechanism for this platform') def uninstall_helpers(): - cmd = 'bitmask_helpers uninstall' - if STANDALONE: - binary_path = os.path.join(here(), "bitmask") - cmd = "%s %s" % (binary_path, cmd) - - # TODO check if the command has succeeded, and display error - # if failed - commands.getoutput('pkexec ' + cmd) + if IS_LINUX: + cmd = 'bitmask_helpers uninstall' + if STANDALONE: + binary_path = os.path.join(here(), "bitmask") + cmd = "%s %s" % (binary_path, cmd) + if os.getuid() != 0: + cmd = 'pkexec ' + cmd + retcode, _ = commands.getstatusoutput(cmd) + commands.getoutput('pkexec ' + cmd) + if retcode != 0: + raise Exception('Could not uninstall helpers') + else: + raise Exception('No install mechanism for this platform') class NoPolkitAuthAgentAvailable(Exception): @@ -66,6 +80,7 @@ class NoPkexecAvailable(Exception): message = 'Could not find pkexec in the system' +# TODO rename to privileged_runner or something like that def is_missing_policy_permissions(): """ Returns True if we do not have implemented a policy checker for this @@ -169,7 +184,7 @@ class LinuxPolicyChecker(PolicyChecker): @classmethod def launch(self): """ - Tries to launch policykit. + Tries to launch polkit agent. """ if not self.is_up(): try: @@ -196,7 +211,7 @@ class LinuxPolicyChecker(PolicyChecker): # polkit-agent, it uses a polkit-agent within its own process so we # can't ps-grep a polkit process, we can ps-grep gnome-shell itself. - # the [x] thing is to avoid grep match itself + # the square brackets are to avoid grep match itself polkit_options = [ 'ps aux | grep "polkit-[g]nome-authentication-agent-1"', 'ps aux | grep "polkit-[k]de-authentication-agent-1"', |