Skip to content

Commit 6225167

Browse files
committed
fix: prevent password leakage in ModifyPasswd
Replace usermod -p with chpasswd -e and pass password via stdin instead of command line arguments to avoid exposing passwords in process listings. Signed-off-by: ComixHe <heyuming@deepin.org>
1 parent 5afeb90 commit 6225167

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

accounts1/users/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
userCmdDelete = "userdel"
2020
userCmdModify = "usermod"
2121
userCmdGroup = "gpasswd"
22+
pwdCmdModify = "chpasswd"
2223

2324
cmdGroupDel = "groupdel"
2425
cmdChAge = "chage"

accounts1/users/prop.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,19 @@ func ModifyPasswd(words, username string) error {
180180
return errInvalidParam
181181
}
182182

183-
return doAction(userCmdModify, []string{"-p", words, username})
183+
cmd := exec.Command(pwdCmdModify, "-e")
184+
input := fmt.Sprintf("%s:%s\n", username, words)
185+
cmd.Stdin = bytes.NewBufferString(input)
186+
187+
var stderr bytes.Buffer
188+
cmd.Stderr = &stderr
189+
190+
err := cmd.Run()
191+
if err != nil {
192+
return fmt.Errorf("failed to modify password: %v, %s", err, stderr.String())
193+
}
194+
195+
return nil
184196
}
185197

186198
func ModifyMaxPasswordAge(username string, nDays int) error {

0 commit comments

Comments
 (0)