summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/bitmask/services/eip/vpnlaunchers.py25
-rw-r--r--src/leap/bitmask/util/polkit_agent.py52
2 files changed, 65 insertions, 12 deletions
diff --git a/src/leap/bitmask/services/eip/vpnlaunchers.py b/src/leap/bitmask/services/eip/vpnlaunchers.py
index a9213a9a..49edc8eb 100644
--- a/src/leap/bitmask/services/eip/vpnlaunchers.py
+++ b/src/leap/bitmask/services/eip/vpnlaunchers.py
@@ -23,8 +23,8 @@ import logging
import getpass
import os
import platform
-import subprocess
import stat
+import subprocess
try:
import grp
except ImportError:
@@ -34,6 +34,7 @@ from abc import ABCMeta, abstractmethod
from functools import partial
from leap.bitmask.config.leapsettings import LeapSettings
+
from leap.bitmask.config.providerconfig import ProviderConfig
from leap.bitmask.services.eip.eipconfig import EIPConfig, VPNGatewaySelector
from leap.bitmask.util import first
@@ -218,19 +219,19 @@ def _is_auth_agent_running():
return any(is_running)
-def _try_to_launch_agent():
+def _try_to_launch_agent(standalone=False):
"""
Tries to launch a polkit daemon.
"""
- opts = [
- "/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1",
- # XXX add kde thing here
- ]
- for cmd in opts:
- try:
- subprocess.Popen([cmd], shell=True)
- except:
- pass
+ env = None
+ if standalone is True:
+ env = {
+ "PYTHONPATH": os.path.abspath('../../../../lib/')}
+ try:
+ subprocess.call(["python", "-m", "leap.bitmask.util.polkit_agent"],
+ shell=True, env=env)
+ except Exception as exc:
+ logger.exception(exc)
class LinuxVPNLauncher(VPNLauncher):
@@ -314,7 +315,7 @@ class LinuxVPNLauncher(VPNLauncher):
"""
if _is_pkexec_in_system():
if not _is_auth_agent_running():
- _try_to_launch_agent()
+ _try_to_launch_agent(ProviderConfig.standalone)
if _is_auth_agent_running():
pkexec_possibilities = which(kls.PKEXEC_BIN)
leap_assert(len(pkexec_possibilities) > 0,
diff --git a/src/leap/bitmask/util/polkit_agent.py b/src/leap/bitmask/util/polkit_agent.py
new file mode 100644
index 00000000..a4650273
--- /dev/null
+++ b/src/leap/bitmask/util/polkit_agent.py
@@ -0,0 +1,52 @@
+# -*- 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 logging
+import subprocess
+
+import daemon
+
+logger = logging.getLogger(__name__)
+
+BASE_PATH = "/usr/lib/policykit-1-gnome/"\
+ + "polkit-%s-authentication-agent-1"
+
+GNOME_PATH = BASE_PATH % ("gnome",)
+KDE_PATH = BASE_PATH % ("kde",)
+
+
+def _launch_agent():
+ logger.debug('Launching polkit auth agent')
+ print "launching polkit"
+ try:
+ subprocess.call(GNOME_PATH)
+ except Exception as exc:
+ try:
+ subprocess.call(KDE_PATH)
+ except Exception as exc:
+ logger.error('Exception while running polkit authentication agent '
+ '%s' % (exc,))
+
+
+def launch():
+ with daemon.DaemonContext():
+ _launch_agent()
+
+if __name__ == "__main__":
+ launch()