summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/vpn/helpers
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2018-01-18 15:37:18 +0100
committerKali Kaneko <kali@leap.se>2018-01-25 01:19:16 +0100
commitc3306592fbb54fab0da44a8faaa8a1c6954537fd (patch)
tree0a9b406f81d33af40e1e943f0e330c28b06eb9ed /src/leap/bitmask/vpn/helpers
parent276c717b0d1d662cabc117cea7373418efedde09 (diff)
[feat] report missing polkit properly from main UI
also refactor and move polkit_agent so that it does not depend on having bitmask on the path.
Diffstat (limited to 'src/leap/bitmask/vpn/helpers')
-rw-r--r--src/leap/bitmask/vpn/helpers/__init__.py17
-rw-r--r--src/leap/bitmask/vpn/helpers/linux/polkit_agent.py88
2 files changed, 16 insertions, 89 deletions
diff --git a/src/leap/bitmask/vpn/helpers/__init__.py b/src/leap/bitmask/vpn/helpers/__init__.py
index 8f8c1227..69b34e00 100644
--- a/src/leap/bitmask/vpn/helpers/__init__.py
+++ b/src/leap/bitmask/vpn/helpers/__init__.py
@@ -16,6 +16,7 @@ if IS_LINUX:
from leap.bitmask.vpn.constants import OPENVPN_SYSTEM, OPENVPN_LOCAL
from leap.bitmask.vpn.constants import POLKIT_SYSTEM, POLKIT_LOCAL
from leap.bitmask.vpn.privilege import is_pkexec_in_system
+ from leap.bitmask.vpn.privilege import LinuxPolicyChecker
def install():
helper_from = _config.get_bitmask_helper_path()
@@ -40,6 +41,17 @@ if IS_LINUX:
remove(POLKIT_LOCAL)
remove(OPENVPN_LOCAL)
+ def privcheck(timeout=5):
+ has_pkexec = is_pkexec_in_system()
+ running = LinuxPolicyChecker.is_up()
+ if not running:
+ try:
+ LinuxPolicyChecker.get_usable_pkexec(timeout=timeout)
+ running = LinuxPolicyChecker.is_up()
+ except Exception:
+ running = False
+ return has_pkexec and running
+
def check():
helper = _is_up_to_date(_config.get_bitmask_helper_path(),
BITMASK_ROOT_LOCAL,
@@ -51,7 +63,7 @@ if IS_LINUX:
_is_up_to_date(_config.get_bitmask_openvpn_path(),
OPENVPN_LOCAL, ""))
- return is_pkexec_in_system() and helper and polkit and openvpn
+ return helper and polkit and openvpn
def _is_up_to_date(src, local, system):
if src is None or not access(src, R_OK):
@@ -72,6 +84,9 @@ elif IS_MAC:
# XXX check if bitmask-helper is running
return True
+ def privcheck():
+ return True
+
def digest(path):
with open(path, 'r') as f:
diff --git a/src/leap/bitmask/vpn/helpers/linux/polkit_agent.py b/src/leap/bitmask/vpn/helpers/linux/polkit_agent.py
deleted file mode 100644
index 5ca1a2f0..00000000
--- a/src/leap/bitmask/vpn/helpers/linux/polkit_agent.py
+++ /dev/null
@@ -1,88 +0,0 @@
-# -*- coding: utf-8 -*-
-# polkit_agent.py
-# Copyright (C) 2013 LEAP
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-"""
-Daemonizes polkit authentication agent.
-"""
-
-import os
-import subprocess
-import sys
-
-import daemon
-
-
-POLKIT_PATHS = (
- '/usr/bin/lxpolkit',
- '/usr/bin/lxqt-policykit-agent',
- '/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1',
- '/usr/lib/x86_64-linux-gnu/polkit-mate/polkit-mate-authentication-agent-1',
- '/usr/lib/mate-polkit/polkit-mate-authentication-agent-1',
- '/usr/lib/x86_64-linux-gnu/libexec/polkit-kde-authentication-agent-1',
- '/usr/lib/kde4/libexec/polkit-kde-authentication-agent-1',
- # now we get weird
- '/usr/libexec/policykit-1-pantheon/pantheon-agent-polkit',
- '/usr/lib/polkit-1-dde/dde-polkit-agent',
- # do you know some we're still missing? :)
-)
-
-
-# TODO write tests for this piece.
-def _get_polkit_agent():
- """
- Return a valid polkit agent to use.
-
- :rtype: str or None
- """
- for polkit in POLKIT_PATHS:
- if os.path.isfile(polkit):
- return polkit
-
- return None
-
-
-def _launch_agent():
- """
- Launch a polkit authentication agent on a subprocess.
- """
- polkit_agent = _get_polkit_agent()
-
- if polkit_agent is None:
- print("No usable polkit was found.")
- return
-
- print('Launching polkit auth agent')
- try:
- # XXX fix KDE launch. See: #3755
- subprocess.call(polkit_agent)
- except Exception as e:
- print('Error launching polkit authentication agent %r' % (e, ))
-
-
-def launch():
- """
- Launch a polkit authentication agent as a daemon.
- """
- with daemon.DaemonContext():
- _launch_agent()
-
-
-if __name__ == "__main__":
- if '--nodaemon' in sys.argv:
- _launch_agent()
- else:
- launch()