-
Notifications
You must be signed in to change notification settings - Fork 106
fix: 解决设置快速登录后,切换用户失败的问题 #999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lightdm的state_user文件安全整改后,改为lightdm用户组,修改该文件所属组为可读写权限 但是dde-system-daemon设置快速登录也会修改该文件,通过g_key_file_save_to_file会创建新文件并覆盖旧文件,会将其权限改成root,导致切换用户时修改文件无权限. Log: 解决切换用户失败的问题 PMS: BUG-339935 Influence: quicklogin
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnsures the LightDM greeter state file retains correct ownership and now also enforces group-writable permissions after quick-login updates, preventing permission issues when switching users. Sequence diagram for SetQuickLogin updating lightdm greeter state file permissionssequenceDiagram
participant Daemon as dde_system_daemon
participant DisplayManager as display_manager_SetQuickLogin
participant LightdmUser as lightdm_user
participant OS as os
participant GreeterStateFile as greeter_state_file
Daemon->>DisplayManager: SetQuickLogin(username, enabled)
activate DisplayManager
DisplayManager->>GreeterStateFile: g_key_file_save_to_file
note right of GreeterStateFile: File recreated with owner root and default permissions
DisplayManager->>LightdmUser: Lookup("lightdm")
LightdmUser-->>DisplayManager: Gid
DisplayManager->>OS: Chown(GreeterStateFile, uid 0, gid lightdmGID)
OS-->>DisplayManager: success
DisplayManager->>OS: Chmod(GreeterStateFile, 0664)
OS-->>DisplayManager: success
note right of GreeterStateFile: Ownership root:lightdm and mode 664 (rw-rw-r--)
DisplayManager-->>Daemon: error or nil
deactivate DisplayManager
Flow diagram for SetQuickLogin permission correction logicflowchart TD
A[SetQuickLogin called] --> B[Perform quick login configuration
including g_key_file_save_to_file]
B --> C[Defer permission fix for greeter state file]
subgraph Deferred_cleanup
C --> D[Lookup lightdm user]
D -->|success| E[Parse lightdm Gid to integer]
D -->|failure| I[Return from deferred function]
E -->|success| F[Chown GreeterStateFile to uid 0, gid lightdmGID]
E -->|failure| I
F --> G[Chmod GreeterStateFile to 0664
rw-rw-r--]
G --> H[End deferred cleanup
file owned by root:lightdm and group writable]
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review这段代码的修改主要是在 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进建议
改进后的代码示例const (
GreeterStateFileMode = 0664
)
func SetQuickLogin(username string, enabled bool) error {
// ... 其他代码 ...
defer func() {
// 保持文件所有权为 root:lightdm,权限为 0664(rw-rw-r--)
lightdmUser, err := user.Lookup("lightdm")
if err == nil {
lightdmGID, err := strconv.Atoi(lightdmUser.Gid)
if err == nil {
if err := os.Chown(GreeterStateFile, 0, lightdmGID); err != nil {
log.Printf("Warning: failed to set ownership for %s: %v", GreeterStateFile, err)
}
if err := os.Chmod(GreeterStateFile, GreeterStateFileMode); err != nil {
log.Printf("Warning: failed to set permissions for %s: %v", GreeterStateFile, err)
}
}
}
}()
// ... 其他代码 ...
}总结这段代码的修改是合理的,但可以通过定义常量、记录错误和检查权限合理性来进一步改进。安全性方面,需要确认 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- Consider avoiding magic numbers by defining a named constant or using
os.FileMode(0o664)so the intended permissions are clearer and less error‑prone to change later. - The errors from
os.Chownandos.Chmodare currently ignored; if these operations are important for correct behavior, it may be safer to at least log failures so permission issues can be diagnosed in the field.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider avoiding magic numbers by defining a named constant or using `os.FileMode(0o664)` so the intended permissions are clearer and less error‑prone to change later.
- The errors from `os.Chown` and `os.Chmod` are currently ignored; if these operations are important for correct behavior, it may be safer to at least log failures so permission issues can be diagnosed in the field.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fly602, robertkill 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 |
lightdm的state_user文件安全整改后,改为lightdm用户组,修改该文件所属组为可读写权限
但是dde-system-daemon设置快速登录也会修改该文件,通过g_key_file_save_to_file会创建新文件并覆盖旧文件,会将其权限改成root,导致切换用户时修改文件无权限.
Log: 解决切换用户失败的问题
PMS: BUG-339935
Influence: quicklogin
Summary by Sourcery
Bug Fixes: