fix: revert SetPassword disable, restore with admin auth#1125
Merged
Conversation
1. Restore SetPassword DBus method implementation, as it is used by dde-control-center when creating new users 2. Require polkitActionUserAdministration authentication to prevent unauthorized password changes 3. Keep the chpasswd injection guard in ModifyPasswd Log: SetPassword DBus method is restored for new user creation Influence: 1. creating a new user via control center should set password successfully 2. non-admin user calling SetPassword should still be denied PMS: TASK-390039 fix: 恢复 SetPassword 接口,保留管理员鉴权 1. 恢复 SetPassword DBus 方法实现,因为控制中心创建新用户 时需要调用该接口 2. 要求 polkitActionUserAdministration 鉴权,防止未授权 修改密码 3. 保留 ModifyPasswd 中的 chpasswd 注入防护 Log: SetPassword DBus 方法已恢复,用于新用户创建场景 Influence: 1. 通过控制中心创建新用户时应能成功设置密码 2. 非管理员用户调用 SetPassword 仍应被拒绝
deepin pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff代码。这段代码实现了一个 整体来看,代码逻辑基本完整,但在语法逻辑、代码质量、代码性能和代码安全方面存在一些需要改进的隐患。以下是详细的审查意见和改进建议: 1. 语法与逻辑
2. 代码性能
3. 代码安全
4. 代码质量
改进后的代码建议const (
maxShadowRetries = 10
shadowRetryInterval = 200 * time.Millisecond
)
func (u *User) SetPassword(sender dbus.Sender, password string) *dbus.Error {
logger.Debug("[SetPassword] start ...")
// 安全建议:禁止设置空密码,而非静默忽略
if password == "" {
return dbusutil.ToError(fmt.Errorf("setting an empty password is not allowed"))
}
err := u.checkAuth(sender, false, polkitActionUserAdministration)
if err != nil {
logger.Debug("[SetPassword] access denied:", err)
return dbusutil.ToError(err)
}
// 等待影子文件就绪,使用更短的重试间隔避免长时间阻塞
for i := 0; i < maxShadowRetries; i++ {
_, err := users.GetShadowInfo(u.UserName)
if err == nil {
break
}
if i == maxShadowRetries-1 {
// 明确返回超时/未就绪错误,避免返回可能为nil的err
logger.Warning("[SetPassword] shadow info not ready after retries:", err)
return dbusutil.ToError(fmt.Errorf("shadow info for user %s is not ready: %v", u.UserName, err))
}
time.Sleep(shadowRetryInterval)
}
// 注意:请确保 ModifyPasswd 底层实现不会将密码暴露在命令行参数中(如通过管道传递给 chpasswd)
if err := users.ModifyPasswd(password, u.UserName); err != nil {
logger.Warning("[SetPassword] modify password failed:", err)
return dbusutil.ToError(err)
}
// 密码修改成功后,清理 keyring,即使失败也不影响主流程
err = removeLoginKeyring(u)
if err != nil {
logger.Warningf("[SetPassword] remove login keyring failed: %v", err)
}
u.PropsMu.Lock()
defer u.PropsMu.Unlock()
if u.Locked {
if err := users.LockedUser(false, u.UserName); err != nil {
logger.Warning("[SetPassword] unlock user failed:", err)
return dbusutil.ToError(err)
}
u.Locked = false
_ = u.emitPropChangedLocked(false)
}
logger.Debug("[SetPassword] success for user:", u.UserName)
return nil
}主要改进点总结:
|
| return nil | ||
| } | ||
|
|
||
| err := u.checkAuth(sender, false, polkitActionUserAdministration) |
fly602
approved these changes
May 25, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: caixr23, fly602 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Log: SetPassword DBus method is restored for new user creation
Influence:
PMS: TASK-390039
fix: 恢复 SetPassword 接口,保留管理员鉴权
Log: SetPassword DBus 方法已恢复,用于新用户创建场景
Influence: