Skip to content

Conversation

@fly602
Copy link
Contributor

@fly602 fly602 commented Jan 15, 2026

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:

  • Fix failure to switch users after enabling quick login by restoring the greeter state file group ownership to LightDM.

lightdm的state_user文件安全整改后,改为lightdm用户组
但是dde-system-daemon设置快速登录也会修改该文件,通过g_key_file_save_to_file会创建新文件并覆盖旧文件,会将其权限改成root,导致切换用户时修改文件无权限.

Log: 解决切换用户失败的问题
PMS: BUG-339935
Influence: quicklogin
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 15, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures the LightDM greeter state file created/updated during quick login configuration keeps the correct root:lightdm ownership to avoid permission issues when switching users.

Sequence diagram for SetQuickLogin updating LightDM greeter state file ownership

sequenceDiagram
    participant Caller
    participant DisplayManager as accounts1_display_manager
    participant OS as os
    participant UserPkg as user
    participant Strconv as strconv

    Caller->>DisplayManager: SetQuickLogin(username, enabled)
    alt state file directory does not exist
        DisplayManager->>OS: MkdirAll(stateFileDir)
        OS-->>DisplayManager: error or nil
        alt error
            DisplayManager-->>Caller: error
        else success
            note over DisplayManager: continue to update greeter state file
        end
    end

    DisplayManager->>DisplayManager: setIniStringList(GreeterStateFile, group, key, usernames)
    DisplayManager-->>Caller: error or nil

    opt defer keep ownership root:lightdm
        DisplayManager->>UserPkg: Lookup(lightdm)
        UserPkg-->>DisplayManager: lightdmUser or error
        alt lookup success
            DisplayManager->>Strconv: Atoi(lightdmUser.Gid)
            Strconv-->>DisplayManager: lightdmGID or error
            alt conversion success
                DisplayManager->>OS: Chown(GreeterStateFile, 0, lightdmGID)
                OS-->>DisplayManager: nil or error (ignored)
            else conversion error
                note over DisplayManager: skip Chown
            end
        else lookup error
            note over DisplayManager: skip Chown
        end
    end
Loading

Flow diagram for SetQuickLogin LightDM greeter state file ownership handling

flowchart TD
    A[Start SetQuickLogin] --> B{State file dir exists?}
    B -->|No| C[Create directory with MkdirAll]
    C --> D{MkdirAll error?}
    D -->|Yes| Z[Return error]
    D -->|No| E[Proceed to update greeter state file]
    B -->|Yes| E

    E --> F[Call setIniStringList to write GreeterStateFile]
    F --> G[Deferred: Lookup lightdm user]
    G --> H{Lookup success?}
    H -->|No| I[Skip Chown]
    H -->|Yes| J[Convert lightdmUser.Gid with Atoi]
    J --> K{Atoi success?}
    K -->|No| I
    K -->|Yes| L[Call Chown on GreeterStateFile with uid 0 and gid lightdmGID]
    L --> M[End defer]
    I --> M
    M --> N[Return from SetQuickLogin]
Loading

File-Level Changes

Change Details Files
Ensure greeter state file ownership is corrected to root:lightdm after modifying quick login settings to prevent permission issues.
  • Wrap the quick login file write path with a deferred function that runs after directory creation and before returning
  • In the deferred function, look up the 'lightdm' user and parse its group ID
  • Use os.Chown to set the greeter state file owner to UID 0 and GID of the lightdm group, ignoring errors if lookup or conversion fails
accounts1/users/display_manager.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a 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:

  • The defer that restores root:lightdm ownership is defined only in the branch that creates the directory/file, so existing files that are overwritten won’t get their group fixed; consider moving the defer (or a non-deferred call) so it always runs when GreeterStateFile is modified.
  • User lookup for lightdm is done on every call and only for the deferred chown; you could move the lookup (and GID parsing) outside the defer and reuse the result to avoid repeated work and make error handling clearer.
  • Currently, failures to look up lightdm or to change ownership are silently ignored; consider logging these specific failures so misconfiguration of the lightdm user or file permissions can be diagnosed in the field.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `defer` that restores `root:lightdm` ownership is defined only in the branch that creates the directory/file, so existing files that are overwritten won’t get their group fixed; consider moving the `defer` (or a non-deferred call) so it always runs when `GreeterStateFile` is modified.
- User lookup for `lightdm` is done on every call and only for the deferred chown; you could move the lookup (and GID parsing) outside the `defer` and reuse the result to avoid repeated work and make error handling clearer.
- Currently, failures to look up `lightdm` or to change ownership are silently ignored; consider logging these specific failures so misconfiguration of the `lightdm` user or file permissions can be diagnosed in the field.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, yixinshark

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@fly602 fly602 merged commit b6ba8b0 into linuxdeepin:master Jan 15, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants