Fix: Can not open deepin-devicemanager.#616
Fix: Can not open deepin-devicemanager.#616deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
Conversation
--Polkit daemon (polkitd) runs on the system bus and validates DBus clients based on system bus connection names. Passing a session bus connection name via `SystemBusNameSubject(QDBusConnection::sessionBus().baseService())` was invalid causing Polkit to fail the credential lookups, which resulted in `Authority::Unknown` and silent authorization failures. --This commit fixes the issue by passing the correct system bus connection name (`QDBusConnection::systemBus().baseService()`) to the Polkit authorization subject, ensuring the credentials can be correctly verified and the policy authentication prompts will work as expected. Log: fix issue Bug: https://pms.uniontech.com/bug-view-352627.html
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR fixes Polkit authorization failures in deepin-devicemanager by using the correct system D-Bus connection name when constructing the SystemBusNameSubject for authorization checks, both at startup and before driver installation. Sequence diagram for Polkit authorization at application startupsequenceDiagram
actor User
participant DeepinDeviceManager as DeepinDeviceManager
participant QDBusSystemBus as QDBusSystemBus
participant PolkitAuthority as PolkitAuthority
participant polkitd as polkitd
User->>DeepinDeviceManager: startApplication()
DeepinDeviceManager->>QDBusSystemBus: baseService()
QDBusSystemBus-->>DeepinDeviceManager: systemBusName
DeepinDeviceManager->>PolkitAuthority: checkAuthorizationSync(checkAuthentication, SystemBusNameSubject(systemBusName), AllowUserInteraction)
PolkitAuthority->>polkitd: CheckAuthorization(SystemBusNameSubject(systemBusName))
polkitd-->>PolkitAuthority: Result Yes or No
PolkitAuthority-->>DeepinDeviceManager: Result Yes or No
alt Authorization Yes
DeepinDeviceManager-->>User: showMainWindow()
else Authorization Not Yes
DeepinDeviceManager-->>User: exitApplication()
end
Sequence diagram for Polkit authorization before driver installationsequenceDiagram
actor User
participant DeepinDeviceManager as DeepinDeviceManager
participant QDBusSystemBus as QDBusSystemBus
participant PolkitAuthority as PolkitAuthority
participant polkitd as polkitd
User->>DeepinDeviceManager: installDriverLogical()
DeepinDeviceManager->>DeepinDeviceManager: evaluateCurrentIndex()
alt DriverInstallRequiresPrivilege
DeepinDeviceManager->>QDBusSystemBus: baseService()
QDBusSystemBus-->>DeepinDeviceManager: systemBusName
DeepinDeviceManager->>PolkitAuthority: checkAuthorizationSync(checkAuthentication, SystemBusNameSubject(systemBusName), AllowUserInteraction)
PolkitAuthority->>polkitd: CheckAuthorization(SystemBusNameSubject(systemBusName))
polkitd-->>PolkitAuthority: Result Yes or No
PolkitAuthority-->>DeepinDeviceManager: Result Yes or No
alt Authorization Yes
DeepinDeviceManager->>DeepinDeviceManager: performDriverInstallation()
DeepinDeviceManager-->>User: showInstallationResult()
else Authorization Not Yes
DeepinDeviceManager-->>User: cancelInstallation()
end
else OtherIndexPath
DeepinDeviceManager->>DeepinDeviceManager: executeOtherLogic()
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The authorization subject construction now appears in both main.cpp and PageDriverControl.cpp; consider refactoring this into a shared helper to avoid duplication and ensure future changes to the bus/subject stay consistent.
- When authorization fails (result != Authority::Yes), the code returns silently; consider adding minimal logging or user feedback so failures are diagnosable instead of failing without visible reason.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The authorization subject construction now appears in both main.cpp and PageDriverControl.cpp; consider refactoring this into a shared helper to avoid duplication and ensure future changes to the bus/subject stay consistent.
- When authorization fails (result != Authority::Yes), the code returns silently; consider adding minimal logging or user feedback so failures are diagnosable instead of failing without visible reason.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
deepin pr auto review这段代码的修改主要涉及将 D-Bus 连接从 1. 语法逻辑审查修改内容: 逻辑分析:
判断:
结论:根据代码上下文(安装驱动、提权),修改为 2. 代码质量审查问题:
改进建议:
改进后的代码示例: // 在头文件中定义常量
constexpr const char* AUTH_ACTION = "com.deepin.deepin-devicemanager.checkAuthentication";
// 封装权限检查函数
bool checkSystemAuthorization() {
Authority::Result result = Authority::instance()->checkAuthorizationSync(
AUTH_ACTION,
SystemBusNameSubject(QDBusConnection::systemBus().baseService()),
Authority::AllowUserInteraction
);
return result == Authority::Yes;
}
// 使用示例
void PageDriverControl::installDriverLogical() {
if (!checkSystemAuthorization()) {
return;
}
// 其他逻辑...
}3. 代码性能审查问题:
改进建议:
改进后的代码示例(异步版本): void PageDriverControl::installDriverLogical() {
Authority::instance()->checkAuthorization(
AUTH_ACTION,
SystemBusNameSubject(QDBusConnection::systemBus().baseService()),
Authority::AllowUserInteraction,
[](Authority::Result result) {
if (result == Authority::Yes) {
// 权限验证通过,执行后续逻辑
} else {
// 权限验证失败
}
}
);
}4. 代码安全审查问题:
改进建议:
改进后的代码示例: void PageDriverControl::installDriverLogical() {
if (!checkSystemAuthorization()) {
QMessageBox::warning(this, tr("Error"), tr("Permission denied. Please try again with administrator privileges."));
return;
}
// 其他逻辑...
}总结
以上改进建议可提升代码的可维护性、性能和安全性。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GongHeng2017, KT-lcz, max-lvs 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 |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
114ccd2
into
linuxdeepin:develop/eagle
--Polkit daemon (polkitd) runs on the system bus and validates DBus clients based on system bus connection names. Passing a session bus connection name via
SystemBusNameSubject(QDBusConnection::sessionBus().baseService())was invalid causing Polkit to fail the credential lookups, which resulted inAuthority::Unknownand silent authorization failures.--This commit fixes the issue by passing the correct system bus connection name (
QDBusConnection::systemBus().baseService()) to the Polkit authorization subject, ensuring the credentials can be correctly verified and the policy authentication prompts will work as expected.Log: fix issue
Bug: https://pms.uniontech.com/bug-view-352627.html
Summary by Sourcery
Bug Fixes: