diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-05-05 17:29:30 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-05-05 17:31:40 -0700 |
| commit | b33477b0f589c8a25bc8077756155791bb763233 (patch) | |
| tree | 503404c5772e4f5b306fdc583b0faef4db8c6520 /hotline | |
| parent | 1efbb15f239d7da32dadcc121a8b6db5061d297f (diff) | |
Fix bug that clears account password on permission edit
Diffstat (limited to 'hotline')
| -rw-r--r-- | hotline/transaction_handlers.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go index 1ef8ad3..2275319 100644 --- a/hotline/transaction_handlers.go +++ b/hotline/transaction_handlers.go @@ -793,15 +793,24 @@ func HandleUpdateUser(cc *ClientConn, t *Transaction) (res []Transaction, err er if acc, ok := cc.Server.Accounts[login]; ok { cc.logger.Infow("UpdateUser", "login", login) - // account dataFile, so this is an update action + // account exists, so this is an update action if !cc.Authorize(accessModifyUser) { res = append(res, cc.NewErrReply(t, "You are not allowed to modify accounts.")) return res, err } + // This part is a bit tricky. There are three possibilities: + // 1) The transaction is intended to update the password. + // In this case, FieldUserPassword is sent with the new password. + // 2) The transaction is intended to remove the password. + // In this case, FieldUserPassword is not sent. + // 3) The transaction updates the users access bits, but not the password. + // In this case, FieldUserPassword is sent with zero as the only byte.. if getField(FieldUserPassword, &subFields) != nil { newPass := getField(FieldUserPassword, &subFields).Data - acc.Password = hashAndSalt(newPass) + if !bytes.Equal([]byte{0}, newPass) { + acc.Password = hashAndSalt(newPass) + } } else { acc.Password = hashAndSalt([]byte("")) } |