summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2017-08-22 19:13:08 +0200
committerRuben Pollan <meskio@sindominio.net>2017-09-15 23:40:03 +0200
commit9360b8fadc0124bbc545f293312477f290101885 (patch)
treeb392b956fbc5aebab7a4e898c11e4a8e13c24456
parent0ca001c29e6ce7ab9de76639ef93bda79af51504 (diff)
[feat] use psutil to discover polkit process
Better psutil than ps+grep.
-rw-r--r--src/leap/bitmask/vpn/privilege.py33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/leap/bitmask/vpn/privilege.py b/src/leap/bitmask/vpn/privilege.py
index 3fe693e..beb843e 100644
--- a/src/leap/bitmask/vpn/privilege.py
+++ b/src/leap/bitmask/vpn/privilege.py
@@ -24,6 +24,7 @@ import commands
import os
import subprocess
import platform
+import psutil
import time
from abc import ABCMeta, abstractmethod
@@ -209,20 +210,24 @@ 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 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"',
- 'ps aux | grep "polkit-[m]ate-authentication-agent-1"',
- 'ps aux | grep "[l]xpolkit"',
- 'ps aux | grep "[l]xsession"',
- 'ps aux | grep "[g]nome-shell"',
- 'ps aux | grep "[f]ingerprint-polkit-agent"',
- 'ps aux | grep "[x]fce-polkit"',
- ]
- is_running = [commands.getoutput(cmd) for cmd in polkit_options]
-
- return any(is_running)
+ polkit_options = (
+ 'polkit-gnome-authentication-agent-1',
+ 'polkit-kde-authentication-agent-1',
+ 'polkit-mate-authentication-agent-1',
+ 'lxpolkit',
+ 'lxsession',
+ 'gnome-shell',
+ 'fingerprint-polkit-agent',
+ 'xfce-polkit',
+ )
+
+ is_running = False
+ for proc in psutil.process_iter():
+ if any((polkit in proc.name() for polkit in polkit_options)):
+ is_running = True
+ break
+
+ return is_running
@classmethod
def _is_pkexec_in_system(self):