From b7f2fd7399a258d008de66af4c295f8ab2549d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B8=D1=80=D0=B5=D1=86=D0=BA=D0=B8=D0=B9=20=D0=9C?= =?UTF-8?q?=D0=B8=D1=85=D0=B0=D0=B8=D0=BB?= Date: Tue, 4 Aug 2020 11:02:06 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B2=D1=8B=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B8=20=D1=81=D0=B5=D1=81=D1=81=D0=B8=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20elogind?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/desktop/desktop.py | 31 +++++++++++++++++++++++++++++++ pym/desktop/variables/desktop.py | 16 ++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/pym/desktop/desktop.py b/pym/desktop/desktop.py index ebf69ad..600a9c0 100644 --- a/pym/desktop/desktop.py +++ b/pym/desktop/desktop.py @@ -261,6 +261,37 @@ class Desktop(MethodsInterface): return False def userLogout(self, urLogin): + if self.clVars.GetBool('cl_desktop_elogind_set'): + return self.userLogoutByElogind(urLogin) + else: + return self.userLogoutBySession(urLogin) + + def getElogindSessionId(self, urLogin): + loginctl = getProgPath("/bin/loginctl") + p = process(loginctl, "--no-legend") + try: + for line in p: + cols = [x.strip() for x in line.split()] + if len(cols) >= 3: + sessionid, uid, username = cols[:3] + if username == urLogin: + return sessionid + finally: + p.close() + return None + + def terminateUserSession(self, session_id): + loginctl = getProgPath("/bin/loginctl") + p = process(loginctl, "terminate-session", session_id) + return p.success() + + def userLogoutByElogind(self, urLogin): + elogin_session_id = self.getElogindSessionId(urLogin) + if not elogin_session_id: + raise DesktopError(_("Unable to detect user session id")) + return self.terminateUserSession(elogin_session_id) + + def userLogoutBySession(self, urLogin): """ Выполнить logout пользователя через dbus """ diff --git a/pym/desktop/variables/desktop.py b/pym/desktop/variables/desktop.py index 86f7a36..0628c14 100644 --- a/pym/desktop/variables/desktop.py +++ b/pym/desktop/variables/desktop.py @@ -32,6 +32,7 @@ from itertools import * import glob from calculate.lib.cl_template import templateFunction from calculate.lib.cl_ini_parser import iniParser +from calculate.lib.utils.portage import isPkgInstalled import hashlib from calculate.lib.cl_lang import setLocalTranslate @@ -474,3 +475,18 @@ class VariableClDesktopFastloginPath(ReadonlyVariable): Путь до каталога в котором указаны пользователи быстрого входа в сеанс """ value = "/var/lib/calculate/calculate-desktop/fastlogin" + + +class VariableClDesktopElogindSet(ReadonlyVariable): + """ + В системе используется elogind + """ + type = Variable.Types.Boolean + elogind = "sys-auth/elogind" + consolekit = "sys-auth/consolekit" + + def get(self): + if isPkgInstalled(self.elogind) and \ + not isPkgInstalled(self.consolekit): + return Variable.On + return Variable.Off