Protect htpasswd user list from race condition

This commit is contained in:
Damien Degois
2022-11-03 15:38:41 +01:00
parent aafa966550
commit 86011e8ac7
3 changed files with 14 additions and 1 deletions
+11
View File
@@ -139,6 +139,17 @@ func passShaOrBcrypt(h *htpasswdMap, user, password string) (invalidEntries []st
return invalidEntries
}
// GetUsers return a "thread safe" copy of the internal user list
func (h *htpasswdMap) GetUsers() map[string]interface{} {
newUserList := make(map[string]interface{})
h.rwm.Lock()
for key, value := range h.users {
newUserList[key] = value
}
h.rwm.Unlock()
return newUserList
}
// Validate checks a users password against the htpasswd entries
func (h *htpasswdMap) Validate(user string, password string) bool {
realPassword, exists := h.users[user]