Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ tests/report/*
.cursor/
# for snipe
src/global_util/dbus/*
obj-x86_64-linux-gnu/
.debhelper/
.codegraph/
8 changes: 8 additions & 0 deletions misc/images/remote_login.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<file>misc/images/login_wait.svg</file>
<file>misc/images/password_hint.svg</file>
<file>misc/images/select.svg</file>
<file>misc/images/remote_login.svg</file>
<file>misc/images/auth/face.svg</file>
<file>misc/images/auth/passkey.svg</file>
<file>misc/images/auth/fingerprint.svg</file>
Expand Down
13 changes: 13 additions & 0 deletions src/app/lightdm-deepin-greeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "sessionbasemodel.h"
#include "public_func.h"
#include "plugin_manager.h"
#include "fullscreenbackground.h"
#include "warningcontent.h"

#ifndef ENABLE_DSS_SNIPE
#include <dde-api/eventlogger.hpp>
Expand Down Expand Up @@ -143,11 +145,22 @@ int main(int argc, char* argv[])

// 初始化LoginContent
LoginContent::instance()->init(model);
WarningContent::instance()->setModel(model);
QObject::connect(LoginContent::instance(), &LoginContent::requestSwitchToUser, worker, &GreeterWorker::switchToUser);
QObject::connect(LoginContent::instance(), &LoginContent::requestSetLayout, worker, &GreeterWorker::setKeyboardLayout);
QObject::connect(LoginContent::instance(), &LoginContent::requestCheckAccount, worker, &GreeterWorker::checkAccount);
QObject::connect(LoginContent::instance(), &LoginContent::requestCheckSameNameAccount, worker, &GreeterWorker::checkSameNameAccount);
QObject::connect(worker, &GreeterWorker::requestShowUsersWithTheSameName, LoginContent::instance(), &LoginContent::showUsersWithTheSameName);
QObject::connect(worker, &GreeterWorker::requestShowActiveSessionConfirm, WarningContent::instance(), &WarningContent::showActiveSessionConfirm);
QObject::connect(worker, &GreeterWorker::requestShowActiveSessionLoading, WarningContent::instance(), &WarningContent::showActiveSessionLoading);
QObject::connect(worker, &GreeterWorker::requestHideActiveSessionOverlay, WarningContent::instance(), &WarningContent::hideActiveSessionOverlay);
QObject::connect(worker, &GreeterWorker::requestShowRemoteUserLimitMessage, WarningContent::instance(), &WarningContent::showRemoteUserLimitMessage);
QObject::connect(WarningContent::instance(), &WarningContent::requestActiveSessionOverlayHide, LoginContent::instance(), [model] {
FullScreenBackground::setContent(LoginContent::instance());
model->setCurrentContentType(SessionBaseModel::LockContent);
});
QObject::connect(WarningContent::instance(), &WarningContent::activeSessionConfirmAccepted, worker, &GreeterWorker::onActiveSessionConfirmAccepted);
QObject::connect(WarningContent::instance(), &WarningContent::activeSessionConfirmCanceled, worker, &GreeterWorker::onActiveSessionConfirmCanceled);
QObject::connect(LoginContent::instance(), &LoginContent::requestStartAuthentication, worker, &GreeterWorker::startAuthentication);
QObject::connect(LoginContent::instance(), &LoginContent::sendTokenToAuth, worker, &GreeterWorker::sendTokenToAuth);
QObject::connect(LoginContent::instance(), &LoginContent::requestEndAuthentication, worker, &GreeterWorker::endAuthentication);
Expand Down
3 changes: 2 additions & 1 deletion src/dde-lock/lockworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "lockworker.h"

#include "authcommon.h"
#include "sessionconflict.h"
#include "sessionbasemodel.h"
#include "userinfo.h"
#include "login_plugin_util.h"
Expand Down Expand Up @@ -892,7 +893,7 @@ void LockWorker::switchToUser(std::shared_ptr<User> user)
* 当前用户界面还未更新完成,已经切换为下一用户界面了,导致切换回来时,闪现用户列表。
* 故使用 QTimer 将切换用户的操作放在事件队列最后处理。
*/
if (user->isLogin()) {
if (user->isLogin() && !SessionConflict::hasActiveSessionConflict(m_login1Inter, user->name())) {
QTimer::singleShot(0, this, [user] {
QProcess::startDetached("dde-switchtogreeter", QStringList() << user->name());
});
Expand Down
8 changes: 4 additions & 4 deletions src/global_util/dbus/dbusvariant.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2015 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2015-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -90,7 +90,7 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, SeatInfo &obj)
}

