Skip to content

feat(accounts1): support autologin configuration for DDM - #1224

Open
glyvut wants to merge 1 commit into
linuxdeepin:masterfrom
glyvut:master
Open

feat(accounts1): support autologin configuration for DDM#1224
glyvut wants to merge 1 commit into
linuxdeepin:masterfrom
glyvut:master

Conversation

@glyvut

@glyvut glyvut commented Aug 26, 2026

Copy link
Copy Markdown

Add DDM support to the accounts module, so the autologin setting is persisted to /etc/ddm.conf and the default session is forced to treeland when DDM is active.

为账户模块增加DDM适配,自动登录配置写入 /etc/ddm.conf,并
在DDM下强制默认会话为treeland。

Log: 适配DDM自动登录配置
PMS: BUG-294419
Influence: DDM环境下自动登录配置生效,默认会话固定为treeland。

Summary by Sourcery

Support DDM account integration by persisting autologin settings and enforcing treeland as the default session.

New Features:

  • Add account-module support for DDM autologin users and sessions through /etc/ddm.conf.

Bug Fixes:

  • Ensure DDM environments use treeland as the default session.

Enhancements:

  • Detect DDM from the configured display manager or system service and expose its configuration path.

Tests:

  • Add coverage and fixtures for DDM autologin configuration, session handling, and service detection.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: glyvut

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

@sourcery-ai

sourcery-ai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Reviewer's Guide

The accounts module now detects DDM, reads and writes autologin settings in /etc/ddm.conf, and forces the default user session to Treeland while DDM is active; accompanying fixtures and tests cover DDM configuration parsing and service detection.

Sequence diagram for DDM autologin configuration

sequenceDiagram
    participant Accounts as Accounts module
    participant DM as Display manager detection
    participant Config as /etc/ddm.conf

    Accounts->>DM: GetDefaultDM()
    DM-->>Accounts: ddm
    Accounts->>Config: GetAutoLoginUser()
    Config-->>Accounts: Autologin.User
    Accounts->>Config: SetAutoLoginUser(username, session)
    Config-->>Accounts: updated Autologin.User and Session
Loading

Flow diagram for DDM default session selection

flowchart TD
    Start[Load user configuration] --> Detect["GetDefaultDM()"]
    Detect --> IsDDM{Display manager is ddm?}
    IsDDM -->|Yes| Force[Set XSession to treeland]
    IsDDM -->|No| Existing{XSession is empty?}
    Existing -->|Yes| Default["GetDefaultXSession()"]
    Existing -->|No| Keep[Keep configured session]
    Force --> Save[Persist user configuration]
    Default --> Save
    Keep --> End[Finish]
    Save --> End
Loading

File-Level Changes

Change Details Files
Add DDM as a supported display manager for autologin and session configuration.
  • Define DDM configuration path and INI keys.
  • Write and read the autologin user from the [Autologin] section in /etc/ddm.conf.
  • Persist the session key when provided.
  • Return /etc/ddm.conf from display-manager configuration lookup.
accounts1/users/display_manager.go
Force Treeland as the account session whenever DDM is active.
  • Detect DDM through the default display-manager file or system service.
  • Override non-Treeland sessions with treeland and persist the change.
  • Use treeland as DDM’s default session.
accounts1/user.go
accounts1/users/display_manager.go
Cover DDM parsing and display-manager detection with test fixtures and assertions.
  • Add DDM autologin configurations for enabled and disabled users.
  • Add DDM service fixtures and verify manager detection.
  • Verify DDM user and session parsing.
accounts1/users/testdata/autologin/ddm.conf
accounts1/users/testdata/autologin/ddm.service
accounts1/users/testdata/autologin/ddm_autologin.conf
accounts1/users/testdata/autologin/ddmdir/ddm.service
accounts1/users/users_test.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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="accounts1/users/display_manager.go" line_range="123-130" />
<code_context>
 		}
 		return setIniKeys(sddmConfig, kfGroupSDDMAutologin,
 			keys, values)
+	case "ddm":
+		keys := []string{kfKeyDDMUser}
+		values := []string{username}
+		if session != "" {
+			keys = append(keys, kfKeyDDMSession)
+			values = append(values, session)
+		}
+		return setIniKeys(ddmConfig, kfGroupDDMAutologin,
+			keys, values)
 	case "lxdm":
