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
29 changes: 29 additions & 0 deletions src/greeter/greeterproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ void GreeterProxy::setLock(bool isLocked)
setShowShutdownView(false);
}

void GreeterProxy::beginAuthentication(const QString &user)
{
m_authenticationUser = user;
Q_EMIT authPendingChanged();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pending 只有 4 个出口(disconnected / error / LoginFailed / 匹配用户的 UserActivateMessage),既没有超时,也没有「greeter 重新出现」时的重置。而 ddm 侧现在仍有静默丢弃的路径,linuxdeepin/ddm master src/daemon/Display.cpp:286:

if (auth->authenticated) {
    qWarning() << "Existing authentication ongoing, aborting";
    return;   // 不给 greeter 回包
}

你在 12:48 的回复里把它的触发条件定位成「treeland 重启 + 旧会话仍存活」,并靠 linuxdeepin/ddm#123 修掉——但那个 PR 目前还是 open。在这条路径命中期间:

  • 改之前:Login 被 ddm 静默吞掉,界面只是「点了没反应」,用户再点一次即可;
  • 改之后:m_authenticationUser 永远非空 → 密码框和登录按钮永久灰掉 → 用户只能重启或切 VT。

这个不对称值得用一行兜底挡住(进入新一轮 greeter 会话时不可能有合法在途请求):

void GreeterProxy::lock()
{
    // 卡死的 pending 不能带进新一轮锁屏/登录
    finishAuthentication();
    ...
}

ShowGreeter / SwitchToGreeter 分支同理。更彻底的做法是超时(仿 m_undecidedTimer:超时后 finishAuthentication() + 一条提示),但一行重置已经能把「永久锁死」降级成「重进一次锁屏就好」。

另外 ddm 那个分支本身建议改成 Q_EMIT loginFailed(socket, user),可以并进你已有的那个 ddm PR——客户端的状态永远只是 ddm 回包契约的镜像,契约有洞时客户端只能自保。

}

void GreeterProxy::finishAuthentication()
{
if (!authPending())
return;

m_authenticationUser.clear();
Q_EMIT authPendingChanged();
}

///////////
// Slots //
///////////
Expand Down Expand Up @@ -227,6 +242,9 @@ void GreeterProxy::hybridSleep()