SessionInfo::SessionInfo()
: pid(-1)
: uid(-1)
{
}
SessionInfo::~SessionInfo() {}
Expand All @@ -105,15 +105,15 @@ void SessionInfo::registerMetaType() {
QDBusArgument &operator<<(QDBusArgument &argument, const SessionInfo &obj)
{
argument.beginStructure();
argument << obj.session << obj.pid << obj.user << obj.id << obj.seat;
argument << obj.session << obj.uid << obj.user << obj.seat << obj.path;
argument.endStructure();
return argument;
}

const QDBusArgument &operator>>(const QDBusArgument &argument, SessionInfo &obj)
{
argument.beginStructure();
argument >> obj.session >> obj.pid >> obj.user >> obj.id >> obj.seat;
argument >> obj.session >> obj.uid >> obj.user >> obj.seat >> obj.path;
argument.endStructure();
return argument;
}
7 changes: 3 additions & 4 deletions src/global_util/dbus/dbusvariant.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2015 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2015-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -56,10 +56,10 @@ class SeatInfo {
class SessionInfo {
public:
QString session;
qlonglong pid;
quint32 uid;
QString user;
QString id;
QString seat;
QDBusObjectPath path;

SessionInfo();
~SessionInfo();
Expand Down Expand Up @@ -87,4 +87,3 @@ typedef QList<SessionInfo> SessionList;
Q_DECLARE_METATYPE(SessionInfo)
Q_DECLARE_METATYPE(SessionList)
#endif // DBUSVARIANT

166 changes: 166 additions & 0 deletions src/global_util/sessionconflict.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "sessionconflict.h"

#include "constants.h"
#include "dbusvariant.h"

#include <QDBusInterface>
#include <QSet>

namespace {

bool isGraphicalSessionType(const QString &type)
{
return type == QLatin1String("x11") || type == QLatin1String("wayland") || type == QLatin1String("mir");
}

// 真实远程用户会话由 lightdm 启动,service 为 "lightdm";
// greeter 登录界面的 service 是 "lightdm-greeter",不计入远程用户。
bool isLightdmService(const QString &service)
{
return service == QLatin1String("lightdm");
}

QVariant sessionProperty(const QString &sessionPath, const QString &name)
{
QDBusInterface props("org.freedesktop.login1", sessionPath, "org.freedesktop.DBus.Properties",
QDBusConnection::systemBus());
QDBusReply<QVariant> reply = props.call("Get", "org.freedesktop.login1.Session", name);
if (!reply.isValid()) {
return QVariant();
}
return reply.value();
}

} // namespace

bool SessionConflict::isCurrentSessionRemote(DBusLogin1Manager *login1Inter)
{
static QPair<bool, bool> cached {false, false}; // <query succeeded, is remote>
if (cached.first) {
return cached.second;
}

if (login1Inter == nullptr || !login1Inter->isValid()) {
qCWarning(DDE_SHELL) << "Login1 not available, treat current session as local";
return false;
}

QDBusPendingReply<QDBusObjectPath> sessionReply = login1Inter->GetSessionByPID(0);
sessionReply.waitForFinished();
if (!sessionReply.isValid()) {
return false;
}

const QVariant remote = sessionProperty(sessionReply.value().path(), QStringLiteral("Remote"));
if (!remote.isValid()) {
qCWarning(DDE_SHELL) << "Failed to read current session Remote property";
return false;
}

cached.first = true;
cached.second = remote.toBool();
return cached.second;
}

bool SessionConflict::hasActiveSessionConflict(DBusLogin1Manager *login1Inter, const QString &username)
{
if (username.isEmpty() || username == "..." || login1Inter == nullptr || !login1Inter->isValid()) {
qCWarning(DDE_SHELL) << "Login1 not available, skip active session check";
return false;
}

const bool currentRemote = isCurrentSessionRemote(login1Inter);
qCInfo(DDE_SHELL) << "Checking active session conflicts, current remote:" << currentRemote;
QDBusPendingReply<SessionList> reply = login1Inter->ListSessions();
reply.waitForFinished();
if (!reply.isValid()) {
qCWarning(DDE_SHELL) << "ListSessions failed:" << reply.error().message();
return false;
}

const SessionList sessions = reply.value();
for (const SessionInfo &info : sessions) {
if (info.user != username) {
continue;
}

QDBusPendingReply<QDBusObjectPath> sessionReply = login1Inter->GetSession(info.session);
sessionReply.waitForFinished();
if (!sessionReply.isValid()) {
continue;
}

const QString sessionPath = sessionReply.value().path();
const QVariant type = sessionProperty(sessionPath, QStringLiteral("Type"));
const QVariant remote = sessionProperty(sessionPath, QStringLiteral("Remote"));
if (!type.isValid() || !remote.isValid()) {
continue;
}

const QString typeValue = type.toString();
if (!isGraphicalSessionType(typeValue)) {
continue;
}

const bool remoteValue = remote.toBool();
qCInfo(DDE_SHELL) << "Found session for user" << username << ", type:" << typeValue << ", remote:" << remoteValue;
if ((currentRemote && !remoteValue) || (!currentRemote && remoteValue)) {
return true;
}
}

return false;
}

int SessionConflict::countActiveRemoteUsers(DBusLogin1Manager *login1Inter, const QString &excludeUsername)
{
if (login1Inter == nullptr || !login1Inter->isValid()) {
qCWarning(DDE_SHELL) << "Login1 not available, skip remote user count";
return 0;
}

QDBusPendingReply<SessionList> reply = login1Inter->ListSessions();
reply.waitForFinished();
if (!reply.isValid()) {
qCWarning(DDE_SHELL) << "ListSessions failed:" << reply.error().message();
return 0;
}

QSet<QString> remoteUsers;
const SessionList sessions = reply.value();
for (const SessionInfo &info : sessions) {
if (info.user.isEmpty() || info.user == excludeUsername) {
continue;
}

QDBusPendingReply<QDBusObjectPath> sessionReply = login1Inter->GetSession(info.session);
sessionReply.waitForFinished();
if (!sessionReply.isValid()) {
continue;
}

const QString sessionPath = sessionReply.value().path();
const QVariant remote = sessionProperty(sessionPath, QStringLiteral("Remote"));
const QVariant service = sessionProperty(sessionPath, QStringLiteral("Service"));
if (!remote.isValid() || !service.isValid()) {
continue;
}

if (!remote.toBool()) {
continue;
}
if (!isLightdmService(service.toString())) {
continue;
}

remoteUsers.insert(info.user);
}

qCInfo(DDE_SHELL) << "Active remote users count:" << remoteUsers.size()
<< ", excluding:" << excludeUsername;
return remoteUsers.size();
}
19 changes: 19 additions & 0 deletions src/global_util/sessionconflict.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef SESSIONCONFLICT_H
#define SESSIONCONFLICT_H

#include "dbuslogin1manager.h"

#include <QString>

namespace SessionConflict {
constexpr int kMaxRemoteLoginUsers = 2;
bool isCurrentSessionRemote(DBusLogin1Manager *login1Inter);
bool hasActiveSessionConflict(DBusLogin1Manager *login1Inter, const QString &username);
int countActiveRemoteUsers(DBusLogin1Manager *login1Inter, const QString &excludeUsername);
}

#endif // SESSIONCONFLICT_H
Loading
Loading