</code_context>
<issue_to_address>
**issue (bug_risk):** SetAutoLoginUser returns before the new DDM branch whenever the configured autologin username already equals `username`, so changing only the session leaves the old `Session` value in `/etc/ddm.conf`. The DDM session setting is therefore not persisted for an already-configured user.

**Triggers:** When autologin remains enabled for the same user but the user changes the session.

**Suggested fix:** Compare the existing session as well as the username before returning, or move the unchanged-username fast path after applying session changes.
</issue_to_address>

### Comment 2
<location path="accounts1/users/display_manager.go" line_range="126-130" />
<code_context>
+	case "ddm":
+		keys := []string{kfKeyDDMUser}
+		values := []string{username}
+		if session != "" {
+			keys = append(keys, kfKeyDDMSession)
+			values = append(values, session)
+		}
+		return setIniKeys(ddmConfig, kfGroupDDMAutologin,
+			keys, values)
 	case "lxdm":
</code_context>
<issue_to_address>
**issue (bug_risk):** The DDM configuration fixture uses `Session=treeland.desktop`, but the account's forced session value is `treeland` and SetAutoLoginUser writes the supplied value unchanged. Enabling DDM autologin therefore writes `Session=treeland`, which does not match the DDM session identifier used by the configuration and prevents the requested Treeland session from being selected.

**Triggers:** When DDM autologin is enabled through the accounts module.

**Suggested fix:** Use the DDM desktop-entry identifier (`treeland.desktop`) when writing the DDM `Session` key, while retaining the account module's internal `XSession` representation if needed.
</issue_to_address>

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.

Comment on lines +123 to +130
case "ddm":
keys := []string{kfKeyDDMUser}
values := []string{username}
if session != "" {
keys = append(keys, kfKeyDDMSession)
values = append(values, session)
}
return setIniKeys(ddmConfig, kfGroupDDMAutologin,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): SetAutoLoginUser returns before the new DDM branch whenever the configured autologin username already equals username, so changing only the session leaves the old Session value in /etc/ddm.conf. The DDM session setting is therefore not persisted for an already-configured user.

Triggers: When autologin remains enabled for the same user but the user changes the session.

Suggested fix: Compare the existing session as well as the username before returning, or move the unchanged-username fast path after applying session changes.

Comment thread accounts1/users/display_manager.go
Add DDM support to the accounts module, so the autologin
setting is persisted to /etc/ddm.conf and the default session
is forced to treeland when DDM is active.

为账户模块增加DDM适配,自动登录配置写入 /etc/ddm.conf,并
在DDM下强制默认会话为treeland。

Log: 适配DDM自动登录配置
PMS: BUG-294419
Influence: DDM环境下自动登录配置生效,默认会话固定为treeland。
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:93分 (大于70分通过)

■ 【总体评价】

代码审查通过
代码实现了 DDM(Deepin Display Manager)显示管理器的自动登录配置支持,遵循了现有代码模式,测试覆盖完善,未发现安全漏洞。存在少量代码质量改进建议。

■ 【详细分析】

  • 1.语法逻辑(22/25分)✓通过 — 语法正确,逻辑清晰

文件 accounts1/user.go,函数 loadUserConfigInfo(第783行):新增 DDM 显示管理器判断逻辑,当默认 DM 为 "ddm" 时强制将 XSession 设置为 "treeland"。代码逻辑正确,遵循了现有代码的 switch-case 模式。
文件 accounts1/users/display_manager.go,函数 GetDefaultDM(第465-475行):新增 GetDefaultDM 函数,封装了 getDefaultDM 和 getDMFromSystemService 的回退逻辑,先读取 /etc/X11/default-display-manager 文件,失败后查询 systemd 的 display-manager.service。
文件 accounts1/users/display_manager.go,函数 SetAutoLoginUser(第123-131行):新增 "ddm" case,使用 INI 格式写入 /etc/ddm.conf 的 [Autologin] 组,支持 User 和 Session 键。
文件 accounts1/users/display_manager.go,函数 GetAutoLoginUser(第175-177行):新增 "ddm" case,从 /etc/ddm.conf 读取自动登录用户名。
文件 accounts1/users/display_manager.go,函数 GetDefaultXSession(第341-342行):新增 "ddm" case,返回固定值 "treeland"。
文件 accounts1/users/display_manager.go,函数 GetDMConfig(第368-369行):新增 "ddm" case,返回 ddmConfig 常量。
文件 accounts1/users/display_manager.go,函数 getDMFromSystemService(第517-518行):新增 "ddm.service" 识别,返回 "ddm"。