void GreeterProxy::login(const QString &user, const QString &password, const int sessionIndex)
{
if (authPending())
return;

if (!m_socket->isValid()) {
qCDebug(lcTlGreeter) << "Socket is not valid. Local password check.";
if (localValidation(user, password)) {
Expand All @@ -243,11 +261,15 @@ void GreeterProxy::login(const QString &user, const QString &password, const int
// send command to the daemon
QString name = sessionModel()->data(index, SessionModel::FileRole).toString();
qCInfo(lcTlGreeter) << "Logging user" << user << "in with session" << name;
beginAuthentication(user);
SocketWriter(m_socket) << quint32(GreeterMessages::Login) << user << password << name;
}

void GreeterProxy::unlock(const QString &user, const QString &password)
{
if (authPending())
return;

if (!m_socket->isValid()) {
qCDebug(lcTlGreeter) << "Socket is not valid. Local password check.";
if (localValidation(user, password)) {
Expand All @@ -261,6 +283,7 @@ void GreeterProxy::unlock(const QString &user, const QString &password)
auto userInfo = userModel()->get(user);
if (userInfo.isValid()) {
qCInfo(lcTlGreeter) << "Unlocking user" << user;
beginAuthentication(user);
SocketWriter(m_socket) << quint32(GreeterMessages::Unlock) << user << password;
}
}
Expand Down Expand Up @@ -469,12 +492,14 @@ void GreeterProxy::disconnected()
{
qCWarning(lcTlGreeter) << "Disconnected from the ddm";

finishAuthentication();
Q_EMIT socketDisconnected();
}

void GreeterProxy::error()
{
qCCritical(lcTlGreeter) << "Socket error: " << m_socket->errorString();
finishAuthentication();
}

void GreeterProxy::readyRead()
Expand Down Expand Up @@ -556,6 +581,7 @@ void GreeterProxy::readyRead()

qCDebug(lcTlGreeter) << "Message received from daemon: LoginFailed" << user;

finishAuthentication();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

两处清理的判据不一致:UserActivateMessage 会比较 user == m_authenticationUser(:621),这里不比对就直接清。

考虑到 TreelandDisplayServer::onLoginFailed() 是向所有 greeter socket 广播,而 greeter 侧一次只可能有一笔在途请求,无条件清其实是更安全的选择(反过来会导致用户名形态不一致时卡死),所以行为我不反对。建议补一行注释说明是有意为之(「任何失败回执都视为本轮结束,不比对用户名」),否则下次有人看到 :621 的比对,会以为这里漏了判断。

Q_EMIT failedAttemptsChanged(++m_failedAttempts);
} break;
case DaemonMessages::InformationMessage: {
Expand Down Expand Up @@ -592,6 +618,9 @@ void GreeterProxy::readyRead()
if (!input.commitTransaction())
return;

if (user == m_authenticationUser)
finishAuthentication();

// NOTE: maybe DDM will active dde user.
if (!userModel()->getUser(user)) {
qCInfo(lcTlGreeter) << "activate user, but switch to greeter";
Expand Down
23 changes: 23 additions & 0 deletions src/greeter/greeterproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class GreeterProxy
Q_PROPERTY(bool isLocked READ isLocked NOTIFY lockChanged)
Q_PROPERTY(bool undecided READ undecided NOTIFY undecidedChanged)
Q_PROPERTY(int failedAttempts READ failedAttempts NOTIFY failedAttemptsChanged)
Q_PROPERTY(bool authPending READ authPending NOTIFY authPendingChanged)
Q_PROPERTY(bool showShutdownView READ showShutdownView WRITE setShowShutdownView NOTIFY showShutdownViewChanged)
Q_PROPERTY(bool showAnimation READ showAnimation NOTIFY showAnimationChanged)
Q_PROPERTY(bool hasActiveSession READ hasActiveSession NOTIFY hasActiveSessionChanged)
Expand Down Expand Up @@ -114,6 +115,14 @@ class GreeterProxy
*/
inline int failedAttempts() const { return m_failedAttempts; };

/**
* @brief Get whether DDM authentication is pending
* QML uses this property to disable the password field and login buttons.
*
* @return true if a login or unlock request is awaiting a result
*/
inline bool authPending() const { return !m_authenticationUser.isEmpty(); };

/**
* @brief Get whether the shutdown view is shown
* QML elements should listen to this property to show/hide the shutdown view
Expand Down Expand Up @@ -296,6 +305,9 @@ private Q_SLOTS:
/** @brief Emitted when failed attempts changes. See failedAttempts() */
void failedAttemptsChanged (int failedAttempts);

/** @brief Emitted when the authentication pending state changes. See authPending() */
void authPendingChanged();

/** @brief Emitted when showShutdownView changes. See showShutdownView() */
void showShutdownViewChanged (bool showShutdownView);

Expand All @@ -321,6 +333,16 @@ private Q_SLOTS:
*/
void setLock(bool isLocked);

/**
* @brief Start waiting for the given user's authentication result.
*
* @param user Username submitted in the login or unlock request
*/
void beginAuthentication(const QString &user);

/** @brief Clear the pending authentication request, if any. */
void finishAuthentication();

/**
* @brief Update the DDM communication socket
*/
Expand All @@ -346,6 +368,7 @@ private Q_SLOTS:
bool m_undecided { true };
QTimer *m_undecidedTimer{ nullptr };
int m_failedAttempts { 0 };
QString m_authenticationUser;
bool m_showShutdownView { false };
bool m_showAnimation { true };
bool m_hasActiveSession { false };
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/lockscreen/qml/UserInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Item {
width: loginGroup.width
height: 30
anchors.horizontalCenter: parent.horizontalCenter
enabled: !GreeterProxy.authPending

TextField {
id: passwordField
Expand Down Expand Up @@ -271,7 +272,7 @@ Item {
bottom: userCol.bottom
leftMargin: 20
}
enabled: passwordField.length != 0
enabled: passwordField.length != 0 && !GreeterProxy.authPending
font: D.DTK.fontManager.t8
background: RoundBlur {
anchors.fill: parent
Expand Down Expand Up @@ -398,6 +399,9 @@ Item {
}

function userLogin() {
if (!loginGroup.noPasswdLogin && passwordField.length === 0)
return

let user = UserModel.get(UserModel.currentUserName)
let pwd = loginGroup.noPasswdLogin ? "" : passwordField.text
Comment thread
gugullll marked this conversation as resolved.
Resolved
if (user.loggedIn)
Expand Down
Loading