Skip to content

Commit

Permalink
Fix: Refactor auth logic and clean up unused variable
Browse files Browse the repository at this point in the history
Adjusted authentication checks to ensure proper user validation, and moved backend assignment within the `updateAuthentication` function. Also removed an unused variable from `lua.go` to improve code clarity.

Signed-off-by: Christian Roessner <[email protected]>
  • Loading branch information
Christian Roessner committed Nov 18, 2024
1 parent d1ed22b commit 588e775
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
8 changes: 4 additions & 4 deletions server/core/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ func (a *AuthState) verifyPassword(passDBs []*PassDBMap) (*PassDBResult, error)
}

// Enforce authentication
if a.NoAuth {
if a.NoAuth && passDBResult != nil && passDBResult.UserFound {
passDBResult.Authenticated = true
}

Expand Down Expand Up @@ -1069,6 +1069,9 @@ func processPassDBResult(passDBResult *PassDBResult, a *AuthState, passDB *PassD
func updateAuthentication(a *AuthState, passDBResult *PassDBResult, passDB *PassDBMap) {
if passDBResult.UserFound {
a.UserFound = true

a.SourcePassDBBackend = passDBResult.Backend
a.UsedPassDBBackend = passDB.backend
}

if passDBResult.AccountField != nil {
Expand All @@ -1090,9 +1093,6 @@ func updateAuthentication(a *AuthState, passDBResult *PassDBResult, passDB *Pass
if passDBResult.Attributes != nil && len(passDBResult.Attributes) > 0 {
a.Attributes = passDBResult.Attributes
}

a.SourcePassDBBackend = passDBResult.Backend
a.UsedPassDBBackend = passDB.backend
}

// setStatusCodes sets different status codes for various services.
Expand Down
1 change: 0 additions & 1 deletion server/core/lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func luaAccountDB(auth *AuthState) (accounts AccountList, err error) {
}

accountSet := config.NewStringSet()
_ = accountSet

if luaBackendResult.Attributes != nil {
for _, value := range luaBackendResult.Attributes {
Expand Down

0 comments on commit 588e775

Please sign in to comment.