潜在问题:

  1. user.go 第783行:if dm, _ := users.GetDefaultDM(); dm == "ddm" 中 GetDefaultDM() 返回的错误被静默忽略。当 GetDefaultDM() 失败时,dm 为空字符串,代码回退到 else if 分支。虽然回退行为合理,但静默忽略错误不利于系统问题排查。——非常重要
  2. user.go 第783-792行:DDM 和非 DDM 的 XSession 处理逻辑不对称。DDM 模式下强制覆盖用户已设置的 XSession 为 "treeland"(即使用户已设置其他值),而非 DDM 模式仅在 XSession 为空时设置默认值。确认这是预期行为。——非常重要

建议:

  • 在 user.go loadUserConfigInfo 函数中,考虑记录 GetDefaultDM() 的错误信息,便于系统问题排查
  • 确认 DDM 模式下强制覆盖 XSession 的行为是否符合产品需求
  • 2.代码质量(22/25分)✓通过 — 代码结构清晰,注释完整

测试覆盖:新增了完整的测试用例(users_test.go),覆盖了 DDM 自动登录用户读取(有用户/无用户两种场景)、Session 读取、DM 服务识别等功能。测试数据文件结构清晰。
文档更新:在 display_manager.org 中补充了 DDM 配置格式文档,包含 Config 路径、Autologin 和 XSession 键说明。
代码模式:DDM 的各个 case 分支严格遵循了 SDDM 的实现模式,代码风格一致。
新增函数:GetDefaultDM() 函数有注释说明,封装了重复的错误处理逻辑。

潜在问题:

  1. accounts1/user.go 第785行 和 accounts1/users/display_manager.go 第342行:字符串 "treeland" 在两处硬编码。如果 DDM 默认会话变更,需要同步修改多处,存在维护风险。——非常重要
  2. accounts1/users/display_manager.go 第465行:GetDefaultDM 函数注释 "GetDefaultDM return the current display manager name" 过于简略,未说明回退机制(先读取配置文件,失败后查询 systemd 服务)。——非常重要

建议:

  • 将 "treeland" 提取为常量(如 const ddmDefaultSession = "treeland"),避免硬编码字符串散布在多处
  • 补充 GetDefaultDM 函数注释,说明回退机制
  • 考虑在现有函数(SetAutoLoginUser、GetAutoLoginUser 等)中复用 GetDefaultDM(),减少重复的错误处理代码
  • 3.代码性能(19/20分)✓通过 — 性能良好,资源使用合理

文件 accounts1/user.go,函数 loadUserConfigInfo(第783行):GetDefaultDM() 在 loadUserConfigInfo 中被调用,涉及文件读取(/etc/X11/default-display-manager)和潜在的 systemd 服务查询(符号链接读取)。该函数在用户配置加载时调用,不在高频热路径上。
新增的 case 分支:SetAutoLoginUser、GetAutoLoginUser 等函数中的 "ddm" case 使用 INI 文件读写,与现有 DM 实现方式一致,无不必要的性能开销。

潜在问题:

  1. accounts1/user.go 第783行:loadUserConfigInfo 中的 GetDefaultDM() 调用增加了文件 I/O 操作。虽然该函数不在热路径上,但如果 loadUserConfigInfo 被频繁调用,可考虑缓存 DM 查询结果。——非常重要

