diff options
author | Kali Kaneko <kali@leap.se> | 2015-01-08 14:34:13 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2015-01-08 14:34:13 -0400 |
commit | fdbfe431c52b2bc5a88a2328fe79de3035201099 (patch) | |
tree | 60d6af48f468f0dcd1922998e663f2273a55c41e /src/leap/bitmask/util/polkit_agent.py | |
parent | 77b576b58f7f533ff4f6a31594bb53d4ffad9d49 (diff) | |
parent | 54521d35d239c2e62d42e9c77690b9d1bc94f7db (diff) |
Merge branch 'release/0.8.x' into debian/experimental
Diffstat (limited to 'src/leap/bitmask/util/polkit_agent.py')
-rw-r--r-- | src/leap/bitmask/util/polkit_agent.py | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/src/leap/bitmask/util/polkit_agent.py b/src/leap/bitmask/util/polkit_agent.py index 7764f571..af5e431c 100644 --- a/src/leap/bitmask/util/polkit_agent.py +++ b/src/leap/bitmask/util/polkit_agent.py @@ -18,6 +18,7 @@ Daemonizes polkit authentication agent. """ import logging +import os import subprocess import daemon @@ -30,21 +31,52 @@ BASE_PATH_KDE = "/usr/lib/kde4/libexec/" GNO_PATH = BASE_PATH_GNO + AUTH_FILE % ("gnome",) KDE_PATH = BASE_PATH_KDE + AUTH_FILE % ("kde",) +POLKIT_PATHS = { + '/usr/lib/lxpolkit/lxpolkit', + '/usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1', + '/usr/lib/mate-polkit/polkit-mate-authentication-agent-1', + '/usr/lib/kde4/libexec/polkit-kde-authentication-agent-1', +} + + +def _get_polkit_agent(): + """ + Return a valid polkit agent to use. + + :rtype: str or None + """ + # TODO: in caso of having more than one polkit agent we may want to + # stablish priorities. E.g.: lxpolkit over gnome-polkit for minimalistic + # desktops. + 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: + logger.erro("No usable polkit was found.") + return + logger.debug('Launching polkit auth agent') try: - subprocess.call(GNO_PATH) - except Exception as exc: - logger.error('Exception while running polkit authentication agent ' - '%s' % (exc,)) # XXX fix KDE launch. See: #3755 - # try: - # subprocess.call(KDE_PATH) - # except Exception as exc: + subprocess.call(polkit_agent) + except Exception as e: + logger.error('Error launching polkit authentication agent %r' % (e, )) def launch(): + """ + Launch a polkit authentication agent as a daemon. + """ with daemon.DaemonContext(): _launch_agent() |