Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1433,3 +1433,13 @@ func TestReuseConnectionAfterTimeout(t *testing.T) {
_, err = conn.QueryContext(ctx, "select * from rdb$database")
require.NoError(t, err)
}

func TestAuth(t *testing.T) {
conn, err := sql.Open("firebirdsql", GetTestUser()+":wrongpassword@localhost/employee")
err = conn.Ping()
assert.EqualError(t, err, "Your user name and password are not defined. Ask your database administrator to set up a Firebird login.\n")

conn, err = sql.Open("firebirdsql", "notexisting:wrongpassword@localhost/employee")
err = conn.Ping()
assert.EqualError(t, err, "Your user name and password are not defined. Ask your database administrator to set up a Firebird login.\n")
}
17 changes: 11 additions & 6 deletions wireprotocol.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
The MIT License (MIT)

Copyright (c) 2013-2019 Hajime Nakagami
Copyright (c) 2013-2024 Hajime Nakagami

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down Expand Up @@ -501,8 +501,9 @@ func (p *wireProtocol) _parse_connect_response(user string, password string, opt
return
}

if DEBUG_SRP && op != op_cont_auth {
panic("auth error")
if op != op_cont_auth {
err = errors.New("Your user name and password are not defined. Ask your database administrator to set up a Firebird login.\n")
return
}

b, _ = p.recvPackets(4)
Expand All @@ -521,6 +522,10 @@ func (p *wireProtocol) _parse_connect_response(user string, password string, opt
ln = int(bytes_to_bint32(b))
_, _ = p.recvPacketsAlignment(ln) // keys
}
if len(data) == 0 {
err = errors.New("Your user name and password are not defined. Ask your database administrator to set up a Firebird login.\n")
return
}

ln = int(bytes_to_int16(data[:2]))
serverSalt := data[2 : ln+2]
Expand All @@ -533,7 +538,7 @@ func (p *wireProtocol) _parse_connect_response(user string, password string, opt
} else if p.pluginName == "Legacy_Auth" {
authData = bytes.NewBufferString(crypt.Crypt(password, "9z")[2:]).Bytes()
} else {
err = errors.New("_parse_connect_response() Unauthorized")
err = errors.New("Your user name and password are not defined. Ask your database administrator to set up a Firebird login.\n")
return
}
}
Expand Down Expand Up @@ -1250,8 +1255,8 @@ func (p *wireProtocol) opResponse() (int32, []byte, []byte, error) {
}

if bytes_to_bint32(b) != op_response {
if DEBUG_SRP && bytes_to_bint32(b) == op_cont_auth {
panic("auth error")
if bytes_to_bint32(b) == op_cont_auth {
return 0, nil, nil, errors.New("Your user name and password are not defined. Ask your database administrator to set up a Firebird login.\n")
}
return 0, nil, nil, NewErrOpResonse(bytes_to_bint32(b))
}
Expand Down