建议:

  • 如果 loadUserConfigInfo 被频繁调用,可考虑缓存 DM 查询结果
  • 4.代码安全(30/30分)✓通过 — 存在 0 个安全漏洞

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
安全分析

  • 所有配置文件路径均为硬编码常量(ddmConfig = "/etc/ddm.conf"),不存在路径遍历风险
  • 用户名和会话值通过 setIniKeys 函数写入 INI 配置文件,不存在命令注入或 SQL 注入风险
  • 无用户输入直接用于文件路径构造
  • 无敏感信息泄露(测试数据中使用的是示例用户名 "wen")
  • 无不安全的密码算法使用
  • 无硬编码密钥或凭证
  • getDMFromSystemService 通过 os.Readlink 读取符号链接,仅返回匹配的服务名称,无安全风险

未发现安全漏洞

建议:

  • 所有配置文件路径均为硬编码常量,不存在路径遍历风险
  • 无用户输入直接用于文件操作,不存在注入风险
  • 无敏感信息泄露
  • 5.项目规范(不计入评分,仅作为维护参考)

项目规范检查(21项):

  • UOS 大小写(文档中全大写,代码中按代码规范):✓ 符合
  • deepin 大小写(文档中全小写包括首字母,代码中按代码规范):✓ 符合
  • DDE 使用(专有名词,禁止拆开使用如 Deepin Desktop Environment):✓ 符合
  • 文件名中的 dde(文件名中 dde 全小写):✓ 符合
  • 项目名称(全小写、-连接、不超过2个-):✓ 符合
  • 文件命名(全小写、-连接,不使用_):✓ 符合
  • DBus 命名(倒置域名格式,如 org.deepin.DDE1.Accounts):✓ 符合
  • 版权信息(deepin 必须小写):✓ 符合
  • Git 分支命名(上游upstream/*、主干master、研发develop/*project/*、发布release/*):✓ 符合
  • Debian Changelog 版本规范(版本号格式是否符合统信软件版本规范):✓ 符合
  • systemd 服务检查(后台程序是否通过 systemd service 启动):✓ 符合
  • systemd 权限限制(是否包含 User=、ProtectSystem=、NoNewPrivileges= 等最小权限配置):✓ 符合
  • 新增自启动程序评审(未经过系统部/架构部评审的自启动程序):✓ 符合
  • prerm/preinst/postrm/postinst 机制评审(是否使用该机制实现功能,需提供评审记录):✓ 符合
  • 交付版本 debug 信息(禁止带有 debug 信息):✓ 符合
  • 不安全密码算法(是否使用 md5/sha1/des 等不安全算法,需安全部评审):✓ 符合
  • 隐私与敏感信息(代码日志中是否包含用户名、密钥、口令等敏感信息):✓ 符合
  • IPC 敏感数据保护(进程间通信敏感数据是否使用 memfd/hash/密钥协商协议保护):✓ 符合
  • FHS 文件系统分层规范(是否写入动态数据到 /usr、/opt 等静态目录):✓ 符合
  • DBus 安全编码要求(systemd conf 变动、allow own 字段是否仅 root 或非普通用户):✓ 符合
  • 多语言翻译与本地化(源码国际化、翻译文件同步更新、术语一致性):✓ 符合
    潜在问题:无
    建议:无

■ 【改进建议代码示例】

建议1:记录 GetDefaultDM 错误日志(accounts1/user.go)

// 修改前:
if dm, _ := users.GetDefaultDM(); dm == "ddm" {
    if u.XSession != "treeland" {
        u.XSession = "treeland"
        isSave = true
    }
} else if u.XSession == "" {

// 修改后:
dm, err := users.GetDefaultDM()
if err != nil {
    logger.Warning("failed to get default display manager:", err)
}
if dm == "ddm" {
    if u.XSession != ddmDefaultSession {
        u.XSession = ddmDefaultSession
        isSave = true
    }
} else if u.XSession == "" {

建议2:提取 treeland 为常量(accounts1/users/display_manager.go)

// 在 const 块中添加:
const ddmDefaultSession = "treeland"

// GetDefaultXSession 中使用常量:
case "ddm":
    return ddmDefaultSession, nil

// user.go 中使用常量:
u.XSession = ddmDefaultSession

建议3:补充 GetDefaultDM 函数注释(accounts1/users/display_manager.go)

// GetDefaultDM return the current display manager name.
// It first reads /etc/X11/default-display-manager file,
// and falls back to checking systemd display-manager.service symlink on failure.
func GetDefaultDM() (string, error) {

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.

2 participants