summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/vpn
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2017-05-31 18:00:48 +0200
committerKali Kaneko (leap communications) <kali@leap.se>2017-05-31 18:53:42 +0200
commit72d93a61cf9aff5996952d55e56981eb5a22d989 (patch)
tree6b36868fdb46132c413c6fbcfe72f20d3df3fc79 /src/leap/bitmask/vpn
parent59807917612e301ac37d59f0d4d832979316896c (diff)
[refactor] factor out installer function
Diffstat (limited to 'src/leap/bitmask/vpn')
-rw-r--r--src/leap/bitmask/vpn/helpers/__init__.py7
-rw-r--r--src/leap/bitmask/vpn/privilege.py24
2 files changed, 15 insertions, 16 deletions
diff --git a/src/leap/bitmask/vpn/helpers/__init__.py b/src/leap/bitmask/vpn/helpers/__init__.py
index 3b7e117..f57bd7f 100644
--- a/src/leap/bitmask/vpn/helpers/__init__.py
+++ b/src/leap/bitmask/vpn/helpers/__init__.py
@@ -6,6 +6,8 @@ import sys
from leap.bitmask.vpn.constants import IS_LINUX
from leap.bitmask.vpn import _config
+from leap.bitmask.util import STANDALONE
+
if IS_LINUX:
helper_to = '/usr/local/sbin/bitmask-root'
@@ -22,8 +24,9 @@ if IS_LINUX:
copyfile(polkit_from, polkit_to)
- copyfile(openvpn_from, openvpn_to)
- chmod(openvpn_to, 0700)
+ if STANDALONE:
+ copyfile(openvpn_from, openvpn_to)
+ chmod(openvpn_to, 0700)
def uninstall():
remove(helper_to)
diff --git a/src/leap/bitmask/vpn/privilege.py b/src/leap/bitmask/vpn/privilege.py
index d918a30..c7cf119 100644
--- a/src/leap/bitmask/vpn/privilege.py
+++ b/src/leap/bitmask/vpn/privilege.py
@@ -41,31 +41,27 @@ log = Logger()
# TODO wrap the install/uninstall helper functions around the policychecker
# classes below.
+
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')
+ _helper_installer('install')
def uninstall_helpers():
+ _helper_installer('uninstall')
+
+
+def _helper_installer(action):
+ if action not in ('install', 'uninstall'):
+ raise Exception('Wrong action: %s' % action)
+
if IS_LINUX:
- cmd = 'bitmask_helpers uninstall'
+ cmd = 'bitmask_helpers ' + action
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: