downstream: fix panic due to nil user in setUser

Fixes: 4ca8dfa37d ("downstream: fix nil pointer deref in downstreamConn.setUser")
This commit is contained in:
Simon Ser 2023-03-21 18:02:59 +01:00
parent e510cef208
commit 9579998e63

View File

@ -1251,13 +1251,13 @@ func (dc *downstreamConn) setUser(username, clientName, networkName string) erro
dc.user = dc.srv.getUser(username) dc.user = dc.srv.getUser(username)
if dc.user == nil && dc.srv.Config().EnableUsersOnAuth { if dc.user == nil && dc.srv.Config().EnableUsersOnAuth {
ctx := context.TODO() ctx := context.TODO()
if _, err := dc.user.srv.db.GetUser(ctx, username); err != nil { if _, err := dc.srv.db.GetUser(ctx, username); err != nil {
// Can't find the user in the DB -- try to create it // Can't find the user in the DB -- try to create it
record := database.User{ record := database.User{
Username: username, Username: username,
Enabled: true, Enabled: true,
} }
dc.user, err = dc.user.srv.createUser(ctx, &record) dc.user, err = dc.srv.createUser(ctx, &record)
if err != nil { if err != nil {
return fmt.Errorf("failed to automatically create user %q after successful authentication: %v", username, err) return fmt.Errorf("failed to automatically create user %q after successful authentication: %v", username, err)
} }