Repository navigation
fix: login fails after retrying with the correct password - #1639
Conversation
Reviewer's GuideData structuresAdd the stored pending-user state and expose its authentication-pending property and notification for the greeter UI.
ImplementationSerialize login and unlock requests, track the submitted user, and clear pending state on authentication failure, socket errors or disconnect, or activation of that user.
UIDisable the password field and login button while authentication is pending, and ignore empty passwords for accounts that require one while retaining passwordless login.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/plugins/lockscreen/qml/UserInput.qml" line_range="408" />
<code_context>
+
let user = UserModel.get(UserModel.currentUserName)
let pwd = loginGroup.noPasswdLogin ? "" : passwordField.text
+ loginGroup.authenticationPending = true
if (user.loggedIn)
GreeterProxy.unlock(user.name, pwd)
</code_context>
<issue_to_address>
**Lock-screen retries stay blocked**
When the service stays connected without returning a result, a socket error occurs without a disconnect, or an initial login succeeds while `GreeterProxy` is not locked and the same view is reused, `authenticationPending` is cleared only by `failedAttemptsChanged` and `socketDisconnected`; in these cases it stays true, so later `userLogin()` calls are ignored and the user cannot retry or unlock.
Clear `authenticationPending` on every authentication success and failure, and provide a reset path for timeouts and socket errors that do not disconnect.
</issue_to_address>95deb3e to
746687d
Compare
746687d to
3d16e10
Compare
Groveer
left a comment
There was a problem hiding this comment.
整体方向没问题(一次只挂一笔 DDM 认证请求 + 等待期间禁用输入),空密码的 guard 也有价值(空密码会让 PAM 返回失败,从而误报“密码错误”并累加 failedAttempts)。几点建议,主要是状态表达可以更准和pending 卡死的兜底:
user != "dde"换成“消息里的 user 是否就是本次请求的 user”,特例和 bool 成员一起消失。- 补 pending 的兜底:ddm 有“收下请求但不回复”的路径,一旦漏回复,输入控件会永久禁用(详见行内评论)。
- 丢弃重复请求补一行日志;守卫挪到发包前;
login()/unlock()收敛成beginAuthentication()/finishAuthentication()。 - QML 三处同款
enabled绑定收敛为一处;header 的 doc / 对齐按文件既有风格补齐。
改完大概是这个形状(本地改过一版验证:greeterproxy.cpp.o 过 -Wall -Wextra -Werror,qmllint 无语法错误):
bool GreeterProxy::beginAuthentication(const QString &user)
{
if (authenticationPending()) {
qCDebug(lcTlGreeter) << "Authentication for" << m_authenticationUser
<< "is still pending, ignore request for" << user;
return false;
}
m_authenticationUser = user;
Q_EMIT authenticationPendingChanged();
return true;
}
void GreeterProxy::finishAuthentication()
{
if (!authenticationPending())
return;
m_authenticationUser.clear();
Q_EMIT authenticationPendingChanged();
}// login(): 放在 socket 校验之后、发包之前
if (!beginAuthentication(user))
return;
// unlock()
if (userInfo.isValid() && beginAuthentication(user)) {
qCInfo(lcTlGreeter) << "Unlocking user" << user;
SocketWriter(m_socket) << quint32(GreeterMessages::Unlock) << user << password;
}
// LoginFailed / 断连 / error:finishAuthentication();
// UserActivateMessage:if (user == m_authenticationUser) finishAuthentication();这些都不阻塞合并,但第 2 点是会让用户彻底登不进去的回归风险,建议至少先把兜底加上。
1. Serialize DDM requests and disable the password field and login buttons while authentication is pending. 2. Track the submitted user and clear pending state on matching activation, authentication failure, socket error, or disconnect. 3. Skip empty password submissions for accounts that require a password. Log: Fix login failure when a correct password follows a wrong one. Influence: 1. Hold Enter or click repeatedly during unlock and verify one pending request. 2. Verify an activation for another user keeps the controls disabled. Retry with the correct password after a failed attempt. 3. Verify that empty input is ignored and passwordless login still works. fix: 输入错误密码后再输入正确密码登录失败 1. 逐次提交 DDM 认证请求,等待结果时禁用密码框和登录按钮。 2. 记录提交时的用户名,在该用户会话激活、认证失败、socket 报错或断开时结束等待。 3. 需要密码的账户在密码框为空时跳过提交。 Log: 输入错误密码后再输入正确密码登录失败 Influence: 1. 解锁时长按回车或连续点击,确认同时只有一笔请求在等待结果。 2. 等待期间收到其他用户的激活消息时确认控件仍禁用,认证失败后输入正确密码重试。 3. 确认普通密码框为空时不提交,免密账户仍可登录。 PMS: BUG-383137
3d16e10 to
0583711
Compare
deepin-wm
left a comment
There was a problem hiding this comment.
代码审查:fix: login fails after retrying with the correct password
结论:没有阻塞项,可以合并。 但我建议顺手补一处兜底,理由见第三节第 1 条——现在的写法一旦漏一条 DDM 回包,代价比原 bug 更重。
方向是对的:把「同时只挂一笔 DDM 认证请求」做成 GreeterProxy 里的显式状态,QML 只消费状态,比上一版用 bool + "dde" 特例干净得多。
审查范围:3 文件 / +57 −1,head 05837114c,base master。三个文件逐行过完,另外核对了 ddm 侧的回包契约(Display::login() / unlock()、TreelandDisplayServer::activateUser() / onLoginFailed())。
一、上一轮意见的落实情况
| 上轮意见 | 现状 |
|---|---|
user != "dde" 魔法字符串 |
已删,改成 user == m_authenticationUser(greeterproxy.cpp:621),语义正确:ddm 侧 Display::login() 本来就拒绝 dde 的登录请求 |
authenticationPending 和 user 两份状态 |
已合并成「m_authenticationUser 非空即 pending」(greeterproxy.h:124),finishAuthentication() 带幂等判断,不会重复发信号 |
| 守卫挪到发包前 / 补一条丢弃日志 | 守卫仍在 socket 校验之前,但你的反驳成立:pending 存续期间 socket 必然有效,本地 PAM 兜底这条分支本来就到不了,无实际差异;日志不加也接受 |
begin/finish 命名收敛 |
已按此实现,setAuthenticationPending(bool) 那种「随手动一下」的用法没了 |
| QML 三处同款绑定 | 收敛为 passwordSlot(UserInput.qml:110)+ loginBtn(:275)两处,passwordField / noPwdLoginBtn 随父项生效 |
| header 的 doc / 对齐 | getter 的 @brief / @return、信号注释、Q_PROPERTY 对齐都补齐了,现在和邻居一致 |
二、改动正确性(已确认)
- 状态机闭合:pending 只在 4 处被清——
disconnected(:495)、error(:502)、LoginFailed(:584)、匹配到本人UserActivateMessage(:622)。这几处覆盖了 ddm 现有的全部回包出口:成功走startUserSession()→activateSession()→activateUser()→UserActivateMessage,失败走loginFailed()→LoginFailed广播。 - 本地 PAM 兜底没被挡住:
beginAuthentication()在两处都在m_socket->isValid()分支之后调用,socket 无效时走localValidation(),不会留下 pending。 - 空密码拦截放在 QML 是对的:
noPasswdLogin来自 AccountsService 的noPassword(user.cpp:33→UserModel),免密账户走noPwdLoginBtn分支不受影响;需要密码的账户空提交只会让 PAM 返回失败并被累加成一次「密码错误」误报,现在直接不提交,符合预期。 - 没有把整个锁屏一起锁死:只禁用了
passwordSlot和loginBtn,关机/重启视图仍然可用——这点很关键,见下一条建议。
三、建议(非阻塞)
- pending 缺少恢复路径,命中后比原 bug 更严重(行内评论附在
greeterproxy.cpp:202)。ddm 当前 master 仍有「收下请求但不回包」的分支,而 treeland 侧只有 socket 报错/断开才清 pending;漏一条回包就是锁屏输入永久禁用,用户只能重启或切 VT。你在 12:48 的回复里把触发条件定位到「treeland 重启 + 旧会话仍存活」,并靠linuxdeepin/ddm#123修掉——但那个 PR 目前仍是 open。建议加一行兜底(lock()/ShowGreeter/SwitchToGreeter分支里finishAuthentication()),或仿m_undecidedTimer加超时。 - 两处清理的判据不一致(行内评论附在
greeterproxy.cpp:584):LoginFailed不比对用户就清,UserActivateMessage比对。行为我不反对(广播语义下无条件清更安全),但建议补一行注释说明是有意为之。 - PR 描述里点明依赖:建议写一句「依赖 DDM 每条
Login/Unlock必须有且只有一个回包」,并指向你提的 ddm PR。否则后人会把客户端这份状态当成可靠的,而不是 ddm 契约的镜像。
四、四维度
| 维度 | 结论 |
|---|---|
| 语法逻辑 | ✓ 状态机闭合,清理幂等,两个入口的守卫一致;无未初始化路径 |
| 代码质量 | ✓ 与文件既有风格(getter doc、命名、分区块)一致,改动面最小,没有多余的抽象 |
| 代码性能 | ✓ 每笔请求一次 QString 拷贝 + 一次属性通知,可忽略 |
| 代码安全 | ✓ 不新增信任边界;空密码不再触发无意义的 PAM 失败,反而少了一条误报路径 |
五、本地验证情况(诚实标注)
qmllint过UserInput.qml:只有本机 dtk 缺dtk6declarative.qmltypes的 import 告警,无语法错误。- 未编译 C++:本机没有 treeland 的完整依赖(waylib / wlroots / DDM
Messages.h),greeterproxy.cpp未单独编译,结论基于 diff + 周边代码静态分析。 - 用 QtTest 实测了「父项
enabled=false后再置true」的焦点行为:activeFocus会回到密码框。也就是说onFailedAttemptsChanged里那句if (loginGroup.activeFocus) passwordField.forceActiveFocus()不会因为等待期间禁用输入而失效(这条我原本怀疑是回归,已验证不是)。 - ddm 侧结论基于
linuxdeepin/ddm当前 master 的src/daemon/Display.cpp:login()的auth->authenticated早退分支仍在(:286),unlock()在找不到活跃会话时回loginFailed(:568)。
| void GreeterProxy::beginAuthentication(const QString &user) | ||
| { | ||
| m_authenticationUser = user; | ||
| Q_EMIT authPendingChanged(); |
There was a problem hiding this comment.
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 回包契约的镜像,契约有洞时客户端只能自保。
|
|
||
| qCDebug(lcTlGreeter) << "Message received from daemon: LoginFailed" << user; | ||
|
|
||
| finishAuthentication(); |
There was a problem hiding this comment.
两处清理的判据不一致:UserActivateMessage 会比较 user == m_authenticationUser(:621),这里不比对就直接清。
考虑到 TreelandDisplayServer::onLoginFailed() 是向所有 greeter socket 广播,而 greeter 侧一次只可能有一笔在途请求,无条件清其实是更安全的选择(反过来会导致用户名形态不一致时卡死),所以行为我不反对。建议补一行注释说明是有意为之(「任何失败回执都视为本轮结束,不比对用户名」),否则下次有人看到 :621 的比对,会以为这里漏了判断。
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: gugullll, wineee The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Log: Fix login failure when a correct password follows a wrong one.
Influence:
fix: 输入错误密码后再输入正确密码登录失败
Log: 输入错误密码后再输入正确密码登录失败
Influence:
PMS: BUG-383137
Summary by Sourcery
Ensure login and unlock accept only one authentication request at a time and reliably allow retries after the request completes.
Bug Fixes:
Enhancements: